Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
verify: run the self-timed guard self-test alone after the pool drains
garrytan21b5109141d5
diff --git a/docs/TESTING.md b/docs/TESTING.mdindex 4115a310f8..222621acfb 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -404,7 +404,7 @@ Test command tiers, each with a clear scope:| Command | What it runs | Wallclock | When to use ||---|---|---|---|| `bun run test` | Parallel unit loop (`scripts/run-unit-parallel.sh`): weighted shards (CPU-detected, 4 by default, at most 8; CI uses 8), then the serial pass. Excludes `*.slow.test.ts` and `test/e2e/*`; no typecheck. Builds the PGLite schema snapshot first and exports `GBRAIN_PGLITE_SNAPSHOT` (opt out: `GBRAIN_NO_SNAPSHOT=1`). Caps total concurrency to available memory at `GBRAIN_TEST_MEM_PER_FILE_MB` (default 1536) per slot, shedding intra-shard width before shards. Shards that fail with the WASM out-of-memory signature or are killed externally get one serial rescue pass: phantoms go green with an `oom_rescued` note, real failures stay red. Knobs: `GBRAIN_TEST_NO_MEM_ADAPT=1`, `GBRAIN_TEST_NO_OOM_FALLBACK=1`, `GBRAIN_TEST_MAX_CONCURRENCY` (default 4), `GBRAIN_TEST_SHARD_TIMEOUT` / `GBRAIN_TEST_SHARD_KILL_AFTER`, `--shards N` / `--max-concurrency N` / `--dry-run`. | a few minutes on a laptop | Inner edit loop. Default. |-| `bun run verify` | CI's authoritative pre-test gate set, fanned out by `scripts/run-verify-parallel.sh` through a bounded worker pool (default `detect_cpus`; override `GBRAIN_VERIFY_MAX_PARALLEL`) with the heavy checks ordered first (typecheck, the two compile-embed checks, admin build, fuzz bundles, guard self-tests, whole-tree greps). `check:eval-chronicle` and `check:eval-canary` are deliberately NOT in the battery (their test-file twins `test/eval-chronicle.test.ts` and `test/eval-canary.test.ts` run the identical evals in the unit matrix, and CI's verify job and matrix always run together — the package scripts stay for on-demand runs, so `verify`-only local callers should know both evals ride the unit lane instead). The `CHECKS` array in that script is the single source of truth — CI literally calls `bun run verify` in a dedicated job. | ~50s (pool-bounded; longest check dominates) | Before pushing; before `/ship`. |+| `bun run verify` | CI's authoritative pre-test gate set, fanned out by `scripts/run-verify-parallel.sh` through a bounded worker pool (default `detect_cpus`; override `GBRAIN_VERIFY_MAX_PARALLEL`) with the heavy checks ordered first (typecheck, the two compile-embed checks, admin build, fuzz bundles, whole-tree greps), then the `SOLO_CHECKS` that time themselves (the guard self-test and its 30 s budget) one at a time after the pool drains, so their budgets measure their own work and not the heavy checks beside them. `outcomes.tsv` in the log directory records every check's wall seconds and the summary names the five slowest. `check:eval-chronicle` and `check:eval-canary` are deliberately NOT in the battery (their test-file twins `test/eval-chronicle.test.ts` and `test/eval-canary.test.ts` run the identical evals in the unit matrix, and CI's verify job and matrix always run together — the package scripts stay for on-demand runs, so `verify`-only local callers should know both evals ride the unit lane instead). The `CHECKS` array in that script is the single source of truth — CI literally calls `bun run verify` in a dedicated job. | ~65-85s (pool makespan, typecheck dominates, plus the ~15-19s solo guard self-test) | Before pushing; before `/ship`. || `bun run test:full` | `verify && bun run test && bun run test:slow && [smart e2e]`. Smart e2e runs only when `DATABASE_URL` is set and propagates its failure; otherwise it prints a skip notice to stderr. Use `ci:local` to provision the databases and require PgBouncer execution. | ~3-5min depending on slow + e2e | Pre-merge sanity, before opening a PR. || `bun run ci:local` | Independent host gitleaks scans, then frozen dependencies, guards/typecheck, the complete serial and slow lanes, and four unit/E2E shards inside Docker. Each E2E shard has its own pgvector database; selected PgBouncer tests must execute against the transaction-mode pooler. Unit, serial, and slow lanes have database URL overrides unset. Any failed stage fails the command. Complete shard logs survive container teardown under `.context/ci-local-shards/`. `ci:local:diff` runs only gitleaks and the doc checks on a doc-only diff and the full gate otherwise; `--no-shard` runs unit/E2E sequentially. Doc-only diffs still require successful gitleaks scans. | Depends on the full corpus | Full local gate before shipping. || `bun run ci:ubicloud` | The `ci:local` lanes (gitleaks, guards/typecheck, serial, slow, unit, all E2E with required PgBouncer execution) fanned out across ephemeral Ubicloud VMs from one heaviest-first work queue; `ci:ubicloud:diff` takes the same doc-only fast path as `ci:local:diff`. Needs `UBICLOUD_API_KEY` or `UBICLOUD_API_TOKEN`, no local Docker. See "Ubicloud fan-out" below. | ~5 min (floor: the longest single file) | Full gate before shipping when a Ubicloud token is available. |@@ -432,7 +432,8 @@ array in `scripts/run-verify-parallel.sh` is the single execution list`check:no-legacy-getconnection`). The guard REGISTRY is `scripts/guards-manifest.tsv` (see "Guard registry andself-test" below).-`bun run typecheck` uses TypeScript's native incremental analysis in+`bun run typecheck` runs tsc under `node --max-old-space-size=6144` (tsc peaks+near 3.5 GB of heap; Node's default limit is about 2 GB on an 8 GB host) and uses TypeScript's native incremental analysis in`node_modules/.cache/gbrain-typecheck.tsbuildinfo`. Every invocation still runsthe compiler; source, root-file, configuration and dependency changes invalidatethe affected analysis, and cached diagnostics remain failures. The cache is localdiff --git a/scripts/run-verify-parallel.sh b/scripts/run-verify-parallel.shindex c443f4f208..f54bacb7bb 100755--- a/scripts/run-verify-parallel.sh+++ b/scripts/run-verify-parallel.sh@@ -2,13 +2,15 @@# scripts/run-verify-parallel.sh — parallel verify dispatcher.## Runs the verify checks (privacy, jsonb, source-id, … + typecheck +-# admin-build) as background jobs, waits for all, aggregates exit codes,+# admin-build) as background jobs through a bounded pool, then the+# self-timed SOLO_CHECKS one at a time, waits for all, aggregates exit codes,# surfaces failed-check name + tail of its log to stderr. The CHECKS array-# below is the single source of truth for what runs (50+ checks; count it,-# don't trust prose).+# plus SOLO_CHECKS below are the single source of truth for what runs (50++# checks; count them, don't trust prose).## Replaces the sequential `&&`-chain in package.json's `verify` script.-# Wallclock: pool-bounded — the longest check (typecheck) dominates.+# Wallclock: the pool makespan (the longest check, typecheck, dominates) plus+# the solo phase (the guard self-test alone, ~15-19 s).## Usage:# bash scripts/run-verify-parallel.sh # run every CHECK below@@ -49,12 +51,14 @@ receipts_init verify || exit 2# GBRAIN_VERIFY_MAX_PARALLEL workers, so the heaviest checks go FIRST# (LPT-style — makespan ≈ max(longest check, total/POOL)). The heavy block:# typecheck (tsc), two `cp -R src` + `bun build --compile` binary builds,-# the admin vite+tsc build, the fuzz bundles, guard self-tests, the-# PGLite-booting eval checks, and the whole-tree greps. Everything after is-# sub-second; that tail keeps its historical order for grep-ability.+# the admin vite+tsc build, the fuzz bundles, the PGLite-booting eval+# checks, and the whole-tree greps. Everything after is sub-second; that tail+# keeps its historical order for grep-ability. The guard self-test is not+# here: it times itself, so it runs in SOLO_CHECKS below.#-# To add a check: append to the right block. To skip in CI temporarily,-# comment the line — the runner doesn't care about count.+# To add a check: add one line to the right block of CHECKS (a plain list).+# To skip in CI temporarily, comment the line — the runner doesn't care+# about count.# ──────────────────────────────────────────────────────────────────────────CHECKS=(# ── heavy (longest-first) ──@@ -66,10 +70,6 @@ CHECKS=(# bundles a handful of modules, not the CLI)."check:image-decoders""check:fuzz-purity"- # W0 fix-wave (Tier-1 #11): guard self-tests — every scanner guard proves it- # can fail (bad fixture → exit 1) before it counts as coverage. Registry:- # scripts/guards-manifest.tsv (package.json's stale `check:all` copy deleted).- "check:guard-self-test"# B4 (test-gap wave 2): runtime-reachability walk over src/** — hard-fails# true orphans (unreachable from every entrypoint AND every test) and any# test-only module without a reasoned PERMITTED_TEST_ONLY entry. ~1s.@@ -187,6 +187,23 @@ CHECKS=("check:compile-autoload")+# ──────────────────────────────────────────────────────────────────────────+# Solo checks: a check that enforces its OWN wall-clock budget runs here, one+# at a time, after the pool above has drained, with the whole machine. In the+# pool its budget measured the neighbours: on the 8-vCPU verify runner the+# guard self-test (15-19 s alone) crossed its 30 s budget beside typecheck and+# the binary builds (31 s, job 111694069284; 32 s on macOS 26). Everything+# else belongs in CHECKS; add here only a check that times itself.+# ──────────────────────────────────────────────────────────────────────────+SOLO_CHECKS=(+ # W0 fix-wave (Tier-1 #11): guard self-tests — every scanner guard proves it+ # can fail (bad fixture → exit 1) before it counts as coverage. Registry:+ # scripts/guards-manifest.tsv (package.json's stale `check:all` copy deleted).+ # Budget: 30 s wall clock (scripts/guard-self-test.sh BUDGET_SECONDS).+ "check:guard-self-test"+)+ALL_CHECKS=("${CHECKS[@]}" "${SOLO_CHECKS[@]}")+if [ "${#CHECKS[@]}" -eq 0 ]; thenecho "ERROR: no checks defined in run-verify-parallel.sh" >&2exit 2@@ -194,7 +211,7 @@ fi# Dry-run path: list checks, exit. Used by tests + ops debugging.if [ "${1:-}" = "--dry-list" ]; then- printf '%s\n' "${CHECKS[@]}"+ printf '%s\n' "${ALL_CHECKS[@]}"exit 0fi@@ -241,7 +258,7 @@ fiensure_pglite_snapshot "verify-parallel"START_TS=$(date +%s)-echo "[verify-parallel] running ${#CHECKS[@]} checks (pool=$MAX_PAR, timeout=${TIMEOUT}s, logs=$LOG_DIR)" >&2+echo "[verify-parallel] running ${#ALL_CHECKS[@]} checks: ${#CHECKS[@]} in the pool, then ${#SOLO_CHECKS[@]} solo (pool=$MAX_PAR, timeout=${TIMEOUT}s, logs=$LOG_DIR)" >&2# ──────────────────────────────────────────────────────────────────────────# Spawn one background process per check. Each child captures its own exit@@ -253,11 +270,8 @@ echo "[verify-parallel] running ${#CHECKS[@]} checks (pool=$MAX_PAR, timeout=${T# ──────────────────────────────────────────────────────────────────────────PIDS=()SAFE_NAMES=()-for c in "${CHECKS[@]}"; do- # Throttle to the worker pool (bash 3.2 — no wait -n; jobs -rp reaps).- while [ "$(jobs -rp | wc -l | tr -d ' ')" -ge "$MAX_PAR" ]; do- sleep 0.1- done+spawn_check() {+ c="$1"safe="${c//:/_}"SAFE_NAMES+=("$safe")LOG_FILE="$LOG_DIR/$safe.log"@@ -298,12 +312,27 @@ for c in "${CHECKS[@]}"; doecho "$rc" > "$EXIT_FILE") &PIDS+=($!)+}++for c in "${CHECKS[@]}"; do+ # Throttle to the worker pool (bash 3.2 — no wait -n; jobs -rp reaps).+ while [ "$(jobs -rp | wc -l | tr -d ' ')" -ge "$MAX_PAR" ]; do+ sleep 0.1+ done+ spawn_check "$c"done# Wait for every background job. Ignore wait's aggregate exit — exit codes# live in the sentinel files.for pid in "${PIDS[@]}"; do wait "$pid" 2>/dev/null || true; done+# Solo phase: each SOLO_CHECKS entry runs alone after the pool has drained,+# so its own wall-clock budget measures its own work, not the heavy checks.+for c in "${SOLO_CHECKS[@]}"; do+ spawn_check "$c"+ wait "$!" 2>/dev/null || true+done+END_TS=$(date +%s)ELAPSED=$((END_TS - START_TS))@@ -323,8 +352,8 @@ printf 'check\toutcome\trc\tdetail\tseconds\n' > "$OUTCOMES"xml_escape() { sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' -e 's/"/\"/g'; }JUNIT_CASES=""-for i in "${!CHECKS[@]}"; do- c="${CHECKS[$i]}"+for i in "${!ALL_CHECKS[@]}"; do+ c="${ALL_CHECKS[$i]}"safe="${SAFE_NAMES[$i]}"EXIT_FILE="$LOG_DIR/$safe.exit"LOG_FILE="$LOG_DIR/$safe.log"@@ -382,8 +411,8 @@ receipt_begin primary all "" "" "" verifyif [ -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\">"+ echo "<testsuites name=\"verify\" tests=\"${#ALL_CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"+ echo " <testsuite name=\"verify\" file=\"verify\" tests=\"${#ALL_CHECKS[@]}\" failures=\"$FAIL\" skipped=\"$SKIP\">"printf '%s' "$JUNIT_CASES"echo " </testsuite>"echo "</testsuites>"@@ -396,7 +425,7 @@ if [ "$FAIL" -gt 0 ]; then{echo ""echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"- echo "❌ verify failed: $FAIL/${#CHECKS[@]} checks did not pass"+ echo "❌ verify failed: $FAIL/${#ALL_CHECKS[@]} checks did not pass"echo "Failed: ${FAIL_NAMES[*]}"echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"printf '%s' "$FAIL_REPORT"