Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(verify): the guard self-test runs its guards 4 at a time, well inside the 30 s budget

time-attackb537cf9ff448
diff --git a/docs/TESTING.md b/docs/TESTING.md
index 420525a58b..e036baa383 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -832,7 +832,9 @@ guards are exempt-with-reason, not fixture-tested).
`bun run verify`) proves every `selftest=yes` scanner CAN fail: it runs each
one against known-bad (must exit non-zero) and known-good (must pass) fixture
trees under `test/fixtures/guards/<guard>/{bad,good}/` via the
-`GBRAIN_GUARD_ROOT` env seam, and enforces manifest completeness — a new
+`GBRAIN_GUARD_ROOT` env seam (guards run 4 at a time, `GUARD_SELF_TEST_JOBS`
+overrides; results print in manifest order; the whole pass must finish inside
+its 30 s budget), and enforces manifest completeness — a new
`scripts/check-*` script that isn't registered in the manifest fails the
build. A guard whose pattern rots into a permanently-green no-op fails CI
instead of masquerading as coverage.
diff --git a/docs/architecture/key-files/tooling-and-tests.md b/docs/architecture/key-files/tooling-and-tests.md
index f2189feb79..324470a6d0 100644
--- a/docs/architecture/key-files/tooling-and-tests.md
+++ b/docs/architecture/key-files/tooling-and-tests.md
@@ -54,7 +54,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `scripts/generate-wave-1-moves.ts` + `docs/architecture/wave-1-moves.json` + `docs/architecture/wave-1-porting.md` — the refactor wave 1 porting kit. The generator diffs `src/**/*.ts` between the merge-base with `origin/master` (`--base`) and HEAD (`--head`) and maps every changed top-level symbol (functions, class members, variables, types) to its new home(s): whole-body token containment first (the `scripts/lib/normalize-tokens.ts` normal form, relative `import()`/`require()` specifiers resolved to repo paths), then sub-statement chunks for splits, then same-named delegation from a remaining façade member, then the name. Symbols with unchanged tokens and in-place edits are omitted; removed symbols with no destination go to `unmapped`. Each entry records `kind` (`moved` / `split` / `extracted`), the old path that still exports the name (`facade`) and `wasExported`. The markdown (recipes per conflict kind, generated-file commands, agent prompt, landing window) is rendered from the JSON; the JSON's `landing` block (integration owner, freeze window, who lifts it) survives regeneration, and `--render` refreshes only the markdown. Pinned by `test/scripts/generate-wave-1-moves.test.ts` (every `new`/`facade` entry resolves in the tree; markdown equals the rendering; classifier on a synthetic base/head pair).
-- `scripts/guards-manifest.tsv` + `scripts/guard-self-test.sh` — THE single registry of `scripts/check-*` CI guards (53 guards) and its self-test harness. Every guard is classified `scanner` (greps/parses repo sources — must eventually carry fixtures), `buildfresh`, or `repostate` (exempt-with-reason, not fixture-tested). `guard-self-test.sh` (`bun run check:guard-self-test`, wired into `bun run verify`) runs each `selftest=yes` scanner against known-bad (must exit non-zero) and known-good (must pass) fixture trees under `test/fixtures/guards/<guard>/{bad,good}/` via the `GBRAIN_GUARD_ROOT` env seam, and fails the build when a new `scripts/check-*` script is missing from the manifest — so a guard whose pattern rots into a permanently-green no-op fails CI instead of masquerading as coverage. The manifest registers and classifies guards but does not itself schedule them — `run-verify-parallel.sh`'s `CHECKS` array remains the execution list, and a registered guard is not automatically wired into verify. New guard = new manifest row (+ fixtures if scanner) + a `CHECKS` entry if it should gate pushes.
+- `scripts/guards-manifest.tsv` + `scripts/guard-self-test.sh` — THE single registry of `scripts/check-*` CI guards (53 guards) and its self-test harness. Every guard is classified `scanner` (greps/parses repo sources — must eventually carry fixtures), `buildfresh`, or `repostate` (exempt-with-reason, not fixture-tested). `guard-self-test.sh` (`bun run check:guard-self-test`, wired into `bun run verify`) runs each `selftest=yes` scanner against known-bad (must exit non-zero) and known-good (must pass) fixture trees under `test/fixtures/guards/<guard>/{bad,good}/` via the `GBRAIN_GUARD_ROOT` env seam (independent guards run `GUARD_SELF_TEST_JOBS`, default 4, at a time; results print in manifest order; the pass has a 30 s wall-clock budget), and fails the build when a new `scripts/check-*` script is missing from the manifest — so a guard whose pattern rots into a permanently-green no-op fails CI instead of masquerading as coverage. The manifest registers and classifies guards but does not itself schedule them — `run-verify-parallel.sh`'s `CHECKS` array remains the execution list, and a registered guard is not automatically wired into verify. New guard = new manifest row (+ fixtures if scanner) + a `CHECKS` entry if it should gate pushes.
- `scripts/llms-config.ts` + `scripts/build-llms.ts` — Generator for `llms.txt` (llmstxt.org-spec web index) + `llms-full.txt` (inlined single-fetch bundle). Curated config drives both. Run `bun run build:llms` after adding a new doc. `LLMS_REPO_BASE` env lets forks regenerate with their own URL base. `FULL_SIZE_BUDGET` (600KB) caps the inline bundle; generator WARNs if exceeded. Committed output has no runtime consumer; committed for GitHub browsing and fork-safe fetching.
diff --git a/scripts/guard-self-test.sh b/scripts/guard-self-test.sh
index 79d315d603..7b8984bc39 100755
--- a/scripts/guard-self-test.sh
+++ b/scripts/guard-self-test.sh
@@ -47,39 +47,62 @@ run_guard() {
esac
}
-while IFS=$'\t' read -r guard klass selftest _notes; do
- case "$guard" in ''|'#'*) continue ;; esac
- [ "$selftest" = "yes" ] || continue
- tested=$((tested + 1))
-
+# One guard's bad/good cases; prints its result line and exits non-zero per failure.
+self_test_guard() {
+ local guard="$1" bad good guard_ok=1 variants=0 failed=0 bad_tree
bad="$FIXTURES/$guard/bad"
good="$FIXTURES/$guard/good"
if [ ! -d "$bad" ] || [ ! -d "$good" ]; then
echo "FAIL $guard: manifest says selftest=yes but fixtures missing under $FIXTURES/$guard/{bad,good}"
- failures=$((failures + 1))
- continue
+ return 1
fi
# bad/ plus any bad-<variant>/ trees (e.g. one per refactor-wave-1 module
# dir): each must fail ON ITS OWN, proving the guard scans that location.
- guard_ok=1
- variants=0
for bad_tree in "$bad" "$FIXTURES/$guard"/bad-*; do
[ -d "$bad_tree" ] || continue
variants=$((variants + 1))
if run_guard "$guard" "$bad_tree"; then
echo "FAIL $guard: did NOT flag the known-bad fixture $(basename "$bad_tree") — the guard is a no-op there (the check-no-double-retry class)"
- failures=$((failures + 1))
+ failed=$((failed + 1))
guard_ok=0
fi
done
if ! run_guard "$guard" "$good"; then
echo "FAIL $guard: flagged the known-good fixture — false positive"
- failures=$((failures + 1))
+ failed=$((failed + 1))
elif [ "$guard_ok" = "1" ]; then
echo "ok $guard (bad→fail x$variants, good→pass)"
fi
+ return "$failed"
+}
+
+# Guards are independent (each reads only its own fixture root), so run up to
+# GUARD_SELF_TEST_JOBS at once and print results in manifest order.
+JOBS="${GUARD_SELF_TEST_JOBS:-4}"
+OUT_DIR="$(mktemp -d)"
+trap 'rm -rf "$OUT_DIR"' EXIT
+guards=()
+while IFS=$'\t' read -r guard klass selftest _notes; do
+ case "$guard" in ''|'#'*) continue ;; esac
+ [ "$selftest" = "yes" ] || continue
+ guards+=("$guard")
done < "$MANIFEST"
+pids=()
+for i in "${!guards[@]}"; do
+ if [ "${#pids[@]}" -ge "$JOBS" ]; then
+ wait "${pids[0]}"
+ pids=("${pids[@]:1}")
+ fi
+ ( self_test_guard "${guards[$i]}" > "$OUT_DIR/$i.out" 2>&1; echo $? > "$OUT_DIR/$i.rc" ) &
+ pids+=("$!")
+done
+wait
+for i in "${!guards[@]}"; do
+ tested=$((tested + 1))
+ cat "$OUT_DIR/$i.out"
+ failures=$((failures + $(cat "$OUT_DIR/$i.rc" 2>/dev/null || echo 1)))
+done
# Manifest completeness: every scripts/check-* guard must have a manifest row
# (new guards can't silently skip classification).