Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(migrate-embeddings): check every bad control in-process and one CLI run per rejection class
garrytana0e0c9b0bfe2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9964b950f0..4c16660fba 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,19 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.93.0] - 2026-10-06++**The embedding-migration bad-flag test stops timing out in serial shard 3, and it now actually catches a CLI that opens the brain before rejecting a flag.**++No user-facing behavior changes. A bad flag on `gbrain migrate embeddings` or `gbrain retrieval-upgrade` already exits 2 with an `unknown_flag` envelope before touching the brain, and it still does when another process holds the brain lock. For contributors and agents working on gbrain:++- **`test/migrate-embeddings-recovery-cli.serial.test.ts`** never had a hung child. Its matrix test ran 126 cold CLI starts and 126 in-process PGLite reopens, one after another, inside a single 180-second budget. That took 69 s on an idle 4-core machine and more than 180 s on a shared CI runner, where the runner killed whichever child was running at the deadline ("killed 1 dangling process"). Every control is still checked on both routes, now in-process through the same `parseGlobalFlags` and `migrationCliArgumentError` call the CLI entry makes. One real CLI process runs for each distinct rejection (14 per route), and the test takes 27 s instead of 69 s. Pinned to one core beside three other serial files, the old test hit its 180 s timeout and the new one passed in 135 s.+- **The test is stronger.** After each rejected run, it now requires the brain directory to be untouched (same size, mtime and ctime for every file), and it still compares the row snapshot once per route. It also runs a bad flag while the test itself holds the brain open. A mutation that opens the engine before validating the flags passed the old test, but it fails the new one on both checks.++## To take advantage of v0.60.93.0++Nothing to do: this release changes a test only.+## [0.60.90.0] - 2026-10-06**The keyed tool-routing E2E stops failing at random: it now reads the model's most likely tool choice instead of one random sample.**diff --git a/test/migrate-embeddings-recovery-cli.serial.test.ts b/test/migrate-embeddings-recovery-cli.serial.test.tsindex 55eecd1ec8..a2b29ecf11 100644--- a/test/migrate-embeddings-recovery-cli.serial.test.ts+++ b/test/migrate-embeddings-recovery-cli.serial.test.ts@@ -1,5 +1,5 @@import { expect, test } from 'bun:test';-import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { existsSync, mkdtempSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';import { join } from 'node:path';import { tmpdir } from 'node:os';import { PGLiteEngine } from '../src/core/pglite-engine.ts';@@ -30,10 +30,40 @@ const invalidControls = [['--dim', '8', '--dim', '16'], ['--', '--facts'],];+const routes = [['migrate', 'embeddings'], ['retrieval-upgrade']];+const invalidInvocation = (route: string[], narrowing: string[]) => {+ const flag = narrowing[0].split('=')[0];+ const controls = [['--to', 'openai:text-embedding-3-large'], ['--dim', '8'], ['--yes'], ['--max-cost-usd', '1']]+ .filter(([name]) => name !== flag).flat();+ return { flag, argv: [...route, ...controls, '--json', ...narrowing] };+};+const cliRejection = (argv: string[]) => {+ const { rest } = parseGlobalFlags(argv);+ return migrationCliArgumentError(rest[0], rest.slice(1), argv);+};+const rejectionClasses = (route: string[]) => {+ const classes = new Map<string, string[]>();+ for (const narrowing of invalidControls) {+ const { argv } = invalidInvocation(route, narrowing);+ const error = cliRejection(argv)!;+ const key = `${error.message.split(error.flag).join('<flag>')} ${parseGlobalFlags(argv).rest.length}`;+ if (!classes.has(key)) classes.set(key, narrowing);+ }+ return [...classes.values()];+};+test.each(invalidControls.map(args => [args.join(' '), args] as const))('direct migration parser rejects %s', (_label, args) => {expect(() => parseMigrateEmbeddingsFlags([...args])).toThrow();});+test.each(routes.flatMap(route => invalidControls.map(narrowing => [`${route.join(' ')} ${narrowing.join(' ')}`, route, narrowing] as const)))(+ 'the CLI entry rejects gbrain %s from its argv before dispatch', (_label, route, narrowing) => {+ const { flag, argv } = invalidInvocation(route, narrowing);+ const error = cliRejection(argv);+ expect(error?.flag).toBe(flag);+ if (['--source', '--slugs'].includes(flag)) expect(error?.message).toContain(`unknown flag ${flag}`);+ });+test('the shared migration contract preserves supported pacing, globals and exact numeric values', () => {expect(parseMigrateEmbeddingsFlags(['--to', MODEL, '--dim', '8', '--batch-size', '1', '--max-cost-usd', '0.25','--non-interactive', '--pace=gentle', '--pace-max-concurrency=2'])).toMatchObject({@@ -183,15 +213,18 @@ test('both actual migration CLI routes reject unsupported or malformed controls}const snapshot = async () => Promise.all(['pages', 'content_chunks', 'facts', 'config', 'gbrain_cycle_locks'].map(table =>engine.executeRaw(`SELECT to_jsonb(t) AS row FROM ${table} t ORDER BY to_jsonb(t)::text`)));+ const fileState = (dir = data): string[] => readdirSync(dir).sort().flatMap(name => {+ const path = join(dir, name);+ const stat = statSync(path, { bigint: true });+ return [`${path} ${stat.size} ${stat.mtimeNs} ${stat.ctimeNs}`, ...(stat.isDirectory() ? fileState(path) : [])];+ });const before = await snapshot();await engine.disconnect();- for (const route of [['migrate', 'embeddings'], ['retrieval-upgrade']]) {- for (const narrowing of invalidControls) {- const flag = narrowing[0].split('=')[0];- const controls = [['--to', 'openai:text-embedding-3-large'], ['--dim', '8'], ['--yes'], ['--max-cost-usd', '1']]- .filter(([name]) => name !== flag).flat();- const child = Bun.spawn([process.execPath, '--preload', preload, cliPath, ...route,- ...controls, '--json', ...narrowing], {+ for (const route of routes) {+ for (const narrowing of rejectionClasses(route)) {+ const { flag, argv } = invalidInvocation(route, narrowing);+ const untouched = fileState();+ const child = Bun.spawn([process.execPath, '--preload', preload, cliPath, ...argv], {cwd: home, env, stdout: 'pipe', stderr: 'pipe',});const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);@@ -202,10 +235,21 @@ test('both actual migration CLI routes reject unsupported or malformed controlsexpect(stderr).not.toContain('PGLite');expect(existsSync(calls)).toBe(false);expect(readFileSync(join(data, 'config.json'), 'utf8')).toBe(config);- await engine.connect(database as never);- expect(await snapshot()).toEqual(before);- await engine.disconnect();+ expect(fileState()).toEqual(untouched);+ }+ await engine.connect(database as never);+ expect(await snapshot()).toEqual(before);+ for (const narrowing of [['--facts'], ['--dim', '0']]) {+ const child = Bun.spawn([process.execPath, '--preload', preload, cliPath, ...invalidInvocation(route, narrowing).argv], {+ cwd: home, env, stdout: 'pipe', stderr: 'pipe',+ });+ const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);+ expect({ code, envelope: JSON.parse(stdout).code }).toEqual({ code: 2, envelope: 'unknown_flag' });+ expect(stderr).toContain(narrowing[0]);+ expect(stderr).not.toContain('PGLite');}+ expect(await snapshot()).toEqual(before);+ await engine.disconnect();for (const supported of [['--dry-run', '--pace=gentle', '--pace-max-concurrency=2', '--quiet', '--progress-json', '--progress-interval=0', '--brain=host'],['--dry-run', '--pace', '--pace-max-concurrency', '3', '--quiet'], ['--status'], ['--help'],