Skip to content

[MTP Reporters Analysis] TrxReport lets one bad attachment abort the whole TRX #8415

@Evangelink

Description

@Evangelink

Summary

A single missing or inaccessible attachment can abort the entire TRX generation path. The reporter currently treats attachment copy failures as fatal instead of skipping the bad attachment and still producing the TRX.

Evidence

  • Per-test attachments are copied during report generation in src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Results.cs:160-170
    foreach (TrxTestFileArtifact testFileArtifact in testResult.FileArtifacts)
    {
        resultFiles ??= new XElement("ResultFiles");
    
        string href = CopyArtifactIntoTrxDirectoryAndReturnHrefValue(new FileInfo(testFileArtifact.FullPath), runDeploymentRoot, executionId);
        resultFiles.Add(new XElement(
            "ResultFile",
            new XAttribute("path", href)));
    }
  • The copy helper performs an unchecked copy in src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.Artifacts.cs:83-85
    _fileSystem.CopyFile(artifact.FullName, new FileInfo(destination).FullName);
    
    return Path.Combine(_environment.MachineName, Path.GetFileName(destination));
  • The session-finish path awaits report generation directly in src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxDataConsumer.cs:223-223
    (string reportFileName, string? warning) = await GenerateReportAndCleanupAsync(trxReportGeneratorEngine, cancellationToken).ConfigureAwait(false);
    and GenerateReportAndCleanupAsync just forwards engine.GenerateReportAsync(...) (TrxDataConsumer.cs:337-340).

Why this is a real issue

If a test attaches a temp file and deletes it before session end, or if a copy hits UnauthorizedAccessException / IOException, that exception bubbles out of TRX generation. The result is that one bad attachment can prevent the run from producing any TRX file, even though the rest of the test results are valid.

Suggested resolution

Handle attachment copy failures per artifact:

  • catch copy/open exceptions around the individual attachment,
  • emit a warning / RunInfo entry describing the skipped artifact,
  • continue generating the TRX for the rest of the run.

Related issues

  • none found

Metadata

Metadata

Labels

area/mtp-extensionsMTP extensions (TrxReport, Retry, HtmlReport, ...).area/trxTRX report extension.type/automationCreated or maintained by an agentic workflow.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions