Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs: key-files entries and lane record for executed-test receipts
garrytanef00e2decb95
diff --git a/docs/architecture/key-files/tooling-and-tests.md b/docs/architecture/key-files/tooling-and-tests.mdindex a43bce80ae..1ae6c0aae3 100644--- a/docs/architecture/key-files/tooling-and-tests.md+++ b/docs/architecture/key-files/tooling-and-tests.md@@ -68,13 +68,14 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `scripts/r1-namedthing-rerank-ab.ts` — Phase C′ rule R1 receipt: balanced reranker ON vs OFF on NamedThingBench, paired per query, in ONE in-memory PGLite brain seeded ONCE with real embeddings (`seedNamedThingCorpus`; `--relational` adds `relational/corpus.ts` + its 38 `RELATIONAL_QUESTIONS`, which with the fixture's own `graph-relationship` query are the 39 relational questions the receipt reports beside the 11 non-relational core queries). Arms are applied with `engine.setConfig` (`ARM_PINS`: OFF = `search.mode balanced`, `search.reranker.enabled false`, `search.autocut false`; ON adds `search.reranker.enabled true` + `search.reranker.model voyage:rerank-2.5`; autocut pinned off in both by default — a rerank-only comparison — and `--autocut on|off` is an overlay applied to BOTH arms through `applyArmPins(engine, arm, overlay)` so the ON arm can run in the pre-R2 shipped balanced shape (autocut on) without changing the pinned defaults the tests pin), so bare `hybridSearch` resolves them the way a production balanced brain would; scoring reuses `runRetrievalQuality`/`evaluateGate` (no local hit@k). Per query it records deduped top-3, the rank-1 `evidence`/`create_safety` tier, finite-`rerank_score` row count and the `degraded` stamp. INVARIANTS: readiness (`rerankerReadinessForEngine`) is checked BEFORE any spend and the ON arm must show no `reranker_skipped`/`rerank_passthrough` stage and ≥1 reranked row per non-empty query, else exit 2 (fail-open would silently turn ON into OFF); embedding degradation (`embed_unavailable`/`embed_timeout`/`vector_arm_failed`) in a live arm is exit 2 too; `--embed-cache PATH` (`installEmbedCache`) makes both arms see byte-identical query vectors and the receipt says whether that held (`identical_query_vectors`). `r1Verdict` is pure: PASS iff hit@1 losses == 0 and hit@3 losses ≤ 1, losses counted per query (OFF hit, ON miss) and never offset by wins; create_safety downgrades are counted and named, not gated. A pass-through rerank transport tees the API-echoed model id + usage into the receipt. `--stub-embed` is the hermetic dry run (embed transport throws, OFF arm only, ON reported as skipped — needs `VOYAGE_API_KEY`). `--json` carries `_meta.metric_glossary` (`hit@1`, `hit@3`, `mrr`, `create_safety`); exit 0 PASS/dry-run · 1 FAIL · 2 integrity/usage. Receipt (shipped `balanced`, `voyage:rerank-2.5`): the 11 core queries show 0 hit@1 / 0 hit@3 losses in every cell; the 39 relational queries WITHOUT the relational re-pin fell hit@1 21→3 (19 losses) and hit@3 27→5 (22 losses) — R1 FAIL; WITH `search.relational_rerank_pin` at its default 3 (measured with `--autocut on`, the shape that shipped before rule R2 turned autocut off) 0 losses, hit@1 21/39 and hit@3 27/39 — R1 PASS, the balanced reranker stays ON. `--relational-pin N|off` overlays `search.relational_rerank_pin` on BOTH arms: the no-pin cell is `--relational-pin off` (or `0`); the default cell omits the flag and resolves the bundle default 3 exactly as production does. Pinned by `test/r1-namedthing-rerank-ab.test.ts`.-- `scripts/run-e2e.sh` — Sequential E2E runner. Accepts an optional argv-driven file list (used by `ci:local:diff`) and a `--dry-run-list` flag that prints the resolved file list and exits (used by `ci-local.sh`'s startup smoke-test). Falls back to `test/e2e/*.test.ts` plus `test/phantom-redirect-engine-parity.test.ts` when invoked with no args (the phantom-redirect Postgres arm is only reachable through a DATABASE_URL-bearing lane; the unit wrappers strip the URL, so this lane must carry it). This wrapper is the database-URL opt-in boundary: it exports `GBRAIN_TEST_ALLOW_DATABASE_URL=1` so the bunfig preload guard (`test/helpers/database-url-guard-preload.ts`) lets the run start, unsets `GBRAIN_DATABASE_URL` (the e2e suite runs on `DATABASE_URL` only — an ambient `GBRAIN_DATABASE_URL` would pass the opt-in yet reach CLI-subprocess paths with no name floor), and its GBRAIN_* env scrub preserves `GBRAIN_E2E_ALLOW_DB` so the name-floor escape hatch the guard's own error message names stays usable. It also preserves `GBRAIN_CI_DISABLE_TEST_ENV_FILE=1`, keeping CI runs from loading checkout-local `.env.testing` credentials after the shell-to-Bun handoff. It also exports `GBRAIN_TEST_KEEP_PROVIDER_KEYS=1` so the unit-lane provider-key strip preload (`test/helpers/provider-keys-preload.ts`) leaves the real keys that live embed/parity e2e tests skip-gate on. Each file runs under a gtimeout/timeout wedge backstop (default signal: SIGTERM — the bun test child installs no JS-level handler for it, so kernel-default termination applies) — 180s default, with a per-file override for known-slow files (`skills.test.ts` gets 420s: the real ingest-skill run replays every migration, so its floor grows as master adds migrations); the cap is a wedge backstop, not a per-test budget, and bare `bun` (no outer cap) is the fallback when neither timeout binary is installed. It activates the PGLite schema snapshot like the other runners: sources `scripts/lib/test-env.sh` + `ensure_pglite_snapshot` after the `--dry-run-list` early exit (list mode stays instant; non-fatal on build failure), re-exports `GBRAIN_PGLITE_SNAPSHOT` as an ABSOLUTE path (e2e tests spawn CLI subprocesses with varying cwd — a relative path silently misses the tar there), and its env keep-list preserves the var; e2e files that assert the path TO post-`initSchema()` state carry per-file `delete process.env.GBRAIN_PGLITE_SNAPSHOT` opt-outs with one-line reasons.+- `scripts/run-e2e.sh` — Sequential E2E runner. Accepts an optional argv-driven file list (used by `ci:local:diff`) and a `--dry-run-list` flag that prints the resolved file list and exits (used by `ci-local.sh`'s startup smoke-test). Falls back to `test/e2e/*.test.ts` plus `test/phantom-redirect-engine-parity.test.ts` when invoked with no args (the phantom-redirect Postgres arm is only reachable through a DATABASE_URL-bearing lane; the unit wrappers strip the URL, so this lane must carry it). This wrapper is the database-URL opt-in boundary: it exports `GBRAIN_TEST_ALLOW_DATABASE_URL=1` so the bunfig preload guard (`test/helpers/database-url-guard-preload.ts`) lets the run start, unsets `GBRAIN_DATABASE_URL` (the e2e suite runs on `DATABASE_URL` only — an ambient `GBRAIN_DATABASE_URL` would pass the opt-in yet reach CLI-subprocess paths with no name floor), and its GBRAIN_* env scrub preserves `GBRAIN_E2E_ALLOW_DB` so the name-floor escape hatch the guard's own error message names stays usable. It also preserves `GBRAIN_CI_DISABLE_TEST_ENV_FILE=1`, keeping CI runs from loading checkout-local `.env.testing` credentials after the shell-to-Bun handoff. It also exports `GBRAIN_TEST_KEEP_PROVIDER_KEYS=1` so the unit-lane provider-key strip preload (`test/helpers/provider-keys-preload.ts`) leaves the real keys that live embed/parity e2e tests skip-gate on. Each file runs under a gtimeout/timeout wedge backstop (default signal: SIGTERM — the bun test child installs no JS-level handler for it, so kernel-default termination applies) — 180s default, with a per-file override for known-slow files (`skills.test.ts` gets 420s: the real ingest-skill run replays every migration, so its floor grows as master adds migrations); the cap is a wedge backstop, not a per-test budget, and bare `bun` (no outer cap) is the fallback when neither timeout binary is installed. It activates the PGLite schema snapshot like the other runners: sources `scripts/lib/test-env.sh` + `ensure_pglite_snapshot` after the `--dry-run-list` early exit (list mode stays instant; non-fatal on build failure), re-exports `GBRAIN_PGLITE_SNAPSHOT` as an ABSOLUTE path (e2e tests spawn CLI subprocesses with varying cwd — a relative path silently misses the tar there), and its env keep-list preserves the var; e2e files that assert the path TO post-`initSchema()` state carry per-file `delete process.env.GBRAIN_PGLITE_SNAPSHOT` opt-outs with one-line reasons. Each file pass records an executed-test receipt (below) that keeps its native JUnit report; processes still running with a file's HOME after its bun process exits are killed and named, and a HOME that still cannot be removed fails that file by name while the partition continues. `executed-files.txt` lists every attempted file, pass or fail; `lane-manifest.json` (`complete:true`) is written only on a green run.+- `scripts/lib/test-env.sh` receipts (`receipts_init`, `receipt_begin`, `receipt_end`, `receipt_empty`) + `scripts/run-with-receipt.sh` + `scripts/ci-executed-counts.ts` — executed-test receipts and the identity ledger. With `GBRAIN_TEST_RECEIPT_DIR` set, every bun invocation a runner makes (test-shard, run-unit-shard per file, run-unit-parallel rescue passes, run-serial-tests pooled and rescue runs, run-slow-tests, run-e2e per file pass, and CI's bare `bun test` steps through `run-with-receipt.sh <lane> <tag> -- bun test ...`) writes `<id>.receipt` (lane, kind primary/rerun/rescue, shard/of, arm, sha, run id and attempt, exit), `<id>.files` and Bun's JUnit report; the runner unsets the variables so tests and nested runners never inherit them (`GBRAIN_TEST_RECEIPT_LANE` overrides the default lane). `run-unit-parallel.sh` writes receipts by default under `.context/test-receipts/`. `run-verify-parallel.sh` records each check as pass, fail, timeout or skip (a self-skipping check prints `GBRAIN_CHECK_SKIPPED: <reason>`) in `outcomes.tsv` and a JUnit receipt, and keeps its logs on failure. `ci-executed-counts.ts --head-run <id>[,<id>] [--base-run ...]` (or `--head-dir/--base-dir`) accounts for every test by (lane, file, test, arm): repeated names inside a file are numbered by occurrence, a later rerun/rescue supersedes earlier attempts for its files, and missing, truncated or prior-attempt receipts, missing shards, empty lanes and missing artifacts make the result `incomplete` (exit 1). Each base identity that no longer executes must match a row of the expected-deltas TSV (`--deltas`; retire with evidence, move, skip, job), or the tool prints the row to add. test.yml and e2e.yml upload `receipts-<lane>` artifacts and run it report-only in their `executed-receipts` jobs (e2e also prints the missing-provider-key skip count). Tests: `test/scripts/ci-executed-counts.test.ts`, `test/scripts/run-with-receipt.test.ts`.Every file needs a fresh parent-owned native JUnit report, its selected-file header and matching final console totals; zero exit alone or a nested child's summary cannot establish completion. All-skipped reports remain valid and explicit. Coverage runs atomically claim a new destination, refusing existing paths without deleting their contents, and write `executed-files.txt` plus a same-commit manifest only after all selected files succeed. `SHARD=N/M` produces lane `e2e-N`; unsharded runs retain `e2e`. The per-file LCOV directories remain independent, and the nightly validator accounts for every partition without equating LCOV count with executed-file count.- `scripts/select-e2e.ts` + `scripts/e2e-test-map.ts` — Diff-aware E2E test selector. Reads three git sources (committed `origin/master...HEAD`, working-tree `HEAD`, and `git ls-files --others --exclude-standard` for untracked NOT-gitignored files), classifies as EMPTY / DOC_ONLY / SRC. Fail-closed: EMPTY → all files; DOC_ONLY (every path matches the README/CLAUDE/AGENTS/CHANGELOG/TODOS allowlist) → empty stdout; SRC → escape-hatch paths (schema, package.json, skills/) trigger all, else the hand-tuned `E2E_TEST_MAP` glob narrows, and an unmapped src/ change still emits ALL files (never silently nothing). Pure-function exports `selectTests`, `classify`, `matchGlob`. `bun run ci:select-e2e` prints the current selection on stdout. `test/select-e2e.test.ts` covers all 4 branches plus 3 guards (skills/, untracked files, unmapped src/) — 24 cases.-- `scripts/sharding.ts` + `scripts/mine-shard-weights.ts` + `scripts/capture-test-log.ts` — shared deterministic weighted partitioning and timing refresh. CLI accepts lane-specific weights; missing entries use p75, equal loads prefer fewer files then shard index, and serial may explicitly opt into warning/fallback on bad advisory weights. `weights:mine --lane unit|serial|e2e` validates completed lane logs before replacement and records run/commit/unit metadata. E2E defaults to merging selected-job observations; explicit `--e2e-profile full --run ID` requires a successful source-matched run, pins its attempt/job IDs, resolves basename headers against committed default discovery including the outside-directory parity entry, and replaces the map only after exact disjoint corpus validation. Metadata retains log/corpus hashes; file/stdin sources cannot claim full-profile provenance. Capture preserves stdout/stderr, records timestamped GitHub-format artifacts, forwards cancellation to its owned process group and marks failed runs unmineable. Unit and E2E artifact retention is 14 days.+- `scripts/sharding.ts` + `scripts/mine-shard-weights.ts` + `scripts/capture-test-log.ts` — shared deterministic weighted partitioning and timing refresh. CLI accepts lane-specific weights; missing entries use p75, equal loads prefer fewer files then shard index, and serial may explicitly opt into warning/fallback on bad advisory weights. `weights:mine --lane unit|serial|e2e` validates completed lane logs before replacement and records run/commit/unit metadata. E2E defaults to merging selected-job observations; explicit `--e2e-profile full --run ID` requires a successful source-matched run, pins its attempt/job IDs, resolves basename headers against committed default discovery including the outside-directory parity entry, and replaces the map only after exact disjoint corpus validation. Metadata retains log/corpus hashes; file/stdin sources cannot claim full-profile provenance. Capture preserves stdout/stderr, records timestamped GitHub-format artifacts, forwards cancellation to its owned process group and marks failed runs unmineable. On a failed run under Actions it appends the last 50 failures to the step summary: file, test, backend arm, the first error block and a reproduction command (or the last log lines when no `(fail)` line was printed). Unit and E2E artifact retention is 14 days.- `test/e2e/codex-plugin-install-real.serial.test.ts` + `test/e2e/claude-plugin-install-real.serial.test.ts` — the plugin doors: clean-tree staging (`git archive HEAD`), real marketplace add/plugin add, snapshot + exec-bit + non-root-mcp.json pins, tools/list starter-surface oracle, cold-home fast-fail, --source-guard block/allow, coexistence + removal probes, auth-gated SMOKE turns. CI: the `plugin-doors` job in heavy-tests.yml (pinned binary provisioning + expected-pass-count refuse-green).diff --git a/docs/test-audit/2026-10-04/implementation/s0-receipts.md b/docs/test-audit/2026-10-04/implementation/s0-receipts.mdnew file mode 100644index 0000000000..77b970e5af--- /dev/null+++ b/docs/test-audit/2026-10-04/implementation/s0-receipts.md@@ -0,0 +1,91 @@+# Lane S0: executed-test receipts and the identity ledger++Plan tasks: T0.1 (X2 receipts), T0.2 (`scripts/ci-executed-counts.ts`,+`expected-deltas.tsv`, report-only CI step), B9, B13, the run-e2e.sh part of+B2, and A9's missing-key summary line. No test was deleted or retired, so+there are no Retiring-a-test rows.++## What each lane writes++| Lane (identity) | Producer | CI artifact |+|---|---|---|+| `unit` | `scripts/test-shard.sh` (one bun per shard); locally `run-unit-shard.sh` (one bun per file) and `run-unit-parallel.sh` rescue passes (`kind=rescue`) | `receipts-unit-<n>` |+| `serial` | `scripts/run-serial-tests.sh`, one bun per file, rescue re-runs `kind=rescue` | `receipts-serial-<n>` |+| `slow` | `run-with-receipt.sh` in the three slow jobs; `run-slow-tests.sh` locally | `receipts-slow-eval`, `receipts-slow-perf`, `receipts-slow-brainbench` |+| `verify` | `run-verify-parallel.sh` (one testcase per check: pass, fail, timeout, skip) | `receipts-verify` |+| `verify-tests` | the bash 3.2 parser test in the verify job | `receipts-verify` |+| `shared-skills` | old-binary compatibility test | `receipts-shared-skills` |+| `e2e` | `run-e2e.sh` per file pass via `e2e-matrix.ts run`; an empty selection writes `declared_empty=1` | `receipts-e2e-<n>` |+| `backend-matrix` | `run-e2e.sh` in Tier 1 (`arm` = `postgres-direct` / `pgbouncer`) | `receipts-tier1` |+| `tier1`, `tier2`, `jsonb-parity` | `run-with-receipt.sh` per step | `receipts-tier1`, `receipts-tier2`, `receipts-jsonb-parity` |+| `full-unit`, `full-serial`, `full-e2e` | nightly coverage lanes | `receipts-full-*` |++Not receipted: the `security-regressions` matrix (the same files run in the+unit lane; Windows cells use PowerShell), the six inline `bun test` calls of+the nightly `coverage-full-slow` job, and `persistence-validation.yml` (owned+by another lane; its jobs are outside this lane's files).++## Rollout proof (X2: one shard first)++`GBRAIN_TEST_RECEIPT_DIR=… COVERAGE_DIR=… bun scripts/capture-test-log.ts --job 'test (8)' … -- bash scripts/test-shard.sh 8 8`+on Bun 1.4.2: exit 0, console output unchanged (`4215 pass / 9 skip / 0 fail`,+309 files), `coverage/shard/lcov.info` and `lane-manifest.json` written, and+the JUnit receipt read by the ledger as 309 files, 4215 executed, 9 skipped.+Bun's JUnit keeps `test.each` titles as the unformatted template (`… %s`),+so repeated names inside one file are numbered by occurrence (`name [#2]`).++A local Postgres run of four real E2E files (`run-e2e.sh` with receipts)+produced 19 executed identities, and the HOME sweep named the leaked B2 child:+`WARN: self-upgrade-marker.test.ts left processes running with HOME=… (killed): pid …: bun src/cli.ts check-update --refresh-cache`.++## Discriminating mutations++Each mutation was applied, the named test run, and the file restored.++| Mutation | Test that fails |+|---|---|+| rescue/rerun rank ignored | `completeness > a rescue supersedes the failing primary…`, `…killed shard re-run by its rescue…` |+| prior-attempt receipts accepted | `completeness > a receipt from an earlier run attempt is incomplete…` |+| JUnit declared-count check removed | `parseJUnit > a truncated or miscounted report throws…` |+| truncation check removed | `completeness > a truncated JUnit report is incomplete` |+| backend arms grouped together | `identity comparison > backend arms of one file are separate identities` |+| missing shard ignored | `completeness > a missing shard and a lane that executed nothing…` |+| move target not checked | `identity comparison > a declared file-level move passes only when…` |+| retirement without evidence accepted | `identity comparison > a retirement passes with its evidence row…` |+| repeated names merged | `parseJUnit > repeated names in one file … stay distinct identities` |+| run-e2e.sh back to bare `rm -rf` under `set -e` (B2) | `per-file HOME cleanup and receipts > a HOME that cannot be removed fails that file by name…` |+| HOME leak sweep removed | `…a child left running with the file HOME is killed before cleanup and named` |+| executed-files.txt green-only again (B9) | `sequential E2E runner > coverage keeps fresh processes…` |+| run-e2e.sh JUnit not kept as receipt | `…each file pass leaves a receipt with its native JUnit report…` |+| verify self-skip counted as pass | `run-verify-parallel.sh … records every check's real outcome…` |+| rescue pass writes no receipt | `run-unit-parallel.sh OOM rescue lane > writes a receipt per bun invocation…` |+| receipt variables not unset | `run-with-receipt.sh > records lane, files, exit…` (the wrapped test asserts it cannot see them) |+| capture collector not fed (B13) | all three `failure step summary (B13)` cases |+| timeout note not attached (B13) | `failure step summary (B13) > a timeout names the test…` |++## Existing tests changed++- `test/scripts/e2e-runner.test.ts`: three assertions pinned+ `executed-files.txt` as absent on a failed run. B9 changes that contract+ (the receipt is written pass or fail; `lane-manifest.json` stays+ green-only), so they now assert the file lists the attempted files while the+ manifest is still absent. The interrupted-run assertion is unchanged.+- `test/scripts/run-unit-shard.test.ts`: the sandbox stages+ `scripts/lib/test-env.sh`, which the runner now sources.++## Commands for T0.3++After a full run of test.yml and e2e.yml on one PR head (rerun all jobs, not+only failed ones):++```bash+# one side: per-lane table + completeness+bun scripts/ci-executed-counts.ts --head-run <test.yml run>,<e2e.yml run>+# baseline stability: identities must be identical across the three reruns+bun scripts/ci-executed-counts.ts --base-run <A test>,<A e2e> --head-run <B test>,<B e2e> --fail-on-additions --json b-vs-a.json+# acceptance: final wave SHA against the baseline+bun scripts/ci-executed-counts.ts --base-run <base test>,<base e2e> --head-run <head test>,<head e2e> --summary pr-table.md+```++Local artifact directories work the same with `--base-dir` / `--head-dir`+(a directory of `receipts-*` subdirectories or one receipts directory).