Repository navigation
Fix MTP affected-test collection in headless Windows runs - #11896
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60094118-e0a2-49e7-8ae9-b97c0d7efa54
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 60094118-e0a2-49e7-8ae9-b97c0d7efa54
There was a problem hiding this comment.
🟢 Approval recommended
The changes consistently address the documented failure modes with focused unit and packed acceptance coverage.
0 open findings
What changed in this PR
Stabilizes MTP affected-test collection for headless Windows processes by preserving clean, valid JSON output and fixing environment-dependent tests.
Changes:
- Emits ASCII-safe JSON while preserving decoded Unicode values.
- Redirects diagnostics to stderr and fixes Windows fixture/dependency loading.
- Adds unit, packed acceptance, and contract documentation coverage.
Confidence at a glance
🟢 Serialization, Windows behavior, tests, and documentation
No actionable defects identified.| File | Description |
|---|---|
src/Platform/Microsoft.Testing.Platform/OutputDevice/JsonStringWriter.cs |
Escapes non-ASCII JSON characters. |
docs/affected-test-selection.md |
Documents headless collection requirements. |
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/DesktopTestDataSourceTests.cs |
Resolves copied XML fixtures reliably. |
test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/DiscoveredTestsJsonSerializerTests.cs |
Verifies ASCII output and Unicode round-tripping. |
test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/NamedPipeServerSecurityTests.cs |
Preloads security assemblies before impersonation. |
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Program.cs |
Moves startup diagnostics to stderr. |
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/Program.cs |
Moves process statistics to stderr. |
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Program.cs |
Moves process statistics to stderr. |
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DotnetTestPipe/DotnetTestPipeListTestsJsonTests.cs |
Adds packed headless Unicode discovery coverage. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🧪 Test quality review — PR #11896
🧵 Parallel safety
STATUS: CLEAN (delegated to the parallel-safety-reviewer specialist).
| Test assembly | Scope | Workers |
|---|---|---|
MSTest.Acceptance.IntegrationTests |
MethodLevel |
0 (CPU count) |
Microsoft.Testing.Platform.Acceptance.IntegrationTests |
MethodLevel |
0 (CPU count) |
MSTestAdapter.PlatformServices.UnitTests |
off (TestContainer/bespoke engine, no scheduler) |
n/a |
Microsoft.Testing.Extensions.VSTestBridge.UnitTests |
MethodLevel |
0 (CPU count) |
Microsoft.Testing.Platform.UnitTests |
MethodLevel |
0 (CPU count) |
No Critical/High/Warning/Info findings. Notes from the specialist:
DesktopTestDataSourceTests'sPath.Combine(AppContext.BaseDirectory, "DataTestSourceFile.xml")change reads aCopyToOutputDirectory=Alwayscontent file that both methods in the class only read; no writer collides, and the class runs under the parallelism-freeTestContainerengine anyway.NamedPipeServerSecurityTests.TryConnectManagedClientAs's new eager assembly-load (typeof(...).Assembly) is a helper, not a test method, and introduces no shared mutable state.- The new
DotnetTestPipeListTestsJsonTests.ListTestsJson_HeadlessProcess_PreservesUnicodetest and its fixture follow the repo's standard build-once, read-onlyTestAssetFixtureBasepattern already used by its sibling test in the same class. - The three
Console.WriteLine→Console.Error.WriteLinechanges only touch unreferenced diagnostic lines; no test asserts on their presence/absence in stdout.
Per-test assessment
| Result | Quality | Test | Notes | How to improve |
|---|---|---|---|---|
| Pass | B (80–89) | mod DesktopTestDataSourceTests. |
One clear mock-verify assertion (`SetDataConnection` called once) protects the claimed behavior; only the fixture path changed. | None |
| Pass | A (90–100) | mod DesktopTestDataSourceTests. |
New `dataRows.Should().HaveCount(4)` now pins the row count (matches the 4 `` entries in the fixture) in addition to the per-row value check. | None |
| Pass | A (90–100) | new DiscoveredTestsJsonSerializerTests. |
Exact-equality raw-string JSON assertion plus independent round-trip decode checks for both `uid` and `displayName`. | None |
| Pass | A (90–100) | new DotnetTestPipeListTestsJsonTests. |
Checks exit code, empty stderr, schema version, array length, and the exact unicode `uid`/`displayName` pair end-to-end through a real headless process. | None |
NamedPipeServerSecurityTests.TryConnectManagedClientAs (lines 939–944) is a static test helper invoked by existing tests, not a test method itself, so it is out of grading scope per Step 1 filtering; its only change is the assembly-preload fix described in the parallel-safety section above.
No inline suggestions were prepared: every graded test is Pass with no actionable improvement, and the parallel-safety result is CLEAN.
This advisory review is heuristic and non-blocking.
Re-run the combined review with /review-tests, or only the parallel-safety
specialist with /parallel-audit.
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 Test Quality Review on PR (on open / sync) workflow. · copilot · auto · 226.6 AIC · ⌖ 10.1 AIC · ⊞ 20.8K · ◷
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
Summary
Reviewed the full diff against the 22 dimensions (Algorithmic Correctness, Security/IPC, Public API, Performance, Cross-TFM, Resource Management, Defensive Coding, Localization, Test Isolation, Assertion Quality, Flakiness, Test Completeness, Code Structure, Documentation Accuracy, IPC Wire Compatibility, Scope Discipline, and others). This is a focused, well-scoped bugfix PR addressing three related headless/process-isolation defects uncovered by the affected-test collection workflow:
JsonStringWriternon-ASCII escaping (src/Platform/Microsoft.Testing.Platform/OutputDevice/JsonStringWriter.cs) — now\u-escapes every character>= 0x7F(not just surrogate pairs and\u2028/\u2029), guarding against a legacy-console-encoding best-fit fallback corrupting Unicode (or worse, emitting raw control characters) when discovery runs in a headless Windows child process. Verified the schema/decoded values are unaffected —JsonDocument.Parseround-trips correctly in the newSerialize_NonAsciiCharacters_ProducesLosslessAsciiJsontest, and the ASCII-only existing test (Serialize_DisplayNameWithSpecialCharacters_EscapesProperly) is unaffected since all its characters are< 0x7F.Console.WriteLine→Console.Error.WriteLinein three test-hostProgram.csentry points — keeps stdout clean for the collection/affected-tests pipeline, which depends on an uncluttered stdout for--list-tests json. Confirmed via grep that no other test asserts on this stdout text, so this is safe.- AppContainer pipe test preloading
WindowsIdentity/GenericSecurityDescriptorassemblies before impersonation (NamedPipeServerSecurityTests.cs) — correctly addresses lazy assembly loading under a restricted token that can't read the desktop runtime install directory; preloading beforeImpersonateLoggedOnUseris the right fix shape. DesktopTestDataSourceTestsresolving the fixture viaAppContext.BaseDirectory— fixes a working-directory-dependent test; verifiedDataTestSourceFile.xmlhas exactly 4<settings>entries, matching the newHaveCount(4)assertion, and the project's.csprojalready copies the file to output, so the fixture is actually present at that path.
All four fixes are independently verifiable, narrowly targeted, and backed by regression tests (Serialize_NonAsciiCharacters_ProducesLosslessAsciiJson unit test + ListTestsJson_HeadlessProcess_PreservesUnicode packed acceptance test) that exercise the actual failure mode rather than just the implementation detail. The doc update in docs/affected-test-selection.md accurately describes the headless-compatibility rationale and correctly cross-references the two key regression tests.
Dimension-by-dimension notes
- Public API & Binary Compatibility: No public API surface touched;
JsonStringWriterandDiscoveredTestsJsonSerializerare bothinternal. Clean. - IPC Wire Compatibility: The JSON schema (
schemaVersion, field names, structure) is unchanged — only the character-escaping policy within string values changed, and\u-escaped non-ASCII is valid JSON that decodes identically. No consumer-visible breaking change. - Security: The
NamedPipeServerSecurityTests.cschange strengthens (doesn't weaken) the AppContainer restricted-token test by ensuring assembly loads happen on the caller's (non-impersonated) identity rather than accidentally failing/short-circuiting the restricted-token validation. No regression in coverage — the actual connect/impersonate/deny logic is untouched. - Test Isolation / Flakiness: The
AppContext.BaseDirectory-based path fix removes a cwd-dependent flakiness source; no new static mutable state or unguarded shared paths introduced. - Performance:
JsonStringWriter's hot loop still does a single pass over the string with no added allocations beyond the pre-existingAppendUnicodeEscapecalls (just invoked more often now). - Scope Discipline: All four changes are tightly related (headless/isolated-process correctness for the affected-tests collection path) and appropriately bundled as a single PR rather than scattered; no unrelated drive-by changes detected.
Minor suggestion (non-blocking)
Since JsonStringWriter is shipped product code in Microsoft.Testing.Platform and this change alters the --list-tests json output encoding for non-ASCII display names/UIDs (a user-observable behavior change, even though it's strictly loss-preventing), consider adding a docs/Changelog.md entry under the next unreleased ### Fixed section, consistent with how other behavior-affecting bugfixes in this repo are tracked. Not blocking since the fix is purely corrective (previously-corrupting data is now preserved) and well-documented in affected-test-selection.md.
No blocking issues found across the applicable review dimensions. Submitting as COMMENT (not APPROVE, per this workflow's restrictions).
|
Final test-triage resolution — Azure Pipelines build 1632088 Build 1632088 (PR #11896, head The only non-passed records in the normalized results are three intentional retry-validation test probes on the Windows App Model Diagnostics leg, each of which failed on attempt 1 and passed on a subsequent retry attempt within the same build:
These are self-tests of the MTP retry/AppContainer-host-recovery mechanism itself (test names and messages make the by-design fail-then-pass contract explicit), not product regressions. Cross-checking Conclusion: No actionable test failure, flake, crash, or performance regression attributable to this PR's changes. No issue created.
|
Pull request
Summary
Fix the Windows Release affected-test collection failures in pipeline run 20261012.11. The failures had multiple causes, not an SDK handshake regression:
No tests are disabled, and pipeline fallback, exit-code handling, scheduling, package versions, and public APIs are unchanged.
Design and decision record
The existing affected-test collection contract records the rationale. A separate feature record is unnecessary for these repairs.
Escaping Unicode keeps the JSON schema and decoded values unchanged without changing process-global console encoding or adding a dependency. Strict parsing and real collection exposed issues that serializer-only and ordinary test execution missed: preloading access control alone still failed when the collector reached the lazy Windows-principal dependency.
Demonstration
A text transcript is clearer than screenshots for these JSON/process failures.
Discovery was exercised through real apphosts with
CreateNoWindow=trueand--list-tests json, not just in-memory serialization. The packed headless regression consumesMicrosoft.Testing.Platform/2.6.0-devon net10.0; its executed DLL matches the freshly packed payload by SHA-256.Validation and regression proof
Baseline production:
7d50b3e8c232c49573d37da996c9a665eb2f4dac, with the new regression tests retained in the task-owned worktree. Final source:1a29ef2b83a604e31278e9b4efa769f7c832cb92. Validation used Release, the pinned SDK12.0.100-alpha.1.26509.101, and affected-tests/coverage packages18.13.0-preview.26508.3.Serialize_NonAsciiCharacters_ProducesLosslessAsciiJsonListTestsJson_HeadlessProcess_PreservesUnicodeNamedPipeServerSecurityTestsDesktopTestDataSourceTests.GetDataShould*methodsBuild/pack commands, all successful with exit 0:
Focused runner commands used the repo-local SDK on PATH and
DOTNET_ROOTpointing to.dotnet; modern acceptance runs also setDOTNET_ROLL_FORWARD=MajorandDOTNET_ROLL_FORWARD_TO_PRERELEASE=1:Real collector validation used a task-owned solution containing the four affected unit-test projects and a nested
global.jsonselecting the supported local storage provider. Collection rejects filters by design; none were used. From that validation directory, with repo-localdotneton PATH andDOTNET_CLI_ENABLE_AFFECTED_TESTS=1:Here
$rootis the worktree root and$projectin the collection block is the absoluteMicrosoft.Testing.Platform.UnitTests.csprojpath. Collection intentionally suppresses ordinary SDK reporting, so the parent's zero-test summary is not execution proof: map contents, discovered UIDs, source associations, and absence of failed-batch output were checked explicitly.Package SHA-256:
0FE351E345A589D75246BC8FEA366288566AA4D54B887322A41BC1EF0A973888. Executed consumer/platform DLL SHA-256:3AF928F7CE13E5C8472052E01EF5270F28EC38E711D28634AC8425D8666AD833;obj/project.assets.jsonconfirms the isolated cache and resolved package.TRX, binlogs, map summaries, and red/green logs are retained locally, not uploaded:
artifacts\TestResults\pipeline-fixes,artifacts\collection-final-summary.json, andartifacts\packed-consumer-provenance.json. Azure DevOps artifact upload and the full acceptance collection matrix were not rerun locally; CI on this PR remains the verification for those paths.