Skip to content

Add aspire test testing-loop spec and Phase 0 walking skeleton - #18428

Closed
Mitch Denny (mitchdenny) wants to merge 4 commits into
mainfrom
mitchdenny-aspire-test-command
Closed

Mitch Denny (mitchdenny) wants to merge 4 commits into
mainfrom
mitchdenny-aspire-test-command

Conversation

@mitchdenny

@mitchdenny Mitch Denny (mitchdenny) commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

Description

This PR introduces a new aspire test command 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 test behaves like aspire run, but its lifetime is bounded by resources marked with a TestAnnotation. 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:

  1. The design-exploration mini-spec (docs/specs/testing-loop.md).
  2. The Phase 0 "walking skeleton" implementation of the core primitive.

Part 1: the spec (docs/specs/testing-loop.md)

  • TestAnnotation primitive carrying an async, context-driven callback that records results as they occur or in batch, reports live progress, and attaches files.
  • Command surface: --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.
  • Operation mode: recommends "run sub-mode + test flag" over a new DistributedApplicationOperation.Test.
  • Results model + output directory, backchannel test.v1 capability additions, extensibility (database upgrade-sequence example), and higher-level layers for MTP/xUnit, pytest, and Playwright.
  • Open questions: granular single-test execution and a dedicated dashboard Test tab.

This complements the existing outer-loop spec at docs/specs/polyglot-apphost-testing.md as 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 (mirroring CliOrphanDetector) rather than in the CLI, so the MVP needs zero backchannel changes and aspire test is essentially aspire run plus one env var.

  • TestAnnotation (IResourceAnnotation) marks a resource as a test resource.
  • WithTestRun() attaches the annotation (exported to ATS).
  • TestLoopCoordinator is 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 (Finished / Exited / FailedToStart) and then stops the AppHost. It no-ops under a normal aspire run.
  • TestCommand subclasses RunCommand, reuses the entire run flow, and sets the test-mode env var through a new ConfigureAppHostEnvironment hook on RunCommand.

Behavior: aspire test starts the app like aspire 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 DistributedApplicationTestContext recording API, backchannel test.v1, the MTP/pytest/Playwright layers, --isolated/--timeout/keep-alive semantics, real pass/fail exit codes, and a dashboard Test tab.

Verification

  • Unit tests for TestLoopCoordinator (no-op outside test mode, immediate exit with no test resources, single/multiple resources, FailedToStart is terminal).
  • An in-process end-to-end test that boots a real AppHost in test mode, marks a resource with WithTestRun(), drives it to a terminal state, and confirms the host self-terminates.
  • aspire test --help shows the command wired up and inheriting the run options.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Phase 0 only; follow-up phases expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes (TestAnnotation, WithTestRun())
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

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]>
Copilot AI review requested due to automatic review settings June 23, 2026 08:54
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18428

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18428"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.md describing the aspire test command, the TestAnnotation/DistributedApplicationTestContext abstractions, output-directory/result model (run.json), test.v1 backchannel 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]>
@mitchdenny Mitch Denny (mitchdenny) changed the title Add testing-loop mini-spec for aspire test Add aspire test testing-loop spec and Phase 0 walking skeleton Jun 23, 2026
@github-actions

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]>
Copilot AI review requested due to automatic review settings June 23, 2026 10:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

Files not reviewed (1)
  • src/Aspire.Cli/Resources/TestCommandStrings.Designer.cs: Generated file
  • Files reviewed: 33/34 changed files
  • Comments generated: 1

Comment on lines +120 to +122
<data name="Description" xml:space="preserve">
<value>Run an Aspire AppHost and exit when its test resources finish</value>
</data>
@github-actions

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]>
@github-actions

Copy link
Copy Markdown
Contributor

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)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.EndToEnd.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.GitHub.Models.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Managed.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected jobs (5)

cli-starter, deployment-e2e, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

⚠️ 29 of the 51 selected test projects come from a single change — tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorEndToEndTests.cs.

🧪 tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorEndToEndTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 28 via the project graph

show 28

Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests

🔧 src/Shared/KnownConfigNames.cs (changed source)
→ 9 via the project graph: Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.GitHub.Models.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Testing.Tests, Aspire.Managed.Tests (2 hops), Aspire.Templates.Tests

🔧 src/Aspire.Hosting/ApplicationModel/TestAnnotation.cs (changed source)
→ 5 via the project graph: Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Playground.Tests

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

📦 affected project Aspire.Hosting
→ 1 test: Aspire.EndToEnd.Tests

🔧 src/Shared/CliExitCodes.cs (changed source)
→ 1 via the project graph: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/Commands/PublishCommandPromptingIntegrationTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Commands/TestCommandTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/TestAppHostCliBackchannel.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Java.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Python.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Rust.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/HostingContainerResourceCapabilities.verified.txt (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.TypeScript.Tests

🧪 tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter • affected project Aspire.Cli
• selected test Aspire.Cli.Tests
deployment-e2e affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Backchannel/AppHostCliBackchannel.cs, src/Aspire.Cli/Backchannel/BackchannelJsonSerializerContext.cs, src/Aspire.Cli/Commands/RootCommand.cs, src/Aspire.Cli/Commands/RunCommand.cs, src/Aspire.Cli/Commands/TestCommand.cs, src/Aspire.Cli/Program.cs, src/Aspire.Cli/Resources/TestCommandStrings.Designer.cs, src/Aspire.Cli/Resources/TestCommandStrings.resx, src/Aspire.Cli/Resources/xlf/TestCommandStrings.cs.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.de.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.es.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.fr.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.it.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.ja.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.ko.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.pl.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.pt-BR.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.ru.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.tr.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.zh-Hans.xlf, src/Aspire.Cli/Resources/xlf/TestCommandStrings.zh-Hant.xlf, src/Aspire.Hosting/ApplicationModel/TestAnnotation.cs, src/Aspire.Hosting/Backchannel/AppHostRpcTarget.cs, src/Aspire.Hosting/Backchannel/BackchannelDataTypes.cs, src/Aspire.Hosting/Cli/TestRunCoordinator.cs, src/Aspire.Hosting/DistributedApplicationBuilder.cs, src/Aspire.Hosting/TestResourceBuilderExtensions.cs, tests/Aspire.Cli.Tests/Commands/PublishCommandPromptingIntegrationTests.cs, tests/Aspire.Cli.Tests/Commands/TestCommandTests.cs, tests/Aspire.Cli.Tests/TestServices/TestAppHostCliBackchannel.cs, tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs, tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorEndToEndTests.cs, tests/Aspire.Hosting.Tests/Cli/TestRunCoordinatorTests.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit 6f5875b.

@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.6 milestone Aug 20, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants