From 3cd1c90de6d942974c2c632754261df5a117c9c1 Mon Sep 17 00:00:00 2001 From: piquel Date: Wed, 4 Nov 2026 11:41:56 +0100 Subject: [PATCH 1/2] ci: report Rust and TypeScript test coverage The rust job runs its unit and database tests through cargo-llvm-cov with `just coverage`, printing line and function coverage per crate and uploading lcov.info. The TypeScript SDK's tests print Node's coverage. Nothing fails on coverage yet. --- .github/workflows/ci.yml | 21 +++++++++++++++------ README.md | 13 +++++++++---- just/web.just | 3 ++- justfile | 30 ++++++++++++++++++++++++++++-- packages/auth/package.json | 2 +- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d191e4435..52a140f6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,10 +3,11 @@ # # checks -> Rust formatting and the Rust dependency audit, which compile nothing # web -> Prettier, tsc and ESLint, the passkey script included, the -# TypeScript SDK's package checks, tests and runtime smoke in Node, -# Bun and workerd, and the web dependency audit -# rust -> Clippy, unit, database and doc tests against PostgreSQL, and the -# SQLx query cache checked to match the migrated schema exactly +# TypeScript SDK's package checks, tests with coverage and runtime +# smoke in Node, Bun and workerd, and the web dependency audit +# rust -> Clippy, unit and database tests against PostgreSQL with +# coverage, doc tests, and the SQLx query cache checked to match +# the migrated schema exactly # e2e -> the browser suite over HTTPS against the real binary and PostgreSQL, # with the admin dashboard on its own listener and host, and the # binary's CLI granting administrators and recovering accounts @@ -153,7 +154,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 - uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2 with: - tool: just,cargo-nextest + tool: just,cargo-nextest,cargo-llvm-cov - &rust-cache uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2 with: @@ -166,7 +167,15 @@ jobs: # the latest release, until main next saves a cache. - run: just db install-sqlx - run: just rust lint - - run: just test --workspace --run-ignored all + # Every unit and database test, instrumented. Coverage is reported, not + # enforced: per crate in the log, per line in the rust-coverage artifact. + # cargo-llvm-cov adds the llvm-tools-preview component it needs. + - run: just coverage + - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: rust-coverage + path: target/lcov.info + if-no-files-found: error # The database tests migrated TEST_DATABASE_URL, so a migration that # breaks a cached query fails here even if no test runs that query, as # does a cached query the code no longer uses. diff --git a/README.md b/README.md index 9b632bb2c..4c2b29b90 100644 --- a/README.md +++ b/README.md @@ -725,8 +725,9 @@ explains how to choose a requirement and handle the challenge. `just` runs `validate` by default. `just install` installs the web tools, Prettier, ESLint, tsc and Playwright, which need Node 24+ and pnpm (the workspace pins its version). -`just install-tools` installs `cargo-nextest`, `cargo-deny` and `sqlx-cli`. The -`db` recipes also need the PostgreSQL 18 server binaries (`initdb`, `pg_ctl`). +`just install-tools` installs `cargo-nextest`, `cargo-llvm-cov`, `cargo-deny` and +`sqlx-cli`. The `db` recipes and `just coverage` also need the PostgreSQL 18 +server binaries (`initdb`, `pg_ctl`). Recipes are grouped into `rust`, `web`, `db`, `auth` and `infra` modules under `just/`; `just --list --list-submodules` shows every recipe. The root `fmt`, `fmt-check`, `lint`, `check` and `audit` run the same recipe in `rust` and `web`. @@ -740,9 +741,10 @@ Use individual recipes while iterating: | Clippy and ESLint, warnings denied; `publint` and `attw` on the built TypeScript SDK | `just lint` (`just rust lint` / `just web lint`) | | Regenerate the SDK vectors / the TypeScript SDK's wire types | `just sdk-vectors` / `just sdk-types` | | Unit tests / focused package tests | `just test` / `just test -p auth-service` | -| TypeScript SDK tests, the shared vectors included / the built SDK in Node, Bun and workerd | `just web test` / `just web smoke` | +| TypeScript SDK tests with coverage, the shared vectors included / the built SDK in Node, Bun and workerd | `just web test` / `just web smoke` | | Documentation tests | `just doc-test` | | Database integration tests and query cache check, in a scratch cluster | `just db test` | +| Rust coverage per crate over every test, database tests included, in a scratch cluster; `target/lcov.info` | `just coverage` | | Query cache check alone, against a migrated `TEST_DATABASE_URL` | `just db prepare-check` | | Regenerate the query cache after changing SQL or migrations | `just db prepare` | | Run any command against a scratch cluster | `just db scratch -- psql` | @@ -753,7 +755,10 @@ Use individual recipes while iterating: CI runs these recipes on every pull request whose changes they can affect, including the database and browser tests, and on every push to `main`. -Require its `ci` check: it summarizes the others. +Require its `ci` check: it summarizes the others. CI runs the Rust tests through +`just coverage`, printing coverage per crate and uploading `lcov.info` as the +`rust-coverage` artifact; `just web test` prints the TypeScript SDK's coverage. +Coverage is reported only; nothing fails on it. Web code is formatted by Prettier and linted by type-aware ESLint (typescript-eslint `strictTypeChecked`), configured once at the repository root. diff --git a/just/web.just b/just/web.just index b7e47d866..d313fb6c5 100644 --- a/just/web.just +++ b/just/web.just @@ -12,7 +12,8 @@ fmt-check: lint: @pnpm lint -# The TypeScript SDK's unit tests, every shared vector included. +# The TypeScript SDK's unit tests, every shared vector included, with line, branch +# and function coverage of its sources. test: @pnpm test diff --git a/justfile b/justfile index 2269a27fa..6f3c26058 100644 --- a/justfile +++ b/justfile @@ -25,9 +25,9 @@ validate: fmt-check lint check test web::test doc doc-test audit install: @pnpm install --frozen-lockfile -# Cargo tools used by the test, audit and database recipes. +# Cargo tools used by the test, coverage, audit and database recipes. install-tools: db::install-sqlx - @cargo install --locked cargo-nextest cargo-deny + @cargo install --locked cargo-nextest cargo-llvm-cov cargo-deny # The release auth-service executable. build: (rust::build "--release") @@ -53,6 +53,32 @@ doc: doc-test: @cargo test --locked --doc --workspace +# Uses a scratch cluster unless TEST_DATABASE_URL names a disposable database, +# which the database tests leave migrated. Instrumented builds live in +# target/llvm-cov-target; `cargo llvm-cov report --html` renders the last run. +# Extra arguments go to `cargo llvm-cov nextest`; target/lcov.info has the +# coverage per line. +# Coverage per crate of every Rust test, database tests included. +[positional-arguments] +coverage *ARGS: + #!/usr/bin/env bash + set -euo pipefail + if [[ -z "${TEST_DATABASE_URL:-}" ]]; then exec just db scratch just coverage "$@"; fi + cargo llvm-cov nextest --locked --workspace --run-ignored all --lcov --output-path target/lcov.info "$@" + # lcov names each source file by absolute path; its crate is the + # apps/ or crates/ directory holding it. + awk -v root="$PWD/" ' + function row(name, hit, lines, fn_hit, fns) { + return sprintf("%-20s %6.2f%% of %6d lines %6.2f%% of %5d functions", name, 100 * hit / lines, lines, 100 * fn_hit / fns, fns) + } + /^SF:/ { split(substr($0, length(root) + 4), path, "/"); crate = path[1] "/" path[2] } + /^LF:/ { lf[crate] += substr($0, 4) } /^LH:/ { lh[crate] += substr($0, 4) } + /^FNF:/ { ff[crate] += substr($0, 5) } /^FNH:/ { fh[crate] += substr($0, 5) } + END { + for (c in lf) { print row(c, lh[c], lf[c], fh[c], ff[c]) | "sort"; LH += lh[c]; LF += lf[c]; FH += fh[c]; FF += ff[c] } + close("sort"); print row("workspace", LH, LF, FH, FF) + }' target/lcov.info + # Regenerate tests/sdk-vectors; `just test` fails while the committed files are stale. sdk-vectors: @UPDATE_SDK_VECTORS=1 cargo nextest run --locked -p piquel-common --test sdk_vectors diff --git a/packages/auth/package.json b/packages/auth/package.json index cad657b83..621765b7a 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -34,7 +34,7 @@ "scripts": { "build": "tsc", "lint": "tsc && publint --strict && attw --pack --profile esm-only", - "test": "node --test 'test/**/*.test.ts'" + "test": "node --test --experimental-test-coverage --test-coverage-exclude='test/**' 'test/**/*.test.ts'" }, "devDependencies": { "@arethetypeswrong/cli": "0.18.5", From 875e63146a13329f6773b416174eac103570e629 Mon Sep 17 00:00:00 2001 From: piquel Date: Wed, 4 Nov 2026 11:45:40 +0100 Subject: [PATCH 2/2] ci: say what the rust job's Clippy build still shares --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 52a140f6f..91d1868ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -131,8 +131,9 @@ jobs: - if: needs.changes.outputs.deps == 'true' run: just web audit - # Clippy runs first so lint failures report early; the tests then reuse the - # dependencies it compiled for build scripts and proc macros. + # Clippy runs first so lint failures report early; the doc tests then reuse + # the dependencies it compiled for build scripts and proc macros. Coverage + # builds its own instrumented copy of everything, in target/llvm-cov-target. rust: name: rust needs: changes