Coverage measures the page's Node tests and runs the Rust on Postgres (#407)

page-unit.ts and native-bridge.ts run the page's script outside a
browser, so the page's coverage counted none of what they test, and
native.ts read as mostly untested. In a coverage run they now run the
script from a file of its own, named as the browser names it, under
NODE_V8_COVERAGE (scripts/coverage-node.sh, before the browser suite in
npm run coverage:page and coverage.sh api), and the report's teardown
takes their record in, mapped to web/src by the build's source map: the
page's lines went from 73.3% to 80.0% of 3,043, native.ts to 93 of 120.

The cargo tests in coverage.sh's container run on Postgres, as
production does, when IPX_TEST_DATABASE_URL names the _test database,
from the shell or else /src/.envrc (that variable only); on SQLite
without it. The integration tests' own files are left out of the
totals; a crate's inline mod tests cannot be on stable Rust.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-07 04:57:32 +00:00
parent 7994f93f31
commit f6ba08d506
7 changed files with 56 additions and 11 deletions

10
scripts/coverage-node.sh Normal file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
# The page's Node tests, measured (#407): page-unit.ts and native-bridge.ts run the page's script
# outside a browser, so the browser suite's coverage never saw what they test. Run before the
# browser suite in a coverage run; its teardown (tests/ui/coverage-teardown.ts) takes this in.
set -eu
cd "$(dirname "$0")/.."
rm -rf target/coverage/node-v8
export IPX_COVERAGE=1 NODE_V8_COVERAGE=target/coverage/node-v8
node --test tests/page-unit.ts >/dev/null
node tests/native-bridge.ts >/dev/null

View File

@@ -14,6 +14,11 @@
# it, say so and leave the cap be. The browser suite runs here, as it always does, its servers the
# container's build: the image is Ubuntu's, as code-server is, so they start here.
#
# The cargo tests run on Postgres, production's database, when IPX_TEST_DATABASE_URL names the
# _test one (#407), from the shell or else /src/.envrc; on SQLite without it, whose paths are then
# the only ones measured. The integration tests' own files (tests/) are left out of the totals;
# a crate's inline `mod tests` cannot be, on stable Rust.
#
# Reports: target/coverage/cargo and target/coverage/api (summary.txt, a line a file; lcov.info;
# html/index.html), target/coverage/page (npm run coverage:page's, or api's). Each run ends by
# writing the numbers for Grafana (scripts/coverage-metrics.ts).
@@ -35,6 +40,13 @@ LLVM_TARGET=$TARGET/llvm-cov-target
cd "$(dirname "$0")/.."
# Only the one variable, not the whole file: it holds keys the tests are not to see.
if [ -z "${IPX_TEST_DATABASE_URL:-}" ] && [ -f /src/.envrc ]; then
IPX_TEST_DATABASE_URL=$(sed -n 's/^export IPX_TEST_DATABASE_URL=//p' /src/.envrc | tr -d "\"'")
fi
export IPX_TEST_DATABASE_URL="${IPX_TEST_DATABASE_URL:-}"
[ -n "$IPX_TEST_DATABASE_URL" ] && echo "the cargo tests run on Postgres (IPX_TEST_DATABASE_URL)"
room() {
avail=$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo)
load=$(cut -d' ' -f1 /proc/loadavg)
@@ -55,6 +67,7 @@ run() {
docker run --rm --memory "$MEM" --memory-swap "$MEM" --cpuset-cpus "$CPUS" \
-v "$SRC:/work:ro" -v "$TARGET:/target" -v "$REGISTRY:/usr/local/cargo/registry" \
-e CARGO_TARGET_DIR=/target/llvm-cov-target -e CARGO_LLVM_COV_TARGET_DIR=/target/llvm-cov-target \
-e IPX_TEST_DATABASE_URL \
"$IMAGE" "$@" || {
code=$?
[ "$code" -eq 137 ] && echo "killed at the ${MEM} memory cap: tell the user, do not raise it" >&2
@@ -66,9 +79,10 @@ run() {
report() {
room
mkdir -p "$TARGET/coverage/$1"
run sh -c "cargo llvm-cov report --lcov --output-path /target/coverage/$1/lcov.info \
&& cargo llvm-cov report --html --output-dir /target/coverage/$1 \
&& cargo llvm-cov report --summary-only > /target/coverage/$1/summary.txt"
skip="--ignore-filename-regex '(^|/)tests/'"
run sh -c "cargo llvm-cov report $skip --lcov --output-path /target/coverage/$1/lcov.info \
&& cargo llvm-cov report $skip --html --output-dir /target/coverage/$1 \
&& cargo llvm-cov report $skip --summary-only > /target/coverage/$1/summary.txt"
# The paths inside the container are /work/...; the tree's own, from here.
sed -i 's#/work/##' "$TARGET/coverage/$1/summary.txt" "$TARGET/coverage/$1/lcov.info"
tail -1 "$TARGET/coverage/$1/summary.txt"
@@ -91,6 +105,7 @@ if [ "${1:-}" = api ]; then
# Not `set -e`'s to stop on: a failing test still ran what it ran, and the report says so; the
# suite's own exit code is this script's at the end.
suite=0
sh scripts/coverage-node.sh
IPX_API_COVERAGE=$LLVM_TARGET IPX_COVERAGE=1 IPX_SIGNALS_TESTS=1 LLVM_PROFILE_FILE="$LLVM_TARGET/ipx-browser-%p-%14m.profraw" \
npx playwright test || suite=$?
ls "$LLVM_TARGET"/ipx-browser-*.profraw >/dev/null 2>&1 \