Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,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
Expand All @@ -153,7 +155,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:
Expand All @@ -166,7 +168,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.
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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` |
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion just/web.just
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
30 changes: 28 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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/<name> or crates/<name> 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
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading