Repository navigation
Add aspire test testing-loop spec and Phase 0 walking skeleton - #18428
Mitch Denny (mitchdenny) wants to merge 4 commits into
Conversation
Explores using Aspire as a polyglot test orchestrator via an `aspire test` command and a core `TestAnnotation` abstraction whose async, context-driven callback drives a resource's test run, records results live or in batch, and attaches artifacts. The app model owns the run lifetime: the AppHost shuts down once test resources reach a terminal state. Covers the command surface (`--output-dir`, `--isolated`, `--timeout`, keep-alive/detach), operation mode, results model and output directory, backchannel `test.v1` additions, extensibility, and higher-level MTP/xUnit, pytest, and Playwright layers. Design exploration only; APIs and schemas are illustrative. Co-authored-by: Copilot <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18428Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18428" |
There was a problem hiding this comment.
Pull request overview
This PR adds a single new design-exploration document, docs/specs/testing-loop.md, which proposes using Aspire as an inner-loop test orchestrator via a new aspire test CLI command and a TestAnnotation app-model primitive. It positions itself as the inner-loop complement to the existing outer-loop spec (polyglot-apphost-testing.md). The PR is explicitly docs-only: all C# APIs, CLI options, backchannel methods, and result schemas are labeled illustrative and not final, and no production code, public API, or tests are introduced.
Changes:
- Adds
docs/specs/testing-loop.mddescribing theaspire testcommand, theTestAnnotation/DistributedApplicationTestContextabstractions, output-directory/result model (run.json),test.v1backchannel additions, extensibility, and higher-level layers (MTP/xUnit, pytest, Playwright). - Documents post-completion lifetime switches (
--output-dir,--isolated,--timeout, keep-alive/detach) and an outcome × switch matrix. - Captures open questions and a suggested phasing plan, with cross-links to related specs.
Show a summary per file
| File | Description |
|---|---|
docs/specs/testing-loop.md |
New design-exploration mini-spec for aspire test and TestAnnotation; verified that all referenced docs and codebase APIs/strings cited in the document are accurate, and that internal TOC anchors and the example run.json totals are self-consistent. |
I verified the document's accuracy against the codebase: the referenced specs all exist; the cited APIs (KnownResourceStates.TerminalStates, RunCommand.ExecuteDetachedAsync, DetachOutputInfo, GetPublishingActivitiesAsync, GetResourceStatesAsync, GetCapabilitiesAsync, WaitForResourceHealthyAsync, ResourceCommandAnnotation, TestDistributedApplicationBuilder) and the statement that DistributedApplicationOperation has only Run/Publish are all correct; the quoted --isolated description and worktree warning match the resx exactly; and the run.json totals, per-resource outcomes, TOC anchors, and code-fence language identifiers are all consistent. No spelling, grammar, accuracy, or consistency issues were found, so I have no comments to store.
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
Adds the core primitive from the testing-loop spec: an `aspire test` command whose lifetime is bounded by resources marked as test resources, with no backchannel changes. - TestAnnotation: marks a resource as a test resource. - WithTestRun(): attaches the annotation (exported to ATS). - TestLoopCoordinator: a run-mode BackgroundService that, only when the CLI requested test mode (ASPIRE_CLI_TEST_MODE), waits for every test resource to reach a terminal state and then stops the app host. No-ops under `aspire run`. - TestCommand: subclasses RunCommand, reuses the entire run flow, and sets the test-mode env var via a new ConfigureAppHostEnvironment hook on RunCommand. Lifetime control lives inside the app host (mirroring CliOrphanDetector), so the CLI just flips an env var. Result harvesting, the test context recording API, backchannel additions, MTP/pytest/Playwright layers, --isolated/--timeout, and a dashboard Test tab are deferred to later phases. Verified with unit tests for the coordinator and an in-process end-to-end test that boots a real app host in test mode and confirms it self-terminates once its test resource finishes. Co-authored-by: Copilot <[email protected]>
aspire testaspire test testing-loop spec and Phase 0 walking skeleton
This comment has been minimized.
This comment has been minimized.
Register TestCommand in the CLI test DI helper (CliTestHelper) so the RootCommand can be resolved in tests, mirroring the production registration in Program.cs. Without this, every test that builds the CLI service provider failed with 'Unable to resolve service for type Aspire.Cli.Commands.TestCommand'. Regenerate the polyglot code-generation snapshots to include the new [AspireExport] WithTestRun() binding across Go, Java, Python, Rust, and TypeScript (plus the TypeScript container capability snapshot). Co-authored-by: Copilot <[email protected]>
| <data name="Description" xml:space="preserve"> | ||
| <value>Run an Aspire AppHost and exit when its test resources finish</value> | ||
| </data> |
This comment has been minimized.
This comment has been minimized.
Previously the app host self-stopped when test resources reached a terminal state. Now the CLI owns the run's lifetime: aspire test launches the app host like aspire run (dashboard URLs + streamed logs), opens a backchannel stream of test-run updates, ticks off each resource as it passes/fails, and once the stream completes asks the app host to stop via RequestStopAsync. The command's exit code reflects pass/fail (TestRunFailed = 23 on any failure). - Replace the TestLoopCoordinator hosted service with a TestRunCoordinator singleton that only observes test resources and streams TestRunUpdate values; it never stops the application itself. - Add a capability-gated (test.v1) GetTestRunUpdatesAsync streaming backchannel method on both the app host RPC target and the CLI backchannel. - Add a TryRunCommandInteractionAsync seam on RunCommand so TestCommand can drive the interactive result loop and report a command outcome. - Add TestRunUpdate / KnownTestRunStatuses DTOs and register them for AOT serialization in the CLI. Co-authored-by: Copilot <[email protected]>
Tests selector (audit mode)The full test matrix and all jobs still run in audit mode. The tests and jobs below are what selective CI would run under enforcement. 51 / 97 test projects · 5 jobs, from 41 changed files. Selected test projects (51 / 97)
Selected jobs (5)
How these were chosen — grouped by what changed
🧪 show 28
🔧 🔧 📦 affected project 📦 affected project 🔧 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 🧪 Job reasons
Selection computed for commit |
Description
This PR introduces a new
aspire testcommand and the supporting AppHost infrastructure behind it. The motivation: Aspire already excels at standing up the infrastructure an app needs (databases, caches, brokers, cloud resources) and wiring it together. Many tests need exactly that same infrastructure, yet today nothing lets the app model itself describe a test run and own its lifetime. The goal is to use Aspire not just as a local dev orchestrator but as a polyglot test orchestrator.The core idea:
aspire testbehaves likeaspire run, but its lifetime is bounded by resources marked with aTestAnnotation. Once those resources reach a terminal state, the AppHost shuts down. Eventually the CLI also harvests results into an output directory readable by both humans and agents.This PR contains two parts:
docs/specs/testing-loop.md).Part 1: the spec (
docs/specs/testing-loop.md)TestAnnotationprimitive carrying an async, context-driven callback that records results as they occur or in batch, reports live progress, and attaches files.--output-dir,--isolated(framed around multiple git worktrees),--timeout, and a single post-completion lifetime switch (keep-alive/detach), including the--timeout+ keep-alive interaction.DistributedApplicationOperation.Test.test.v1capability additions, extensibility (database upgrade-sequence example), and higher-level layers for MTP/xUnit, pytest, and Playwright.This complements the existing outer-loop spec at
docs/specs/polyglot-apphost-testing.mdas the inner-loop counterpart.Part 2: Phase 0 walking skeleton
The shortest path to a runnable
aspire test. The key decision is to put lifetime control inside the AppHost (mirroringCliOrphanDetector) rather than in the CLI, so the MVP needs zero backchannel changes andaspire testis essentiallyaspire runplus one env var.TestAnnotation(IResourceAnnotation) marks a resource as a test resource.WithTestRun()attaches the annotation (exported to ATS).TestLoopCoordinatoris a run-modeBackgroundServicethat, only when the CLI requested test mode (ASPIRE_CLI_TEST_MODE), waits for every test resource to reach a terminal state (Finished/Exited/FailedToStart) and then stops the AppHost. It no-ops under a normalaspire run.TestCommandsubclassesRunCommand, reuses the entire run flow, and sets the test-mode env var through a newConfigureAppHostEnvironmenthook onRunCommand.Behavior:
aspire teststarts the app likeaspire run, and as soon as all test resources finish, the AppHost tears itself down. If test mode is set but no resources are marked, it exits immediately with a warning instead of hanging.Deferred to later phases
Result harvesting and the output directory, the
DistributedApplicationTestContextrecording API, backchanneltest.v1, the MTP/pytest/Playwright layers,--isolated/--timeout/keep-alive semantics, real pass/fail exit codes, and a dashboard Test tab.Verification
TestLoopCoordinator(no-op outside test mode, immediate exit with no test resources, single/multiple resources,FailedToStartis terminal).WithTestRun(), drives it to a terminal state, and confirms the host self-terminates.aspire test --helpshows the command wired up and inheriting the run options.Checklist
TestAnnotation,WithTestRun())