Skip to content

Add code coverage + HTML report machinery - #19692

Open
woodruffw wants to merge 5 commits into
mainfrom
ww/cov
Open

woodruffw wants to merge 5 commits into
mainfrom
ww/cov

Conversation

@woodruffw

@woodruffw woodruffw commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

This adds a new cargo dev coverage subcommand, which invokes nextest under our new coverage pesudo-profile. This profile in turn enables -C instrument-coverage.

cargo dev coverage also takes care of merging raw profiling samples into profdata and LCOV reports for us, which our new coverage-html-report.py script can turn into a readable (but very large) HTML report.

The basic flow for this is:

$ # any nextest flags will work
$ cargo dev coverage ...

That will output something like:

Merged profile: .../astral-sh/uv/target/coverage/profdata/b46cc0f3-7cd0-4309-9df2-10ab653e6dd8.profdata
LCOV profile: .../astral-sh/uv/target/coverage/lcov/b46cc0f3-7cd0-4309-9df2-10ab653e6dd8.lcov
Generate an HTML report with: uv run --script scripts/coverage-html-report.py b46cc0f3-7cd0-4309-9df2-10ab653e6dd8

And then you can run:

uv run --script scripts/coverage-html-report.py b46cc0f3-7cd0-4309-9df2-10ab653e6dd8

(or add --open to auto-open in the browser).

Under the hood, this only uses existing dependencies plus Rust's own LLVM toolchain, plus coverage.py for the HTML report generation.

TODOs:

  • Document this in CONTRIBUTING.md
  • Figure out if/how best to surface this in CI -- maybe we want to export combined LCOVs for each test job, similarly to what we do for JUnit test summaries?

Test Plan

Internal only.

@woodruffw woodruffw self-assigned this Jun 5, 2026
@woodruffw woodruffw added the internal A refactor or improvement that is not user-facing label Jun 5, 2026
@woodruffw

Copy link
Copy Markdown
Member Author

Example from running cargo dev coverage -p uv-audit:

image

@woodruffw
woodruffw requested a review from Gankra June 5, 2026 19:12
@woodruffw woodruffw added the coverage Perform a dedicated coverage-instrumented test run label Jun 5, 2026
Comment thread .github/workflows/coverage.yml Resolved
Comment thread crates/uv-dev/src/coverage.rs Resolved
@codspeed

codspeed Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing ww/cov (316e053) with main (9f58086)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@woodruffw

Copy link
Copy Markdown
Member Author

Noting: the reason I'm currently gating this behind a label is because it makes tests in CI more than twice as slow.

Comment thread .github/workflows/test.yml Resolved
Comment thread .github/workflows/test.yml Resolved
@woodruffw
woodruffw force-pushed the ww/cov branch 4 times, most recently from f310af7 to 226b0e5 Compare June 12, 2026 14:26
@woodruffw
woodruffw marked this pull request as ready for review June 12, 2026 14:42
Comment thread .cargo/coverage.toml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/coverage.yml Resolved
Comment thread .github/workflows/test.yml Resolved
Comment thread .github/workflows/test.yml Resolved
Comment thread .github/workflows/test.yml Resolved
Comment thread crates/uv-dev/src/main.rs Resolved
@woodruffw

Copy link
Copy Markdown
Member Author

NB: I'm going to clean this up and change it to just run on main.

@woodruffw

Copy link
Copy Markdown
Member Author

NB: I've refactored this quite a bit, to avoid putting the coverage performance hit on the happy CI path. What we do now:

  1. We run separate coverage-instrumented builds (and tests) after each push to main.
  2. We can also manually dispatch coverage runs with a workflow_dispatch.

(1) in particular means we won't slow down our normal CI runs.


- name: "Upload pending snapshots"
if: ${{ failure() }}
if: ${{ failure() && !inputs.collect-coverage }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: no point in doing this work for coverage.


- name: "Upload JUnit results"
if: always()
if: ${{ always() && !inputs.collect-coverage }}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no point in uploading JUnit results for coverage.

Comment thread .github/workflows/test.yml Resolved
This adds a new `cargo dev coverage` subcommand, which invokes nextest
under our new coverage pesudo-profile. This profile in turn enables
`-C instrument-coverage`.

`cargo dev coverage` also takes care of merging raw profiling
samples into profdata and LCOV reports for us, which our
new `coverage-html-report.py` script can turn into a readable
(but very large) HTML report.

The basic flow for this is:

```
$ # any nextest flags will work
$ cargo dev coverage ...
```

That will output something like:

```
Merged profile: .../astral-sh/uv/target/coverage/profdata/b46cc0f3-7cd0-4309-9df2-10ab653e6dd8.profdata
LCOV profile: .../astral-sh/uv/target/coverage/lcov/b46cc0f3-7cd0-4309-9df2-10ab653e6dd8.lcov
Generate an HTML report with: uv run --script scripts/coverage-html-report.py b46cc0f3-7cd0-4309-9df2-10ab653e6dd8
```

And then you can run:

```
uv run --script scripts/coverage-html-report.py b46cc0f3-7cd0-4309-9df2-10ab653e6dd8
```

(or add `--open` to auto-open in the browser).

Under the hood, this only uses existing dependencies plus
Rust's own LLVM toolchain, plus coverage.py for the HTML
report generation.

Signed-off-by: William Woodruff <[email protected]>

MVP coverage workflow

Signed-off-by: William Woodruff <[email protected]>

MVP coverage workflow, take 2

Signed-off-by: William Woodruff <[email protected]>

Use a pool of 16 raw profiles for pooling

Signed-off-by: William Woodruff <[email protected]>

Avoid some Windows UNC pain

Signed-off-by: William Woodruff <[email protected]>

Fix rustflags for coverage on Windows

Signed-off-by: William Woodruff <[email protected]>

Remove coverage ID chum

Signed-off-by: William Woodruff <[email protected]>

Avoid Windows nonsense

Signed-off-by: William Woodruff <[email protected]>

Add coverage guide to CONTRIBUTING

Signed-off-by: William Woodruff <[email protected]>

Be less strict about the ID

Signed-off-by: William Woodruff <[email protected]>

Prettier

Signed-off-by: William Woodruff <[email protected]>

Use plan job to determine coverage run

Signed-off-by: William Woodruff <[email protected]>

Remove coverage.yml

Signed-off-by: William Woodruff <[email protected]>

Remove test-only changes

Signed-off-by: William Woodruff <[email protected]>

Run macos tests if we're collecting coverage

Signed-off-by: William Woodruff <[email protected]>

Make pool size a property of concurrency

Signed-off-by: William Woodruff <[email protected]>

Only instrument workspace members

Signed-off-by: William Woodruff <[email protected]>

Use single-argument form

Signed-off-by: William Woodruff <[email protected]>

Add a lockfile

Signed-off-by: William Woodruff <[email protected]>

Remove exclude-newer

Signed-off-by: William Woodruff <[email protected]>

Limit coverage to main pushes

Signed-off-by: William Woodruff <[email protected]>

Simplify

Signed-off-by: William Woodruff <[email protected]>

Refactor coverage dispatch

Signed-off-by: William Woodruff <[email protected]>

Avoid pruning weirdness

Signed-off-by: William Woodruff <[email protected]>

Try to generate the HTML report in CI

Signed-off-by: William Woodruff <[email protected]>

Normalize source paths

Signed-off-by: William Woodruff <[email protected]>

Avoid -Zpanic-abort-tests on Windows during cov

Signed-off-by: William Woodruff <[email protected]>

Remove intermediate HTML builds

Signed-off-by: William Woodruff <[email protected]>

Don't use `-Z panic-abort-tests` for any coverage builds

Signed-off-by: William Woodruff <[email protected]>

Emit combined LCOV too

Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>
Signed-off-by: William Woodruff <[email protected]>

This branch was previously deployed

1 inactive (outdated) deployment
automations — 316e0538 Deployed Aug 13, 2026 by woodruffw via review / security review #44617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage Perform a dedicated coverage-instrumented test run internal A refactor or improvement that is not user-facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants