Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

CI: run the enumeration and census tests on every pull request

garrytan6013f0c4c4dc
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 904e1c13e1..2dce5d1354 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -89,6 +89,7 @@ jobs:
native-locks: ${{ steps.dynamic-ci.outputs.native-locks }}
persistence-validation: ${{ steps.dynamic-ci.outputs.persistence-validation }}
stress-changed-tests: ${{ steps.dynamic-ci.outputs.stress-changed-tests }}
+ enumeration-census-tests: ${{ steps.dynamic-ci.outputs.enumeration-census-tests }}
steps:
- id: dynamic-ci
uses: trunk-io/dynamic-ci@5bcddbf3615c2b032c21eed1b514c91164bda4a8 # v1 (v0.1.7)
@@ -96,7 +97,7 @@ jobs:
timeout-minutes: 3
with:
token: ${{ secrets.TRUNK_API_TOKEN }}
- job-keys: security-regressions,native-locks,persistence-validation,stress-changed-tests
+ job-keys: security-regressions,native-locks,persistence-validation,stress-changed-tests,enumeration-census-tests
enable-annotation: 'true'
# Planning gate for the native platform matrix. Pull requests that touch
@@ -117,6 +118,7 @@ jobs:
outputs:
native-scope: ${{ steps.scope.outputs.native }}
convergence: ${{ steps.convergence.outputs.convergence }}
+ census: ${{ steps.census.outputs.census }}
reuse: ${{ steps.reuse.outputs.reuse }}
reuse-source-run-id: ${{ steps.reuse.outputs.source_run_id }}
steps:
@@ -126,10 +128,11 @@ jobs:
scripts/ci-native-scope.sh
scripts/ci-manifest-diff.sh
scripts/ci-convergence-scope.sh
+ scripts/select-e2e.ts
scripts/ci-reuse.ts
scripts/lib/gh-issue.ts
sparse-checkout-cone-mode: false
- - if: github.event_name == 'push'
+ - if: github.event_name == 'push' || github.event_name == 'pull_request'
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: 1.4.4
@@ -211,6 +214,27 @@ jobs:
fi
echo "convergence gate: $convergence"
echo "convergence=$convergence" >> "$GITHUB_OUTPUT"
+ # A pull request runs enumeration-census-tests unless every changed file is
+ # a doc (scripts/select-e2e.ts --classify-only says DOC_ONLY); an unknown or
+ # unreadable diff runs it.
+ - id: census
+ if: github.event_name == 'pull_request'
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR: ${{ github.event.pull_request.number }}
+ REPO: ${{ github.repository }}
+ CHANGED_FILES: ${{ github.event.pull_request.changed_files }}
+ run: |
+ set -euo pipefail
+ census=run
+ if [[ "$CHANGED_FILES" =~ ^[0-9]{1,4}$ ]] && [ "$CHANGED_FILES" -lt 3000 ] \
+ && files=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename') \
+ && [ "$(printf '%s\n' "$files" | awk 'NF { count++ } END { print count+0 }')" -eq "$CHANGED_FILES" ] \
+ && [ "$(printf '%s\n' "$files" | bun scripts/select-e2e.ts --classify-only --changed-files -)" = DOC_ONLY ]; then
+ census=skip
+ fi
+ echo "enumeration and census tests: $census"
+ echo "census=$census" >> "$GITHUB_OUTPUT"
# Re-run checks for every event, except a master push reusing a passed full-suite run of its exact tree (scripts/ci-reuse.ts). Only dependencies and PGLite snapshots are cached.
gitleaks:
@@ -541,6 +565,49 @@ jobs:
path: node_modules/.cache/gbrain-typecheck.tsbuildinfo
key: tsbuildinfo-${{ runner.os }}-${{ hashFiles('bun.lock', 'tsconfig.json') }}-${{ github.sha }}
+ # Enumeration and census tests: the unit files that fail when a change adds an
+ # operation, command, flag, error code, doctor check, caller or route without its
+ # reviewed entry, or changes a golden (scripts/ci-census-tests.sh prints them; the
+ # crew runs the same command by hand). No aggregate, merge rule or reuse check
+ # reads it. Two shards of about 175 s of mined weight each on 2 vCPUs, like one
+ # of the two unit shards a 4-vCPU test runner packs.
+ # Event parity (docs/ci-event-parity.md#enumeration-and-census-tests): pull
+ # requests only, and not on a doc-only diff. Every full run (the full-ci
+ # dispatch, every push to master, the nightly schedule) runs these files in the
+ # unit shards.
+ enumeration-census-tests:
+ name: enumeration and census tests (${{ matrix.shard }}/2)
+ needs: [changes, dynamic-ci]
+ if: ${{ !cancelled() && needs.dynamic-ci.outputs.enumeration-census-tests != 'false' && needs.changes.result == 'success' && (github.event_name == 'pull_request' && needs.changes.outputs.census != 'skip') }}
+ runs-on: ubicloud-standard-2-ubuntu-2404
+ timeout-minutes: 15
+ strategy:
+ fail-fast: false
+ matrix:
+ shard: [1, 2]
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
+ with:
+ bun-version: 1.4.4
+ - uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
+ with:
+ path: ~/.bun/install/cache
+ key: bun-cache-${{ runner.os }}-${{ hashFiles('bun.lock') }}
+ restore-keys: bun-cache-${{ runner.os }}-
+ - uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
+ with:
+ path: |
+ test/fixtures/pglite-snapshot.tar
+ test/fixtures/pglite-snapshot.version
+ key: pglite-snapshot-${{ runner.os }}-${{ hashFiles('src/core/**/*.ts', 'test/helpers/legacy-embedding-config.ts', 'scripts/build-pglite-snapshot.ts') }}
+ - name: Install dependencies (bounded, retried once)
+ timeout-minutes: 8
+ run: bun scripts/ci-bun-install.ts --frozen-lockfile
+ - name: Run shard ${{ matrix.shard }} of 2
+ timeout-minutes: 10
+ run: bash scripts/ci-census-tests.sh --run ${{ matrix.shard }} 2
+
# Event parity (docs/ci-event-parity.md#full-ci-on-pull-requests): full profile only. A
# pull request runs the cheap tier; this job runs in the full-ci dispatch on its
# head before merge (merge-train requires full-suite), on every push to master
diff --git a/docs/ci-event-parity.md b/docs/ci-event-parity.md
index f67c966b9e..0bf1db561a 100644
--- a/docs/ci-event-parity.md
+++ b/docs/ci-event-parity.md
@@ -28,6 +28,7 @@ checks ([below](#full-ci-on-pull-requests)), never per-cell matrix names.
| `test.yml` | `native_only`, `race_hunt`, `stress_*` dispatch inputs; concurrency suffixes | Parity: manual modes and run grouping, never applied to PR, push or schedule events | — |
| `persistence-validation.yml` | Bun matrix of read latency, deployment matrix, unit-lane PostgreSQL arms, soak, crash robot, reconciliation, convergence | Parity: every supported Bun version on every event that runs the lane | — |
| `test.yml`, `persistence-validation.yml` | Cheap tier on pull requests: no unit shards, serial, slow, BrainBench, admin-browser, shared-skills, coverage or `test-status`; of the persistence lanes only the crash robot and convergence, and those and the native cells only when the diff selects them | Named exception ([below](#full-ci-on-pull-requests)) | The full-ci dispatch on the head before merge (merge-train requires `full-suite`), every push to master, the merge queue and the nightly Test schedule |
+| `test.yml` | `enumeration-census-tests` on pull requests that aren't doc-only | Named exception ([below](#enumeration-and-census-tests)): pull requests only, an early copy of files the unit shards already run | The full-ci dispatch, every push to master, the merge queue and the nightly Test schedule run every one of these files in the unit shards |
| `e2e.yml` | No `pull_request` trigger | Named exception ([below](#full-ci-on-pull-requests)) | The full-ci dispatch on the head before merge (merge-train requires `e2e-full-suite`), every push to master, the merge queue and the nightly E2E schedule |
| `test.yml`, `e2e.yml` | A push to master skips its full lanes when it reuses a passed full-suite run of its exact tree | Named exception ([below](#master-push-reuse)) | The reused run (same tree, full profile); schedules never reuse |
| `persistence-validation.yml` | `convergence` selected on pull requests by `scripts/ci-convergence-scope.sh` (test.yml `changes`; never by `package.json` alone) | Named exception | Every merge-queue run and every push to master; the nightly cell runs in `convergence-nightly.yml` |
@@ -80,6 +81,42 @@ produce either one. Each uploads `full-suite-tree` / `e2e-full-suite-tree`,
a `tree.json` recording the tested tree (`scripts/ci-full-suite-tree.sh`).
Pushes to master, the merge queue and schedules always run the full profile.
+## Enumeration and census tests
+
+Some unit tests fail whenever a change adds something to a list without
+updating the list's reviewed copy: a new operation, command, `--flag`, error
+code, doctor check or repair kind, a new caller or route that a source census
+counts, or output that a golden file pins. The cheap tier used to skip them, so
+the first full-ci run on a pull request was often where they failed, and each
+miss cost another push and another full run.
+
+`enumeration-census-tests` runs them on every pull-request push whose diff
+isn't doc-only (the `changes` job classifies the diff with
+`scripts/select-e2e.ts --classify-only`; an unreadable diff runs them). It needs
+no Postgres. `scripts/ci-census-tests.sh` prints the file list, and the job and
+a person checking a branch by hand use the same command:
+
+```bash
+bash scripts/ci-census-tests.sh # print the files
+bash scripts/ci-census-tests.sh --run # run them all (about 10 minutes on 2 cores)
+bash scripts/ci-census-tests.sh --run 1 2 # run shard 1 of 2, as CI does
+```
+
+The list holds the source censuses (files marked
+`test-reads-source-ok[structural]`), every file that imports
+`test/helpers/golden`, the files whose names match the enumeration pattern in
+the script, and the consumer idle-pass statement bounds
+(`test/persistence-consumer-*` files that mention idle). It leaves out
+`test/e2e/`, serial and slow files, and `test/setup.test.ts`. To add a file,
+change the script, not the workflow.
+
+The job is two shards on 2-vCPU runners. It is advisory: `cheap-tier`,
+`full-suite`, merge-train, the remote pregate and master-push reuse never read
+it, and `contributor-gate` stays the only required check. It is gated by Trunk
+Dynamic CI like the other cheap-tier jobs ([below](#trunk-dynamic-ci)). Every
+full run already runs these files in the unit shards, so nothing is lost when
+it doesn't run.
+
## Master-push reuse
A push to master runs nothing again when its tree equals the tree of a passed,
diff --git a/scripts/ci-census-tests.sh b/scripts/ci-census-tests.sh
new file mode 100755
index 0000000000..7dbcd9a42f
--- /dev/null
+++ b/scripts/ci-census-tests.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+# The enumeration and census tests: the unit files that fail when a change adds
+# an operation, command, flag, error code, doctor check, repair kind, caller or
+# route without its reviewed entry, or changes a golden. They need no Postgres.
+# The pull-request job enumeration-census-tests in .github/workflows/test.yml
+# runs them, so a pull request finds these failures in minutes instead of in its
+# full-ci run (docs/ci-event-parity.md#enumeration-and-census-tests).
+#
+# Usage:
+# bash scripts/ci-census-tests.sh print the files, one per line
+# bash scripts/ci-census-tests.sh --run run every file
+# bash scripts/ci-census-tests.sh --run <k> <n> run shard k of n (scripts/sharding.ts)
+#
+# The set, from tracked files under test/:
+# - source censuses: files marked test-reads-source-ok[structural]
+# - goldens: files that import test/helpers/golden
+# - enumeration lists: file names matching ENUMERATION below
+# - idle-pass statement bounds: test/persistence-consumer-*.test.ts files that mention idle
+# minus test/e2e/ (Postgres), *.serial.test.ts and *.slow.test.ts (their own
+# full-ci jobs) and test/setup.test.ts (about 7 minutes on its own).
+set -euo pipefail
+cd "$(dirname "$0")/.."
+
+ENUMERATION='registry|inventory|catalog|coverage-ledger|operations-|behavior-change-notice|error-|exit-codes|fix-wave-5-integration|repair-explicit-only|cli-flag-validation|allowlist-drift|mcp-tool-defs|cli-flag-equals|remote-privacy-sweep|tool-catalog'
+
+list() {
+ {
+ git grep -l 'test-reads-source-ok\[structural\]' -- test || true
+ git grep -l helpers/golden -- test || true
+ git ls-files test | grep -E "$ENUMERATION" || true
+ git grep -l -i idle -- 'test/persistence-consumer-*.test.ts' || true
+ } | grep '\.test\.ts$' | grep -v -E '^test/e2e/|\.(serial|slow)\.test\.ts$|^test/setup\.test\.ts$' | LC_ALL=C sort -u
+}
+
+if [ "$#" -eq 0 ]; then
+ list
+ exit 0
+fi
+if [ "$1" != --run ] || { [ "$#" -ne 1 ] && [ "$#" -ne 3 ]; }; then
+ echo "usage: bash scripts/ci-census-tests.sh [--run [<shard> <total>]]" >&2
+ exit 2
+fi
+
+files=$(list)
+if [ "$#" -eq 3 ]; then
+ files=$(printf '%s\n' "$files" | bun run scripts/sharding.ts "$2" "$3")
+fi
+if [ -z "$files" ]; then
+ echo "no census files selected" >&2
+ exit 1
+fi
+echo "enumeration and census tests: $(printf '%s\n' "$files" | grep -c '^') files; $(printf '%s\n' "$files" | bun run scripts/sharding.ts --sum 2>/dev/null || echo 'predicted weight unavailable')"
+
+# The unit phase never sees a database URL, in CI or here: a Postgres arm would
+# turn this into a different run.
+unset DATABASE_URL GBRAIN_DATABASE_URL
+. scripts/lib/test-env.sh
+ensure_pglite_snapshot census
+# ./ makes each argument a path, run in the order given (see scripts/test-shard.sh).
+printf '%s\n' "$files" | sed 's#^#./#' | xargs -n 100000 -x bun test --timeout=120000 --max-concurrency="${GBRAIN_TEST_MAX_CONCURRENCY:-4}"
diff --git a/test/scripts/ci-census-tests.test.ts b/test/scripts/ci-census-tests.test.ts
new file mode 100644
index 0000000000..3525d63166
--- /dev/null
+++ b/test/scripts/ci-census-tests.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, test } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { join } from 'node:path';
+
+// scripts/ci-census-tests.sh is the one list test.yml's enumeration-census-tests job and the crew's
+// by-hand check both read (docs/ci-event-parity.md#enumeration-and-census-tests).
+const root = join(import.meta.dir, '../..');
+const script = join(root, 'scripts/ci-census-tests.sh');
+const run = (...args: string[]) => spawnSync('bash', [script, ...args], { cwd: root, encoding: 'utf8' });
+
+describe('ci-census-tests.sh', () => {
+ const listed = run();
+ const files = listed.stdout.split('\n').filter(Boolean);
+
+ test('prints a sorted, unique list of tracked unit test files', () => {
+ expect(listed.status, listed.stderr).toBe(0);
+ expect(files.length).toBeGreaterThan(100);
+ expect(files).toEqual([...new Set(files)].sort());
+ for (const file of files) expect(file, file).toMatch(/^test\/.+\.test\.ts$/);
+ });
+
+ test('covers each kind of file that failed a first full-ci run', () => {
+ for (const file of [
+ 'test/doctor-json-golden.test.ts',
+ 'test/cli-flag-validation.test.ts',
+ 'test/conversation-facts-type-allowlist-drift.test.ts',
+ 'test/mcp-tool-defs.test.ts',
+ 'test/cli-flag-equals.test.ts',
+ 'test/remote-privacy-sweep.test.ts',
+ 'test/persistence-consumer-idle.test.ts',
+ ]) expect(files, file).toContain(file);
+ const structural = spawnSync('git', ['grep', '-l', 'test-reads-source-ok\\[structural\\]', '--', 'test'], { cwd: root, encoding: 'utf8' }).stdout
+ .split('\n').filter(file => /\.test\.ts$/.test(file) && !/\.serial\.test\.ts$/.test(file));
+ expect(structural.length).toBeGreaterThan(40);
+ for (const file of structural) expect(files, file).toContain(file);
+ });
+
+ test('leaves out E2E, serial, slow and setup files', () => {
+ for (const file of files) expect(file, file).not.toMatch(/^test\/e2e\/|\.(serial|slow)\.test\.ts$|^test\/setup\.test\.ts$/);
+ });
+
+ test('refuses arguments it does not know', () => {
+ for (const args of [['--list'], ['--run', '1'], ['--run', '1', '2', '3']]) expect(run(...args).status, args.join(' ')).toBe(2);
+ });
+});
diff --git a/test/scripts/full-ci-workflow.test.ts b/test/scripts/full-ci-workflow.test.ts
index 96496aab1c..599bee36a6 100644
--- a/test/scripts/full-ci-workflow.test.ts
+++ b/test/scripts/full-ci-workflow.test.ts
@@ -45,7 +45,7 @@ const step = (job: Job, name: string) => job.steps!.find(s => s.name === name)!;
const bash = (script: string, env: Record<string, string>, cwd = root) =>
spawnSync('bash', ['-c', script], { cwd, encoding: 'utf8', env: { PATH: process.env.PATH, ...env } });
-const CHEAP = ['changes', 'cheap-tier', 'dependency-audit', 'executed-receipts', 'gitleaks', 'security-regressions', 'stress-changed-tests', 'typecheck', 'verify'];
+const CHEAP = ['changes', 'cheap-tier', 'dependency-audit', 'enumeration-census-tests', 'executed-receipts', 'gitleaks', 'security-regressions', 'stress-changed-tests', 'typecheck', 'verify'];
const FULL_ONLY = ['serial-tests', 'slow-brainbench-e2e', 'brainbench', 'slow-entity-resolve-perf', 'test', 'admin-browser',
'shared-skills-compatibility', 'coverage-report', 'test-status', 'full-suite'];
@@ -59,15 +59,27 @@ describe('full CI on pull requests', () => {
for (const job of [...FULL_ONLY, 'native-locks', 'persistence-validation']) expect(full, `${event}: ${job}`).toContain(job);
expect(full).not.toContain('cheap-tier');
expect(full).not.toContain('dynamic-ci');
+ expect(full).not.toContain('enumeration-census-tests');
}
});
+ // docs/ci-event-parity.md#enumeration-and-census-tests: a doc-only pull request skips the job, a failed
+ // classifier runs it, and no aggregate, merge check or reuse rule waits for it.
+ test('the enumeration and census tests run on every pull request that is not doc-only and nothing needs them', () => {
+ const smoke = { 'native-scope': 'smoke', convergence: 'skip' };
+ expect(runs(unit, { event: 'pull_request', outputs: { ...smoke, census: 'skip' } })).not.toContain('enumeration-census-tests');
+ expect(runs(unit, { event: 'pull_request', outputs: { ...smoke, census: 'run' } })).toContain('enumeration-census-tests');
+ expect(runs(unit, { event: 'pull_request', outputs: smoke, changes: 'failure' })).not.toContain('enumeration-census-tests');
+ for (const [name, job] of Object.entries(unit.jobs)) expect(job.needs ?? [], name).not.toContain('enumeration-census-tests');
+ expect(step(unit.jobs['enumeration-census-tests']!, 'Run shard ${{ matrix.shard }} of 2').run).toBe('bash scripts/ci-census-tests.sh --run ${{ matrix.shard }} 2');
+ });
+
// Trunk Dynamic CI (docs/ci-event-parity.md#trunk-dynamic-ci): the filter runs only on pull requests, so every other event
// sees empty verdicts and runs every gated job; on a pull request only an exact 'false' skips a job, and a gated job still
// waits for its other needs to succeed.
test('Dynamic CI skips a gated pull-request lane only on an exact false verdict and never filters another event', () => {
const gated = Object.keys(unit.jobs['dynamic-ci']!.outputs!).sort();
- expect(gated).toEqual(['native-locks', 'persistence-validation', 'security-regressions', 'stress-changed-tests']);
+ expect(gated).toEqual(['enumeration-census-tests', 'native-locks', 'persistence-validation', 'security-regressions', 'stress-changed-tests']);
const selected = { 'native-scope': 'primary', convergence: 'run' };
const all = runs(unit, { event: 'pull_request', outputs: selected });
for (const verdict of ['', 'true']) {
@@ -78,7 +90,7 @@ describe('full CI on pull requests', () => {
}
for (const event of ['push', 'merge_group', 'schedule', 'workflow_dispatch']) {
expect(Boolean(evaluate(unit.jobs['dynamic-ci']!.if!, { event })), event).toBe(false);
- for (const job of gated) expect(runs(unit, { event }), `${event}: ${job}`).toContain(job);
+ for (const job of gated.filter(name => name !== 'enumeration-census-tests')) expect(runs(unit, { event }), `${event}: ${job}`).toContain(job);
}
for (const job of ['native-locks', 'persistence-validation']) {
expect(runs(unit, { event: 'push', changes: 'failure' }), job).not.toContain(job);
diff --git a/test/scripts/native-only-workflow.test.ts b/test/scripts/native-only-workflow.test.ts
index f3396e636b..b3e12959a1 100644
--- a/test/scripts/native-only-workflow.test.ts
+++ b/test/scripts/native-only-workflow.test.ts
@@ -48,7 +48,7 @@ describe('native-only CI remains separate from full validation', () => {
for (const flag of [undefined, false, true]) {
const nativeOnly = event === 'workflow_dispatch' && flag === true;
const expected = name === 'native-only-status' ? nativeOnly
- : name === 'cheap-tier' || name === 'dynamic-ci' ? event === 'pull_request'
+ : name === 'cheap-tier' || name === 'dynamic-ci' || name === 'enumeration-census-tests' ? event === 'pull_request'
: name === 'reused-full-suite' ? false
: !nativeOnly && !(event === 'pull_request' && FULL_ONLY.has(name));
expect(Boolean(evaluate(job.if!, event, flag)), `${name}/${event}/${flag}`).toBe(expected);