|
| 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. |
0 commit comments