Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(migrations): fresh-install audit for every fresh_install_noop flag (E8)

garrytanbe8d15a3dd1e
diff --git a/scripts/serial-weights.json b/scripts/serial-weights.json
index 6437252ed5..8f7407397a 100644
--- a/scripts/serial-weights.json
+++ b/scripts/serial-weights.json
@@ -176,6 +176,7 @@
"test/migration-in-process.serial.test.ts": 16,
"test/migration-orchestrator-v0_46_3.serial.test.ts": 12,
"test/migration-v0-29-1.serial.test.ts": 10,
+ "test/migrations-fresh-install-audit.serial.test.ts": 30,
"test/minions/delegated-execution.serial.test.ts": 15,
"test/model-config.serial.test.ts": 1,
"test/models-per-task-extract-atoms.serial.test.ts": 1,
diff --git a/scripts/test-weights.json b/scripts/test-weights.json
index 2dc10460ca..a5814fc73c 100644
--- a/scripts/test-weights.json
+++ b/scripts/test-weights.json
@@ -1139,6 +1139,7 @@
"test/migration-v120.test.ts": 209,
"test/migration-vector-replay.test.ts": 3137,
"test/migrations-cjk-wave.test.ts": 229,
+ "test/migrations-fresh-install.test.ts": 3900,
"test/migrations-registry.test.ts": 5,
"test/migrations-v0_11_0.test.ts": 21,
"test/migrations-v0_12_0.test.ts": 2,
diff --git a/scripts/ubicloud/weights.json b/scripts/ubicloud/weights.json
index ef9b828e23..84be757f2a 100644
--- a/scripts/ubicloud/weights.json
+++ b/scripts/ubicloud/weights.json
@@ -465,6 +465,7 @@
"serial:test/migrate-quiet-replay.serial.test.ts": 5483,
"serial:test/migration-in-process.serial.test.ts": 9878,
"serial:test/migration-v0-29-1.serial.test.ts": 6189,
+ "serial:test/migrations-fresh-install-audit.serial.test.ts": 30000,
"serial:test/minions/delegated-execution.serial.test.ts": 24258,
"serial:test/model-config.serial.test.ts": 331,
"serial:test/models-newer-hint.serial.test.ts": 497,
@@ -1691,6 +1692,7 @@
"unit:test/migration-resume.test.ts": 257,
"unit:test/migration-v120.test.ts": 1271,
"unit:test/migrations-cjk-wave.test.ts": 1508,
+ "unit:test/migrations-fresh-install.test.ts": 4500,
"unit:test/migrations-registry.test.ts": 266,
"unit:test/migrations-v0_11_0.test.ts": 218,
"unit:test/migrations-v0_12_0.test.ts": 262,
diff --git a/test/helpers/fresh-brain-snapshot.ts b/test/helpers/fresh-brain-snapshot.ts
new file mode 100644
index 0000000000..2a0c70a259
--- /dev/null
+++ b/test/helpers/fresh-brain-snapshot.ts
@@ -0,0 +1,96 @@
+/**
+ * State snapshot of a keyless PGLite brain for the E8 fresh-install audit
+ * (`test/migrations-fresh-install-audit.serial.test.ts`): the public schema
+ * (columns, indexes, constraints), per-table row counts, the config table and
+ * the GBRAIN_HOME file tree. Two equal snapshots taken around an orchestrator
+ * run prove the orchestrator changed nothing.
+ *
+ * File-tree noise every engine open produces is excluded by name, each with
+ * its reason, so a real write by an orchestrator is never hidden:
+ * - the PGLite datastore directory (binary pages change on any open; its
+ * logical state is the schema/config/row-count part of the snapshot);
+ * - lock files and owner records (rewritten with the opener's pid);
+ * - Bun's install cache under HOME (not gbrain state).
+ */
+import { createHash } from 'node:crypto';
+import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
+import { join, relative } from 'node:path';
+import { PGLiteEngine } from '../../src/core/pglite-engine.ts';
+
+export interface BrainSnapshot {
+ columns: string[];
+ indexes: string[];
+ constraints: string[];
+ row_counts: Record<string, number>;
+ config: Record<string, string>;
+ files: Record<string, string>;
+}
+
+const VOLATILE_FILE = [
+ /(^|\/)\.locks(\/|$)/,
+ /(^|\/)locks\//,
+ /\.lock$/,
+ /\.gbrain-owner\.json$/,
+ /(^|\/)\.bun(\/|$)/,
+ /(^|\/)\.capy(\/|$)/,
+ /(^|\/)persistence\/[^/]+\.(cli|stdio|http)\.json$/,
+ /(^|\/)last-update-check$/,
+];
+
+function walk(root: string, dir: string, skip: string, out: Record<string, string>): void {
+ for (const name of readdirSync(dir).sort()) {
+ const path = join(dir, name);
+ const rel = relative(root, path);
+ if (path === skip || VOLATILE_FILE.some(pattern => pattern.test(rel))) continue;
+ const stat = statSync(path);
+ if (stat.isDirectory()) {
+ out[`${rel}/`] = 'dir';
+ walk(root, path, skip, out);
+ } else {
+ out[rel] = createHash('sha256').update(readFileSync(path)).digest('hex');
+ }
+ }
+}
+
+export function snapshotFiles(home: string, databasePath: string): Record<string, string> {
+ const files: Record<string, string> = {};
+ if (existsSync(home)) walk(home, home, databasePath, files);
+ return files;
+}
+
+export async function snapshotBrain(home: string, databasePath: string): Promise<BrainSnapshot> {
+ const snapshot = await snapshotDatabase(databasePath);
+ return { ...snapshot, files: snapshotFiles(home, databasePath) };
+}
+
+async function snapshotDatabase(databasePath: string): Promise<BrainSnapshot> {
+ const engine = new PGLiteEngine();
+ await engine.connect({ database_path: databasePath });
+ try {
+ const columns = await engine.executeRaw<{ c: string }>(
+ `SELECT table_name || '.' || column_name || ' ' || data_type || ' null=' || is_nullable || ' default=' || COALESCE(column_default, '') AS c
+ FROM information_schema.columns WHERE table_schema = 'public' ORDER BY table_name, column_name`);
+ const indexes = await engine.executeRaw<{ c: string }>(
+ `SELECT tablename || ' ' || indexdef AS c FROM pg_indexes WHERE schemaname = 'public' ORDER BY tablename, indexname`);
+ const constraints = await engine.executeRaw<{ c: string }>(
+ `SELECT conrelid::regclass::text || ' ' || conname || ' ' || pg_get_constraintdef(oid) AS c
+ FROM pg_constraint WHERE connamespace = 'public'::regnamespace ORDER BY 1`);
+ const tables = await engine.executeRaw<{ t: string }>(
+ `SELECT table_name AS t FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' ORDER BY 1`);
+ const row_counts: Record<string, number> = {};
+ for (const { t } of tables) {
+ const [row] = await engine.executeRaw<{ n: number }>(`SELECT count(*)::int AS n FROM "${t.replace(/"/g, '""')}"`);
+ row_counts[t] = Number(row?.n ?? 0);
+ }
+ const config: Record<string, string> = {};
+ for (const row of await engine.executeRaw<{ key: string; value: string }>('SELECT key, value FROM config ORDER BY key')) {
+ config[row.key] = row.value;
+ }
+ return {
+ columns: columns.map(r => r.c), indexes: indexes.map(r => r.c), constraints: constraints.map(r => r.c),
+ row_counts, config, files: {},
+ };
+ } finally {
+ await engine.disconnect();
+ }
+}
diff --git a/test/migrations-fresh-install-audit.serial.test.ts b/test/migrations-fresh-install-audit.serial.test.ts
new file mode 100644
index 0000000000..d2b245c487
--- /dev/null
+++ b/test/migrations-fresh-install-audit.serial.test.ts
@@ -0,0 +1,142 @@
+/**
+ * E8 fresh-install audit (agent-first operator wave, Lane E).
+ *
+ * `gbrain init` records a migration complete on a new brain only when the
+ * migration declares `fresh_install_noop: true`. This file is the proof for
+ * every flag: on one keyless PGLite brain created by the real CLI
+ * (`init --pglite --no-embedding`, hermetic HOME = GBRAIN_HOME, provider keys
+ * scrubbed, `fetch` refused), each flagged orchestrator runs for real and the
+ * public schema (columns, indexes, constraints), every table's row count, the
+ * config table and the GBRAIN_HOME file tree must be byte-identical before and
+ * after. The unflagged migrations list as `pending_fresh_install` and
+ * `apply-migrations --yes --no-autopilot-install` completes them.
+ *
+ * Orchestrators that shell out (`extract`, `repair-jsonb`, `get_stats`) run the
+ * source CLI through `GBRAIN_JOB_CHILD_CLI` with the no-network preload; none
+ * of the audited orchestrators installs a service.
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { runCli } from './helpers/cli-spawn.ts';
+import { withEnv } from './helpers/with-env.ts';
+import { PROVIDER_ENV_KEYS } from './helpers/provider-env.ts';
+import { snapshotBrain } from './helpers/fresh-brain-snapshot.ts';
+import { migrations } from '../src/commands/migrations/index.ts';
+import { SHARED_CONTENT_INSPECT_ARGV } from '../src/commands/migrations/shared-content.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import type { CompletedMigrationEntry } from '../src/core/preferences.ts';
+
+const REPO = join(import.meta.dir, '..');
+const FLAGGED = ['0.12.0', '0.12.2', '0.13.0', '0.13.1', '0.16.0', '0.18.0', '0.18.1', '0.21.0', '0.29.1', '0.31.0', '0.32.2', '0.43.0', '0.46.3', '0.60.31'];
+const SETUP = ['0.11.0', '0.14.0', '0.22.4', '0.28.0', '0.53.0'];
+
+let home = '';
+let tools = '';
+let databasePath = '';
+const keyless = Object.fromEntries([...PROVIDER_ENV_KEYS, 'GBRAIN_PGLITE_SNAPSHOT'].map(key => [key, undefined]));
+
+function ledger(): CompletedMigrationEntry[] {
+ return readFileSync(join(home, '.gbrain', 'migrations', 'completed.jsonl'), 'utf8').trim().split('\n').map(line => JSON.parse(line));
+}
+
+beforeAll(async () => {
+ home = mkdtempSync(join(tmpdir(), 'gbrain-e8-home-'));
+ tools = mkdtempSync(join(tmpdir(), 'gbrain-e8-tools-'));
+ const child = join(tools, 'gbrain');
+ writeFileSync(child, `#!/bin/sh\nexec "${process.execPath}" --no-env-file --preload "${join(REPO, 'test/helpers/no-network-preload.ts')}" "${join(REPO, 'src/cli.ts')}" "$@"\n`);
+ chmodSync(child, 0o755);
+ const init = await runCli(['init', '--pglite', '--no-embedding'], { home, cwd: home, env: keyless, timeoutMs: 120_000 });
+ expect(init.exitCode).toBe(0);
+ databasePath = JSON.parse(readFileSync(join(home, '.gbrain', 'config.json'), 'utf8')).database_path;
+}, 180_000);
+
+afterAll(() => {
+ rmSync(home, { recursive: true, force: true });
+ rmSync(tools, { recursive: true, force: true });
+});
+
+describe('E8 — gbrain init stamps only fresh_install_noop migrations', () => {
+ test('the flagged set is exactly the audited set; everything else is setup work', () => {
+ expect(migrations.filter(m => m.fresh_install_noop).map(m => m.version)).toEqual(FLAGGED);
+ expect(migrations.filter(m => !m.fresh_install_noop).map(m => m.version)).toEqual(SETUP);
+ });
+
+ test('init writes a fresh_install ledger entry for each flagged migration and nothing else', () => {
+ const entries = ledger();
+ expect(entries.map(e => e.version)).toEqual(FLAGGED);
+ for (const entry of entries) {
+ expect(entry).toMatchObject({ status: 'complete', fresh_install: true });
+ expect(typeof entry.installed_version).toBe('string');
+ }
+ });
+
+ test('apply-migrations --list --json reports the rest as pending_fresh_install with the finishing command', async () => {
+ const list = await runCli(['apply-migrations', '--list', '--json'], { home, cwd: home, env: keyless });
+ expect(list.exitCode).toBe(0);
+ const body = JSON.parse(list.stdout.trim().split('\n').at(-1)!);
+ const byStatus = (status: string) => body.migrations.filter((m: { status: string }) => m.status === status).map((m: { version: string }) => m.version);
+ expect(byStatus('applied')).toEqual(FLAGGED);
+ expect(byStatus('pending_fresh_install')).toEqual(SETUP);
+ expect(byStatus('pending')).toEqual([]);
+ expect(body.needs_action).toBe(0);
+ expect(body.pending_fresh_install).toBe(SETUP.length);
+ expect(body.next.argv).toEqual(['gbrain', 'apply-migrations', '--yes', '--no-autopilot-install']);
+ expect(body.migrations.filter((m: { fresh_install?: boolean }) => m.fresh_install).length).toBe(FLAGGED.length);
+ }, 60_000);
+});
+
+describe('E8 audit — each fresh_install_noop orchestrator changes nothing on a new brain', () => {
+ for (const version of FLAGGED) {
+ test(`v${version}`, async () => {
+ const migration = migrations.find(m => m.version === version)!;
+ const fetched: string[] = [];
+ const realFetch = globalThis.fetch;
+ globalThis.fetch = (async (input: unknown) => {
+ fetched.push(String(input));
+ throw new Error('network disabled in the fresh-install audit');
+ }) as unknown as typeof fetch;
+ try {
+ await withEnv({
+ ...keyless, HOME: home, GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined,
+ GBRAIN_JOB_CHILD_CLI: join(tools, 'gbrain'), GBRAIN_SKIP_STARTUP_HOOKS: '1', GBRAIN_NO_AUTOPILOT_INSTALL: '1',
+ }, async () => {
+ const before = await snapshotBrain(home, databasePath);
+ const result = await migration.orchestrator({ yes: true, dryRun: false, noAutopilotInstall: true });
+ expect(result.status).toBe('complete');
+ expect(result.phases.filter(phase => phase.status === 'failed')).toEqual([]);
+ expect(await snapshotBrain(home, databasePath)).toEqual(before);
+ });
+ } finally {
+ globalThis.fetch = realFetch;
+ }
+ expect(fetched).toEqual([]);
+ }, 120_000);
+ }
+});
+
+describe('E8 — finishing setup', () => {
+ test('apply-migrations --yes completes pending_fresh_install; shared-skills names its command; max_stalled keeps its default', async () => {
+ const run = await runCli(['apply-migrations', '--yes', '--no-autopilot-install'], { home, cwd: home, env: keyless, timeoutMs: 120_000 });
+ expect(run.exitCode).toBe(0);
+ expect(run.stdout).toContain(`next step: ${SHARED_CONTENT_INSPECT_ARGV.join(' ')}`);
+ const shared = ledger().filter(e => e.version === '0.53.0').at(-1)!;
+ expect(shared.phases?.[0]).toMatchObject({ name: 'content-checkpoints', argv: SHARED_CONTENT_INSPECT_ARGV });
+
+ const list = await runCli(['apply-migrations', '--list', '--json'], { home, cwd: home, env: keyless });
+ const body = JSON.parse(list.stdout.trim().split('\n').at(-1)!);
+ expect(body.migrations.every((m: { status: string }) => m.status === 'applied')).toBe(true);
+ expect(body.next).toBeUndefined();
+
+ const engine = new PGLiteEngine();
+ await engine.connect({ database_path: databasePath });
+ try {
+ const [column] = await engine.executeRaw<{ column_default: string }>(
+ "SELECT column_default FROM information_schema.columns WHERE table_name = 'minion_jobs' AND column_name = 'max_stalled'");
+ expect(column.column_default).toBe('5');
+ } finally {
+ await engine.disconnect();
+ }
+ }, 180_000);
+});
diff --git a/test/migrations-fresh-install.test.ts b/test/migrations-fresh-install.test.ts
new file mode 100644
index 0000000000..ef5d4d815f
--- /dev/null
+++ b/test/migrations-fresh-install.test.ts
@@ -0,0 +1,175 @@
+/**
+ * E8 fresh-install stamping: the ledger stamps init writes, the
+ * `pending_fresh_install` status every migration surface derives from them
+ * (apply-migrations plan, get_health ledger summary, doctor), and the
+ * in-process config read in v0.12.0. The end-to-end proof on a real
+ * `gbrain init` brain is test/migrations-fresh-install-audit.serial.test.ts.
+ */
+import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { withEnv } from './helpers/with-env.ts';
+import { migrations } from '../src/commands/migrations/index.ts';
+import { stampFreshInstallMigrations } from '../src/commands/migrations/fresh-install.ts';
+import { __testing as planTesting } from '../src/commands/apply-migrations.ts';
+import { __testing as v0120Testing } from '../src/commands/migrations/v0_12_0.ts';
+import { migrationLedgerSummary } from '../src/core/migration-ledger.ts';
+import { loadCompletedMigrations, type CompletedMigrationEntry } from '../src/core/preferences.ts';
+import { buildChecks } from '../src/commands/doctor.ts';
+import { getDbUrlSource } from '../src/core/config.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+
+const FLAGGED = migrations.filter(m => m.fresh_install_noop).map(m => m.version);
+const SETUP = migrations.filter(m => !m.fresh_install_noop).map(m => m.version);
+const homes: string[] = [];
+
+function freshHome(): string {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-e8-unit-'));
+ homes.push(home);
+ return home;
+}
+
+function writeLedger(home: string, entries: CompletedMigrationEntry[]): void {
+ mkdirSync(join(home, '.gbrain', 'migrations'), { recursive: true });
+ writeFileSync(join(home, '.gbrain', 'migrations', 'completed.jsonl'), entries.map(e => JSON.stringify(e)).join('\n') + '\n');
+}
+
+const stamp = (version: string, installed: string): CompletedMigrationEntry =>
+ ({ version, status: 'complete', fresh_install: true, installed_version: installed });
+
+afterEach(() => {
+ for (const home of homes.splice(0)) rmSync(home, { recursive: true, force: true });
+});
+
+describe('stampFreshInstallMigrations', () => {
+ test('stamps every fresh_install_noop migration, lists the rest as pending_fresh_install, and is idempotent', async () => {
+ const home = freshHome();
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const receipt = stampFreshInstallMigrations('0.60.37');
+ expect(receipt).toEqual({ installed_version: '0.60.37', stamped: FLAGGED, pending_fresh_install: SETUP });
+ const entries = loadCompletedMigrations();
+ expect(entries.map(e => e.version)).toEqual(FLAGGED);
+ for (const entry of entries) {
+ expect(entry).toMatchObject({ status: 'complete', fresh_install: true, installed_version: '0.60.37' });
+ expect(entry.phases?.[0]).toMatchObject({ name: 'fresh_install', status: 'skipped' });
+ }
+ stampFreshInstallMigrations('0.60.37');
+ expect(loadCompletedMigrations().length).toBe(FLAGGED.length);
+ });
+ });
+
+ test('never stamps a migration newer than the creating binary', async () => {
+ const home = freshHome();
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const receipt = stampFreshInstallMigrations('0.20.0');
+ expect(receipt.stamped).toEqual(['0.12.0', '0.12.2', '0.13.0', '0.13.1', '0.16.0', '0.18.0', '0.18.1']);
+ expect(receipt.pending_fresh_install).toEqual(['0.11.0', '0.14.0']);
+ });
+ });
+});
+
+describe('pending_fresh_install status', () => {
+ test('ledger summary: setup work on a new brain is pending_fresh_install, not pending', async () => {
+ const home = freshHome();
+ writeLedger(home, FLAGGED.map(v => stamp(v, '0.60.37')));
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const summary = migrationLedgerSummary('0.60.37');
+ expect(summary.pending).toEqual([]);
+ expect(summary.pending_fresh_install).toEqual(SETUP);
+ });
+ });
+
+ test('migrations newer than the creating version stay ordinary pending upgrade work', async () => {
+ const home = freshHome();
+ writeLedger(home, ['0.12.0', '0.12.2', '0.13.0', '0.13.1', '0.16.0', '0.18.0', '0.18.1', '0.21.0', '0.29.1'].map(v => stamp(v, '0.30.0')));
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const summary = migrationLedgerSummary('99.0.0');
+ expect(summary.pending_fresh_install).toEqual(['0.11.0', '0.14.0', '0.22.4', '0.28.0']);
+ expect(summary.pending).toEqual(['0.31.0', '0.32.2', '0.43.0', '0.46.3', '0.53.0', '0.60.31']);
+ });
+ });
+
+ test('a brain with no stamps (created before stamping) keeps every unrun migration pending', async () => {
+ const home = freshHome();
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const summary = migrationLedgerSummary('99.0.0');
+ expect(summary.pending_fresh_install).toEqual([]);
+ expect(summary.pending.length).toBe(migrations.length);
+ });
+ });
+
+ test('apply-migrations plan puts unrun setup work in pending_fresh_install and runs it like pending', () => {
+ const idx = planTesting.indexCompleted(FLAGGED.map(v => stamp(v, '0.60.37')));
+ const plan = planTesting.buildPlan(idx, '0.60.37');
+ expect(plan.applied.map(m => m.version)).toEqual(FLAGGED);
+ expect(plan.pending_fresh_install.map(m => m.version)).toEqual(SETUP);
+ expect(plan.pending).toEqual([]);
+ });
+});
+
+describe('doctor minions_migration with fresh-install stamps', () => {
+ async function minionsChecks(home: string) {
+ return withEnv({ HOME: home, GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () =>
+ (await buildChecks(null, ['--fast', '--json'], getDbUrlSource())).filter(c => c.name === 'minions_migration'));
+ }
+
+ test('a stamped newer no-op does not hide a real partial', async () => {
+ const home = freshHome();
+ writeLedger(home, [...FLAGGED.map(v => stamp(v, '0.60.37')), { version: '0.11.0', status: 'partial' }]);
+ const checks = await minionsChecks(home);
+ expect(checks).toHaveLength(1);
+ expect(checks[0].status).toBe('fail');
+ expect(checks[0].message).toContain('0.11.0');
+ });
+
+ test('a real newer completion still supersedes a stale partial', async () => {
+ const home = freshHome();
+ writeLedger(home, [{ version: '0.11.0', status: 'partial' }, { version: '0.60.31', status: 'complete' }]);
+ const checks = await minionsChecks(home);
+ expect(checks.filter(c => c.status === 'fail')).toEqual([]);
+ });
+
+ test('pending setup work is an info row with the finishing command, never a failure', async () => {
+ const home = freshHome();
+ writeLedger(home, FLAGGED.map(v => stamp(v, '0.60.37')));
+ const [check] = await minionsChecks(home);
+ expect(check).toMatchObject({ status: 'ok', severity: 'info', details: { pending_fresh_install: SETUP } });
+ expect(check.message).toContain('not a failed upgrade');
+ expect(check.fix).toMatchObject({ argv: ['gbrain', 'apply-migrations', '--yes', '--no-autopilot-install'], consent: [], actor: 'agent' });
+ });
+});
+
+describe('v0.12.0 config check reads auto_link in-process', () => {
+ let home = '';
+ let database = '';
+ let engine: PGLiteEngine;
+
+ beforeAll(async () => {
+ home = mkdtempSync(join(tmpdir(), 'gbrain-e8-autolink-'));
+ database = join(home, '.gbrain', 'brain.pglite');
+ mkdirSync(join(home, '.gbrain'), { recursive: true });
+ writeFileSync(join(home, '.gbrain', 'config.json'), JSON.stringify({ engine: 'pglite', database_path: database }));
+ engine = new PGLiteEngine();
+ await engine.connect({ database_path: database });
+ await engine.initSchema();
+ await engine.disconnect();
+ }, 60_000);
+
+ afterAll(async () => {
+ await engine.disconnect();
+ rmSync(home, { recursive: true, force: true });
+ });
+
+ const check = () => withEnv({ HOME: home, GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined },
+ () => v0120Testing.phaseBConfigCheck({ yes: true, dryRun: false, noAutopilotInstall: true }));
+
+ // Before E8 this shelled out to `gbrain config get`, which has no CLI to
+ // resolve under bun test, so the disabled value was never seen.
+ test('database plane auto_link=false skips the backfill; unset defaults to enabled', async () => {
+ expect((await check()).autoLink).toEqual({ status: 'unknown', raw: undefined });
+ await engine.connect({ database_path: database });
+ try { await engine.setConfig('auto_link', 'false'); } finally { await engine.disconnect(); }
+ expect((await check()).autoLink).toEqual({ status: 'disabled', raw: 'false' });
+ }, 60_000);
+});