Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(ci): executed-test receipts from every bun invocation (X2, B2, B9)
garrytan99f784a74a99
diff --git a/scripts/check-admin-build.sh b/scripts/check-admin-build.shindex 028faa48ae..512fb1a231 100755--- a/scripts/check-admin-build.sh+++ b/scripts/check-admin-build.sh@@ -15,6 +15,7 @@ set -euo pipefailif [ "${GBRAIN_SKIP_ADMIN_BUILD:-0}" = "1" ]; thenecho "[check:admin-build] GBRAIN_SKIP_ADMIN_BUILD=1, skipping"+ echo "GBRAIN_CHECK_SKIPPED: GBRAIN_SKIP_ADMIN_BUILD=1"exit 0fi@@ -22,6 +23,7 @@ cd "$(dirname "$0")/.."if [ ! -d admin ]; thenecho "[check:admin-build] no admin/ directory, skipping"+ echo "GBRAIN_CHECK_SKIPPED: no admin/ directory"exit 0fidiff --git a/scripts/check-bootstrap-tag.sh b/scripts/check-bootstrap-tag.shindex 69465dfebe..24e521609f 100755--- a/scripts/check-bootstrap-tag.sh+++ b/scripts/check-bootstrap-tag.sh@@ -132,6 +132,7 @@ if [ "$fail" -ne 0 ]; thenfiif [ "$checked" -eq 0 ]; thenecho "check-bootstrap-tag: ok (no bootstrap entry docs present yet — all checks skipped)"+ echo "GBRAIN_CHECK_SKIPPED: no bootstrap entry docs present"elseecho "check-bootstrap-tag: ok ($checked doc(s) on the '$SANCTIONED' distribution ref)"fidiff --git a/scripts/check-bootstrap-templates.sh b/scripts/check-bootstrap-templates.shindex 4824afa604..d471a24b7b 100755--- a/scripts/check-bootstrap-templates.sh+++ b/scripts/check-bootstrap-templates.sh@@ -56,6 +56,7 @@ fail=0if [ ! -d "$TDIR" ]; thenecho "SKIP: templates/bootstrap/ absent — nothing to check yet"echo "check-bootstrap-templates: ok (skipped)"+ echo "GBRAIN_CHECK_SKIPPED: templates/bootstrap/ absent"exit 0fidiff --git a/scripts/check-grok-pin.sh b/scripts/check-grok-pin.shindex 24e0d17f9d..44608c1a7f 100755--- a/scripts/check-grok-pin.sh+++ b/scripts/check-grok-pin.sh@@ -34,10 +34,12 @@ WORKFLOW="$ROOT/.github/workflows/heavy-tests.yml"if [ ! -f "$WORKFLOW" ]; thenecho "check-grok-pin: SKIP (no $WORKFLOW)"+ echo "GBRAIN_CHECK_SKIPPED: no heavy-tests.yml"exit 0fiif ! grep -q '^ grok-door:' "$WORKFLOW"; thenecho "check-grok-pin: SKIP (no grok-door job in heavy-tests.yml yet)"+ echo "GBRAIN_CHECK_SKIPPED: no grok-door job in heavy-tests.yml"exit 0fi# Once the grok-door job EXISTS, a missing pin doc is a FAILURE, not a skip —diff --git a/scripts/check-opencode-pin.sh b/scripts/check-opencode-pin.shindex 54dba64532..f76e2ac2f0 100755--- a/scripts/check-opencode-pin.sh+++ b/scripts/check-opencode-pin.sh@@ -34,10 +34,12 @@ WORKFLOW="$ROOT/.github/workflows/heavy-tests.yml"if [ ! -f "$WORKFLOW" ]; thenecho "check-opencode-pin: SKIP (no $WORKFLOW)"+ echo "GBRAIN_CHECK_SKIPPED: no heavy-tests.yml"exit 0fiif ! grep -q '^ opencode-door:' "$WORKFLOW"; thenecho "check-opencode-pin: SKIP (no opencode-door job in heavy-tests.yml yet)"+ echo "GBRAIN_CHECK_SKIPPED: no opencode-door job in heavy-tests.yml"exit 0fi# Once the opencode-door job EXISTS, a missing pin doc is a FAILURE, not a skip —diff --git a/scripts/check-pagetype-exhaustive.sh b/scripts/check-pagetype-exhaustive.shindex 85aa7975a4..ebbb0e9d97 100755--- a/scripts/check-pagetype-exhaustive.sh+++ b/scripts/check-pagetype-exhaustive.sh@@ -32,6 +32,7 @@ PAGETYPE_FILES=$(grep -rlE "import.*PageType.*from.*types" src 2>/dev/null || trif [ -z "$PAGETYPE_FILES" ]; thenecho "[check-pagetype-exhaustive] No files import PageType. Skipping."+ echo "GBRAIN_CHECK_SKIPPED: no src file imports PageType"exit 0fidiff --git a/scripts/check-pglite-embedded.sh b/scripts/check-pglite-embedded.shindex e8d8ab68cd..cff5ee9f4c 100755--- a/scripts/check-pglite-embedded.sh+++ b/scripts/check-pglite-embedded.sh@@ -55,6 +55,7 @@ if ! (cd "$BUILD_DIR" && bun build --compile --no-compile-autoload-bunfig --outf# e2e — so local dev without compile support isn't blocked. CI has compile.if grep -qiE 'not (found|available)|permission denied|Could not download|ETIMEDOUT|network' "$BUILD_DIR/compile.log"; thenecho "[check-pglite-embedded] SKIP: bun build --compile unavailable in this sandbox." >&2+ echo "GBRAIN_CHECK_SKIPPED: bun build --compile unavailable"sed -n '1,20p' "$BUILD_DIR/compile.log" >&2 || trueexit 0fidiff --git a/scripts/check-pin-doc-privacy.sh b/scripts/check-pin-doc-privacy.shindex 9a887dffba..9a55091564 100755--- a/scripts/check-pin-doc-privacy.sh+++ b/scripts/check-pin-doc-privacy.sh@@ -28,6 +28,7 @@ shopt -u nullglobif [ "${#PIN_DOCS[@]}" -eq 0 ]; thenecho "check-pin-doc-privacy: SKIP (no docs/mcp/*-CLI-PIN.md yet)"+ echo "GBRAIN_CHECK_SKIPPED: no docs/mcp/*-CLI-PIN.md"exit 0fidiff --git a/scripts/check-schema-migration-order.ts b/scripts/check-schema-migration-order.tsindex 92352b01d3..5851c35ffa 100644--- a/scripts/check-schema-migration-order.ts+++ b/scripts/check-schema-migration-order.ts@@ -71,6 +71,7 @@ function main(): number {return 1;}console.log(`skip: ${msg}`);+ console.log(`GBRAIN_CHECK_SKIPPED: base ref ${ref} unavailable`);return 0;}let head;diff --git a/scripts/check-synthetic-corpus-privacy.sh b/scripts/check-synthetic-corpus-privacy.shindex 5ef5068175..c349a6a000 100755--- a/scripts/check-synthetic-corpus-privacy.sh+++ b/scripts/check-synthetic-corpus-privacy.sh@@ -37,6 +37,7 @@ PLACEHOLDERS=(# Skip if directory doesn't exist yet (early-clone state).if [ ! -d "$CORPUS_DIR" ]; thenecho "OK: $CORPUS_DIR does not exist yet (skipping privacy scan)"+ echo "GBRAIN_CHECK_SKIPPED: $CORPUS_DIR absent"exit 0fidiff --git a/scripts/lib/test-env.sh b/scripts/lib/test-env.shindex 08497a57a3..ca796cbb81 100644--- a/scripts/lib/test-env.sh+++ b/scripts/lib/test-env.sh@@ -104,3 +104,88 @@ ensure_default_pglite_snapshot() {esacecho "[$label] default PGLite snapshot active: $GBRAIN_TEST_DEFAULT_SNAPSHOT" >&2}++# ──────────────────────────────────────────────────────────────────────────+# Executed-test receipts (X2). With GBRAIN_TEST_RECEIPT_DIR set, every bun+# invocation a runner makes records one receipt in that directory:+# <id>.receipt key=value lines: lane, kind (primary|rerun|rescue),+# shard/of, arm, sha, run_id, run_attempt, started, and+# exit= once the invocation returns+# <id>.files the test files assigned to the invocation+# <id>.junit.xml Bun's native JUnit report (--reporter=junit)+# scripts/ci-executed-counts.ts reads them: an assigned file with no valid+# JUnit from any attempt is `incomplete`, and a later attempt (rerun/rescue)+# supersedes an earlier one for the files it re-ran.+#+# receipts_init captures the directory and lane, then UNSETS both variables so+# test processes (and the nested runners some tests start) never inherit+# them; a runner that starts another runner passes+# GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" explicitly.+# GBRAIN_TEST_RECEIPT_DIR receipt directory (unset = receipts off)+# GBRAIN_TEST_RECEIPT_LANE overrides the runner's default lane name+# ──────────────────────────────────────────────────────────────────────────+receipts_init() {+ TEST_RECEIPT_LANE="${GBRAIN_TEST_RECEIPT_LANE:-$1}"+ TEST_RECEIPT_DIR="${GBRAIN_TEST_RECEIPT_DIR:-}"+ unset GBRAIN_TEST_RECEIPT_DIR GBRAIN_TEST_RECEIPT_LANE+ RECEIPT_ID=""+ RECEIPT_ARGS=()+ [ -n "$TEST_RECEIPT_DIR" ] || return 0+ case "$TEST_RECEIPT_DIR" in /*) ;; *) TEST_RECEIPT_DIR="$PWD/$TEST_RECEIPT_DIR" ;; esac+ mkdir -p "$TEST_RECEIPT_DIR" || {+ echo "[receipts] cannot create $TEST_RECEIPT_DIR; receipts are required when GBRAIN_TEST_RECEIPT_DIR is set" >&2+ return 1+ }+ TEST_RECEIPT_SHA="${GITHUB_SHA:-$(git rev-parse HEAD 2>/dev/null || echo unknown)}"+}++# receipt_begin <kind> <tag> <shard> <of> <arm> [file...]+# Sets RECEIPT_ID and RECEIPT_ARGS (the bun reporter flags; empty when+# receipts are off). <tag> must be unique per invocation within the lane.+receipt_begin() {+ local kind="$1" tag="$2" shard="$3" of="$4" arm="$5" id n=1+ shift 5+ RECEIPT_ID=""+ RECEIPT_ARGS=()+ [ -n "${TEST_RECEIPT_DIR:-}" ] || return 0+ id="${TEST_RECEIPT_LANE}--${tag}--${kind}"+ while [ -e "$TEST_RECEIPT_DIR/$id.receipt" ]; do+ n=$((n + 1))+ id="${TEST_RECEIPT_LANE}--${tag}--${kind}-$n"+ done+ {+ echo "version=1"+ echo "lane=$TEST_RECEIPT_LANE"+ echo "kind=$kind"+ echo "tag=$tag"+ echo "shard=$shard"+ echo "of=$of"+ echo "arm=$arm"+ echo "sha=$TEST_RECEIPT_SHA"+ echo "root=$PWD"+ echo "run_id=${GITHUB_RUN_ID:-}"+ echo "run_attempt=${GITHUB_RUN_ATTEMPT:-}"+ echo "job=${GITHUB_JOB:-}"+ echo "started=$(date +%s)"+ } > "$TEST_RECEIPT_DIR/$id.receipt"+ if [ "$#" -gt 0 ]; then printf '%s\n' "$@" > "$TEST_RECEIPT_DIR/$id.files"; else : > "$TEST_RECEIPT_DIR/$id.files"; fi+ RECEIPT_ID="$id"+ RECEIPT_ARGS=(--reporter=junit "--reporter-outfile=$TEST_RECEIPT_DIR/$id.junit.xml")+}++# receipt_end <exit-code>: records how the invocation returned. A receipt+# without exit= was interrupted before its runner saw the result.+receipt_end() {+ [ -n "${TEST_RECEIPT_DIR:-}" ] && [ -n "${RECEIPT_ID:-}" ] || return 0+ echo "exit=$1" >> "$TEST_RECEIPT_DIR/$RECEIPT_ID.receipt"+}++# receipt_empty <tag> <shard> <of>: this invocation was assigned no files.+# Keeps an empty shard from reading as a missing one.+receipt_empty() {+ receipt_begin primary "$1" "$2" "$3" ""+ [ -n "${RECEIPT_ID:-}" ] || return 0+ echo "empty=1" >> "$TEST_RECEIPT_DIR/$RECEIPT_ID.receipt"+ receipt_end 0+ RECEIPT_ARGS=()+}diff --git a/scripts/run-e2e.sh b/scripts/run-e2e.shindex 0742151e14..514d87cc99 100755--- a/scripts/run-e2e.sh+++ b/scripts/run-e2e.sh@@ -38,6 +38,12 @@ RUNNER_SHARD="${SHARD:-}"unset SHARDcd "$(dirname "$0")/.."+# Executed-test receipts (X2): captured here, before the GBRAIN_* scrub below,+# and unset so test processes never inherit them. Each file pass keeps its+# native JUnit report as a receipt (lane e2e unless GBRAIN_TEST_RECEIPT_LANE+# says otherwise; backend-matrix passes record their arm).+. scripts/lib/test-env.sh+receipts_init e2e || exit 2# COVERAGE_DIR (opt-in lcov coverage) must be an ABSOLUTE path: this script# redirects HOME (and E2E tests spawn CLI subprocesses with varying cwd), so@@ -208,9 +214,19 @@ if [ "$DRY_RUN_LIST" = "1" ]; thenexit 0fi+RECEIPT_SHARD=""+RECEIPT_OF=""+RECEIPT_TAG="run"+if [ -n "$RUNNER_SHARD" ]; then+ RECEIPT_SHARD="$shard_n"+ RECEIPT_OF="$shard_m"+ RECEIPT_TAG="s${shard_n}of${shard_m}"+fi+if [ "${#files[@]}" -eq 0 ]; then# Empty shard (e.g. SHARD=4/4 with only 3 files): nothing to do.echo "No files for shard ${RUNNER_SHARD:-(unsharded)}; exiting clean."+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"exit 0fi@@ -345,8 +361,41 @@ except (OSError, ET.ParseError, ValueError, TypeError) as error:PY}+# A file's HOME must be removable once its bun process exits. Anything still+# running with HOME=<file home> is a leaked child of that file (the B2 class:+# a detached refresh still writing Bun's install cache). Kill those first+# (Linux /proc scan; elsewhere none can be found), then remove the HOME. A+# HOME that still cannot be removed fails THIS file by name instead of+# letting `set -e` abort the rest of the partition. Prints a note on stdout+# (empty when nothing leaked); returns 1 when the HOME is still there.+remove_file_home() {+ local home="$1" leaked="" pid cmd details=""+ if [ -d /proc/self ]; then+ leaked=$(grep -lzxF "HOME=$home" /proc/[0-9]*/environ 2>/dev/null | sed 's|^/proc/||; s|/environ$||' || true)+ fi+ for pid in $leaked; do+ [ "$pid" = "$$" ] && continue+ cmd=$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null | cut -c1-200 || true)+ details="$details+ pid $pid: ${cmd:-<exited>}"+ kill -KILL "$pid" 2>/dev/null || true+ done+ if rm -rf "$home" 2>/dev/null || { sleep 1; rm -rf "$home" 2>/dev/null; }; then+ [ -z "$details" ] || echo "WARN: $name left processes running with HOME=$home after its bun process exited (killed):$details"+ return 0+ fi+ echo "FAILED: $name left a process writing to its HOME; cleanup could not remove $home"+ echo " Why: a test started a child (often detached) that outlived the test file and kept writing under HOME."+ echo " Fix: make the test wait for or stop its children; reproduce with: bash scripts/run-e2e.sh $f"+ [ -z "$details" ] || echo " Leaked processes (killed):$details"+ find "$home" -mindepth 1 -maxdepth 4 2>/dev/null | head -10 | sed 's/^/ Remaining: /'+ return 1+}++executed_files=()for f in "${files[@]}"; doname=$(basename "$f")+ executed_files+=("$f")file_idx=$((file_idx + 1))# COVERAGE_DIR (opt-in): each E2E file runs in its OWN bun process, so each# needs its OWN coverage dir — a second bun process reusing a coverage dir@@ -407,29 +456,41 @@ for f in "${files[@]}"; doin_backend_matrix=0case "$backend_matrix" in *" ${f#./} "*) in_backend_matrix=1 ;; esacrun_e2e_pass() {- # $1 = pass label; remaining args = env assignments for this pass.- local pass_label="$1"- shift+ # $1 = pass label; $2 = receipt arm ("" outside the backend matrix);+ # remaining args = env assignments for this pass.+ local pass_label="$1" arm="$2"+ shift 2FILE_HOME="$E2E_TMP_HOME/file-$file_idx-$pass_label"mkdir -p "$FILE_HOME/.gbrain"rc=0p=0rm -f "$E2E_TMP_HOME/current.junit.xml"+ receipt_begin primary "$RECEIPT_TAG-f$file_idx-$pass_label" "$RECEIPT_SHARD" "$RECEIPT_OF" "$arm" "${f#./}"env "$@" HOME="$FILE_HOME" GBRAIN_HOME="$FILE_HOME" $TIMEOUT_CMD bun test --timeout=60000 --reporter=junit --reporter-outfile="$E2E_TMP_HOME/current.junit.xml" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} "$f" > "$E2E_TMP_HOME/current.log" 2>&1 &ACTIVE_E2E_PID=$!wait "$ACTIVE_E2E_PID" || rc=$?ACTIVE_E2E_PID=""+ if [ -n "$RECEIPT_ID" ] && [ -f "$E2E_TMP_HOME/current.junit.xml" ]; then+ cp "$E2E_TMP_HOME/current.junit.xml" "$TEST_RECEIPT_DIR/$RECEIPT_ID.junit.xml"+ fi+ receipt_end "$rc"output=$(cat "$E2E_TMP_HOME/current.log")- rm -rf "$FILE_HOME"+ if ! cleanup_note=$(remove_file_home "$FILE_HOME"); then+ output="$output+$cleanup_note"+ rc=1+ return+ fi+ [ -z "$cleanup_note" ] || echo "$cleanup_note"if [ "$rc" -eq 0 ] && ! p=$(completed_e2e_passes "$f"); thenecho "FAILED: $name did not produce a complete native Bun report for the selected file"rc=1fi}if [ "$in_backend_matrix" = "1" ]; then- run_e2e_pass direct GBRAIN_TEST_BACKEND=postgres-direct+ run_e2e_pass direct postgres-direct GBRAIN_TEST_BACKEND=postgres-directelse- run_e2e_pass direct+ run_e2e_pass direct ""fiif [ "$rc" -eq 0 ] && [ "$in_backend_matrix" = "1" ] && [ -n "${DATABASE_URL:-}" ]; thendirect_passes="$p"@@ -455,7 +516,7 @@ for f in "${files[@]}"; docase "$pooled_timeout" in ''|*[!0-9]*) ;; *) [ -n "$TIMEOUT_CMD" ] && TIMEOUT_CMD="${TIMEOUT_CMD%% *} $pooled_timeout" ;; esac;;esac- run_e2e_pass pgbouncer DATABASE_URL="$PGBOUNCER_E2E_URL" GBRAIN_TEST_BACKEND=pgbouncer+ run_e2e_pass pgbouncer pgbouncer DATABASE_URL="$PGBOUNCER_E2E_URL" GBRAIN_TEST_BACKEND=pgbouncerTIMEOUT_CMD="$pooled_timeout_cmd"if [ "$rc" -eq 0 ] && { [ "$p" -eq 0 ] || [ "$p" -ne "$direct_passes" ]; }; thenecho "$output"@@ -493,6 +554,13 @@ for f in "${files[@]}"; dofidone+# Execution receipt (B9): which files this lane ran, written pass or fail so a+# red nightly still records them. lane-manifest.json (complete:true) stays+# green-only, written at the end.+if [ -n "${COVERAGE_DIR:-}" ]; then+ printf '%s\n' "${executed_files[@]}" > "$COVERAGE_DIR/executed-files.txt"+fi+echo ""echo "========================================"echo "E2E SUMMARY (sequential execution)"@@ -555,7 +623,6 @@ if [ -n "${COVERAGE_DIR:-}" ]; thenLANE="e2e"[ -z "$RUNNER_SHARD" ] || LANE="e2e-$shard_n"RUN_SHA=$(git rev-parse HEAD)- printf '%s\n' "${files[@]}" > "$COVERAGE_DIR/executed-files.txt"printf '{"lane":"%s","sha":"%s","lcovCount":%s,"complete":true}\n' \"$LANE" "$RUN_SHA" "${LCOV_COUNT:-0}" > "$COVERAGE_DIR/lane-manifest.json"fidiff --git a/scripts/run-serial-tests.sh b/scripts/run-serial-tests.shindex 91bcb131bf..e1fda9e9ba 100755--- a/scripts/run-serial-tests.sh+++ b/scripts/run-serial-tests.sh@@ -73,6 +73,15 @@ case "${1:-}" inesac. scripts/lib/test-env.sh+receipts_init serial+RECEIPT_SHARD=""+RECEIPT_OF=""+RECEIPT_TAG="all"+if [ -n "$SERIAL_SHARD" ]; then+ RECEIPT_SHARD="$shard_n"+ RECEIPT_OF="$shard_m"+ RECEIPT_TAG="s${shard_n}of${shard_m}"+fi# ──────────────────────────────────────────────────────────────────────────# EXCLUSIVE_FILES: files that must never run concurrently with anything else@@ -156,7 +165,11 @@ if [ "$DRY_RUN_MODE" = "--dry-run-list-exclusive" ]; thenexit 0fi-if [ "${#ordered_files[@]}" -gt 0 ]; then ensure_pglite_snapshot "serial-tests"; fi+if [ "${#ordered_files[@]}" -gt 0 ]; then+ ensure_pglite_snapshot "serial-tests"+else+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"+fi# ──────────────────────────────────────────────────────────────────────────# Pool sizing: min(detect_cpus, 4) — each pooled bun process can hold a@@ -293,8 +306,9 @@ echo "[serial-tests] ${#ordered_files[@]} file(s): pool=$POOL (${#exclusive_pres# against in v0.40.10. The literal `bun test --max-concurrency=1` below is# contract-pinned by test/scripts/serial-files.test.ts.run_one_file() {- # $1 file, $2 log path, $3 exit-sentinel path, $4 wrap ("wrap"|"nowrap")- local f="$1" log="$2" exitf="$3" wrap="$4" rc=0+ # $1 file, $2 log path, $3 exit-sentinel path, $4 wrap ("wrap"|"nowrap"),+ # $5 receipt kind (primary|rescue; default primary)+ local f="$1" log="$2" exitf="$3" wrap="$4" kind="${5:-primary}" rc=0local key="${log%.log}" started finishedprintf '%s\n' "$f" > "$key.file"started=$(now_ms)@@ -309,12 +323,14 @@ run_one_file() {cov_key=$(basename "$log" .log)cov_args=(--coverage --coverage-reporter=lcov --coverage-dir="$COVERAGE_DIR/serial-$cov_key")fi+ receipt_begin "$kind" "$RECEIPT_TAG-$(basename "$log" .log)" "$RECEIPT_SHARD" "$RECEIPT_OF" "" "$f"if [ "$wrap" = "wrap" ] && [ -n "$TIMEOUT_BIN" ]; then"$TIMEOUT_BIN" -k 15 "$PER_FILE_TIMEOUT" \- bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} "$f" > "$log" 2>&1 || rc=$?+ bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$f" > "$log" 2>&1 || rc=$?else- bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} "$f" > "$log" 2>&1 || rc=$?+ bun test --max-concurrency=1 --timeout=120000 ${cov_args[@]+"${cov_args[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$f" > "$log" 2>&1 || rc=$?fi+ receipt_end "$rc"echo "$rc" > "$exitf"finished=$(now_ms)echo "$((finished - started))" > "$key.duration-ms"@@ -420,7 +436,7 @@ if [ "${#rescue_files[@]}" -gt 0 ]; thenis_exclusive "$f" && wrap_mode="nowrap"s=$(date +%s)[ "$wrap_mode" != "nowrap" ] || running_exclusive=1- run_one_file "$f" "$LOG_DIR/$i.log" "$LOG_DIR/$i.exit" "$wrap_mode" &+ run_one_file "$f" "$LOG_DIR/$i.log" "$LOG_DIR/$i.exit" "$wrap_mode" rescue &wait "$!"running_exclusive=0e=$(date +%s)diff --git a/scripts/run-slow-tests.sh b/scripts/run-slow-tests.shindex 8c4024006a..0e6f929ee5 100755--- a/scripts/run-slow-tests.sh+++ b/scripts/run-slow-tests.sh@@ -39,11 +39,13 @@ if [ "$DRY_RUN" = "1" ]; thenfi. scripts/lib/test-env.sh+receipts_init slowensure_pglite_snapshot "run-slow-tests"ensure_default_pglite_snapshot "run-slow-tests"if [ "${#slow_files[@]}" -eq 0 ]; thenecho "[run-slow-tests] no *.slow.test.ts files; nothing to do."+ receipt_empty all "" ""exit 0fi@@ -53,4 +55,8 @@ echo "[run-slow-tests] running ${#slow_files[@]} slow files (CI runs these as pa# when bun runs slow files in parallel, CPU contention pushes them past# 60s and individual tests timeout even though they'd pass solo. Slow# tests are explicit by-name — generous per-test budget is correct.-exec bun test --timeout=120000 "${slow_files[@]}"+receipt_begin primary all "" "" "" "${slow_files[@]}"+rc=0+bun test --timeout=120000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "${slow_files[@]}" || rc=$?+receipt_end "$rc"+exit "$rc"diff --git a/scripts/run-unit-parallel.sh b/scripts/run-unit-parallel.shindex 996a058ffa..115df8a1a4 100755--- a/scripts/run-unit-parallel.sh+++ b/scripts/run-unit-parallel.sh@@ -201,6 +201,15 @@ firm -f "$LOG_DIR"/shard-*.log "$LOG_DIR"/shard-*.exit "$LOG_DIR"/shard-*.wedged "$LOG_DIR"/shard-*.lastkb "$LOG_DIR"/shard-*.lastprogress "$LOG_DIR"/shard-*.start "$LOG_DIR"/shard-*.end "$LOG_DIR"/shard-*.watchdog "$LOG_DIR"/shard-*.assigned "$LOG_DIR"/shard-*.hbsum 2>/dev/null: > "$FAILURES_LOG": > "$SUMMARY_FILE"+# Executed-test receipts (X2): on by default for this loop, under+# .context/test-receipts (cleared per run) unless GBRAIN_TEST_RECEIPT_DIR names+# another directory. `bun scripts/ci-executed-counts.ts --head-dir <dir>`+# reads them; the shard and serial runners each write their own.+if [ "$DRY_RUN" = "0" ] && [ -z "${GBRAIN_TEST_RECEIPT_DIR:-}" ] && [ "$LOG_DIR" = ".context/test-shards" ]; then+ rm -rf .context/test-receipts+ GBRAIN_TEST_RECEIPT_DIR=.context/test-receipts+fi+receipts_init unit || exit 2# ──────────────────────────────────────────────────────────────────────────# Resolve `timeout` command. macOS without coreutils has neither; we degrade@@ -294,12 +303,12 @@ for i in $(seq 1 "$N"); dodate +%s > "$LOG_DIR/shard-$i.start"if [ -n "$TIMEOUT_BIN" ]; then"$TIMEOUT_BIN" --signal=TERM --kill-after="${SHARD_KILL_AFTER}s" "${SHARD_TIMEOUT}s" \- env SHARD="$i/$N" \+ env SHARD="$i/$N" GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" \bash scripts/run-unit-shard.sh --max-concurrency="$INTRA_CONC" \> "$SHARD_LOG" 2>&1rc=$?else- env SHARD="$i/$N" \+ env SHARD="$i/$N" GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" \bash scripts/run-unit-shard.sh --max-concurrency="$INTRA_CONC" \> "$SHARD_LOG" 2>&1 &pid=$!@@ -820,7 +829,7 @@ SERIAL_FILES_COUNT=0SERIAL_FILES_COUNT=$(find test -name '*.serial.test.ts' -not -path 'test/e2e/*' 2>/dev/null | wc -l | tr -d ' ')if [ "$SERIAL_FILES_COUNT" -gt 0 ]; thenecho "════════════ serial pass ($SERIAL_FILES_COUNT files) ════════════"- bash scripts/run-serial-tests.sh > "$LOG_DIR/serial.log" 2>&1+ GBRAIN_TEST_RECEIPT_DIR="$TEST_RECEIPT_DIR" bash scripts/run-serial-tests.sh > "$LOG_DIR/serial.log" 2>&1SERIAL_RC=$?cat "$LOG_DIR/serial.log"if [ "$SERIAL_RC" != "0" ]; then@@ -895,23 +904,33 @@ if [ "$TOTAL_RC" != "0" ] && [ "${RESCUE_COUNT:-0}" -gt 0 ]; thengrep '\.serial\.test\.ts$' "$OOM_RESCUE_LIST" > "$LOG_DIR/oom-rescue-serial.txt" || trueRESCUE_RC=0: > "$RESCUE_LOG"- run_rescue() { # $1 = per-invocation timeout seconds; rest = test-file args- local t="$1"; shift+ # Each rescue invocation writes its own receipt (kind=rescue), which+ # supersedes the killed or failed attempt for the files it re-ran.+ run_rescue() { # $1 = per-invocation timeout seconds; $2 = receipt lane; $3 = receipt tag; rest = test-file args+ local t="$1" lane="$2" tag="$3" rc=0 primary_lane="$TEST_RECEIPT_LANE"+ shift 3+ TEST_RECEIPT_LANE="$lane"+ receipt_begin rescue "$tag" "" "" "" "$@"+ TEST_RECEIPT_LANE="$primary_lane"if [ -n "$TIMEOUT_BIN" ]; then"$TIMEOUT_BIN" --signal=TERM --kill-after="${SHARD_KILL_AFTER}s" "${t}s" \- bun test --max-concurrency 1 --timeout=60000 "$@" >> "$RESCUE_LOG" 2>&1+ bun test --max-concurrency 1 --timeout=60000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" >> "$RESCUE_LOG" 2>&1 || rc=$?else- bun test --max-concurrency 1 --timeout=60000 "$@" >> "$RESCUE_LOG" 2>&1+ bun test --max-concurrency 1 --timeout=60000 ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" >> "$RESCUE_LOG" 2>&1 || rc=$?fi+ receipt_end "$rc"+ return "$rc"}if [ -s "$LOG_DIR/oom-rescue-batch.txt" ]; then# shellcheck disable=SC2046- run_rescue "$RESCUE_TIMEOUT" $(cat "$LOG_DIR/oom-rescue-batch.txt") || RESCUE_RC=1+ run_rescue "$RESCUE_TIMEOUT" unit batch $(cat "$LOG_DIR/oom-rescue-batch.txt") || RESCUE_RC=1fiif [ -s "$LOG_DIR/oom-rescue-serial.txt" ]; then+ rescue_idx=0while IFS= read -r serial_file; do[ -n "$serial_file" ] || continue- run_rescue 300 "$serial_file" || RESCUE_RC=1+ rescue_idx=$((rescue_idx + 1))+ run_rescue 300 serial "file$rescue_idx" "$serial_file" || RESCUE_RC=1done < "$LOG_DIR/oom-rescue-serial.txt"ficat "$RESCUE_LOG"diff --git a/scripts/run-unit-shard.sh b/scripts/run-unit-shard.shindex 33054ec5d2..f1f9f5fa41 100755--- a/scripts/run-unit-shard.sh+++ b/scripts/run-unit-shard.sh@@ -28,6 +28,8 @@ unset DATABASE_URL GBRAIN_DATABASE_URLunset GBRAIN_HOMEcd "$(dirname "$0")/.."+. scripts/lib/test-env.sh+receipts_init unit# --max-concurrency=N is forwarded to `bun test`. v0.26.4: invoked by# run-unit-parallel.sh; safe to call without (defaults to bun's default cap).@@ -79,13 +81,23 @@ elsefiles=("${all_files[@]}")fi-if [ "${#files[@]}" -eq 0 ]; then- echo "[unit-shard ${RUNNER_SHARD:-(unsharded)}] no files; exiting clean."+if [ "$DRY_RUN" = "1" ]; then+ [ "${#files[@]}" -eq 0 ] || printf '%s\n' "${files[@]}"exit 0fi-if [ "$DRY_RUN" = "1" ]; then- printf '%s\n' "${files[@]}"+RECEIPT_SHARD=""+RECEIPT_OF=""+RECEIPT_TAG="all"+if [ -n "$RUNNER_SHARD" ]; then+ RECEIPT_SHARD="$shard_n"+ RECEIPT_OF="$shard_m"+ RECEIPT_TAG="s${shard_n}of${shard_m}"+fi++if [ "${#files[@]}" -eq 0 ]; then+ echo "[unit-shard ${RUNNER_SHARD:-(unsharded)}] no files; exiting clean."+ receipt_empty "$RECEIPT_TAG" "$RECEIPT_SHARD" "$RECEIPT_OF"exit 0fi@@ -121,12 +133,14 @@ for ((offset=0, group=1; offset<${#files[@]}; offset+=GROUP_SIZE, group++)); dolog="$GROUP_LOG_DIR/$group.log"printf '%s\n' "${group_files[@]}" > "$GROUP_LOG_DIR/$group.assigned"echo "__gbrain_unit_group_start__ group=$group/$GROUPS_TOTAL files=${#group_files[@]}"+ receipt_begin primary "$RECEIPT_TAG-g$group" "$RECEIPT_SHARD" "$RECEIPT_OF" "" "${group_files[@]}"set +e- bun "${TEST_ARGS[@]}" "${group_files[@]}" 2>&1 | tee "$log"+ bun "${TEST_ARGS[@]}" ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "${group_files[@]}" 2>&1 | tee "$log"statuses=("${PIPESTATUS[@]}")set -ebun_rc=${statuses[0]}tee_rc=${statuses[1]}+ receipt_end "$bun_rc"sed "s/${ESC}\\[[0-9;]*[a-zA-Z]//g" "$log" > "$GROUP_LOG_DIR/$group.clean"# Child tests can print their own Bun summaries. Use the final block, require# its exact selected-file count, and independently check every file header.diff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex ef451d1f6d..23cfd042a2 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -16,7 +16,16 @@## Env overrides:# GBRAIN_VERIFY_TIMEOUT per-check wallclock cap, seconds (default 120)-# GBRAIN_VERIFY_LOG_DIR where to write per-check logs (default tempdir)+# GBRAIN_VERIFY_LOG_DIR where to write per-check logs (default tempdir,+# removed on success and kept on failure)+# GBRAIN_TEST_RECEIPT_DIR also write the verify receipt (X2): one JUnit+# testcase per check with its real outcome+#+# Outcomes: every check is recorded as pass, fail, timeout or skip in+# <log dir>/outcomes.tsv and in the receipt. A check that exits 0 without+# checking anything (its subject is absent) must print a line starting with+# `GBRAIN_CHECK_SKIPPED: <reason>`; the recorder reads that marker, so a+# self-skip is never counted as a pass.## Exit codes:# 0 all checks passed@@ -30,6 +39,7 @@ cd "$(dirname "$0")/.."# detect_cpus + ensure_pglite_snapshot (the PGLite-booting eval checks use# the snapshot fast-path when the shape matches).. scripts/lib/test-env.sh+receipts_init verify || exit 2# ──────────────────────────────────────────────────────────────────────────# Checks to run. Each entry is a bun-script name (the `package.json`@@ -188,7 +198,8 @@ if [ -n "${GBRAIN_VERIFY_LOG_DIR:-}" ]; thenmkdir -p "$LOG_DIR" || { echo "ERROR: cannot create $LOG_DIR" >&2; exit 2; }elseLOG_DIR="$(mktemp -d /tmp/gbrain-verify-XXXXXX)"- trap 'rm -rf "$LOG_DIR"' EXIT+ KEEP_LOGS=0+ trap '[ "$KEEP_LOGS" = "1" ] || rm -rf "$LOG_DIR"' EXITfi# Resolve `timeout` for per-check wallclock cap. macOS doesn't ship one;@@ -279,8 +290,14 @@ ELAPSED=$((END_TS - START_TS))# ──────────────────────────────────────────────────────────────────────────PASS=0FAIL=0+SKIP=0FAIL_NAMES=()+SKIP_REPORT=""FAIL_REPORT=""+OUTCOMES="$LOG_DIR/outcomes.tsv"+printf 'check\toutcome\trc\tdetail\n' > "$OUTCOMES"+xml_escape() { sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' -e 's/"/\"/g'; }+JUNIT_CASES=""for i in "${!CHECKS[@]}"; doc="${CHECKS[$i]}"@@ -290,10 +307,26 @@ for i in "${!CHECKS[@]}"; dorc=1[ -f "$EXIT_FILE" ] && rc=$(cat "$EXIT_FILE" 2>/dev/null || echo 1)+ skip_reason=""+ if [ "$rc" = "0" ] && [ -f "$LOG_FILE" ]; then+ skip_reason=$(sed -n 's/^GBRAIN_CHECK_SKIPPED:[[:space:]]*//p' "$LOG_FILE" | head -1 | tr '\t' ' ')+ [ -n "$skip_reason" ] || ! grep -q '^GBRAIN_CHECK_SKIPPED:' "$LOG_FILE" || skip_reason="(no reason given)"+ fi- if [ "$rc" = "0" ]; then+ if [ "$rc" = "0" ] && [ -n "$skip_reason" ]; then+ SKIP=$((SKIP + 1))+ SKIP_REPORT+=" $c: $skip_reason"$'\n'+ printf '%s\tskip\t0\t%s\n' "$c" "$skip_reason" >> "$OUTCOMES"+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\"><skipped message=\"$(printf '%s' "$skip_reason" | xml_escape)\" /></testcase>"$'\n'+ elif [ "$rc" = "0" ]; thenPASS=$((PASS + 1))+ printf '%s\tpass\t0\t\n' "$c" >> "$OUTCOMES"+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\" />"$'\n'else+ outcome=fail+ [ "$rc" = "124" ] && outcome=timeout+ printf '%s\t%s\t%s\t%s\n' "$c" "$outcome" "$rc" "$LOG_FILE" >> "$OUTCOMES"+ JUNIT_CASES+=" <testcase name=\"$c\" classname=\"verify\" file=\"verify\"><failure message=\"$outcome rc=$rc\" /></testcase>"$'\n'FAIL=$((FAIL + 1))FAIL_NAMES+=("$c")if [ "$rc" = "124" ]; then@@ -308,7 +341,28 @@ for i in "${!CHECKS[@]}"; dofidone+if [ -n "$SKIP_REPORT" ]; then+ {+ echo "[verify-parallel] $SKIP check(s) self-skipped (recorded as skip, not pass):"+ printf '%s' "$SKIP_REPORT"+ } >&2+fi++receipt_begin primary all "" "" "" verify+if [ -n "$RECEIPT_ID" ]; then+ {+ echo '<?xml version="1.0" encoding="UTF-8"?>'+ echo "<testsuites name=\"verify\" tests=\"${#CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"+ echo " <testsuite name=\"verify\" file=\"verify\" tests=\"${#CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"+ printf '%s' "$JUNIT_CASES"+ echo " </testsuite>"+ echo "</testsuites>"+ } > "$TEST_RECEIPT_DIR/$RECEIPT_ID.junit.xml"+ receipt_end "$([ "$FAIL" -eq 0 ] && echo 0 || echo 1)"+fi+if [ "$FAIL" -gt 0 ]; then+ KEEP_LOGS=1{echo ""echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"@@ -317,10 +371,11 @@ if [ "$FAIL" -gt 0 ]; thenecho "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"printf '%s' "$FAIL_REPORT"echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"- echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=$FAIL"+ echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=$FAIL skip=$SKIP"+ echo "[verify-parallel] per-check logs kept in $LOG_DIR (outcomes.tsv lists every check)"} >&2exit 1fi-echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=0 | all checks green" >&2+echo "[verify-parallel] elapsed=${ELAPSED}s | pass=$PASS fail=0 skip=$SKIP | all checks green" >&2exit 0diff --git a/scripts/run-with-receipt.sh b/scripts/run-with-receipt.shnew file mode 100755index 0000000000..075e42548e--- /dev/null+++ b/scripts/run-with-receipt.sh@@ -0,0 +1,55 @@+#!/usr/bin/env bash+# scripts/run-with-receipt.sh — run one named `bun test` invocation and record+# its executed-test receipt (X2) when GBRAIN_TEST_RECEIPT_DIR is set.+#+# CI jobs that call `bun test` directly (the slow lanes, Tier 1, Tier 2, the+# JSONB parity guard) go through this wrapper so every bun invocation leaves a+# receipt like the runner scripts do. Receipt format and consumers:+# scripts/lib/test-env.sh (receipts_init) and scripts/ci-executed-counts.ts.+#+# Usage:+# bash scripts/run-with-receipt.sh <lane> <tag> -- bun test --timeout=N [args] <files...>+#+# <lane> names the identity lane (unit, slow, tier1, ...); <tag> must be unique+# per invocation inside that lane. Test files are the *.test.ts arguments.+# Without GBRAIN_TEST_RECEIPT_DIR the command runs unchanged. Exit code: the+# command's.++set -euo pipefail++if [ "$#" -lt 5 ] || [ "$3" != "--" ] || [ "$4" != "bun" ] || [ "$5" != "test" ]; then+ echo "usage: bash scripts/run-with-receipt.sh <lane> <tag> -- bun test --timeout=N [args] <files...>" >&2+ exit 2+fi+lane="$1"+tag="$2"+shift 4++cd "$(dirname "$0")/.."+GBRAIN_TEST_RECEIPT_LANE="$lane"+. scripts/lib/test-env.sh+receipts_init "$lane" || exit 2++shift+files=()+has_timeout=0+for arg in "$@"; do+ case "$arg" in+ *.test.ts) files+=("${arg#./}") ;;+ --timeout|--timeout=*) has_timeout=1 ;;+ esac+done+if [ "$has_timeout" = "0" ]; then+ echo "run-with-receipt: pass an explicit --timeout (scripts/check-bun-test-timeout.sh explains why)" >&2+ exit 2+fi+if [ "${#files[@]}" -eq 0 ]; then+ echo "run-with-receipt: no *.test.ts file arguments; a receipt needs the files the invocation runs" >&2+ exit 2+fi++receipt_begin primary "$tag" "" "" "" "${files[@]}"+rc=0+bun test ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} "$@" || rc=$? # "$@" carries --timeout (refused above otherwise)+receipt_end "$rc"+exit "$rc"diff --git a/scripts/test-shard.sh b/scripts/test-shard.shindex 21d29dbb94..10d21c7c04 100755--- a/scripts/test-shard.sh+++ b/scripts/test-shard.sh@@ -58,6 +58,7 @@ ficd "$(dirname "$0")/..". scripts/lib/test-env.sh+receipts_init unit# Collect non-E2E, non-serial unit test files. Slow files INCLUDED — see# header comment. Local run-unit-shard.sh excludes slow files (different@@ -130,6 +131,7 @@ echo "shard $SHARD_INDEX/$TOTAL_SHARDS: ${SHARD_COUNT}/${ALL_COUNT} files (LPT-bif [ "$SHARD_COUNT" -eq 0 ]; thenecho "warning: shard $SHARD_INDEX has no files (total shards may exceed file count)" >&2+ receipt_empty "s${SHARD_INDEX}of${TOTAL_SHARDS}" "$SHARD_INDEX" "$TOTAL_SHARDS"exit 0fi@@ -153,11 +155,19 @@ if [ -n "${COVERAGE_DIR:-}" ]; thenCOVERAGE_ARGS=(--coverage --coverage-reporter=lcov --coverage-dir="$COVERAGE_DIR/shard")XARGS_FLAGS=(-n 100000 -x)fi+# Receipts (X2): one JUnit report per bun process. A second xargs batch would+# overwrite it the same way it overwrites lcov.info, so receipts also force+# the single-invocation -x tripwire.+shard_file_args=()+while IFS= read -r f; do [ -n "$f" ] && shard_file_args+=("$f"); done <<< "$SHARD_FILES"+receipt_begin primary "s${SHARD_INDEX}of${TOTAL_SHARDS}" "$SHARD_INDEX" "$TOTAL_SHARDS" "" "${shard_file_args[@]}"+[ "${#RECEIPT_ARGS[@]}" -eq 0 ] || XARGS_FLAGS=(-n 100000 -x)# --max-concurrency mirrors the local runner: unbounded intra-process# concurrency under parallel PGLite boots produced real shard deaths (the# 22-minute matrix timeout in test.yml records 13 of them).rc=0-printf '%s\n' "$SHARD_FILES" | xargs ${XARGS_FLAGS[@]+"${XARGS_FLAGS[@]}"} bun test --timeout=60000 --max-concurrency="${GBRAIN_TEST_MAX_CONCURRENCY:-4}" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} || rc=$?+printf '%s\n' "$SHARD_FILES" | xargs ${XARGS_FLAGS[@]+"${XARGS_FLAGS[@]}"} bun test --timeout=60000 --max-concurrency="${GBRAIN_TEST_MAX_CONCURRENCY:-4}" ${COVERAGE_ARGS[@]+"${COVERAGE_ARGS[@]}"} ${RECEIPT_ARGS[@]+"${RECEIPT_ARGS[@]}"} || rc=$?+receipt_end "$rc"# Lane manifest: written ONLY on a fully green run (complete:true means the# lcov data represents the whole shard). The real exit code is preserveddiff --git a/test/scripts/e2e-runner.test.ts b/test/scripts/e2e-runner.test.tsindex 8a99a456e4..d1815bda6e 100644--- a/test/scripts/e2e-runner.test.ts+++ b/test/scripts/e2e-runner.test.ts@@ -1,5 +1,5 @@import { describe, test, expect } from 'bun:test';-import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, copyFileSync, chmodSync, existsSync } from 'node:fs';+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync, copyFileSync, chmodSync, existsSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { spawnSync } from 'node:child_process';@@ -87,8 +87,10 @@ test('fresh process',()=>{const failedCoverage = join(root, 'failed-coverage');const bad = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, env: { ...coverageEnv, COVERAGE_DIR: failedCoverage }, encoding: 'utf8' });expect(bad.status).toBe(1);+ // B9: a red lane still records which files it ran; only the+ // complete:true manifest stays green-only.expect(existsSync(join(failedCoverage, 'lane-manifest.json'))).toBe(false);- expect(existsSync(join(failedCoverage, 'executed-files.txt'))).toBe(false);+ expect(readFileSync(join(failedCoverage, 'executed-files.txt'), 'utf8').trim().split('\n').sort()).toEqual(files);} finally { rmSync(root, { recursive: true, force: true }); }});test.each(['empty', 'populated'])('refuses an existing %s coverage destination without changing its files', kind => {@@ -167,7 +169,7 @@ test('parent',()=>{const complete = kind === 'nested summary with parent';expect(result.status, result.stdout + result.stderr).toBe(complete ? 0 : 1);expect(existsSync(join(root, 'coverage/lane-manifest.json'))).toBe(complete);- expect(existsSync(join(root, 'coverage/executed-files.txt'))).toBe(complete);+ expect(readFileSync(join(root, 'coverage/executed-files.txt'), 'utf8')).toBe('test/e2e/a.test.ts\n');if (!complete) expect(result.stdout).toContain('did not produce a complete native Bun report');} finally { rmSync(root, { recursive: true, force: true }); }});@@ -195,7 +197,7 @@ printf '%s' '${output}'expect(result.status, result.stdout + result.stderr).toBe(1);expect(result.stdout).toContain('did not produce a complete native Bun report');expect(existsSync(join(root, 'coverage/lane-manifest.json'))).toBe(false);- expect(existsSync(join(root, 'coverage/executed-files.txt'))).toBe(false);+ expect(readFileSync(join(root, 'coverage/executed-files.txt'), 'utf8')).toBe(`${selected}\n`);} finally { rmSync(root, { recursive: true, force: true }); }});for (const firstFails of [false, true]) test(`each file has a fresh home after a ${firstFails ? 'failing' : 'passing'} config writer`, () => {@@ -276,3 +278,72 @@ printf '%s' '${output}'}}, 10000);});++describe('per-file HOME cleanup and receipts', () => {+ const env = { ...process.env, GBRAIN_NO_SNAPSHOT: '1', DATABASE_URL: '', GBRAIN_DATABASE_URL: '', SHARD: '', COVERAGE_DIR: '' };+ const files = ['test/e2e/a.test.ts', 'test/e2e/b.test.ts'];++ test('a HOME that cannot be removed fails that file by name and the partition continues (B2)', () => {+ const root = setup();+ const tmp = join(root, 'tmp');+ mkdirSync(tmp);+ try {+ writeFileSync(join(root, files[0]), `import {test} from 'bun:test';+import {mkdirSync,writeFileSync,chmodSync} from 'node:fs';+test('leaves an unremovable HOME entry',()=>{+ const dir = process.env.HOME + '/locked';+ mkdirSync(dir + '/inner', { recursive: true });+ writeFileSync(dir + '/inner/x', 'x');+ chmodSync(dir, 0o500);+});`);+ const r = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, encoding: 'utf8', env: { ...env, TMPDIR: tmp } });+ expect(r.status, r.stdout + r.stderr).toBe(1);+ expect(r.stdout).toMatch(/FAILED: a\.test\.ts left a process writing to its HOME; cleanup could not remove \S+file-1-direct/);+ expect(r.stdout).toContain('Fix: make the test wait for or stop its children; reproduce with: bash scripts/run-e2e.sh test/e2e/a.test.ts');+ expect(r.stdout).toContain('=== b.test.ts ===');+ expect(r.stdout).toContain('Files: 2 total, 1 passed, 1 failed');+ } finally {+ spawnSync('chmod', ['-R', 'u+rwx', tmp]);+ rmSync(root, { recursive: true, force: true });+ }+ });++ test.skipIf(process.platform !== 'linux')('a child left running with the file HOME is killed before cleanup and named', () => {+ const root = setup();+ try {+ writeFileSync(join(root, files[0]), `import {test} from 'bun:test';+import {spawn} from 'node:child_process';+import {writeFileSync} from 'node:fs';+test('leaks a detached child',()=>{+ const child = spawn('sleep', ['60'], { detached: true, stdio: 'ignore', env: process.env });+ child.unref();+ writeFileSync(${JSON.stringify(join(root, 'leak.pid'))}, String(child.pid));+});`);+ const r = spawnSync('bash', ['scripts/run-e2e.sh', files[0]], { cwd: root, encoding: 'utf8', env });+ expect(r.status, r.stdout + r.stderr).toBe(0);+ expect(r.stdout).toContain('WARN: a.test.ts left processes running with HOME=');+ const pid = Number(readFileSync(join(root, 'leak.pid'), 'utf8'));+ let alive = true;+ for (let i = 0; i < 50 && alive; i++) {+ try { process.kill(pid, 0); alive = !/\) Z /.test(readFileSync(`/proc/${pid}/stat`, 'utf8')); } catch { alive = false; }+ if (alive) Bun.sleepSync(20);+ }+ expect(alive).toBe(false);+ } finally { rmSync(root, { recursive: true, force: true }); }+ });++ test('each file pass leaves a receipt with its native JUnit report, failures included', () => {+ const root = setup();+ try {+ writeFileSync(join(root, files[1]), "import {test,expect} from 'bun:test';test('breaks',()=>expect(1).toBe(2));");+ const receipts = join(root, 'receipts');+ const r = spawnSync('bash', ['scripts/run-e2e.sh', ...files], { cwd: root, encoding: 'utf8', env: { ...env, GBRAIN_TEST_RECEIPT_DIR: receipts, GBRAIN_TEST_RECEIPT_LANE: 'tier9' } });+ expect(r.status).toBe(1);+ const ids = readdirSync(receipts).filter(n => n.endsWith('.receipt')).sort();+ expect(ids).toEqual(['tier9--run-f1-direct--primary.receipt', 'tier9--run-f2-direct--primary.receipt']);+ expect(readFileSync(join(receipts, ids[1]), 'utf8')).toContain('exit=1');+ expect(readFileSync(join(receipts, 'tier9--run-f2-direct--primary.junit.xml'), 'utf8')).toContain('<failure');+ expect(readFileSync(join(receipts, 'tier9--run-f2-direct--primary.files'), 'utf8')).toBe('test/e2e/b.test.ts\n');+ } finally { rmSync(root, { recursive: true, force: true }); }+ });+});diff --git a/test/scripts/run-unit-shard.test.ts b/test/scripts/run-unit-shard.test.tsindex 7e3c014f52..69e4440184 100644--- a/test/scripts/run-unit-shard.test.ts+++ b/test/scripts/run-unit-shard.test.ts@@ -17,7 +17,7 @@ import { describe, it, expect } from 'bun:test';import { execFileSync, spawnSync } from 'child_process';import { chmodSync, copyFileSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'fs';import { tmpdir } from 'os';-import { join, resolve } from 'path';+import { dirname, join, resolve } from 'path';const REPO_ROOT = resolve(import.meta.dir, '..', '..');const SHARD_SH = resolve(REPO_ROOT, 'scripts/run-unit-shard.sh');@@ -87,8 +87,10 @@ describe('run-unit-shard.sh timeout multiplier reach', () => {function runGroupedFixture(count: number, mode = 'pass', shard = '') {const root = mkdtempSync(join(tmpdir(), 'gbrain-unit-groups-test-'));try {- for (const dir of ['scripts', 'test', 'bin', 'calls']) mkdirSync(join(root, dir));+ for (const dir of ['scripts', 'scripts/lib', 'test', 'bin', 'calls']) mkdirSync(join(root, dir));copyFileSync(SHARD_SH, join(root, 'scripts/run-unit-shard.sh'));+ // The runner sources the shared lib (receipt helpers) — stage it too.+ copyFileSync(join(dirname(SHARD_SH), 'lib/test-env.sh'), join(root, 'scripts/lib/test-env.sh'));const files = Array.from({ length: count }, (_, i) => `test/case-${String(i).padStart(4, '0')}.test.ts`);for (const file of files) writeFileSync(join(root, file), '');for (const file of ['ignored.slow.test.ts', 'ignored.serial.test.ts']) writeFileSync(join(root, 'test', file), '');diff --git a/test/scripts/run-verify-parallel.test.ts b/test/scripts/run-verify-parallel.test.tsindex e5a445e49b..def298307b 100644--- a/test/scripts/run-verify-parallel.test.ts+++ b/test/scripts/run-verify-parallel.test.ts@@ -272,6 +272,9 @@ describe("run-verify-parallel.sh — no-timeout-binary fallback rc capture (regr`#!/usr/bin/env bashname="\${2:-}"echo "stub check OK: $name"+if [ -n "\${STUB_SKIP_CHECK:-}" ] && [ "$name" = "\${STUB_SKIP_CHECK}" ]; then+ echo "GBRAIN_CHECK_SKIPPED: subject absent in this checkout"+fiif [ -n "\${STUB_FAIL_CHECK:-}" ] && [ "$name" = "\${STUB_FAIL_CHECK}" ]; thenecho "stub check failing: $name" >&2exit 7@@ -309,6 +312,48 @@ exit 0}});+ it("records every check's real outcome: a self-skip is a skip (not a pass) in outcomes.tsv and the receipt", () => {+ const { root, env } = makeFallbackHarness();+ try {+ const receipts = join(root, "receipts");+ const r = spawnSync("bash", [join(root, "scripts", "run-verify-parallel.sh")], {+ encoding: "utf8",+ env: { ...env, STUB_SKIP_CHECK: "check:grok-pin", STUB_FAIL_CHECK: "check:jsonb", GBRAIN_TEST_RECEIPT_DIR: receipts },+ });+ expect(r.status).toBe(1);+ expect(r.stderr).toMatch(/fail=1 skip=1\b/);+ expect(r.stderr).toContain("check:grok-pin: subject absent in this checkout");+ const outcomes = readFileSync(join(root, "logs", "outcomes.tsv"), "utf8");+ expect(outcomes).toContain("check:grok-pin\tskip\t0\tsubject absent in this checkout");+ expect(outcomes).toContain("check:jsonb\tfail\t7\t");+ expect(outcomes).toContain("check:privacy\tpass\t0\t");+ const junit = readFileSync(join(receipts, "verify--all--primary.junit.xml"), "utf8");+ expect(junit).toContain('<testcase name="check:grok-pin" classname="verify" file="verify"><skipped message="subject absent in this checkout" /></testcase>');+ expect(junit).toContain('<testcase name="check:jsonb" classname="verify" file="verify"><failure message="fail rc=7" /></testcase>');+ expect(readFileSync(join(receipts, "verify--all--primary.receipt"), "utf8")).toContain("exit=1");+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+ });++ it("keeps its default temp log directory when a check fails and names it", () => {+ const { root, env } = makeFallbackHarness();+ const { GBRAIN_VERIFY_LOG_DIR: _unused, ...defaults } = env;+ try {+ const r = spawnSync("bash", [join(root, "scripts", "run-verify-parallel.sh")], {+ encoding: "utf8",+ env: { ...defaults, STUB_FAIL_CHECK: "check:jsonb" },+ });+ expect(r.status).toBe(1);+ const kept = /per-check logs kept in (\S+)/.exec(r.stderr)?.[1];+ expect(kept).toBeDefined();+ expect(readFileSync(join(kept!, "check_jsonb.log"), "utf8")).toContain("stub check failing: check:jsonb");+ rmSync(kept!, { recursive: true, force: true });+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+ });+it("one check failing → exit 1, sentinel records the check's own rc (7), not 143", () => {const { root, env } = makeFallbackHarness();try {diff --git a/test/scripts/run-with-receipt.test.ts b/test/scripts/run-with-receipt.test.tsnew file mode 100644index 0000000000..2724c68d62--- /dev/null+++ b/test/scripts/run-with-receipt.test.ts@@ -0,0 +1,59 @@+import { describe, test, expect } from 'bun:test';+import { copyFileSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { spawnSync } from 'node:child_process';+import { buildSide, loadReceiptDir } from '../../scripts/ci-executed-counts.ts';++const REPO = join(import.meta.dir, '../..');++function sandbox() {+ const root = mkdtempSync(join(tmpdir(), 'gbrain-with-receipt-'));+ mkdirSync(join(root, 'scripts/lib'), { recursive: true });+ mkdirSync(join(root, 'test'));+ copyFileSync(join(REPO, 'scripts/run-with-receipt.sh'), join(root, 'scripts/run-with-receipt.sh'));+ copyFileSync(join(REPO, 'scripts/lib/test-env.sh'), join(root, 'scripts/lib/test-env.sh'));+ // Receipt variables are consumed by the wrapper; the test process must never see them.+ writeFileSync(join(root, 'test/a.test.ts'), `import { describe, test, expect } from 'bun:test';+describe('wrapped', () => {+ test('hides receipt routing', () => {+ expect(process.env.GBRAIN_TEST_RECEIPT_DIR).toBeUndefined();+ expect(process.env.GBRAIN_TEST_RECEIPT_LANE).toBeUndefined();+ });+ test.skip('optional', () => {});+});`);+ return root;+}+const run = (root: string, args: string[], env: Record<string, string> = {}) =>+ spawnSync('bash', ['scripts/run-with-receipt.sh', ...args], { cwd: root, encoding: 'utf8', env: { ...process.env, GBRAIN_NO_SNAPSHOT: '1', ...env } });++describe('run-with-receipt.sh', () => {+ test('records lane, files, exit and the native JUnit report for one bun invocation', () => {+ const root = sandbox();+ try {+ const receipts = join(root, 'receipts');+ const r = run(root, ['slow', 'perf-a', '--', 'bun', 'test', 'test/a.test.ts', '--timeout=60000'], { GBRAIN_TEST_RECEIPT_DIR: receipts });+ expect(r.status, r.stdout + r.stderr).toBe(0);+ expect(readdirSync(receipts).sort()).toEqual(['slow--perf-a--primary.files', 'slow--perf-a--primary.junit.xml', 'slow--perf-a--primary.receipt']);+ const meta = readFileSync(join(receipts, 'slow--perf-a--primary.receipt'), 'utf8');+ expect(meta).toContain('lane=slow\n');+ expect(meta).toContain('exit=0\n');+ const side = buildSide('local', loadReceiptDir(receipts));+ expect(side.issues).toEqual([]);+ expect([...side.identities.values()].map(i => [i.test, i.status])).toEqual([['wrapped > hides receipt routing', 'pass'], ['wrapped > optional', 'skip']]);+ } finally { rmSync(root, { recursive: true, force: true }); }+ });++ test('runs the command unchanged without a receipt directory and refuses a missing --timeout', () => {+ const root = sandbox();+ try {+ const plain = run(root, ['slow', 'perf-a', '--', 'bun', 'test', '--timeout=60000', 'test/a.test.ts']);+ expect(plain.status, plain.stdout + plain.stderr).toBe(0);+ expect(readdirSync(root).includes('receipts')).toBe(false);+ const bare = run(root, ['slow', 'perf-a', '--', 'bun', 'test', 'test/a.test.ts']);+ expect(bare.status).toBe(2);+ expect(bare.stderr).toContain('pass an explicit --timeout');+ expect(run(root, ['slow', '--', 'bun', 'test']).status).toBe(2);+ } finally { rmSync(root, { recursive: true, force: true }); }+ });+});