Skip to content

Copy acceptance test diagnostic logs into the test results directory - #16403

Merged
Jakub Jareš (nohwnd) merged 1 commit into
microsoft:mainfrom
nohwnd:pilot/copy-acceptance-test-diagnostic-logs-int-20260824142117
Aug 24, 2026
Merged

Jakub Jareš (nohwnd) merged 1 commit into
microsoft:mainfrom
nohwnd:pilot/copy-acceptance-test-diagnostic-logs-int-20260824142117

Conversation

@nohwnd

Copy link
Copy Markdown
Member

The cleanup already keeps the temp directory when an acceptance test fails, and the pipeline already publishes artifacts/TestResults/<config> when the job fails. Nothing connects the two. TestContext.AddResultFile only records the path it is given, and the diagnostic logs are written under $(Agent.TempDirectory), which is not published and is deleted when the agent is recycled. So the published trx ends up with <ResultFile> entries like D:\a\_work\_temp\vstest\IVpTd\logs\log.datacollector.26-08-24_13-50-25_67394_5.txt that point at nothing.

That is why the CrashDumpOnStackOverflow failure in build 20260824.3 could not be diagnosed. The blame data collector log would have explained it, and it is not in any artifact.

Now the attached files are copied into a per-test directory under the test results directory, and the copies are attached instead. Each test needs a directory of its own because acceptance tests run in parallel and they all write a file called log.txt. Only the log directories that are in _attachments are copied, so crash dumps and extracted packages stay in the temp directory. A file that cannot be copied is logged and skipped, so cleanup never replaces the failure the test reported.

No pipeline change is needed, the existing Publish Test Results folders step picks the files up.

Verified: failed an acceptance test on purpose, the logs landed in artifacts/TestResults/Release/.../attachments/<test name>_<id>/ and the trx <ResultFile> entries pointed at the copies. Unit tests and build.cmd -c Release -pack are green.

🤖

TestContext.AddResultFile only records the path it is given. The diagnostic
logs of an acceptance test are written under the agent temp directory, which
is not published and is deleted when the agent is recycled, so the published
trx points at files that no longer exist.

Copy the attached files into a per-test directory under the test results
directory, and attach the copies. The pipeline already publishes that folder
when the job fails, so no pipeline change is needed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 24, 2026 14:56

Copilot AI 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.

Pull request overview

This PR improves diagnosability of failing acceptance tests by ensuring diagnostic log attachments referenced by TRX results live under the published test results directory (instead of the agent temp directory), so attached paths remain valid in CI artifacts.

Changes:

  • Refactors IntegrationTestBase test cleanup to copy diagnostic attachments into a per-test subdirectory under the test results directory, then attaches the copied files.
  • Introduces AttachmentUtils to sanitize per-test attachment directory names and to enumerate/copy attachment trees in a cleanup-safe (non-throwing) way.
  • Adds acceptance tests validating attachment sanitization and copy semantics (including copying files that are still open for writing).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs Copies attachments into the MSTest results directory on failure and attaches the copied paths so TRX references remain valid in CI artifacts.
test/Microsoft.TestPlatform.TestUtilities/AttachmentUtils.cs New helper for sanitizing per-test attachment directory names and safely enumerating/copying attached files/directories.
test/Microsoft.TestPlatform.Acceptance.IntegrationTests/AttachmentUtilsTests.cs New tests covering sanitize + copy behaviors (directory trees, open files, duplicates, missing attachments).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +49 to +52
// Windows does not allow a name to end with a dot or a space.
var sanitized = builder.ToString().Trim('_', '.', ' ');
return sanitized.Length == 0 ? "test" : sanitized;
}
@nohwnd
Jakub Jareš (nohwnd) enabled auto-merge (squash) August 24, 2026 16:30
@nohwnd
Jakub Jareš (nohwnd) merged commit d6dbc41 into microsoft:main Aug 24, 2026
20 checks passed
This was referenced Oct 13, 2026
This was referenced Oct 14, 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.

3 participants