| | | 1 | | using NexusLabs.Needlr.AgentFramework.Workflows.Sequential; |
| | | 2 | | using NexusLabs.Needlr.AgentFramework.Workspace; |
| | | 3 | | |
| | | 4 | | namespace NexusLabs.Needlr.AgentFramework.Testing; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Runs <see cref="IPipelineScenario"/> instances using the |
| | | 8 | | /// <see cref="SequentialPipelineRunner"/> and reports results. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// <para> |
| | | 12 | | /// The runner handles the full seed → execute → verify lifecycle: |
| | | 13 | | /// </para> |
| | | 14 | | /// <list type="number"> |
| | | 15 | | /// <item>Creates an <see cref="InMemoryWorkspace"/> and calls <see cref="IPipelineScenario.SeedWorkspace"/>.</item> |
| | | 16 | | /// <item>Builds the pipeline stages via <see cref="IPipelineScenario.BuildPipeline"/>.</item> |
| | | 17 | | /// <item>Executes the pipeline using <see cref="SequentialPipelineRunner"/>.</item> |
| | | 18 | | /// <item>Calls <see cref="IPipelineScenario.Verify"/> with the post-execution workspace and result.</item> |
| | | 19 | | /// </list> |
| | | 20 | | /// </remarks> |
| | | 21 | | [DoNotAutoRegister] |
| | | 22 | | public sealed class PipelineScenarioRunner |
| | | 23 | | { |
| | | 24 | | private readonly SequentialPipelineRunner _pipelineRunner; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new <see cref="PipelineScenarioRunner"/>. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="pipelineRunner">The sequential pipeline runner used to execute stages.</param> |
| | 7 | 30 | | public PipelineScenarioRunner(SequentialPipelineRunner pipelineRunner) |
| | | 31 | | { |
| | 7 | 32 | | _pipelineRunner = pipelineRunner ?? throw new ArgumentNullException(nameof(pipelineRunner)); |
| | 6 | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Runs the scenario with full lifecycle management: seed workspace, |
| | | 37 | | /// build pipeline, execute, and verify outcomes. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="scenario">The pipeline scenario to run.</param> |
| | | 40 | | /// <param name="services">Service provider for resolving pipeline dependencies.</param> |
| | | 41 | | /// <param name="cancellationToken">Cancellation token.</param> |
| | | 42 | | /// <returns>The result of the scenario run.</returns> |
| | | 43 | | public async Task<PipelineScenarioResult> RunAsync( |
| | | 44 | | IPipelineScenario scenario, |
| | | 45 | | IServiceProvider services, |
| | | 46 | | CancellationToken cancellationToken = default) |
| | | 47 | | { |
| | 6 | 48 | | ArgumentNullException.ThrowIfNull(scenario); |
| | 5 | 49 | | ArgumentNullException.ThrowIfNull(services); |
| | | 50 | | |
| | 4 | 51 | | var workspace = new InMemoryWorkspace(); |
| | 4 | 52 | | scenario.SeedWorkspace(workspace); |
| | | 53 | | |
| | 4 | 54 | | var stages = scenario.BuildPipeline(services); |
| | 4 | 55 | | var options = scenario.GetOptions(); |
| | | 56 | | |
| | 4 | 57 | | var result = await _pipelineRunner.RunAsync( |
| | 4 | 58 | | workspace, |
| | 4 | 59 | | stages, |
| | 4 | 60 | | options, |
| | 4 | 61 | | cancellationToken); |
| | | 62 | | |
| | 4 | 63 | | scenario.Verify(workspace, result); |
| | | 64 | | |
| | 4 | 65 | | return new PipelineScenarioResult(scenario.Name, workspace, result); |
| | 4 | 66 | | } |
| | | 67 | | } |