Skip to content

Fix CodeScene CLI install and preserve line records in coverage exports - #333

Merged
leynos merged 3 commits into
mainfrom
fix-summary-only-coverage
Jul 9, 2026
Merged

Fix CodeScene CLI install and preserve line records in coverage exports#333
leynos merged 3 commits into
mainfrom
fix-summary-only-coverage

Conversation

@leynos

@leynos leynos commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

This branch fixes two coverage defects surfaced by review feedback on
leynos/mxd#362.

First, upload-codescene-coverage is currently broken for every
consumer: it extracted the CLI version by grepping a version="x.y.z"
literal from the downloaded installer script, but CodeScene rewrote the
installer to take the version as its first positional argument
(version="${1:-latest}"). The grep now matches nothing and, under
pipefail, the "Download installer" step exits 1 before any upload
happens. A new cli-version input (default latest) is passed to the
installer via environment indirection; the CLI cache participates only
when a concrete version is pinned, so latest always fetches fresh and
can never be frozen by a stale cache entry.

Second, generate-coverage passed --summary-only to cargo llvm-cov
unconditionally. cargo-llvm-cov documents that this exports only
summary information, so LCOV files lacked DA line-hit records and
Cobertura files lacked <line> elements — changed-line coverage gates
(CodeScene's PR gate among them) had nothing to evaluate even when the
upload succeeded. The flag is now omitted for the file formats and kept
for streamed formats, whose stdout must remain parseable. Reported
percentages are unaffected: for lcov and cobertura the percentage
is computed from the report file, not stdout.

Review walkthrough

Validation

  • make test: 997 passed, 14 skipped.
  • Local reproduction of the installer breakage: downloading
    install-cs-coverage-tool.sh and running the removed grep exits 1
    (no version="…" literal exists in the current script).

Two defects surfaced while wiring coverage upload in leynos/mxd#362:

- `upload-codescene-coverage` extracted the CLI version by grepping a
  `version="x.y.z"` literal out of the downloaded installer script.
  CodeScene rewrote the installer to take the version as its first
  positional argument (`version="${1:-latest}"`), so the grep matches
  nothing and, under `pipefail`, every upload now fails at the
  "Download installer" step. Replace the extraction with a
  `cli-version` input (default `latest`) passed to the installer; the
  CLI cache participates only when a concrete version is pinned so
  `latest` can never be frozen by a stale cache entry.

- `generate-coverage` passed `--summary-only` to `cargo llvm-cov`
  unconditionally. For file outputs this strips per-line execution
  records (LCOV `DA` lines, Cobertura `<line>` elements), leaving
  changed-line coverage gates such as CodeScene's with nothing to
  evaluate. Omit the flag for `lcov` and `cobertura`; streamed formats
  keep it so stdout remains parseable. The reported percentage is
  unaffected because file formats compute it from the report itself.

@sourcery-ai sourcery-ai Bot 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.

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 44 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3b8166c5-da1e-4503-9efc-59f7601571cb

📥 Commits

Reviewing files that changed from the base of the PR and between d28e04c and 0d4ef30.

📒 Files selected for processing (6)
  • .github/actions/generate-coverage/CHANGELOG.md
  • .github/actions/generate-coverage/scripts/run_rust.py
  • .github/actions/generate-coverage/tests/test_scripts.py
  • .github/actions/upload-codescene-coverage/CHANGELOG.md
  • .github/actions/upload-codescene-coverage/README.md
  • .github/actions/upload-codescene-coverage/action.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-summary-only-coverage

Comment @coderabbitai help to get the list of available commands.

codescene-access[bot]

This comment was marked as outdated.

@leynos

leynos commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph.

If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced.

.github/actions/generate-coverage/tests/test_scripts.py

Comment on file

        "--manifest-path",
        "Cargo.toml",
        "--workspace",
        "--summary-only",

❌ Getting worse: Code Duplication
introduced similar code in: test_get_cargo_coverage_cmd_keeps_summary_only_for_stream_formats,test_get_cargo_coverage_cmd_omits_summary_only_for_cobertura

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4af2e69196

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/actions/upload-codescene-coverage/action.yml
@coderabbitai

This comment was marked as resolved.

Merge the two single-case tests into
`test_get_cargo_coverage_cmd_summary_only_by_format`, parametrised
over (output_format, out_name, expect_summary_only), matching the
parametrize style already used in this module.
Comment thread .github/actions/generate-coverage/tests/test_scripts.py
codescene-access[bot]

This comment was marked as outdated.

Ruff FBT001 forbids boolean positional parameters; pytest passes
parametrised arguments by name, so the keyword-only marker costs
nothing.
@leynos
leynos merged commit 158d04f into main Jul 9, 2026
27 checks passed
@leynos
leynos deleted the fix-summary-only-coverage branch July 9, 2026 10:51
leynos pushed a commit to leynos/mxd that referenced this pull request Jul 9, 2026
Pick up leynos/shared-actions#333: `generate-coverage` now preserves
per-line records in lcov output, and `upload-codescene-coverage`
survives the rewritten CodeScene installer by passing the CLI version
as an argument. The `setup-rust` pins are unchanged.
leynos added a commit to leynos/mxd that referenced this pull request Jul 9, 2026
* Upload coverage to CodeScene from the coverage job

The CodeScene app posts a "Code Coverage" check on every pull request
head and waits for a coverage upload for that commit. The coverage job
generated and merged `lcov.info` but never uploaded it, so the check
timed out on every pull request, driving the status-check rollup to
FAILURE and jamming Dependabot automerge (PRs #343 and #341 sat
BLOCKED with all required checks green).

Switch coverage generation to the shared
`leynos/shared-actions` `generate-coverage` action (pinned to the
same revision the workflow already uses for `setup-rust`, with
`use-cargo-nextest: 'false'` to preserve the existing plain
`cargo llvm-cov` runs) and add the shared
`upload-codescene-coverage` step, guarded so runs without the
`CS_ACCESS_TOKEN` secret skip the upload rather than fail. The
now-unused local `generate-coverage` action is removed.

`CS_ACCESS_TOKEN` is configured as both an Actions secret and a
Dependabot secret so Dependabot-triggered runs can also upload.

* Upload coverage from the pull-request head checkout

CodeScene records each upload against the commit checked out when the
CLI runs, and its pull-request check waits for coverage keyed to the
head SHA. The coverage job previously checked out the default
`refs/pull/<n>/merge` ref, so uploads were keyed to the synthetic
merge commit and the head check could still time out. Check out
`github.event.pull_request.head.sha` in the coverage job instead.

* Pin the coverage actions to shared-actions 158d04f

Pick up leynos/shared-actions#333: `generate-coverage` now preserves
per-line records in lcov output, and `upload-codescene-coverage`
survives the rewritten CodeScene installer by passing the CLI version
as an argument. The `setup-rust` pins are unchanged.

* Drive the CodeScene PR gate with cs-coverage check

CodeScene accepts `cs-coverage upload` only for analysed branches
(main), so the previous upload step could never satisfy the
pull-request "Code Coverage" check. Switch the step to the shared
action's new `mode: check` (shared-actions#334), which runs
`cs-coverage check` against project 68298 to evaluate changed-line
coverage. The check diffs the PR against its merge base, so the
coverage job now checks out with `fetch-depth: 0` on the default
merge ref, matching CodeScene's documented example; the head-SHA
checkout from 574325e is superseded.

* Upload main-branch coverage and ratchet the sqlite leg

Add `coverage-main.yml`, triggered only by pushes to `main`: it
regenerates and merges the same coverage as the pull-request job and
uploads it with `cs-coverage upload`, which CodeScene accepts solely
for analysed branches. This populates the project dashboard and gives
analyses coverage for the analysed commit.

Enable the coverage ratchet (`with-ratchet`) on the sqlite
`generate-coverage` invocation in both workflows. The main run saves
the authoritative baseline — caches created on `main` are readable by
every pull-request run — while PR runs compare against it and fail if
line coverage drops. The ratchet supports one baseline per job, so
the sqlite leg (the default feature set and broadest suite) carries
it; the postgres leg remains unratcheted.

* Run coverage and Makefile tests under nextest

Drop the `use-cargo-nextest: 'false'` overrides so the shared
`generate-coverage` action runs `cargo llvm-cov nextest` in both the
pull-request and main coverage workflows, and adopt the
agent-template-rust Makefile convention: a `TEST_CMD` variable that
prefers nextest when installed and falls back to `cargo test`.

nextest does not execute doctests, so add a `test-doc` target (run
under the default sqlite backend) to the `test` aggregate. The suite
had never run these doctests before; all five pass.

* Pin third-party actions in the main coverage workflow

Pin `taiki-e/install-action` and `oven-sh/setup-bun` to commit hashes,
resolving the CodeQL unpinned-action findings on the new workflow. The
equivalent references in ci.yml predate this branch and are left for a
separate pinning pass.

---------

Co-authored-by: leynos <leynos@rohga>
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.

1 participant