Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(contributor-audit): run each test file in its own Bun process

garrytane932725e6340
diff --git a/docs/TESTING.md b/docs/TESTING.md
index d3105afdc0..e27e604136 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -323,7 +323,7 @@ fails on a harmless rename, and duplicates the behavioral test above.
(`scripts/contributor-audit.ts`) re-proves discrimination for every
first-parent commit in the range and for each PR head in `--prs`, trial-merged
onto `<head>`. In an isolated worktree of `<head>` it runs the change's test
-files (green baseline required), reverses only that change's product hunks
+files, one Bun process per file as the unit loop does (green baseline required), reverses only that change's product hunks
(`git diff M^1 M -- <product files> | git apply -R`; tests and docs stay),
reruns, restores, checks the tree is identical and re-verifies green. Hunks
that no longer apply at `<head>` are audited at the merge commit itself.
diff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.md
index 5a900594a0..1f043822c4 100644
--- a/docs/architecture/key-files/ci-health-and-test-guards.md
+++ b/docs/architecture/key-files/ci-health-and-test-guards.md
@@ -17,5 +17,5 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL
- `test/helpers/brain-template.ts` — disk-backed PGLite brains cloned from one initialized template per process and embedding shape. The template is captured right after `initSchema` with no source, writer or physical-root reservation (asserted); only the data directory is copied; each clone regenerates `brain_id`, the default source incarnation and the shared-skill token secret and serving epoch. Used by `test/helpers/connector-fixture.ts`. Tests: `test/helpers/brain-template.test.ts`.
- `scripts/test-agent-voice.sh` — `bun run test:agent-voice`: the agent-voice recipe's vitest unit suite (`recipes/agent-voice/tests/unit`), with pinned vitest and ws installed into a temporary prefix linked as the recipe's `node_modules`. Needs node, npm and registry access; CI runs it in test.yml's verify job.
- `scripts/check-image-decoders-embedded.sh` — `check:image-decoders` (in `verify`): compiles a smoke binary and proves HEIC and AVIF decode inside a `bun --compile` artifact; a failure prints the bun build error with Why/Fix.
-- `scripts/contributor-audit.ts` + `scripts/contributor-audit-fixture.ts` — `bun run audit:contributors <base>..<head> [--prs <manifest>] [--json]`. Per first-parent commit in the range and per pinned PR head trial-merged onto `<head>`: green baseline of the change's test files, reverse only its product hunks (non-test, non-doc) with `git apply -R` in an isolated worktree of `<head>` (falling back to the merge commit when the hunks no longer apply), classify (`discriminates`, `does_not_discriminate`, `vacuous_failure`, `setup_failed`, `conflict`, `not_audited` with a reason), restore, verify the tree is identical and green again. Untrusted install and tests run under `env -i` with `sandboxEnv()`'s allowlist (temporary `HOME`/`GBRAIN_HOME`, empty `DATABASE_URL`/`GBRAIN_DATABASE_URL` unless `--postgres` names a test-shaped database). Runs the trusted `wave-security-scan.sh` and `check-postgres-lane-coverage.ts` (`GBRAIN_GUARD_ROOT` = audited tree). State, logs and `prs.pinned.json` live in `<git-dir>/contributor-audit/<base>-<head>/`; `--resume` refuses on changed refs or pins (`preview_changed`). Human verdicts come only from the verdicts file. Exit 0 clean, 1 review, 2 refusal envelope, 130 interrupted. The fixture builds the offline demo range. Tests: `test/scripts/contributor-audit.test.ts`. Docs: `docs/TESTING.md#contributor-audit`.
+- `scripts/contributor-audit.ts` + `scripts/contributor-audit-fixture.ts` — `bun run audit:contributors <base>..<head> [--prs <manifest>] [--json]`. Per first-parent commit in the range and per pinned PR head trial-merged onto `<head>`: green baseline of the change's test files (one Bun process per file), reverse only its product hunks (non-test, non-doc) with `git apply -R` in an isolated worktree of `<head>` (falling back to the merge commit when the hunks no longer apply), classify (`discriminates`, `does_not_discriminate`, `vacuous_failure`, `setup_failed`, `conflict`, `not_audited` with a reason), restore, verify the tree is identical and green again. Untrusted install and tests run under `env -i` with `sandboxEnv()`'s allowlist (temporary `HOME`/`GBRAIN_HOME`, empty `DATABASE_URL`/`GBRAIN_DATABASE_URL` unless `--postgres` names a test-shaped database). Runs the trusted `wave-security-scan.sh` and `check-postgres-lane-coverage.ts` (`GBRAIN_GUARD_ROOT` = audited tree). State, logs and `prs.pinned.json` live in `<git-dir>/contributor-audit/<base>-<head>/`; `--resume` refuses on changed refs or pins (`preview_changed`). Human verdicts come only from the verdicts file. Exit 0 clean, 1 review, 2 refusal envelope, 130 interrupted. The fixture builds the offline demo range. Tests: `test/scripts/contributor-audit.test.ts`. Docs: `docs/TESTING.md#contributor-audit`.
- `.github/workflows/fix-wave-gate.yml` + `scripts/fix-wave-gate.ts` — the contributor gate. `pull_request_target` on master (`opened`, `edited`, `reopened`, `synchronize`, `labeled`, `unlabeled`); sparse-checks-out only the script from the default branch and never PR code. `decide()` (pure) passes a head repository equal to `TRUSTED_HEAD_REPO` with the base repository's id, or a present `maintainer-override` label whose latest `labeled` timeline event was made by a `User` on `MAINTAINERS` (no `[bot]` login); a null head repository, a missing label or any other labeler fails. Overrides print a `notice` and step-summary line naming the actor, time and event id. `--comment` (the `welcome-comment` job, `pull-requests: write`, `opened` only) posts `gateMessage()` once per PR, keyed by `COMMENT_MARKER`. The script imports only `node:` modules. Tests: `test/scripts/fix-wave-gate.test.ts` (fixture payloads in `test/fixtures/fix-wave-gate/`). Process and the required-check settings step: `docs/RELEASING.md#fix-wave-gate`.
diff --git a/scripts/contributor-audit.ts b/scripts/contributor-audit.ts
index c7853bbbf3..2dbf8e6b5d 100644
--- a/scripts/contributor-audit.ts
+++ b/scripts/contributor-audit.ts
@@ -377,13 +377,23 @@ async function preflight(o: Options, repo: string): Promise<{ base: string; head
interface Ctx { o: Options; repo: string; runDir: string; scratch: string; cacheDir: string; head: string; timeoutMs: number }
+/** One fresh Bun process per test file (as the unit loop runs them), each in its own throwaway HOME. */
async function runTests(ctx: Ctx, wt: string, tests: string[], log: string): Promise<RunCounts> {
- const home = mkdtempSync(join(ctx.scratch, 'home-'));
- mkdirSync(join(home, 'tmp'));
- const env = sandboxEnv({ home, bunPath: process.execPath, cacheDir: ctx.cacheDir, postgresUrl: ctx.o.postgres });
- const r = await runStep([process.execPath, '--no-env-file', 'test', '--timeout=60000', ...tests.map(t => `./${t}`)], { cwd: wt, env, log, timeoutMs: ctx.timeoutMs });
- rmSync(home, { recursive: true, force: true });
- return { exit: r.exit, timedOut: r.timedOut, ...parseCounts(r.output) };
+ const total: RunCounts = { exit: 0, pass: 0, fail: 0, timedOut: false };
+ for (const [i, test] of tests.entries()) {
+ const home = mkdtempSync(join(ctx.scratch, 'home-'));
+ mkdirSync(join(home, 'tmp'));
+ const env = sandboxEnv({ home, bunPath: process.execPath, cacheDir: ctx.cacheDir, postgresUrl: ctx.o.postgres });
+ const fileLog = tests.length === 1 ? log : log.replace(/\.log$/, `.${i + 1}.log`);
+ const r = await runStep([process.execPath, '--no-env-file', 'test', '--timeout=60000', `./${test}`], { cwd: wt, env, log: fileLog, timeoutMs: ctx.timeoutMs });
+ rmSync(home, { recursive: true, force: true });
+ const counts = parseCounts(r.output);
+ total.pass += counts.pass;
+ total.fail += counts.fail;
+ total.timedOut ||= r.timedOut;
+ if (total.exit === 0) total.exit = r.exit;
+ }
+ return total;
}
async function install(ctx: Ctx, wt: string, log: string): Promise<boolean> {