Skip to content

[MTP Reporters Analysis] HtmlReport rejects path-valued --report-html-filename #8413

Closed

Description

Summary

HtmlReport rejects path-valued --report-html-filename arguments even though the HTML engine already writes through Path.Combine(outputDirectory, fileName). This makes HTML inconsistent with TRX and blocks report-path customization for the HTML reporter.

Evidence

  • src/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlReportGeneratorCommandLine.cs:45-50
    if (!IsValidPureFileName(fileName))
    {
        return ValidationResult.InvalidTask(ExtensionResources.HtmlReportFileNameShouldNotContainPath);
    }
  • src/Platform/Microsoft.Testing.Extensions.HtmlReport/HtmlReportEngine.cs:65-70
    string fileName = fileNameExplicitlyProvided
        ? providedFileName![0]
        : BuildDefaultFileName(finishTime);
    
    string outputDirectory = _configuration.GetTestResultDirectory();
    string finalPath = Path.Combine(outputDirectory, fileName);
  • For comparison, src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCommandLine.cs:45-48 explicitly allows relative or absolute paths for --report-trx-filename.

Why this is a real issue

A command like --report-html --report-html-filename subdir\report.html fails validation today, while the analogous TRX scenario is supported. The HTML engine would already place a relative path under the results directory (and Path.Combine would also honor rooted paths), so the current restriction is a CLI-only inconsistency that blocks a concrete customization scenario.

Suggested resolution

Align --report-html-filename with TRX semantics:

  • allow relative and absolute paths,
  • sanitize/validate only the leaf file name,
  • create missing intermediate directories before writing.

Related issues

Activity

  1. Evangelink commented on May 25, 2026

    @Evangelink
    MemberAuthor

    Resolved by #8523, which aligned --report-html-filename with the TRX semantics: relative and absolute paths are now accepted, only the leaf file name is validated (must end in .html), and missing intermediate directories are created before writing. Verified on main: HtmlReportGeneratorCommandLine.ValidateOptionArgumentsAsync now uses Path.GetFileName + EscapesResultsDirectory (same shape as TrxReportGeneratorCommandLine), and HtmlReportEngine.GenerateReportCoreAsync calls _fileSystem.CreateDirectory for the resolved directory. Microsoft.Testing.Extensions.UnitTests (which contains HtmlReportGeneratorCommandLineTests and HtmlReportEngineTests) passes on net462/net472/net8.0/net9.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions