Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Azure DevOps cannot display cargo test results without conversion to a supported format (JUnit, TRX, etc.). This PR implements test results reporting using nightly Rust's native JSON test output and cargo2junit.

Changes

Test-Packages.ps1

  • Added -CI switch that captures test output using cargo +nightly test -- --format json -Z unstable-options
  • Saves JSON output to uniquely timestamped files in test-results/ directory
  • Parses JSON to display pass/fail/ignored counts and failed test names
  • Maintains backward compatibility (original behavior when -CI omitted)

Convert-TestResultsToJUnit.ps1 (new)

  • Converts JSON test output to JUnit XML using cargo2junit tool
  • Automatically installs cargo2junit if not present
  • Processes all JSON files and outputs to test-results/junit/ directory

TEST-RESULTS-README.md (new)

  • Complete documentation with usage instructions
  • Pipeline integration examples
  • Troubleshooting guide

Pipeline Integration

- task: Powershell@2
  displayName: "Test Packages"
  inputs:
    filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Packages.ps1
    arguments: -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -CI

- task: Powershell@2
  displayName: "Convert Test Results to JUnit XML"
  condition: succeededOrFailed()
  inputs:
    filePath: $(Build.SourcesDirectory)/eng/scripts/Convert-TestResultsToJUnit.ps1

- task: PublishTestResults@2
  condition: succeededOrFailed()
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/test-results/junit/*.xml'

Implementation Approach

This implementation uses:

  • Nightly Rust's native JSON test output: cargo +nightly test -- --format json -Z unstable-options
  • cargo2junit: Purpose-built tool for converting Rust test JSON to JUnit XML

This approach is simpler and more reliable than custom parsing, leveraging Rust's built-in test output format and standard conversion tools.

Requirements

  • Nightly Rust toolchain (automatically used via cargo +nightly)
  • cargo2junit (automatically installed if needed)

Pipeline YAML updates in ci.tests.yml and live.tests.yml pending.

Original prompt

This section details on the original issue you should resolve

<issue_title>Test results should be reported in DevOps</issue_title>
<issue_description>PublishTestResults accepts JUnit and other test result formats https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/publish-test-results-v2?view=azure-pipelines&tabs=trx%2Ctrxattachments%2Cyaml

There should be a way to convert test results from cargo test to one of the accepted formats. A possible approach would be cargo2junit https://docs.rs/crate/cargo2junit/latest</issue_description>

<agent_instructions>Add logic to Test-Packages.ps1 that will, instead of using Invoke-LoggedCommand, call the command directly and write the output to a JSON file. Read the JSON file and output a somewhat human readable summary of failed tests and a summary at the end of total tests run. If there is an error then also output that additional details are available in the test tab for the build. Use a unique file name per run. And only behave this way if we're in CI (as controlled by a switch param)... if running locally just output in human format.

Then in a separate .ps1 file in the scripts repo convert the JSON to junit using cargo2junit before uploading the results using the PublishTestResults task.

Enumerate other possible ways that this output work can be done. Is it possible to have cargo test output results to some --target-dir and will that have the assets we need so that we don't have to force it to not be human readable? </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add logic to report test results in DevOps Add test results reporting for Azure DevOps pipelines Nov 11, 2025
Copilot AI requested a review from danieljurek November 11, 2025 23:32
Copilot finished work on behalf of danieljurek November 11, 2025 23:32
@danieljurek
Copy link
Member

It's OK to use unstable features for cargo test. Revert most of these changes and start from enabling unstable features, having cargo test output with --format json, use cargo2junit to convert the test output, and publish that data to DevOps.

@danieljurek
Copy link
Member

@copilot -- Try again. It's OK to use unstable features for cargo test. Revert most of these changes and start from enabling unstable features, having cargo test output with --format json, use cargo2junit to convert the test output, and publish that data to DevOps.

Copy link
Contributor Author

Copilot AI commented Nov 13, 2025

@copilot -- Try again. It's OK to use unstable features for cargo test. Revert most of these changes and start from enabling unstable features, having cargo test output with --format json, use cargo2j...

Reverted the implementation to use nightly Rust with --format json and cargo2junit as requested.

The changes now:

  • Use cargo +nightly test -- --format json -Z unstable-options to capture JSON test output
  • Leverage cargo2junit to convert JSON to JUnit XML
  • Much simpler approach with only ~200 lines of code vs previous 1000+
  • Test-Packages.ps1 captures JSON when -CI flag is used
  • Convert-TestResultsToJUnit.ps1 handles conversion using cargo2junit

Commit: daf7663

Copilot finished work on behalf of danieljurek November 13, 2025 20:54
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.

Test results should be reported in DevOps

2 participants