Skip to content

Commit e28fba2

Browse files
EvangelinkCopilot
andauthored
Let MTP extensions consume messages from an existing test host controller (#12586)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent b2f3d20 commit e28fba2

22 files changed

Lines changed: 663 additions & 4 deletions
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# MTP controller data consumers: research and decisions
2+
3+
## Problem and contract
4+
5+
Coverlet.MTP publishes `TestCoverageReportMessage` from its controller-side
6+
process-exit handler. A reporter that only registers a test-host `IDataConsumer`
7+
cannot receive that message, while registering another process-exit handler
8+
couples it to extension registration order.
9+
10+
The proposed API lets an extension observe controller-published `IData` when a
11+
controller is already required for another reason. Registering the observer
12+
alone must not create a controller process. It is not a child-process message
13+
relay, a run-completion notification, or a retry-wide aggregation mechanism.
14+
The existing force-restart consumer registration remains internal.
15+
16+
Producer: Coverlet.MTP 10.1.0+ (controller-side coverage report messages).
17+
Consumer: third-party MTP reporters such as ReportGenerator.Mtp. The MTP
18+
consumer boundary is in `Microsoft.Testing.Platform` (source version 3.0.0 at
19+
the inspected revision); downstream package versions and release branches must
20+
be aligned by the consuming integration.
21+
22+
## Research and experiments
23+
24+
### 2026-11-21: inspect issue and MTP lifecycle
25+
26+
Source state: `3bf21c761a747e2c95135401c9138dd1640888d7`.
27+
28+
- Issue #8904 describes ReportGenerator running before Coverlet's exit handler.
29+
The controller invokes exit handlers sequentially and drains its message bus
30+
after each handler. Coverlet publishes the report message from this controller
31+
lifecycle.
32+
- Existing internal `AddDataConsumer` contributes to the controller restart
33+
decision. `AddDataConsumerWhenControllerStarts` is an observer and is only
34+
built after some other registration requires the controller.
35+
- The internal TRX extension already uses controller-side consumers. The
36+
controller's test-host IPC does not forward ordinary child `IData` messages.
37+
- ReportGenerator PR #797 used reflection and observed coverage messages/files
38+
in both handler orders, but did not prove populated ReportGenerator output.
39+
- Three independent design reviews recommended an experimental observer API;
40+
they identified per-message aggregation, cancellation, browser behavior,
41+
composite-factory validation, and consumer lifetime as contract risks.
42+
43+
### 2026-11-21: implement and validate the observer capability
44+
45+
Source state: base commit `3bf21c761a747e2c95135401c9138dd1640888d7` plus the
46+
uncommitted implementation and tests in this worktree. The final review retained
47+
the existing internal TRX consumer's browser-unsupported behavior; only the new
48+
public observer registration is a browser no-op.
49+
50+
- Added the optional experimental `ITestHostControllerDataConsumerManager`
51+
capability and extension methods without changing the shipped
52+
`ITestHostControllersManager` contract. Observer registration does not affect
53+
the controller restart decision. Unsupported custom managers get a localized
54+
`NotSupportedException`.
55+
- Added four focused unit tests and a package-consuming acceptance test. The
56+
acceptance test uses a synthetic controller message producer and report
57+
consumer; it is not a Coverlet + ReportGenerator integration.
58+
- An initial acceptance invocation targeted `net11.0`, but the acceptance test
59+
host targets `net12.0` and could not launch. The project was built and the
60+
same cases were rerun under `net12.0`.
61+
- Some retained generated test-asset outputs had older package contents. Those
62+
were not used as provenance evidence: the final acceptance runs generated
63+
fresh private package caches, and their binlogs record the consumer's
64+
`Microsoft.Testing.Platform` 3.0.0-dev `net11.0` runtime asset and resolved
65+
path. The acceptance harness removes those temporary cache files after the
66+
run.
67+
68+
## Alternatives and decision
69+
70+
- Adding lifetime-handler priorities would expose ordering dependencies without
71+
guaranteeing report publication and would couple unrelated extensions.
72+
- Exposing the existing force-restart consumer path would make a reporting
73+
extension change process topology.
74+
- A coverage-specific hook duplicates the report-message contract and is too
75+
narrow for other controller-published data.
76+
- A run-completion callback is not required for the issue's per-report
77+
consumption scenario. It would be a separate lifecycle contract and is not
78+
included. Consumers needing a merged, run-wide result need a separately
79+
designed completion surface.
80+
81+
Implement an optional controller-data-consumer capability and extension
82+
methods, following the existing test-host-orchestrator middleware pattern. This
83+
preserves implementers of the shipped `ITestHostControllersManager` interface.
84+
The API is experimental. It receives data published on the controller's bus,
85+
not child-host data; it is best-effort during cancellation/finalization; it is
86+
not invoked unless another feature starts a controller; it has no cross-consumer
87+
ordering guarantee; and `SessionUid` is not guaranteed to identify a child
88+
session. Browser registration is a no-op because browser execution has no
89+
controller process.
90+
91+
The observer is invoked per message. It does not notify consumers when all
92+
reports for a run or retry sequence have arrived. Slow or failing consumers
93+
participate in the existing message-bus drain and therefore can delay or affect
94+
controller finalization.
95+
96+
## Validation and demonstration
97+
98+
| Requirement / risk | Automated E2E evidence | Rendered check / gap |
99+
| --- | --- | --- |
100+
| Consumer is created only for an existing controller | Unit tests: observer alone does not construct the consumer or request a process restart; with a lifetime handler, the consumer is included in controller configuration. | Nonvisual lifecycle contract. |
101+
| Consumer registration works through the shipped manager surface | Unit tests call the public extension methods through `ITestHostControllersManager`; include both factory forms and duplicate/null validation where supported. | Nonvisual API. |
102+
| Controller-published report reaches an observer in either registration order | Packed-consumer acceptance cases `ControllerDataConsumerObserver_ConsumesCoverageReportInEitherRegistrationOrder`: consumer before/after producer; both assert exact coverage XML and synthetic HTML output. The generated consumer resolves package `Microsoft.Testing.Platform` 3.0.0-dev, `net11.0`, as recorded in the acceptance build binlog. | Synthetic HTML only. Actual Coverlet + ReportGenerator output remains unverified. |
103+
| Failure, cancellation, retry and host-mode behavior | Existing message-bus/finalization tests remain relevant; focused local tests cover observer activation only. Cancellation, retry, and server-mode composition remain follow-up integration evidence. | No visual changes in MTP itself. |
104+
105+
### Test-value evidence
106+
107+
The green and behavior-removal runs used the same two acceptance test UIDs:
108+
`116ce3d9-05dd-85cb-9e01-872ec54ccc12` (consumer after producer) and
109+
`19916861-de63-8c00-9cdb-a4aee95eed7c` (consumer before producer). Both selected
110+
and executed two tests; neither run skipped tests. The generated consumer
111+
asserts report-file availability and exact HTML content, not merely process
112+
success or text presence.
113+
114+
| State | Source and package | Command and outcome |
115+
| --- | --- | --- |
116+
| Green | Base `3bf21c761a747e2c95135401c9138dd1640888d7` plus this worktree's implementation and test changes. `Microsoft.Testing.Platform.3.0.0-dev` package SHA-256: `EC53017C663A98B64B18494B7D3DEE4F8972EE52BE861B61D376B9B05965967D`. The acceptance build binlog records the package's `net11.0` runtime asset resolved from a fresh private cache. | `.\build.cmd -pack -c Release -bl` — exit 0, 0 warnings/errors. `.\build.cmd -projects "test\IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj" -c Release -bl` — exit 0, 0 warnings/errors. `.\.dotnet\dotnet.exe test test\UnitTests\Microsoft.Testing.Platform.UnitTests\Microsoft.Testing.Platform.UnitTests.csproj -c Debug -f net10.0 --filter "FullyQualifiedName~ControllerDataConsumerObserver" -p:UsingDotNetTest=true` — exit 0, 4 passed, 0 failed/skipped. `.\.dotnet\dotnet.exe test test\IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj -c Release -f net12.0 --no-build -p:UsingDotNetTest=true -p:ArtifactsTestResultsDir=artifacts\TestResults\Release\ControllerDataConsumer -- --filter-uid 116ce3d9-05dd-85cb-9e01-872ec54ccc12 --filter-uid 19916861-de63-8c00-9cdb-a4aee95eed7c` — exit 0, 2 passed, 0 failed/skipped. |
117+
| Red (behavior-removal check, not pristine baseline) | Same base, API, tests, and support changes in the task-owned comparison worktree; removed only the observer factory build/register call from `TestHostControllersManager.BuildAsync`. Repacked that state and retained the test assertions. Comparison package SHA-256: `59D1A0D5DCCFFFE008680E7123537D8766D107A4D0D9A1CA687EE179AF20FD39`. Its acceptance build binlog also records `Microsoft.Testing.Platform` 3.0.0-dev and the `net11.0` runtime asset. | `.\build.cmd -pack -c Release -bl` — exit 0. `.\.dotnet\dotnet.exe test test\IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests\Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj -c Release -f net12.0 --no-build -p:UsingDotNetTest=true -p:ArtifactsTestResultsDir=artifacts\TestResults\Release\ControllerDataConsumer-Red -- --filter-uid 116ce3d9-05dd-85cb-9e01-872ec54ccc12 --filter-uid 19916861-de63-8c00-9cdb-a4aee95eed7c` — exit 2, 2 failed, 0 passed/skipped. Both fail at the intended `File.Exists(htmlPath)` assertion because the observer did not create the synthetic report. |
118+
119+
CI selection was inspected, but CI was not run: the general Windows Release
120+
suite (`TestFx.slnx`) and Linux/macOS suite (`NonWindowsTests.slnf`) include the
121+
MTP acceptance project. The Windows application-model-only category lane is
122+
not the relevant lane for these tests.
123+
124+
The package test proves the MTP observer contract with a synthetic producer
125+
and consumer. It does not prove that downstream Coverlet and ReportGenerator
126+
packages cooperate, populate a real report, or aggregate multiple reports or
127+
retry attempts. No browser runtime, cancellation, server-mode, or downstream
128+
integration run was performed. No commit or GitHub publication was made.
129+
130+
## Open questions
131+
132+
- Downstream adoption must prove a populated report from aligned shipping
133+
packages and decide how a consumer handles multiple reports or retry attempts.
134+
- The current API is intentionally not an end-of-run aggregation mechanism.
135+
- No release-branch servicing or backport decision is made here; the owning
136+
feature team should make it before downstream enablement.

‎src/MTP/Microsoft.Testing.Platform/Extensions/CompositeExtensionsFactory.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class CompositeExtensionFactory<TExtension> : ICompositeExtensionFactory,
3636
"""
3737
You cannot compose extensions that belong to different areas.
3838
Valid composition are:
39-
TestHostControllers: ITestHostProcessLifetimeHandler, ITestHostEnvironmentVariableProvider
39+
TestHostControllers: IDataConsumer, ITestHostProcessLifetimeHandler, ITestHostEnvironmentVariableProvider
4040
TestHost: IDataConsumer, ITestApplicationLifetime
4141
""";
4242
#pragma warning restore RS0051 // Add internal types and members to the declared API

‎src/MTP/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ Microsoft.Testing.Platform.Extensions.TestHostControllers.ITestHostProcessInform
1515
*REMOVED*Microsoft.Testing.Platform.TestHost.ITestHostManager.AddTestSessionLifetimeHandle<T>(Microsoft.Testing.Platform.Extensions.CompositeExtensionFactory<T!>! compositeServiceFactory) -> void
1616
[TPEXP]Microsoft.Testing.Platform.Extensions.ArtifactPostProcessing.ProcessedArtifact.CoverageSummary.get -> System.Collections.Generic.IReadOnlyList<Microsoft.Testing.Platform.Services.CoverageMetricResult!>?
1717
[TPEXP]Microsoft.Testing.Platform.Extensions.ArtifactPostProcessing.ProcessedArtifact.ProcessedArtifact(string! path, string! kind, string! displayName, string? description, System.Collections.Generic.IReadOnlyList<Microsoft.Testing.Platform.Services.CoverageMetricResult!>? coverageSummary) -> void
18+
[TPEXP]Microsoft.Testing.Platform.TestHostControllers.ITestHostControllerDataConsumerManager
19+
[TPEXP]Microsoft.Testing.Platform.TestHostControllers.ITestHostControllerDataConsumerManager.AddDataConsumerWhenControllerStarts(System.Func<System.IServiceProvider!, Microsoft.Testing.Platform.Extensions.IDataConsumer!>! factory) -> void
20+
[TPEXP]Microsoft.Testing.Platform.TestHostControllers.ITestHostControllerDataConsumerManager.AddDataConsumerWhenControllerStarts<T>(Microsoft.Testing.Platform.Extensions.CompositeExtensionFactory<T!>! compositeServiceFactory) -> void
21+
[TPEXP]Microsoft.Testing.Platform.TestHostControllers.TestHostControllersManagerExtensions
22+
[TPEXP]static Microsoft.Testing.Platform.TestHostControllers.TestHostControllersManagerExtensions.AddDataConsumerWhenControllerStarts(this Microsoft.Testing.Platform.TestHostControllers.ITestHostControllersManager! manager, System.Func<System.IServiceProvider!, Microsoft.Testing.Platform.Extensions.IDataConsumer!>! factory) -> void
23+
[TPEXP]static Microsoft.Testing.Platform.TestHostControllers.TestHostControllersManagerExtensions.AddDataConsumerWhenControllerStarts<T>(this Microsoft.Testing.Platform.TestHostControllers.ITestHostControllersManager! manager, Microsoft.Testing.Platform.Extensions.CompositeExtensionFactory<T!>! compositeServiceFactory) -> void

‎src/MTP/Microsoft.Testing.Platform/Resources/PlatformResources.resx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,10 @@ Valid values are 'allow-skipped' (the default) which counts skipped tests as run
11101110
<value>Test host orchestrator manager of type '{0}' does not support 'ITestHostExecutionOrchestratorMiddleware' registration. Implement 'ITestHostExecutionOrchestratorMiddlewareManager' on the manager type to support it.</value>
11111111
<comment>{0} is the concrete manager type name. {Locked="ITestHostExecutionOrchestratorMiddleware"} {Locked="ITestHostExecutionOrchestratorMiddlewareManager"}</comment>
11121112
</data>
1113+
<data name="TestHostControllersManagerDoesNotSupportDataConsumersErrorMessage" xml:space="preserve">
1114+
<value>Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</value>
1115+
<comment>{0} is the concrete manager type name. {Locked="ITestHostControllerDataConsumerManager"}</comment>
1116+
</data>
11131117
<data name="SyncFlushNotSupportedInBrowserErrorMessage" xml:space="preserve">
11141118
<value>Synchronous flush is not supported in browser environments.</value>
11151119
</data>

‎src/MTP/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,11 @@ Přečtěte si další informace o telemetrii Microsoft Testing Platform: https:
13521352
<target state="translated">Rozšíření testovacího hostitelského řadiče, která vyžadují restartování procesu, nejsou na platformách browser/WebAssembly podporována.</target>
13531353
<note>{Locked="WebAssembly"}</note>
13541354
</trans-unit>
1355+
<trans-unit id="TestHostControllersManagerDoesNotSupportDataConsumersErrorMessage">
1356+
<source>Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</source>
1357+
<target state="new">Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</target>
1358+
<note>{0} is the concrete manager type name. {Locked="ITestHostControllerDataConsumerManager"}</note>
1359+
</trans-unit>
13551360
<trans-unit id="TestHostExecutionOrchestratorMiddlewareFabricatedSuccessErrorMessage">
13561361
<source>Middleware '{0}' short-circuited the test host execution orchestrator pipeline (it did not invoke 'next') but returned the success exit code. Short-circuiting middleware must return an explicit non-success exit code so skipped execution cannot be reported as if tests actually ran and passed.</source>
13571362
<target state="translated">Middleware „{0}“ předčasně ukončil kanál orchestrátoru spouštění testovacího hostitele (nevyvolal „next“), ale vrátil úspěšný kód ukončení. Middleware, který kanál předčasně ukončí, musí vrátit explicitní kód ukončení označující neúspěch, aby se přeskočené spuštění nemohlo vykázat tak, jako by testy skutečně proběhly a byly úspěšné.</target>

‎src/MTP/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,11 @@ Read more about Microsoft Testing Platform telemetry: https://aka.ms/testingplat
13521352
<target state="translated">Testhostcontrollererweiterungen, die einen Prozessneustart erfordern, werden auf Browser- und WebAssembly-Plattformen nicht unterstützt.</target>
13531353
<note>{Locked="WebAssembly"}</note>
13541354
</trans-unit>
1355+
<trans-unit id="TestHostControllersManagerDoesNotSupportDataConsumersErrorMessage">
1356+
<source>Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</source>
1357+
<target state="new">Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</target>
1358+
<note>{0} is the concrete manager type name. {Locked="ITestHostControllerDataConsumerManager"}</note>
1359+
</trans-unit>
13551360
<trans-unit id="TestHostExecutionOrchestratorMiddlewareFabricatedSuccessErrorMessage">
13561361
<source>Middleware '{0}' short-circuited the test host execution orchestrator pipeline (it did not invoke 'next') but returned the success exit code. Short-circuiting middleware must return an explicit non-success exit code so skipped execution cannot be reported as if tests actually ran and passed.</source>
13571362
<target state="translated">Middleware „{0}“ hat die Testhostausführungsorchestrator-Pipeline kurzgeschlossen (sie hat „next“ nicht aufgerufen), aber den Exitcode „Erfolgreich“ zurückgegeben. Das Kurzschließen der Middleware muss einen expliziten nicht erfolgreichen Exitcode zurückgeben, sodass die übersprungene Ausführung nicht so gemeldet werden kann, als ob Tests tatsächlich ausgeführt und bestanden worden wären.</target>

‎src/MTP/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,11 @@ Más información sobre la telemetría de la Plataforma de pruebas de Microsoft:
13521352
<target state="translated">Las extensiones de controlador de host de prueba que requieren reinicio del proceso no se admiten en plataformas de explorador o WebAssembly.</target>
13531353
<note>{Locked="WebAssembly"}</note>
13541354
</trans-unit>
1355+
<trans-unit id="TestHostControllersManagerDoesNotSupportDataConsumersErrorMessage">
1356+
<source>Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</source>
1357+
<target state="new">Test host controllers manager of type '{0}' does not support controller data consumer registration. Implement 'ITestHostControllerDataConsumerManager' on the manager type to support it.</target>
1358+
<note>{0} is the concrete manager type name. {Locked="ITestHostControllerDataConsumerManager"}</note>
1359+
</trans-unit>
13551360
<trans-unit id="TestHostExecutionOrchestratorMiddlewareFabricatedSuccessErrorMessage">
13561361
<source>Middleware '{0}' short-circuited the test host execution orchestrator pipeline (it did not invoke 'next') but returned the success exit code. Short-circuiting middleware must return an explicit non-success exit code so skipped execution cannot be reported as if tests actually ran and passed.</source>
13571362
<target state="translated">El middleware "{0}" interrumpió la canalización del orquestador de ejecución del host de pruebas (no invocó a "next"), pero devolvió el código de salida correcto. El middleware de cortocircuito debe devolver un código de salida explícito que no sea correcto, por lo que la ejecución omitida no se puede notificar como si las pruebas se ejecutaran y pasaran realmente.</target>

0 commit comments

Comments
 (0)