Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(ci): move the unit-postgres-arms list into test/postgres-unit-arms.txt
garrytan0a27a1f6cefc
diff --git a/.github/workflows/persistence-validation.yml b/.github/workflows/persistence-validation.ymlindex 635a101749..7df2d223e5 100644--- a/.github/workflows/persistence-validation.yml+++ b/.github/workflows/persistence-validation.yml@@ -161,10 +161,12 @@ jobs:if-no-files-found: error# Unit-lane suites whose PostgreSQL arm is gated on DATABASE_URL: the unit,- # serial and slow lanes unset it, so these arms run only here (both arms per- # file; the PGLite arm also runs in the unit lane). scripts/check-postgres-lane-coverage.ts- # fails a new DATABASE_URL-gated arm until it is listed here or wrapped in a- # test/e2e registerPostgresTests file. The two shards are balanced by measured runtime.+ # serial and slow lanes unset it, so these arms run only here and in the+ # scheduled race hunt (both arms per file; the PGLite arm also runs in the+ # unit lane). The list is test/postgres-unit-arms.txt;+ # scripts/check-postgres-lane-coverage.ts fails a new DATABASE_URL-gated arm+ # until it is listed there or wrapped in a test/e2e registerPostgresTests+ # file. The two shards are balanced by measured runtime.unit-postgres-arms:name: Unit-lane PostgreSQL arms ${{ matrix.shard }}/2 / Bun ${{ matrix.bun }}runs-on: ubicloud-standard-4-ubuntu-2404@@ -203,84 +205,15 @@ jobs:SHARD: ${{ matrix.shard }}run: |: "${DATABASE_URL:?unit-lane PostgreSQL arms require the explicit test database}"- case "$SHARD" in- 1) files=(- test/attribution-backfill-history.test.ts- test/behavior-change-notice.test.ts- test/colon-slug-windows-5032.test.ts- test/decide/conflict-proposals-managed.test.ts- test/declared-lineage-visibility.test.ts- test/extract-endpoint-revision.serial.test.ts- test/graduation-digest.test.ts- test/graduation-drain.test.ts- test/graduation-inventory.test.ts- test/graduation-state.test.ts- test/grandfather-managed.test.ts- test/harness-skills-epoch.test.ts- test/links-attendance-blocked.test.ts- test/managed-cycle-pull-upstream.test.ts- test/managed-lint.test.ts- test/managed-maintenance-links.test.ts- test/managed-sync-drain.test.ts- test/pack-relation-direction-engine.test.ts- test/page-embedding-install-batch.test.ts- test/page-state-engine.test.ts- test/persistence-commit-durability.test.ts- test/persistence-deactivate.test.ts- test/persistence-file-import.test.ts- test/persistence-graph-publication.test.ts- test/persistence-managed-lifecycle.test.ts- test/persistence-managed-sync.test.ts- test/persistence-memory-mutations.test.ts- test/persistence-page-authority.test.ts- test/persistence-skill-bundles.serial.test.ts- test/shared-content-freshness.test.ts- test/shared-skills-writer-boundary.test.ts- test/source-retire-missing-checkout.test.ts- test/sync-legacy-holds.test.ts- test/takes-vector-lifecycle-5885.serial.test.ts- test/withdrawal-overlay-concurrency.test.ts- ) ;;- 2) files=(- test/alias-source-cascade-5094.test.ts- test/company-brain-policy.test.ts- test/company-brain-runtime.test.ts- test/engine-sql-facts-keyset.test.ts- test/derived-link-reconciliation.test.ts- test/doctor-frontmatter-holds.test.ts- test/embedding-completion-atomic.serial.test.ts- test/graduation-copy.test.ts- test/graduation-rollback.test.ts- test/graduation-target.test.ts- test/graduation-verify.test.ts- test/held-read-signals.test.ts- test/import-frontmatter-key-order-5158.test.ts- test/import-revision-concurrency.test.ts- test/managed-sweep-corpus-windows.test.ts- test/managed-sync-bulk.test.ts- test/managed-sync-chunker-version.test.ts- test/managed-sync-group-completion.test.ts- test/persistence-diagnostics.test.ts- test/persistence-git-subdir-origin.test.ts- test/persistence-history-fixture.test.ts- test/persistence-image-import.serial.test.ts- test/persistence-physical-root-device.test.ts- test/persistence-skill-crash.slow.test.ts- test/persistence-sync-cursor-options.test.ts- test/persistence-sync-holds.test.ts- test/persistence-writer-fences.test.ts- test/repair-embedding-effects.test.ts- test/repair-frontmatter.test.ts- test/shared-skills-catalog.test.ts- test/shared-skills-retention-capacity.test.ts- test/shared-skills-source-opt-out.test.ts- test/stats-health-source-scope.test.ts- test/sync-frontmatter-recovery.test.ts- test/sync-frontmatter-slug-conflict.test.ts- test/withdrawal-publication-file.test.ts- ) ;;- *) echo "::error::unknown shard $SHARD" >&2; exit 1 ;;- esac+ # The list lives in test/postgres-unit-arms.txt (one path per line);+ # shards balance by measured runtime (scripts/postgres-arm-weights.json).+ selected=$(bun scripts/postgres-unit-arms.ts shard "$SHARD" 2)+ files=()+ while IFS= read -r file; do [ -n "$file" ] && files+=("$file"); done <<< "$selected"+ if [ "${#files[@]}" -eq 0 ]; then+ echo "::error::shard $SHARD/2 selected no files from test/postgres-unit-arms.txt. Why: an empty shard would pass without running any PostgreSQL arm. Fix: run 'bun scripts/postgres-unit-arms.ts shard $SHARD 2' locally and correct the list. Docs: docs/TESTING.md#postgres-arm-lanes" >&2+ exit 1+ fi# One bun process per file: *.serial.test.ts files require their own# process, and a test that fails while its body keeps running would# otherwise leak process.env into every later file (one such leakdiff --git a/docs/TESTING.md b/docs/TESTING.mdindex e27e604136..d09880a4ad 100644--- a/docs/TESTING.md+++ b/docs/TESTING.md@@ -275,13 +275,19 @@ only where a Postgres lane names it. Those lanes are: a workflow step thatruns with `DATABASE_URL` and names the file, a `test/e2e/` wrapper thatimports it (`registerPostgresTests`), a `tests/heavy/` script that names it,or a row in `scripts/e2e-backend-matrix.txt`. Unit-lane files with no other-Postgres owner run in `persistence-validation.yml`'s `unit-postgres-arms` job-(two shards against a pgvector service, newest Bun on PRs, both supported-versions elsewhere). Each file runs in its own Bun process, so a failing file-cannot leak environment or global state into later files, and each failure-prints an `::error file=…` line with its reproduce command.-`bun run check:postgres-lanes` (in `verify`) fails on every arm with no lane.-An arm deliberately left out is an `ALLOWLIST` row in+Postgres owner are listed in `test/postgres-unit-arms.txt`, one sorted path+per line; adding a file is a one-line edit. Three readers share that list:+`persistence-validation.yml`'s `unit-postgres-arms` job (two shards against a+pgvector service on both supported Bun versions, balanced by+`scripts/postgres-arm-weights.json` through `bun scripts/postgres-unit-arms.ts shard <n> <m>`),+the scheduled [race hunt](#race-hunt) and the lane guard. In the job each file+runs in its own Bun process, so a failing file cannot leak environment or+global state into later files, and each failure prints an `::error file=…`+line with its reproduce command. Refresh the weights from a green run's two+shard logs with `bun scripts/postgres-unit-arms.ts mine <job.log>…`.+`bun run check:postgres-lanes` (in `verify`) fails on every arm with no lane+and on a list row that is malformed, duplicated, out of order, missing or has+no gated arm. An arm deliberately left out is an `ALLOWLIST` row in`scripts/check-postgres-lane-coverage.ts` naming its reason and TODO; a rowfor a file that is laned, has no arm or is gone fails.### Scale tierdiff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.mdindex 37b7f2e795..ea1176c3da 100644--- a/docs/architecture/key-files/ci-health-and-test-guards.md+++ b/docs/architecture/key-files/ci-health-and-test-guards.md@@ -12,7 +12,8 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `scripts/e2e-provider-key-notice.sh` — e2e.yml's visible-skip step: when `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` is empty, prints a `::warning::` and step-summary line naming the empty secret and the owner-only fix, so a green keyless run is never read as keyed coverage. Exits 0 always.- `scripts/scale/watchdog.ts` — out-of-process phase watchdog for the scale harness. `scripts/scale/run.ts` re-runs itself as a child; the supervisor times the `import`, `extract`, `vectors` and `budgets` phases from the child's `[scale] phase <name> start` lines and kills the child's process group at 1.5x the phase's gate ceiling (`scripts/scale/gates.ts` `phaseLimitsMs`), names the phase, elapsed time and last progress line, then removes the brain home and scale database. `GBRAIN_SCALE_PHASE_LIMIT_MS_<PHASE>` overrides one limit; `GBRAIN_SCALE_SUPERVISED` is the internal handshake. Tests: `test/scripts/scale-watchdog.test.ts`.- `scripts/check-test-env-opt-ins.ts` + `test/helpers/operator-env-policy.ts` — the opt-in naming rule. The policy (`STRIP_PREFIX`, `KEEP_EXACT`, `KEEP_PREFIX`, `RENAMED`, `isStripped`) is shared by `test/helpers/operator-env-preload.ts`, which deletes stripped `GBRAIN_*` names before any test loads and stops the run with the rename command when an old opt-in name is set, and by the guard (`check:test-env-opt-ins`, in `verify`), which parses test files and fails on a test that gates execution on a stripped name. Test opt-ins are `GBRAIN_TEST_<AREA>_<WHAT>`, paid ones `GBRAIN_TEST_LIVE_<WHAT>`. Tests: `test/scripts/test-env-opt-ins-guard.test.ts`, `test/operator-env-preload.test.ts`.-- `scripts/check-postgres-lane-coverage.ts` — `check:postgres-lanes` (in `verify`). TypeScript-AST scan of every `test/` file outside `test/e2e/` and `test/fixtures/` for a `DATABASE_URL`-gated PostgreSQL arm (zero-argument `testBackends()`, or a `DATABASE_URL` read used as a condition, connection argument or `database_url` value; `withEnv`-supplied URLs excluded) and a lane that runs it (a workflow step with `DATABASE_URL` naming the file, a `test/e2e/` importer, a `tests/heavy/` script, or a `scripts/e2e-backend-matrix.txt` row). `ALLOWLIST` rows name a reason and TODO; stale rows fail. persistence-validation.yml's `unit-postgres-arms` job is the lane for unit files with no other owner, one Bun process per file. Tests: `test/scripts/postgres-lane-coverage.test.ts`.+- `scripts/check-postgres-lane-coverage.ts` — `check:postgres-lanes` (in `verify`). TypeScript-AST scan of every `test/` file outside `test/e2e/` and `test/fixtures/` for a `DATABASE_URL`-gated PostgreSQL arm (zero-argument `testBackends()`, or a `DATABASE_URL` read used as a condition, connection argument or `database_url` value; `withEnv`-supplied URLs excluded) and a lane that runs it (a workflow step with `DATABASE_URL` naming the file, a `test/e2e/` importer, a `tests/heavy/` script, or a `scripts/e2e-backend-matrix.txt` row). `ALLOWLIST` rows name a reason and TODO; stale rows fail. A `test/postgres-unit-arms.txt` row is a lane; a malformed, duplicate, unsorted, missing-file or arm-less row fails (`postgres_arm_list_invalid`, `postgres_arm_list_stale`). `postgresArm`, `postgresLanes` and `armedFiles` are exported for the stress runner. Tests: `test/scripts/postgres-lane-coverage.test.ts`.+- `test/postgres-unit-arms.txt` + `scripts/postgres-unit-arms.ts` + `scripts/postgres-arm-weights.json` — the one list of unit-lane files whose PostgreSQL arm has no other owner (sorted, one path per line, `#` comments). Read by persistence-validation.yml's `unit-postgres-arms` job (`shard <n> <m>`: LPT over the mined per-file weights, p75 fallback; one Bun process per file), the scheduled race hunt and the lane guard. `mine <job.log>…` rewrites the weights from a green run's shard logs (`##[group]<file>` to the next group or endgroup). Tests: `test/scripts/postgres-unit-arms.test.ts`.- `scripts/serial-files.tsv` + `scripts/lib/serial-manifest.ts` — the serial manifest: every `*.serial.test.ts` outside `test/e2e/` with its class (`R1`, `R2`, `global-state`, `exclusive`) and a reason. `checkSerialManifest` (pure) requires the manifest to match the tree exactly, classes to match what the file does (env mutation, `mock.module`, `EXCLUSIVE_FILES`) and reasons to be specific; each failure prints Why/Fix/Docs with `bash scripts/check-test-isolation.sh --as-parallel <file>` as the first step. Tests: `test/scripts/serial-files.test.ts`.- `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.diff --git a/scripts/check-postgres-lane-coverage.ts b/scripts/check-postgres-lane-coverage.tsindex 7e58a50af4..f4f6ee3cc7 100644--- a/scripts/check-postgres-lane-coverage.ts+++ b/scripts/check-postgres-lane-coverage.ts@@ -12,14 +12,17 @@* a call or constructor argument, or a `database_url`/`databaseUrl`* property value. Code inside a `withEnv({ DATABASE_URL: ... })` callback* supplies its own URL and is not an arm.- * - lane: a workflow step that runs with DATABASE_URL (step, job or workflow- * env, or exported in its script) and names the file; a test/e2e/ file that- * imports it (the registerPostgresTests wrappers); a tests/heavy/ script- * that names it (the heavy job runs with DATABASE_URL); or a row in- * scripts/e2e-backend-matrix.txt.+ * - lane: a row in test/postgres-unit-arms.txt (persistence-validation's+ * unit-postgres-arms job and the race hunt read it); a workflow step that+ * runs with DATABASE_URL (step, job or workflow env, or exported in its+ * script) and names the file; a test/e2e/ file that imports it (the+ * registerPostgresTests wrappers); a tests/heavy/ script that names it (the+ * heavy job runs with DATABASE_URL); or a row in scripts/e2e-backend-matrix.txt.** An arm that is deliberately not run yet is an ALLOWLIST row naming its* reason and TODO; a row for a file that is laned, has no arm or is gone fails.+ * A test/postgres-unit-arms.txt row that is malformed, duplicated, unsorted,+ * names a missing file or a file with no gated arm fails too.** test/fixtures/ is never scanned. Seam: GBRAIN_GUARD_ROOT (fixture tree root);* in a fixture tree `*.test.fixture.ts` files count as their `*.test.ts` names,@@ -29,12 +32,12 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';import { dirname, join, relative, resolve } from 'node:path';import { safeLoad } from 'js-yaml';import ts from 'typescript';+import { ARMS_LIST, readArmsList } from './postgres-unit-arms.ts';const ROOT = process.env.GBRAIN_GUARD_ROOT ?? join(import.meta.dir, '..');const TEST_FILE = process.env.GBRAIN_GUARD_ROOT ? /\.test(\.fixture)?\.ts$/ : /\.test\.ts$/;const DOCS = 'docs/TESTING.md#coverage-responsibilities-before-consolidation';-const LANE = '.github/workflows/persistence-validation.yml';-const LANE_STEP = 'Require PostgreSQL arms of unit-lane suites';+const LIST_DOCS = 'docs/TESTING.md#postgres-arm-lanes';/** Arms deliberately left out of every Postgres lane. Each row names its reason and TODO. */const ALLOWLIST: Record<string, string> = {@@ -103,7 +106,7 @@ function underOwnDatabaseUrl(node: ts.Node): boolean {}/** First line of a Postgres arm in `path`, or null. */-function postgresArm(path: string): { line: number; what: string } | null {+export function postgresArm(path: string): { line: number; what: string } | null {const sf = ts.createSourceFile(path, readFileSync(path, 'utf8'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);const line = (n: ts.Node) => sf.getLineAndCharacterOfPosition(n.getStart(sf)).line + 1;const aliases = new Set<string>();@@ -135,9 +138,10 @@ function postgresArm(path: string): { line: number; what: string } | null {}/** Test files a Postgres lane runs, with where each is named. */-function postgresLanes(): Map<string, string> {+export function postgresLanes(): Map<string, string> {const laned = new Map<string, string>();const add = (path: string, lane: string) => { if (!laned.has(path)) laned.set(path, lane); };+ for (const path of readArmsList(ROOT).files) add(path, ARMS_LIST);for (const workflow of files(join(ROOT, '.github', 'workflows'), name => /\.ya?ml$/.test(name))) {const doc = safeLoad(readFileSync(workflow, 'utf8')) as { env?: Record<string, unknown>; jobs?: Record<string, { env?: Record<string, unknown>; steps?: Array<{ name?: string; env?: Record<string, unknown>; run?: string }> }> } | undefined;for (const [jobName, job] of Object.entries(doc?.jobs ?? {})) for (const step of job.steps ?? []) {@@ -161,34 +165,61 @@ function postgresLanes(): Map<string, string> {return laned;}-const laned = postgresLanes();-const failures: string[] = [];-const armed = new Set<string>();-for (const abs of files(join(ROOT, 'test'), name => TEST_FILE.test(name))) {- const path = rel(abs);- if (path.startsWith('test/e2e/') || path.startsWith('test/fixtures/')) continue;- const arm = postgresArm(abs);- if (!arm) continue;- armed.add(path);- if (laned.has(path) || ALLOWLIST[path]) continue;- failures.push(`FAIL [postgres_arm_unlaned]: ${path}:${arm.line} gates a PostgreSQL arm on DATABASE_URL (${arm.what}) and no Postgres lane runs it\n`- + ` Why: the unit, serial and slow lanes unset DATABASE_URL, so this arm skips in every CI lane.\n`- + ` Fix: add ${path} to the "${LANE_STEP}" list in ${LANE} (or load it from a test/e2e/*-postgres.test.ts wrapper with registerPostgresTests)\n`- + ` Docs: ${DOCS}`);-}-for (const [path, reason] of Object.entries(ALLOWLIST)) {- const problem = !armed.has(path) && !existsSync(join(ROOT, path)) ? 'names a missing file'- : !armed.has(path) ? 'names a file with no DATABASE_URL-gated arm'- : laned.has(path) ? `names a file a Postgres lane already runs (${laned.get(path)})` : null;- if (!problem) continue;- failures.push(`FAIL [postgres_arm_allowlist_stale]: the ALLOWLIST row for ${path} ${problem} (reason was: ${reason})\n`- + ` Why: a stale row would hide the next arm added to that path.\n`- + ` Fix: delete the ${path} row from ALLOWLIST in scripts/check-postgres-lane-coverage.ts\n`- + ` Docs: ${DOCS}`);+/** Every test file outside test/e2e/ and test/fixtures/ with a DATABASE_URL-gated arm, and the arm's first line. */+export function armedFiles(): Map<string, { line: number; what: string }> {+ const armed = new Map<string, { line: number; what: string }>();+ for (const abs of files(join(ROOT, 'test'), name => TEST_FILE.test(name))) {+ const path = rel(abs);+ if (path.startsWith('test/e2e/') || path.startsWith('test/fixtures/')) continue;+ const arm = postgresArm(abs);+ if (arm) armed.set(path, arm);+ }+ return armed;}-if (failures.length) {- console.error(failures.join('\n'));- console.error(`\n${failures.length} Postgres-arm lane problem(s).`);- process.exit(1);++function main(): number {+ const laned = postgresLanes();+ const armed = armedFiles();+ const failures: string[] = [];+ for (const [path, arm] of armed) {+ if (laned.has(path) || ALLOWLIST[path]) continue;+ failures.push(`FAIL [postgres_arm_unlaned]: ${path}:${arm.line} gates a PostgreSQL arm on DATABASE_URL (${arm.what}) and no Postgres lane runs it\n`+ + ` Why: the unit, serial and slow lanes unset DATABASE_URL, so this arm skips in every CI lane.\n`+ + ` Fix: add ${path} to ${ARMS_LIST} (one line, in sorted order), or load it from a test/e2e/*-postgres.test.ts wrapper with registerPostgresTests\n`+ + ` Docs: ${DOCS}`);+ }+ const list = readArmsList(ROOT);+ for (const error of list.errors) {+ failures.push(`FAIL [postgres_arm_list_invalid]: ${error}\n`+ + ` Why: unit-postgres-arms and the race hunt read every row; a bad row drops or duplicates an arm.\n`+ + ` Fix: correct that line of ${ARMS_LIST}\n`+ + ` Docs: ${LIST_DOCS}`);+ }+ for (const path of list.files) {+ if (armed.has(path)) continue;+ const problem = existsSync(join(ROOT, path)) ? 'names a file with no DATABASE_URL-gated arm' : 'names a missing file';+ failures.push(`FAIL [postgres_arm_list_stale]: the ${ARMS_LIST} row ${path} ${problem}\n`+ + ` Why: unit-postgres-arms would run it without any PostgreSQL arm (or fail on the missing path), so the row proves nothing.\n`+ + ` Fix: delete the ${path} line from ${ARMS_LIST}\n`+ + ` Docs: ${LIST_DOCS}`);+ }+ for (const [path, reason] of Object.entries(ALLOWLIST)) {+ const problem = !armed.has(path) && !existsSync(join(ROOT, path)) ? 'names a missing file'+ : !armed.has(path) ? 'names a file with no DATABASE_URL-gated arm'+ : laned.has(path) ? `names a file a Postgres lane already runs (${laned.get(path)})` : null;+ if (!problem) continue;+ failures.push(`FAIL [postgres_arm_allowlist_stale]: the ALLOWLIST row for ${path} ${problem} (reason was: ${reason})\n`+ + ` Why: a stale row would hide the next arm added to that path.\n`+ + ` Fix: delete the ${path} row from ALLOWLIST in scripts/check-postgres-lane-coverage.ts\n`+ + ` Docs: ${DOCS}`);+ }+ if (failures.length) {+ console.error(failures.join('\n'));+ console.error(`\n${failures.length} Postgres-arm lane problem(s).`);+ return 1;+ }+ console.log(`postgres-lane-coverage: ${armed.size} test files with a DATABASE_URL-gated arm; ${armed.size - Object.keys(ALLOWLIST).length} run in a Postgres lane, ${Object.keys(ALLOWLIST).length} allowlisted.`);+ return 0;}-console.log(`postgres-lane-coverage: ${armed.size} test files with a DATABASE_URL-gated arm; ${armed.size - Object.keys(ALLOWLIST).length} run in a Postgres lane, ${Object.keys(ALLOWLIST).length} allowlisted.`);++if (import.meta.main) process.exit(main());diff --git a/scripts/postgres-arm-weights.json b/scripts/postgres-arm-weights.jsonnew file mode 100644index 0000000000..85742ff53b--- /dev/null+++ b/scripts/postgres-arm-weights.json@@ -0,0 +1,73 @@+{+ "test/alias-source-cascade-5094.test.ts": 14880,+ "test/attribution-backfill-history.test.ts": 23717,+ "test/behavior-change-notice.test.ts": 5833,+ "test/colon-slug-windows-5032.test.ts": 10656,+ "test/company-brain-policy.test.ts": 12644,+ "test/company-brain-runtime.test.ts": 23989,+ "test/decide/conflict-proposals-managed.test.ts": 8386,+ "test/declared-lineage-visibility.test.ts": 6760,+ "test/derived-link-reconciliation.test.ts": 6273,+ "test/doctor-frontmatter-holds.test.ts": 9480,+ "test/embedding-completion-atomic.serial.test.ts": 6623,+ "test/engine-sql-facts-keyset.test.ts": 4732,+ "test/extract-endpoint-revision.serial.test.ts": 7982,+ "test/graduation-copy.test.ts": 68724,+ "test/graduation-digest.test.ts": 2940,+ "test/graduation-drain.test.ts": 15098,+ "test/graduation-inventory.test.ts": 15468,+ "test/graduation-rollback.test.ts": 113149,+ "test/graduation-state.test.ts": 303814,+ "test/graduation-target.test.ts": 3052,+ "test/graduation-verify.test.ts": 15521,+ "test/grandfather-managed.test.ts": 42323,+ "test/harness-skills-epoch.test.ts": 2289,+ "test/held-read-signals.test.ts": 8410,+ "test/import-frontmatter-key-order-5158.test.ts": 4974,+ "test/import-revision-concurrency.test.ts": 3872,+ "test/links-attendance-blocked.test.ts": 5807,+ "test/managed-cycle-pull-upstream.test.ts": 5153,+ "test/managed-lint.test.ts": 7886,+ "test/managed-maintenance-links.test.ts": 5147,+ "test/managed-sweep-corpus-windows.test.ts": 5730,+ "test/managed-sync-bulk.test.ts": 5661,+ "test/managed-sync-chunker-version.test.ts": 7460,+ "test/managed-sync-drain.test.ts": 6107,+ "test/managed-sync-group-completion.test.ts": 9472,+ "test/pack-relation-direction-engine.test.ts": 6041,+ "test/page-embedding-install-batch.test.ts": 5563,+ "test/page-state-engine.test.ts": 5120,+ "test/persistence-commit-durability.test.ts": 4456,+ "test/persistence-deactivate.test.ts": 12202,+ "test/persistence-diagnostics.test.ts": 5781,+ "test/persistence-file-import.test.ts": 29303,+ "test/persistence-git-subdir-origin.test.ts": 11550,+ "test/persistence-graph-publication.test.ts": 4867,+ "test/persistence-history-fixture.test.ts": 14371,+ "test/persistence-image-import.serial.test.ts": 5364,+ "test/persistence-managed-lifecycle.test.ts": 16787,+ "test/persistence-managed-sync.test.ts": 75319,+ "test/persistence-memory-mutations.test.ts": 5779,+ "test/persistence-page-authority.test.ts": 4879,+ "test/persistence-physical-root-device.test.ts": 5086,+ "test/persistence-skill-bundles.serial.test.ts": 4997,+ "test/persistence-skill-crash.slow.test.ts": 46408,+ "test/persistence-sync-cursor-options.test.ts": 8150,+ "test/persistence-sync-holds.test.ts": 17961,+ "test/persistence-writer-fences.test.ts": 3722,+ "test/repair-embedding-effects.test.ts": 6585,+ "test/repair-frontmatter.test.ts": 13746,+ "test/shared-content-freshness.test.ts": 3197,+ "test/shared-skills-catalog.test.ts": 56182,+ "test/shared-skills-retention-capacity.test.ts": 5990,+ "test/shared-skills-source-opt-out.test.ts": 5670,+ "test/shared-skills-writer-boundary.test.ts": 9375,+ "test/source-retire-missing-checkout.test.ts": 4532,+ "test/stats-health-source-scope.test.ts": 4000,+ "test/sync-frontmatter-recovery.test.ts": 7485,+ "test/sync-frontmatter-slug-conflict.test.ts": 6146,+ "test/sync-legacy-holds.test.ts": 7514,+ "test/takes-vector-lifecycle-5885.serial.test.ts": 5573,+ "test/withdrawal-overlay-concurrency.test.ts": 2940,+ "test/withdrawal-publication-file.test.ts": 4616+}diff --git a/scripts/postgres-unit-arms.ts b/scripts/postgres-unit-arms.tsnew file mode 100644index 0000000000..3b0a98e7ec--- /dev/null+++ b/scripts/postgres-unit-arms.ts@@ -0,0 +1,102 @@+#!/usr/bin/env bun+/**+ * test/postgres-unit-arms.txt: the unit-lane suites whose PostgreSQL arm runs+ * only in persistence-validation's `unit-postgres-arms` job and the race hunt.+ *+ * bun scripts/postgres-unit-arms.ts list every listed path+ * bun scripts/postgres-unit-arms.ts shard <n> <m> shard n of m, balanced by measured runtime+ * bun scripts/postgres-unit-arms.ts mine <job.log>… rewrite scripts/postgres-arm-weights.json+ * from unit-postgres-arms job logs+ *+ * Weights are milliseconds per file (both arms, one Bun process) mined from+ * the job's `::group::<file>` timestamps; a file without a weight gets the+ * p75 (scripts/sharding.ts). Docs: docs/TESTING.md#postgres-arm-lanes.+ */+import { existsSync, readFileSync, writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { loadWeights, partition } from './sharding.ts';++export const ARMS_LIST = 'test/postgres-unit-arms.txt';+export const ARM_WEIGHTS = 'scripts/postgres-arm-weights.json';+const DOCS = 'docs/TESTING.md#postgres-arm-lanes';+const PATH_RE = /^test\/[\w./-]+\.test\.ts$/;++export interface ArmsList { files: string[]; errors: string[] }++/** Parse the list; every malformed, duplicate or unsorted row is an error naming its line. */+export function parseArmsList(text: string): ArmsList {+ const files: string[] = [];+ const errors: string[] = [];+ text.split('\n').forEach((raw, i) => {+ const line = raw.trim();+ if (!line || line.startsWith('#')) return;+ if (!PATH_RE.test(line)) errors.push(`${ARMS_LIST}:${i + 1}: "${line}" is not a repo-relative test/…/*.test.ts path`);+ else if (files.includes(line)) errors.push(`${ARMS_LIST}:${i + 1}: ${line} is listed twice`);+ else if (files.length && files[files.length - 1]! > line) errors.push(`${ARMS_LIST}:${i + 1}: ${line} is out of sorted order (insert it after the last path that sorts before it)`);+ files.push(line);+ });+ return { files: [...new Set(files)], errors };+}++/** A missing list is empty: the lane guard then reports every gated arm as unlaned. */+export function readArmsList(root: string): ArmsList {+ const path = join(root, ARMS_LIST);+ if (!existsSync(path)) return { files: [], errors: [] };+ return parseArmsList(readFileSync(path, 'utf8'));+}++/** Per-file durations from GitHub job logs: each `##[group]<file>` line to the next group or endgroup. */+export function mineArmWeights(logs: string[]): Map<string, number> {+ const weights = new Map<string, number>();+ for (const log of logs) {+ let open: { file: string; at: number } | undefined;+ for (const line of log.split('\n')) {+ const m = /^(\d{4}-\d{2}-\d{2}T[\d:.]+Z)\s+(?:##\[group\]|::group::)(test\/[\w./-]+\.test\.ts)\s*$/.exec(line);+ const end = /^(\d{4}-\d{2}-\d{2}T[\d:.]+Z)\s+##\[endgroup\]/.exec(line);+ const at = m ? Date.parse(m[1]!) : end ? Date.parse(end[1]!) : NaN;+ if (!Number.isFinite(at) || (!m && !open)) continue;+ if (open && (m || end)) {+ weights.set(open.file, Math.max(weights.get(open.file) ?? 0, at - open.at));+ open = undefined;+ }+ if (m) open = { file: m[2]!, at };+ }+ }+ return weights;+}++function main(argv: string[]): number {+ const root = join(import.meta.dir, '..');+ const [command, ...rest] = argv;+ const list = readArmsList(root);+ if (command !== 'mine' && list.errors.length) {+ console.error(`${list.errors.join('\n')}\n Why: the Postgres-arm lanes read this list; a bad row would drop or duplicate an arm.\n Fix: correct the named line in ${ARMS_LIST}\n Docs: ${DOCS}`);+ return 1;+ }+ if (command === 'list') {+ console.log(list.files.join('\n'));+ return 0;+ }+ if (command === 'shard') {+ const [n, m] = rest.map(Number);+ if (!Number.isInteger(n) || !Number.isInteger(m) || n! < 1 || n! > m!) {+ console.error('usage: bun scripts/postgres-unit-arms.ts shard <n> <m> (1 <= n <= m)');+ return 2;+ }+ const shards = partition(list.files, loadWeights(join(root, ARM_WEIGHTS)), m!);+ console.log([...shards[n! - 1]!].sort().join('\n'));+ return 0;+ }+ if (command === 'mine' && rest.length) {+ const mined = mineArmWeights(rest.map(path => readFileSync(path, 'utf8')));+ const sorted = Object.fromEntries([...mined].sort(([a], [b]) => (a < b ? -1 : 1)));+ writeFileSync(join(root, ARM_WEIGHTS), `${JSON.stringify(sorted, null, 2)}\n`);+ const missing = list.files.filter(f => !mined.has(f));+ console.log(`postgres-arm weights: ${mined.size} files mined into ${ARM_WEIGHTS}${missing.length ? `; no timing for ${missing.join(', ')}` : ''}`);+ return 0;+ }+ console.error('usage: bun scripts/postgres-unit-arms.ts list | shard <n> <m> | mine <job.log>…');+ return 2;+}++if (import.meta.main) process.exit(main(process.argv.slice(2)));diff --git a/test/postgres-unit-arms.txt b/test/postgres-unit-arms.txtnew file mode 100644index 0000000000..9295e98d90--- /dev/null+++ b/test/postgres-unit-arms.txt@@ -0,0 +1,84 @@+# Unit-lane suites whose PostgreSQL arm is gated on DATABASE_URL and that no+# other Postgres lane runs. The unit, serial and slow lanes unset+# DATABASE_URL, so these arms run only where this list is read:+# - persistence-validation.yml `unit-postgres-arms` (shards by+# scripts/postgres-unit-arms.ts, one Bun process per file);+# - the scheduled race hunt (test.yml `race-hunt`, 10 iterations per file,+# a fresh database per iteration);+# - scripts/check-postgres-lane-coverage.ts, which counts each row as a lane+# and fails on a row for a missing file or a file with no gated arm.+# One repo-relative path per line, sorted; '#' starts a comment. Adding a+# file is a one-line edit: insert its path in sorted order. Shards balance+# themselves from scripts/postgres-arm-weights.json.+# Docs: docs/TESTING.md#postgres-arm-lanes+test/alias-source-cascade-5094.test.ts+test/attribution-backfill-history.test.ts+test/behavior-change-notice.test.ts+test/colon-slug-windows-5032.test.ts+test/company-brain-policy.test.ts+test/company-brain-runtime.test.ts+test/decide/conflict-proposals-managed.test.ts+test/declared-lineage-visibility.test.ts+test/derived-link-reconciliation.test.ts+test/doctor-frontmatter-holds.test.ts+test/embedding-completion-atomic.serial.test.ts+test/engine-sql-facts-keyset.test.ts+test/extract-endpoint-revision.serial.test.ts+test/graduation-copy.test.ts+test/graduation-digest.test.ts+test/graduation-drain.test.ts+test/graduation-inventory.test.ts+test/graduation-rollback.test.ts+test/graduation-state.test.ts+test/graduation-target.test.ts+test/graduation-verify.test.ts+test/grandfather-managed.test.ts+test/harness-skills-epoch.test.ts+test/held-read-signals.test.ts+test/import-frontmatter-key-order-5158.test.ts+test/import-revision-concurrency.test.ts+test/links-attendance-blocked.test.ts+test/managed-cycle-pull-upstream.test.ts+test/managed-lint.test.ts+test/managed-maintenance-links.test.ts+test/managed-sweep-corpus-windows.test.ts+test/managed-sync-bulk.test.ts+test/managed-sync-chunker-version.test.ts+test/managed-sync-drain.test.ts+test/managed-sync-group-completion.test.ts+test/pack-relation-direction-engine.test.ts+test/page-embedding-install-batch.test.ts+test/page-state-engine.test.ts+test/persistence-commit-durability.test.ts+test/persistence-deactivate.test.ts+test/persistence-diagnostics.test.ts+test/persistence-file-import.test.ts+test/persistence-git-subdir-origin.test.ts+test/persistence-graph-publication.test.ts+test/persistence-history-fixture.test.ts+test/persistence-image-import.serial.test.ts+test/persistence-managed-lifecycle.test.ts+test/persistence-managed-sync.test.ts+test/persistence-memory-mutations.test.ts+test/persistence-page-authority.test.ts+test/persistence-physical-root-device.test.ts+test/persistence-skill-bundles.serial.test.ts+test/persistence-skill-crash.slow.test.ts+test/persistence-sync-cursor-options.test.ts+test/persistence-sync-holds.test.ts+test/persistence-writer-fences.test.ts+test/repair-embedding-effects.test.ts+test/repair-frontmatter.test.ts+test/shared-content-freshness.test.ts+test/shared-skills-catalog.test.ts+test/shared-skills-retention-capacity.test.ts+test/shared-skills-source-opt-out.test.ts+test/shared-skills-writer-boundary.test.ts+test/source-retire-missing-checkout.test.ts+test/stats-health-source-scope.test.ts+test/sync-frontmatter-recovery.test.ts+test/sync-frontmatter-slug-conflict.test.ts+test/sync-legacy-holds.test.ts+test/takes-vector-lifecycle-5885.serial.test.ts+test/withdrawal-overlay-concurrency.test.ts+test/withdrawal-publication-file.test.tsdiff --git a/test/scripts/postgres-lane-coverage.test.ts b/test/scripts/postgres-lane-coverage.test.tsindex cf6870290d..466ba37bb3 100644--- a/test/scripts/postgres-lane-coverage.test.ts+++ b/test/scripts/postgres-lane-coverage.test.ts@@ -40,7 +40,7 @@ describe('check-postgres-lane-coverage.ts', () => {expect(r.code).toBe(1);expect(r.out).toContain('FAIL [postgres_arm_unlaned]: test/arm.test.ts:');expect(r.out).toContain('Why: the unit, serial and slow lanes unset DATABASE_URL, so this arm skips in every CI lane.');- expect(r.out).toContain('Fix: add test/arm.test.ts to the "Require PostgreSQL arms of unit-lane suites" list in .github/workflows/persistence-validation.yml');+ expect(r.out).toContain('Fix: add test/arm.test.ts to test/postgres-unit-arms.txt (one line, in sorted order), or load it from a test/e2e/*-postgres.test.ts wrapper with registerPostgresTests');expect(r.out).toContain('Docs: docs/TESTING.md#coverage-responsibilities-before-consolidation');});@@ -63,6 +63,32 @@ describe('check-postgres-lane-coverage.ts', () => {expect(r.out).toContain('4 test files with a DATABASE_URL-gated arm; 3 run in a Postgres lane, 1 allowlisted.');});+ test('a test/postgres-unit-arms.txt row is a Postgres lane', () => {+ const arm = ALLOWLISTED['test/export-scale.slow.test.ts'];+ const r = run({ 'test/listed.test.ts': arm, 'test/postgres-unit-arms.txt': '# comment\ntest/listed.test.ts\n' });+ expect(r.code, r.out).toBe(0);+ expect(r.out).toContain('2 test files with a DATABASE_URL-gated arm; 1 run in a Postgres lane, 1 allowlisted.');+ });++ test('a list row for a missing file or a file with no gated arm is stale and names the line to delete', () => {+ const r = run({ 'test/plain.test.ts': "test('pglite only', () => {});\n", 'test/postgres-unit-arms.txt': 'test/gone.test.ts\ntest/plain.test.ts\n' });+ expect(r.code).toBe(1);+ expect(r.out).toContain('FAIL [postgres_arm_list_stale]: the test/postgres-unit-arms.txt row test/gone.test.ts names a missing file');+ expect(r.out).toContain('FAIL [postgres_arm_list_stale]: the test/postgres-unit-arms.txt row test/plain.test.ts names a file with no DATABASE_URL-gated arm');+ expect(r.out).toContain('Fix: delete the test/plain.test.ts line from test/postgres-unit-arms.txt');+ expect(r.out).toContain('Docs: docs/TESTING.md#postgres-arm-lanes');+ });++ test('duplicate, unsorted and malformed list rows fail with their line numbers', () => {+ const arm = ALLOWLISTED['test/export-scale.slow.test.ts'];+ const r = run({ 'test/a.test.ts': arm, 'test/b.test.ts': arm,+ 'test/postgres-unit-arms.txt': 'test/b.test.ts\ntest/a.test.ts\ntest/a.test.ts\nsrc/not-a-test.ts\n' });+ expect(r.code).toBe(1);+ expect(r.out).toContain('FAIL [postgres_arm_list_invalid]: test/postgres-unit-arms.txt:2: test/a.test.ts is out of sorted order');+ expect(r.out).toContain('FAIL [postgres_arm_list_invalid]: test/postgres-unit-arms.txt:3: test/a.test.ts is listed twice');+ expect(r.out).toContain('FAIL [postgres_arm_list_invalid]: test/postgres-unit-arms.txt:4: "src/not-a-test.ts" is not a repo-relative test/…/*.test.ts path');+ });+test('save-and-restore reads, assertions and a self-supplied DATABASE_URL are not arms', () => {const r = run({'test/restore.test.ts': readFileSync(join(FIXTURES, 'good', 'test', 'restore.test.fixture.ts'), 'utf8'),@@ -86,7 +112,9 @@ describe('check-postgres-lane-coverage.ts', () => {expect(r.status, `${r.stdout}\n${r.stderr}`).toBe(0);});- test('the docs anchor the guard prints exists', () => {- expect(readFileSync(join(REPO, 'docs', 'TESTING.md'), 'utf8')).toContain('### Coverage responsibilities before consolidation');+ test('the docs anchors the guard prints exist', () => {+ const docs = readFileSync(join(REPO, 'docs', 'TESTING.md'), 'utf8');+ expect(docs).toContain('### Coverage responsibilities before consolidation');+ expect(docs).toContain('#### Postgres-arm lanes');});});diff --git a/test/scripts/postgres-unit-arms.test.ts b/test/scripts/postgres-unit-arms.test.tsnew file mode 100644index 0000000000..6649401961--- /dev/null+++ b/test/scripts/postgres-unit-arms.test.ts@@ -0,0 +1,50 @@+/**+ * test/postgres-unit-arms.txt is the one list persistence-validation's+ * unit-postgres-arms job, the race hunt and the lane guard read. Its shards+ * must cover every row exactly once, and the weight miner must read the+ * job's per-file group timestamps.+ */+import { describe, expect, test } from 'bun:test';+import { spawnSync } from 'node:child_process';+import { join } from 'node:path';+import { mineArmWeights, parseArmsList, readArmsList } from '../../scripts/postgres-unit-arms.ts';++const REPO = join(import.meta.dir, '..', '..');+const cli = (...args: string[]) => spawnSync(process.execPath, [join(REPO, 'scripts', 'postgres-unit-arms.ts'), ...args], { encoding: 'utf8', cwd: REPO });++describe('postgres-unit-arms list', () => {+ test('the committed list parses cleanly', () => {+ const list = readArmsList(REPO);+ expect(list.errors).toEqual([]);+ expect(list.files.length).toBeGreaterThan(50);+ });++ test('the two CI shards cover every listed file exactly once', () => {+ const all = cli('list').stdout.trim().split('\n');+ const shards = [1, 2].map(n => cli('shard', String(n), '2').stdout.trim().split('\n'));+ expect([...shards[0]!, ...shards[1]!].sort()).toEqual([...all].sort());+ expect(shards[0]!.filter(f => shards[1]!.includes(f))).toEqual([]);+ expect(shards.every(s => s.length > 0)).toBe(true);+ });++ test('comments and blank lines are ignored; a new path is a one-line edit', () => {+ expect(parseArmsList('# header\n\ntest/a.test.ts\ntest/b/c.serial.test.ts\n')).toEqual({ files: ['test/a.test.ts', 'test/b/c.serial.test.ts'], errors: [] });+ });++ test('a bad shard request prints usage', () => {+ const r = cli('shard', '3', '2');+ expect(r.status).toBe(2);+ expect(r.stderr).toContain('usage: bun scripts/postgres-unit-arms.ts shard <n> <m>');+ });++ test('the miner measures each file from its group to the next group or endgroup', () => {+ const log = [+ '2026-10-05T18:44:13.0000000Z ##[group]test/a.test.ts',+ '2026-10-05T18:44:13.0100000Z ##[group]test/a.test.ts:',+ '2026-10-05T18:44:20.0000000Z (pass) a',+ '2026-10-05T18:44:23.0000000Z ##[group]test/b.serial.test.ts',+ '2026-10-05T18:44:24.5000000Z ##[endgroup]',+ ].join('\n');+ expect(Object.fromEntries(mineArmWeights([log]))).toEqual({ 'test/a.test.ts': 10000, 'test/b.serial.test.ts': 1500 });+ });+});