| | | 1 | | using NexusLabs.Needlr.AgentFramework.Diagnostics; |
| | | 2 | | using NexusLabs.Needlr.AgentFramework.Workspace; |
| | | 3 | | |
| | | 4 | | namespace NexusLabs.Needlr.AgentFramework.Testing; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Defines a self-contained agent test scenario with seed → execute → verify lifecycle. |
| | | 8 | | /// Scenarios are discovered automatically when registered via DI. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// <para> |
| | | 12 | | /// Each scenario declares its own system prompt, user prompt, and workspace seed data. |
| | | 13 | | /// The <see cref="AgentScenarioRunner"/> handles workspace creation, context scoping, |
| | | 14 | | /// diagnostics capture, and invokes <see cref="Verify"/> after execution. |
| | | 15 | | /// </para> |
| | | 16 | | /// <para> |
| | | 17 | | /// For multi-agent pipeline scenarios, consumers can implement custom runner logic |
| | | 18 | | /// that coordinates multiple agents using the scenario's prompts and workspace. |
| | | 19 | | /// </para> |
| | | 20 | | /// </remarks> |
| | | 21 | | public interface IAgentScenario |
| | | 22 | | { |
| | | 23 | | /// <summary>Gets the scenario name (used for selection and reporting).</summary> |
| | | 24 | | string Name { get; } |
| | | 25 | | |
| | | 26 | | /// <summary>Gets a human-readable description of what the scenario tests.</summary> |
| | | 27 | | string Description { get; } |
| | | 28 | | |
| | | 29 | | /// <summary>Gets the system prompt (agent instructions) for this scenario.</summary> |
| | | 30 | | string SystemPrompt { get; } |
| | | 31 | | |
| | | 32 | | /// <summary>Gets the user message that starts the agent run.</summary> |
| | | 33 | | string UserPrompt { get; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Populates the workspace with files needed before the agent runs. |
| | | 37 | | /// Called by the runner before execution begins. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="workspace">The workspace to seed with test data.</param> |
| | | 40 | | void SeedWorkspace(IWorkspace workspace); |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Verifies the scenario's expected outcomes after the agent run completes. |
| | | 44 | | /// Throw an exception (e.g., <see cref="ScenarioVerificationException"/>) to indicate failure. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="workspace">The workspace after agent execution (contains any files the agent wrote).</param> |
| | | 47 | | /// <param name="diagnostics"> |
| | | 48 | | /// Diagnostics from the run, or <see langword="null"/> if diagnostics were not captured. |
| | | 49 | | /// </param> |
| | | 50 | | void Verify(IWorkspace workspace, IAgentRunDiagnostics? diagnostics); |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Thrown when a scenario's <see cref="IAgentScenario.Verify"/> method detects a failure. |
| | | 55 | | /// </summary> |
| | | 56 | | public sealed class ScenarioVerificationException : Exception |
| | | 57 | | { |
| | | 58 | | /// <summary>Gets the scenario that failed.</summary> |
| | 1 | 59 | | public string ScenarioName { get; } |
| | | 60 | | |
| | | 61 | | /// <param name="scenarioName">Name of the scenario.</param> |
| | | 62 | | /// <param name="message">Description of the verification failure.</param> |
| | | 63 | | public ScenarioVerificationException(string scenarioName, string message) |
| | 4 | 64 | | : base($"Scenario '{scenarioName}' failed: {message}") |
| | | 65 | | { |
| | 4 | 66 | | ScenarioName = scenarioName; |
| | 4 | 67 | | } |
| | | 68 | | } |