Repository navigation
[rel/4.5] Preserve MSTest result attachments after host shutdown - #12247
Conversation
Backport #12239 to rel/4.5. Retain successfully advertised result files after framework and service disposal while preserving deployment protection and failed-copy cleanup. Adapt attachment-only lifecycle coverage to the release TestContainer project; omit main-only F# and continuation coverage. Backport-of: b6b909c Source-PR: #12239 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🧪 Test quality review — PR #12247
🧵 Parallel safety
STATUS: PARTIAL. The parallel-safety specialist was not run, so this PR has no parallel-safety coverage and nothing here should be read as clean. Worth a manual look: MSTestResultFilesTests.NativeHarness swaps the static PlatformServiceProvider.Instance and calls MSTestSettings.Reset() and MSTestInstrumentation.SetActivityFactory(null). That is process-wide state. If the adapter unit-test assembly runs tests in parallel, these tests could race with others that use the same statics. Please confirm the assembly's parallelization setting.
Per-test grades
| Grade | Test | Mutation | Notes | How to improve |
|---|---|---|---|---|
| B (80–89) | new MSTestResultFilesTests. |
N/A | Windows and non-Windows branches assert different outcomes, so only one runs per platform. | Split the OS-specific assertions into separate tests, or make the file-lock outcome deterministic. |
| A (90–100) | new MSTestResultFilesTests. |
N/A | Staging, content, missing-file and double-dispose behavior are all asserted. | — |
| A (90–100) | new MSTestResultFilesTests. |
N/A | Open-handle disposal, no warnings and byte preservation are all asserted. | — |
| A (90–100) | new ResultFileTests. |
N/A | Exit code, counts, published paths, originals and TRX contents are all checked. | — |
| A (90–100) | new ResultFileTests. |
N/A | Passed nodes, distinct UIDs, attachment URIs and the original files are all asserted. | — |
Grades are based on reading the test bodies only. I did not resolve the production code, so Mutation is N/A. I did not grade the remaining methods in ResultFileTests, for example Trx_AbortedRun_PreservesRecoveredResultFiles and any others below it.
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.
🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · 29.8 AIC · ⌖ 0.722 AIC · ⊞ 7.6K · ◷
Summary
Backport #12239 to
rel/4.5for the MSTest 4.5.2 / MTP 2.5.2 regression reported in #12205. Successfully copied, advertised attachments now remain readable after framework/service disposal and host exit. Keep copy-before-deployment-cleanup (#11606), original-file preservation, all-failed staging cleanup, cleanup warnings and original-path fallback.This changes MSTest.TestAdapter production code only. It retains the source fix's absolute, visible
MSTest-<20 GUID hex digits>result folders. The package readme documents caller-owned retention and possible additional TRX/retry copies. There is no MTP production/protocol/public API change or package/TFM update.Provenance and release adaptation
b6b909cc62c8544d0e2b80209b603e39e482014e.rel/4.5,e8db9f8d499b4d675fe176187ee483f8ffdd2b9d.234c67c7f5f19b02825339def55ebe8771562488; treecdfa8dde8ad8c84fc917740c1a6f43e81e66f9c4matches the staged tree actually validated before committing.4AD6FD6C0729F6E396930FD83DC13DFC22FFF888F797920C993C4D8048483919.Ported the applicable production/readme, result-file consumers, TRX expectations and linked server-test helpers. Release lacks
MSTestTestFrameworkContinuationTests.cs, so the three attachment-specific lifecycle cases are adapted intoMSTestResultFilesTests.csusing its existing TestContainer/AwesomeAssertions conventions; unrelated continuation cases were not imported. Release also lacks the main-only F# module test file, which is omitted.Seven changed files: adapter implementation/readme, lifecycle coverage,
ResultFileTests, existingTrxReportTests, and the two linked server-test helper files. Preserve UTF-8 BOMs and existing scheduling: TestContainer is sequential; acceptance remains MethodLevel, 32 workers. Consumers share only prebuilt immutable assets; each run gets GUID-owned result/source paths and child-process environment values.Actual release validation
These are executions on this release tree, not borrowed source-PR results. Pinned SDK:
12.0.100-alpha.1.26480.103. Packed families: MSTest4.5.3-dev, MTP2.5.3-dev. Lifecycle host:net8.0; outer acceptance host:net11.0; executed inner consumers:net10.0,net8.0,net462.Initial green and final restored green each passed 3/3 lifecycle, 20/20 packed-consumer, 9/9 related cases, exits 0, no skips. Source-derived exact names/data rows were reconciled with independent discovery. The canonical
verify_execution.pygate confirmed fresh TRXs, exact identities/counts and exits separately for all three final selections. The helper was extracted into session artifacts from the source commit (blob3b5e3831555cc756dd9d3ff812cfd3c6f7e9abe2), not added to this release PR.In every green/red/final variant, generated consumers used a different fresh run-owned NuGet cache. Recorded
project.assets.json, generated imports and actual host paths; all 12 adapter/framework/MTP/TRX binary/package pairs across the three inner TFMs matched the respective shipping package entries byte-for-byte. The final adapter payloads also matched initial green and differed from red. FinalMSTest.TestAdapter.4.5.3-dev.nupkgSHA-256:C91DAD4F7C11BA45DE20E5A78B1FD7822FB7429AFD4E019727BD1E650F78852D.Exact build and execution commands
Commands ran at the worktree root.
$proofdenotes the session-owned evidence directory;$phasewasgreen,redorfinal. Build caches and CLI home were under this worktree'sartifacts\backport-cache. Execution retained generated assets withMicrosoft_Testing_TestInfrastructure_TempDirectory_Cleanup=0, enabledDOTNET_CLI_CONTEXT_VERBOSE=1, and used the repo-local.dotnetonPATH/DOTNET_ROOT; generated-consumer caches remained independently randomized by the existing fixture.The temporary solution contains only the 41 release source projects and is ignored/uncommitted:
All exited 0. Source build/pack: 0 warnings/errors, all release TFMs including classic UWP; repository package-content/metadata validation passed.
The changed adapter was independently repacked for red and final; each following command exited 0, with 0 warnings/errors and package validation intact:
Initial green used the same two build commands without
--no-restore; both exited 0, 0 warnings/errors.Discovery exited 0, finding exactly 3/20/9 source-planned identities. Green/final execution outcomes are above; red outcomes are below. The related selection ran in green/final only. Each CLI consumer actually invokes native
dotnet test --test-modules <module> --root-directory <built-host-directory> --results-directory <absolute-or-relative-results> --no-ansi --progress off, with/without TRX, and asserts both exact advertised test-name/path/content associations after process exit. JSON-RPC awaits shutdown and server exit 0 before checking the two distinct passed identities and attachment bytes.Test-value evidence
The task-owned, sequential counterfactual retained identical tests/assertions and the final output layout, but removed the successful-copy flag/write/cleanup guard to restore premature deletion. It is a targeted counterfactual, not an execution of an untouched base revision. Counterfactual patch SHA-256:
68FBDC073E4840A5C0DAF381381C77D79B3E722C1507C89E2A3D50F519BCDCD7. It was separately repacked, rebuilt and verified before execution; correct production/test bytes were restored before the final pack/rerun.PublishedResultFilesSurviveFrameworkAndServiceDisposal;DisposalPreservesOpenPublishedAttachmentsWithoutWarningsFailedResultFileCopiesRemainEligibleForCleanupDotnetTest_PublishedResultFiles_SurviveProcessExit(12 short-path rows);JsonRpc_PublishedResultFiles_SurviveProcessExit(6 rows)Trx_AbortedRun_PreservesRecoveredResultFilesFirstAttachmentidentity/content; intentional parent exit 7 and child abort 3.("net462",False,True,True)TrxReport_ResultFilesUnderTestResultsDirectory_SurviveDeploymentCleanup,TrxReport_MissingResultFile_PreservesWarningAndSkipsResultFile,ServerModeTests.DiscoverAndRun(3 TFMs each)Red totals: 3 lifecycle executed, 2 intended failures + 1 preservation pass; 20 consumers executed, 19 intended failures + 1 compatibility pass; outer exits 2, no skips. Representative red assertion:
Published attachment for 'FirstAttachment' must remain readable after host exit ... actual: false. Build/restore/launch failures and zero-test runs are not counted as red proof.Local evidence retains phase-specific
unit.trx,acceptance.trx,related.trx, binlogs, package/source hashes, exact expected-name plans and consumer provenance JSON. These local artifacts were not uploaded; commands, identities/counts and assertion excerpts here are the public evidence.Setup failures resolved before behavioral proof
These exited 1, were not red evidence, and did not require weakening release source or package verification:
The supported desktop-MSBuild commands above resolved all four setup failures and preserved all release package payloads.
Exclusions and remaining gaps
Do not include #12236 (independent backport #12246), unmerged #12237/#12241, or optional UWP #12238. Main-only F# and unrelated continuation coverage are intentionally absent. No full test suite was run. UWP/WinUI payloads were built/packed, but app activation, Linux/macOS, source-generated runtime variants, Visual Studio UI and live external report publishing were not exercised. JSON-RPC validates the IDE protocol boundary, not the IDE UI. No source-PR/main-branch execution is claimed as release proof. Remote CI is not awaited; merge, auto-merge and Agent merge are not enabled.