Skip to content

[rel/4.5] Preserve MSTest result attachments after host shutdown - #12247

Merged
Amaury Levé (Evangelink) merged 1 commit into
rel/4.5from
evangelink-4-5-attachment-backport
Nov 6, 2026
Merged

Amaury Levé (Evangelink) merged 1 commit into
rel/4.5from
evangelink-4-5-attachment-backport

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

Backport #12239 to rel/4.5 for 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

  • Merged source: Preserve MSTest result attachments after host shutdown #12239, b6b909cc62c8544d0e2b80209b603e39e482014e.
  • Verified live destination and parent: rel/4.5, e8db9f8d499b4d675fe176187ee483f8ffdd2b9d.
  • Backport head: 234c67c7f5f19b02825339def55ebe8771562488; tree cdfa8dde8ad8c84fc917740c1a6f43e81e66f9c4 matches the staged tree actually validated before committing.
  • Validated patch SHA-256: 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 into MSTestResultFilesTests.cs using 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, existing TrxReportTests, 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: MSTest 4.5.3-dev, MTP 2.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.py gate 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 (blob 3b5e3831555cc756dd9d3ff812cfd3c6f7e9abe2), 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. Final MSTest.TestAdapter.4.5.3-dev.nupkg SHA-256: C91DAD4F7C11BA45DE20E5A78B1FD7822FB7429AFD4E019727BD1E650F78852D.

Exact build and execution commands

Commands ran at the worktree root. $proof denotes the session-owned evidence directory; $phase was green, red or final. Build caches and CLI home were under this worktree's artifacts\backport-cache. Execution retained generated assets with Microsoft_Testing_TestInfrastructure_TempDirectory_Cleanup=0, enabled DOTNET_CLI_CONTEXT_VERBOSE=1, and used the repo-local .dotnet on PATH/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:

$solutionDirectory = Join-Path (Get-Location) 'artifacts\backport-build'
$projects = @(Get-ChildItem src -Filter *.csproj -Recurse | ForEach-Object { $_.FullName })
& .\.dotnet\dotnet.exe new sln --name AttachmentBackport --output $solutionDirectory --format slnx --force
& .\.dotnet\dotnet.exe sln "$solutionDirectory\AttachmentBackport.slnx" add @projects
powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine vs -projects artifacts\backport-build\AttachmentBackport.slnx /m:4

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:

powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine vs -projects src\Adapter\MSTest.TestAdapter\MSTest.TestAdapter.csproj /m:4
.\.dotnet\dotnet.exe build test\UnitTests\MSTestAdapter.UnitTests\MSTestAdapter.UnitTests.csproj -c Release --no-restore -f net8.0 -m:4 -nr:false "-bl:$proof\$phase-unit-build.binlog"
.\.dotnet\dotnet.exe build test\IntegrationTests\MSTest.Acceptance.IntegrationTests\MSTest.Acceptance.IntegrationTests.csproj -c Release --no-restore -m:4 -nr:false "-bl:$proof\$phase-acceptance-build.binlog"

Initial green used the same two build commands without --no-restore; both exited 0, 0 warnings/errors.

$unit = 'artifacts\bin\MSTestAdapter.UnitTests\Release\net8.0\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.dll'
$acceptance = 'artifacts\bin\MSTest.Acceptance.IntegrationTests\Release\net11.0\MSTest.Acceptance.IntegrationTests.dll'
$relatedFilter = 'FullyQualifiedName~TrxReportTests.TrxReport_ResultFilesUnderTestResultsDirectory_SurviveDeploymentCleanup|FullyQualifiedName~TrxReportTests.TrxReport_MissingResultFile_PreservesWarningAndSkipsResultFile|FullyQualifiedName~ServerModeTests.DiscoverAndRun'

.\.dotnet\dotnet.exe $unit --list-tests --treenode-filter '/*/*/MSTestResultFilesTests/*' --no-ansi --progress off
.\.dotnet\dotnet.exe $acceptance --list-tests --filter 'FullyQualifiedName~ResultFileTests' --no-ansi --progress off
.\.dotnet\dotnet.exe $acceptance --list-tests --filter $relatedFilter --no-ansi --progress off

.\.dotnet\dotnet.exe $unit --treenode-filter '/*/*/MSTestResultFilesTests/*' --report-trx --report-trx-filename unit.trx --results-directory "$proof\$phase-unit-results" --no-ansi --progress off
.\.dotnet\dotnet.exe $acceptance --filter 'FullyQualifiedName~ResultFileTests' --report-trx --report-trx-filename acceptance.trx --results-directory "$proof\$phase-consumers-results" --no-ansi --progress off --show-test-results all
.\.dotnet\dotnet.exe $acceptance --filter $relatedFilter --report-trx --report-trx-filename related.trx --results-directory "$proof\$phase-related-results" --no-ansi --progress off --show-test-results all

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.

Contract / exact case family Without retention Correct release implementation
PublishedResultFilesSurviveFrameworkAndServiceDisposal; DisposalPreservesOpenPublishedAttachmentsWithoutWarnings Executed: 2 intended assertion failures (advertised file deleted; spurious locked-file cleanup warning). Executed: both pass; mixed success/missing ordering, original bytes, repeated framework/service disposal and open-file retention checked.
FailedResultFileCopiesRemainEligibleForCleanup Executed: passed. Executed: passed; fallback path and cleanup warning/retry/idempotence preserved.
DotnetTest_PublishedResultFiles_SurviveProcessExit (12 short-path rows); JsonRpc_PublishedResultFiles_SurviveProcessExit (6 rows) Executed: all 18 fail at the intended post-exit advertised-file existence assertion, after successful child execution/shutdown. Executed: all 18 pass, including duplicate basenames, exact name/content association, absolute/relative result paths and original preservation.
Trx_AbortedRun_PreservesRecoveredResultFiles Executed: fails on the attachment-skipped warning after recovering one completed result. Executed: passes with recovered FirstAttachment identity/content; intentional parent exit 7 and child abort 3.
CLI long-path row ("net462",False,True,True) Executed: passed because legacy recursive deletion cannot remove the overlong leaf. Executed: passed; source below MAX_PATH and published copy above it. Compatibility coverage only, not retention-sensitivity proof.
Existing TrxReport_ResultFilesUnderTestResultsDirectory_SurviveDeploymentCleanup, TrxReport_MissingResultFile_PreservesWarningAndSkipsResultFile, ServerModeTests.DiscoverAndRun (3 TFMs each) Separate related group not run in red. Executed: all 9 pass, preserving deployment cleanup, missing-file diagnostics and default server-helper behavior.

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:

# $projects joined with ';': MSB1006, unquoted property separators.
powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine dotnet -projects $projects /p:SkipUapTargetFramework=true /m:4
# $projects joined with '%3B': MSB3202, interpreted as one project path.
powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine dotnet "/p:Projects=$projects" /p:SkipUapTargetFramework=true /m:4
# Solution outside the repo: MSB4236, resolver cannot find global.json SDK versions.
powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine dotnet -projects "$proof\AttachmentBackport.slnx" /p:SkipUapTargetFramework=true /m:4
# Omitting classic UWP compiles but correctly fails package-content validation.
powershell -NoProfile -ExecutionPolicy Bypass -File eng\build.ps1 -restore -build -pack -c Release -bl -msbuildEngine dotnet -projects artifacts\backport-build\AttachmentBackport.slnx /p:SkipUapTargetFramework=true /m:4

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.

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>
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Nov 6, 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.

🧪 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

GradeTestMutationNotesHow to improve
B (80–89) new MSTestResultFilesTests.
FailedResultFileCopiesRemainEligibleForCleanup
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.
PublishedResultFilesSurviveFrameworkAndServiceDisposal
N/A Staging, content, missing-file and double-dispose behavior are all asserted. —
A (90–100) new MSTestResultFilesTests.
DisposalPreservesOpenPublishedAttachmentsWithoutWarnings
N/A Open-handle disposal, no warnings and byte preservation are all asserted. —
A (90–100) new ResultFileTests.
DotnetTest_
PublishedResultFiles_
SurviveProcessExit
N/A Exit code, counts, published paths, originals and TRX contents are all checked. —
A (90–100) new ResultFileTests.
JsonRpc_
PublishedResultFiles_
SurviveProcessExit
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 · ◷

@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 Nov 6, 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 Nov 6, 2026
@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 Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit ddfdb3a into rel/4.5 Nov 6, 2026
33 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the evangelink-4-5-attachment-backport branch November 6, 2026 14:42
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Nov 6, 2026
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.

2 participants