Skip to content

[docs] Document recursive MTP test runner invocation guard in testing docs - #1804

Closed
aspire-repo-bot[bot] wants to merge 1 commit into
release/17.0from
docs/pr-20573-36883974620-1-94cef80e8b73ad03
Closed

aspire-repo-bot[bot] wants to merge 1 commit into
release/17.0from
docs/pr-20573-36883974620-1-94cef80e8b73ad03

Conversation

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Documents changes from microsoft/aspire#20573

@danegsta

Target branch: Targeting release/17.0 based on the source PR milestone 17.0 (exact match on microsoft/aspire.dev).

Why this is needed

microsoft/aspire#20573 adds a safety check to DistributedApplicationTestingBuilder.CreateAsync that detects when a Microsoft.Testing.Platform test project is itself built with Aspire.AppHost.Sdk. In that situation the generated Projects.* type can belong to the test application instead of the AppHost, and invoking its entry point recursively re-runs the entire test suite (potentially leaving stray AppHost/DCP processes running). The fix throws a clear InvalidOperationException instead of silently recursing.

This is a new, previously undocumented failure mode and diagnostic message that users of DistributedApplicationTestingBuilder can now hit, so the testing docs need to explain the symptom and the fix.

What changed

Added a new "Avoid building test projects with Aspire.AppHost.Sdk" section to src/frontend/src/content/docs/testing/advanced-scenarios.mdx (alongside the existing "File-based AppHost limitations" section), covering:

  • The root cause: test projects built with Aspire.AppHost.Sdk instead of Microsoft.NET.Sdk.
  • The exact InvalidOperationException message users will see.
  • The three remediation options called out in the source PR: switch the test project to Microsoft.NET.Sdk with a <ProjectReference> to the AppHost, load the AppHost assembly dynamically and pass a type to CreateAsync(Type), or use DistributedApplicationTestingBuilder.Create() when no entry-point invocation is needed.

Files modified

  • src/frontend/src/content/docs/testing/advanced-scenarios.mdx (updated)

No new pages were created; this extends an existing troubleshooting-style page that already documents a related AppHost-testing limitation.

Generated by PR Documentation Check for #20573 · copilot · auto · 58.3 AIC · ⌖ 16.6 AIC · ⊞ 20.3K · ◷

Adds a troubleshooting section to the advanced testing scenarios page
explaining why Aspire.AppHost.Sdk test projects can recursively invoke
the test runner via DistributedApplicationTestingBuilder.CreateAsync,
and how to fix it (Microsoft.NET.Sdk + ProjectReference, dynamic
assembly loading, or DistributedApplicationTestingBuilder.Create()).

Documents microsoft/aspire#20573

Co-authored-by: Copilot <[email protected]>
@aspire-repo-bot aspire-repo-bot Bot added the docs-from-code Copilot initiated issue from dotnet/aspire repo label Oct 1, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor Author

Frontend HTML artifact ready

The latest frontend build uploaded the frontend-dist artifact for PR #1804. Use the VS Code button below to open this PR with GitHub Artifacts Explorer and browse the built HTML locally.

VS Code: Open PR #1804 artifacts

This comment updates automatically when a new frontend build artifact is uploaded.

Copy link
Copy Markdown
Member

docs-pr-reviewer report — [partial — phase A: key claims evaluated; phase B: not run (docs site was not served in this automated run)]

Recommendation: approve

Source used: microsoft/aspire#20573 (merged 2026-10-01)
PR status: draft, mergeable, bot-authored, opened 2026-10-01 — STALE (~33 days).

Phase A — claims

  • ✅ source PR merged ('Prevent recursive MTP test runner invocation'); doc matches its guard and the InvalidOperationException guidance.
  • ⚠️ nuance: confirm the quoted exception message verbatim.

Phase B — doc-tester

Not run; rendering of the changed pages is not browser-checked.

🤖 Posted by aspire.dev - squad (AI Agent)

@IEvangelist
David Pine (IEvangelist) marked this pull request as ready for review November 13, 2026 14:59
Copilot AI balanced review requested due to automatic review settings November 13, 2026 14:59

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.

🟡 Changes recommended

The documentation quotes the wrong diagnostic for generated project metadata and links to an entry-point-based factory example rather than documenting Create(), leaving the remediation misleading.

2 open issues
What changed in this PR

Extends the testing documentation to explain the recursive Microsoft.Testing.Platform test-runner guard introduced in microsoft/aspire#20573.

Changes:

  • Describes how using Aspire.AppHost.Sdk in a test project can cause recursive test execution.
  • Adds an exception-message example and three remediation options.
File Description
src/​frontend/​src/​content/​docs/​testing/​advanced-scenarios.mdx Adds troubleshooting guidance for test-project SDK configuration and recursive entry-point invocation.

Review effort: Balanced

`DistributedApplicationTestingBuilder.CreateAsync` detects this condition before invoking the entry point and throws `InvalidOperationException` with a message that explains the problem and the fix:

```text
The assembly 'MyTests' is a Microsoft.Testing.Platform test application. Invoking its entry point from DistributedApplicationFactory would recursively run the test application. Test projects should use Microsoft.NET.Sdk instead of Aspire.AppHost.Sdk and reference the AppHost project so the entry point type belongs to the AppHost executable assembly. Alternatively, use DistributedApplicationTestingBuilder.Create to construct the application without invoking an entry point.

- Make sure the test project's SDK is `Microsoft.NET.Sdk`, and that it has a `<ProjectReference>` to the AppHost project so `Projects.MyAppHost` resolves to the AppHost's assembly, not the test assembly.
- If the AppHost is discovered dynamically at runtime, load its assembly directly and pass a type from that assembly to `CreateAsync(Type)` instead of relying on the generated `Projects` type.
- If you don't need the entry point invoked at all, use [`DistributedApplicationTestingBuilder.Create()`](/testing/manage-app-host/#use-the-distributedapplicationfactory-class) to construct the application without invoking an entry point.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-from-code Copilot initiated issue from dotnet/aspire repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants