Skip to content

Generate hosted Microsoft.Testing.Platform entry points - #11595

Merged
Amaury Levé (Evangelink) merged 12 commits into
mainfrom
dev/amauryleve/hosted-mtp-entrypoint
Sep 29, 2026
Merged

Amaury Levé (Evangelink) merged 12 commits into
mainfrom
dev/amauryleve/hosted-mtp-entrypoint

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • generate an opt-in Microsoft.Testing.Platform hosted entry point for C#, Visual Basic, and F#
  • use the merged Microsoft.Testing.Extensions.Hosting bridge instead of requiring a handwritten Program.cs for common ASP.NET Core and Aspire tests
  • add host-owned OpenTelemetry activation without creating a second provider, exporter, resource identity, or DI container
  • connect host stopping to MTP cooperative cancellation while allowing MTP cleanup to complete before host shutdown
  • update package assets, samples, RFC/glossary/package docs, API baselines, and package-consuming tests

Opt-in contract

<PropertyGroup>
  <TestingPlatformHostFactory>Contoso.Tests.TestHost.CreateHost</TestingPlatformHostFactory>
  <TestingPlatformOpenTelemetryMode>HostOwned</TestingPlatformOpenTelemetryMode>
</PropertyGroup>

The configured factory is a fully qualified, parameterless static method returning Task<IHost>. It returns one fresh, unstarted host and receives no MTP command-line arguments. Generated code starts/stops the host through RunTestingPlatformAsync, prefers IAsyncDisposable, and preserves the original run failure if disposal also fails.

HostOwned requires Microsoft.Testing.Extensions.OpenTelemetry and contributes only AddTestingPlatformDiagnostics(). The application host remains the sole owner of OpenTelemetry providers, exporters, and service.*/host/OS/process resource identity.

Compatibility defaults

  • when TestingPlatformHostFactory is unset, the existing generated entry point remains unchanged
  • GenerateTestingPlatformEntryPoint=false and handwritten/manual Hosting composition remain supported
  • referencing Hosting alone does not opt a project into generated hosting
  • explicit hosted mode fails clearly for missing/incompatible Hosting or OpenTelemetry package capabilities, disabled self-registration/helper generation, VSTest mode, malformed factories, or protocol-version skew
  • C#, Visual Basic, and F# use the same ownership/lifecycle contract

Validation

  • MSBuild generator unit tests: 140 passed
  • Microsoft.Testing.Extensions unit tests: 2,029 passed, 7 skipped
  • generated package-consuming acceptance: 16 passed across net462, net8.0, net9.0, and net10.0
    • Hosting 8/9/10 compatibility
    • direct and response-file help bypass
    • JSON listing stdout integrity
    • HostOwned builder span, final run metric flush, and preserved service identity
    • async-only host service disposal
  • package-consuming Visual Basic and F# hosted-entry-point acceptance: 2 passed
  • negative hosted package/target validation: 9 scenarios passed
  • package-consuming C#, Visual Basic, and F# builds with warnings as errors
  • exact Windows public-sample Release build: 13/13 solutions passed with binary logs
  • Windows and Linux Release pack validation, including Hosting package build/buildTransitive/buildMultiTargeting content
  • API baseline, package metadata, BOM, and git diff --check validation
  • two fresh review rounds plus MSBuild and lifecycle specialist passes; actionable findings fixed

Bounded limitations

  • configuration-only help/info is resolved after factory construction; direct and response-file help/info bypass the factory
  • process-restart extensions can invoke the factory in both controller and child processes until MTP exposes a role-aware pre-build lifecycle seam; such factories should avoid exclusive global resources such as fixed ports
  • hosted logging, services, and exporters must remain stdout-silent because JSON listing, server, and dotnet test protocols reserve stdout
  • advanced or role-specific composition can continue to use an explicit Program.cs

Copilot AI balanced review requested due to automatic review settings September 28, 2026 09:45
@github-actions github-actions Bot added the needs/merge-conflict-resolution PR has merge conflicts that must be resolved. label Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink
Amaury Levé (Evangelink) force-pushed the dev/amauryleve/hosted-mtp-entrypoint branch from 6c779a7 to 1e16afd Compare September 28, 2026 09:54
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed needs/merge-conflict-resolution PR has merge conflicts that must be resolved. labels Sep 28, 2026

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 review overview

🔵 Needs a closer look

Required experimental notices are missing, and the manual example enables stdout logging that can corrupt MTP protocol output.

Review effort: Balanced
Findings: None

What changed in this PR

Adds generated hosted MTP entry points while keeping host ownership and the dependency-free platform core intact.

Changes:

  • Generates hosted C#, VB, and F# entry points with lifecycle bridging.
  • Adds configuration, logging, and host-owned OpenTelemetry integration.
  • Extends protocol metadata and adds unit, acceptance, and sample coverage.
File Description
TestFx.slnx Includes new extension projects.
docs/​RFCs/​013-Microsoft-Extensions-Bridges.md Documents hosted composition.
docs/​glossary.md Updates terminology.
samples/​public/​MTPHostIntegration/​* Demonstrates generated hosting.
samples/​public/​README.md Links the hosted sample.
Microsoft.Testing.Extensions.Configuration/​* Adds configuration snapshots and package metadata.
Microsoft.Testing.Extensions.Hosting/​* Implements hosting, lifetime, packaging, and APIs.
Microsoft.Testing.Extensions.OpenTelemetry/​* Adds host-owned telemetry hooks.
Microsoft.Testing.Platform.MSBuild/​* Generates and validates hosted entry points.
Microsoft.Testing.Platform/​Builder/​* Adds the internal lifetime bridge contract.
Microsoft.Testing.Platform/​Hosts/​TestHostBuilder.CommonServices.cs Connects host and MTP cancellation.
Microsoft.Testing.Platform/​Services/​ServiceProviderExtensions.cs Generalizes service resolution.
Microsoft.Testing.Platform/​ServerMode/​DotnetTest/​IPC/​* Carries option-provider and arity metadata.
Microsoft.Testing.Platform/​*API/​*.txt Tracks changed API surfaces.
GeneratedMicrosoftExtensionsHostingTests.cs Covers packaged hosted generation.
AcceptanceTestBase.cs Adds package-test support.
MicrosoftExtensionsHostingExtensionsTests.cs Covers lifecycle and failure behavior.
MicrosoftExtensionsConfigurationSnapshotTests.cs Covers snapshot semantics.
MSBuildTests.cs Covers generated sources and validation.
ProtocolTests.cs Covers protocol round trips.
DotnetTestProtocolSerializerTests.cs Covers wire compatibility.
ServiceProviderTests.cs Covers generalized providers.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 28, 2026 10:01

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 review overview

🟡 Changes recommended

The F# templates do not globally qualify host factories, and VB/F# hosted output lacks compilation coverage.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

Open (3)

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 10:26
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

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 review overview

🟡 Changes recommended

The generated F# path can dispose hosts twice and does not reliably globally qualify the configured factory.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity · 2 Low severity

Open (5)

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 10:44
@github-actions github-actions Bot removed the state/needs-review Awaiting review from the team. label Sep 28, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

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 review overview

🔵 Needs a closer look

It spans generated multi-language source, transitive MSBuild assets, and cross-framework host cancellation and disposal semantics.

Review effort: Balanced
Findings: None

Resolved since last review (6)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 12:10
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

@github-actions github-actions Bot 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.

🧵 Parallel-safety audit — PR #11595

Parallelization — one row per test assembly audited:

Test assembly Scope Workers Analyzer coverage
Microsoft.Testing.Platform.Acceptance.IntegrationTests MethodLevel CPU count (Workers = 0) coverable once the parallel-safety analyzers ship (attribute in Program.cs)
Microsoft.Testing.Extensions.UnitTests MethodLevel CPU count (Workers = 0) coverable once the parallel-safety analyzers ship (attribute in Program.cs)
Microsoft.Testing.Platform.MSBuild.UnitTests MethodLevel CPU count (Workers = 0) coverable once the parallel-safety analyzers ship (attribute in Program.cs)

Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — no severities to report.

Analysis performed:

  • New acceptance tests (GeneratedHostedEntryPointValidationTests, GeneratedHostedLanguageEntryPointTests, GeneratedMicrosoftExtensionsHostingTests) build fresh assets via TestAsset.GenerateAssetAsync, which allocates a unique TempDirectory per call (Path.Combine(tempDirectory.Path, assetId)) — no shared-path collisions across concurrently-runnable tests, including the TempDirectory-based response-file scratch path in GeneratedMicrosoftExtensionsHostingTests.GeneratedEntryPoint_ResponseFileHelpDoesNotCreateHost.
  • New unit tests in MicrosoftExtensionsHostingExtensionsTests.cs (ShouldBypassApplicationHost_ExpandsResponseFiles, the host-lifetime/cancellation tests) use Path.GetTempPath() + Guid.NewGuid() for uniqueness and instance-only mock/list fields (Mock<IBuildEngine>, List<BuildErrorEventArgs> in MSBuildTests.cs) — no static mutable state introduced.
  • The only process-global mutation in scope (Environment.SetEnvironmentVariable in TestInitialize/TestCleanup) is pre-existing (predates this PR) and is already correctly declared via the class-level [ResourceLock(WellKnownResources.EnvironmentVariables)] on MicrosoftExtensionsHostingExtensionsTests; the PR's new test methods correctly inherit that declaration with no under/over-declaration.
  • No changes to [ResourceLock] / [DoNotParallelize] / [Parallelize] declarations, .runsettings, testconfig.json, or MSBuild parallelization properties in this PR.

Nothing unsafe found. All three audited assemblies opt into MethodLevel parallelism via [assembly: Parallelize] in their Program.cs (unchanged by this PR).

Advisory only — heuristic, non-blocking. Re-run with /parallel-audit. This audit answers "is it parallel-safe?"; for testability, smells, or flakiness see the detect-static-dependencies / test-smell-detection / test-anti-patterns analyses.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • github.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · copilot · auto · 104.2 AIC · ⌖ 10.6 AIC · ⊞ 24.9K · ◷

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

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 review overview

🔵 Needs a closer look

The cross-language generator, NuGet build assets, and cancellation lifecycle span several compatibility-sensitive boundaries requiring final human review.

Review effort: Balanced
Findings: None

@github-actions github-actions Bot 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.

🧪 Expert test review — PR #11595

GradeTestMutationNotesHow to improve
C (70–79) new EntryPointTask_
Rejects_
Invalid_
Host_
Factory
1/3 killed Only exercises the too-few-segments branch of IsValidHostFactory. Add DataRow cases for an invalid character and an empty segment.
C (70–79) new ShouldBypassApplicationHost_
Recognizes
Informational
Options
1/2 killed Only asserts the true path; an always-true mutation survives. Add a non-bypass DataRow and assert IsFalse.
A (90–100) new ShouldBypassApplicationHost_
ExpandsResponseFiles
1/1 killed Verifies the response-file expansion branch with real file I/O. —
A (90–100) new RunTestingPlatformAsync_
WithoutHostApplicationLifetime_
PreservesPreviousBehavior
1/1 killed Confirms the optional-lifetime null-bridge path preserves the prior exit code. —
A (90–100) new RunTestingPlatformAsync_
WhenHostStops_
CancelsMtp
1/1 killed Focused test confirming host-initiated stop cancels MTP with the expected exit code. —
A (90–100) new RunTestingPlatformAsync_
WhenMtpStops_
RequestsHostStop
2/2 killed Asserts both exit code and that MTP-initiated stop actually requests host shutdown. —
A (90–100) new EntryPointTask_
GloballyQualifies_
FSharp_
HostFactory_
Without_
RootNamespace
1/1 killed Verifies the rootless F# template globally qualifies the factory (regression test for a review finding). —
A (90–100) new EntryPointTask_
Generates_
Hosted_
Application_
For_
All_
Supported_
Languages
4/4 killed Data-driven across C#/VB/F#; asserts factory call, run/dispose/bypass wiring, and single self-registration. —

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Suggestions on the Files
changed tab can be applied with one click. Re-run with
/review-tests.

🤖 Automated content by GitHub Copilot. Generated by the Test Reviewer on PR (on open / sync) workflow. · copilot · auto · 306.9 AIC · ⌖ 8.06 AIC · ⊞ 17.9K · ◷

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 12:34

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 review overview

🟡 Changes recommended

The documented C#/VB opt-in can fail compilation, and project-level sample runs do not build their required MSBuild task.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Generated C# and VB templates lack TPEXP warning suppression

src/​Platform/​Microsoft.Testing.Platform.MSBuild/​Tasks/​TestingPlatformEntryPointTask.cs:324

The advertised two-property opt-in does not compile cleanly for C# or VB: both generated templates call the [Experimental("TPEXP")] Hosting API without suppressing TPEXP, while every new C#/VB consumer and sample has to add <NoWarn>$(NoWarn);TPEXP</NoWarn>. F# already emits #nowarn "57". Emit the equivalent suppression in the generated C# and VB sources, or make the extra suppression part of the documented opt-in contract; otherwise the documented snippet fails for warnings-as-errors consumers.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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 review overview

🔵 Needs a closer look

It changes cross-language code generation, NuGet build assets, and core cancellation and disposal ordering, warranting final human review.

Review effort: Balanced
Findings: None

Resolved since last review (2)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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 review overview

🔵 Needs a closer look

Host-factory validation accepts language keywords that later produce invalid generated source instead of an actionable configuration error.

Review effort: Balanced
Findings: None

Previously missed (1)

In code that hasn't changed since last review

Medium severity Language keywords bypass factory identifier validation

src/​Platform/​Microsoft.Testing.Platform.MSBuild/​Tasks/​TestingPlatformEntryPointTask.cs:122

This lexical check accepts language keywords, so values such as Contoso.class.TestHost.CreateHost pass validation and are then emitted as invalid C#; the same path can succeed for one language and fail for VB or F# because their keyword sets differ. That defeats the promised actionable validation for malformed factories and leaves users with generated-source compiler errors. Make validation/code generation language-aware and either reject reserved segments here or escape them for the selected language (also using the existing identifier-character helpers rather than char.IsLetterOrDigit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants