Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

test(GBRA-47 D8/D9): guard self-test fixtures and shard-isolation fixes

garrytan58a25647a1b0
diff --git a/scripts/check-postgres-lane-coverage.ts b/scripts/check-postgres-lane-coverage.ts
index e2361be48b..7e58a50af4 100644
--- a/scripts/check-postgres-lane-coverage.ts
+++ b/scripts/check-postgres-lane-coverage.ts
@@ -21,7 +21,9 @@
* 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.
*
- * Seam: GBRAIN_GUARD_ROOT (fixture tree root).
+ * 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,
+ * so committed self-test fixtures stay out of bun's test discovery.
*/
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { dirname, join, relative, resolve } from 'node:path';
@@ -29,6 +31,7 @@ import { safeLoad } from 'js-yaml';
import ts from 'typescript';
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';
@@ -48,7 +51,7 @@ function files(dir: string, keep: (name: string) => boolean): string[] {
}
return out;
}
-const rel = (abs: string) => relative(ROOT, abs).replace(/\\/g, '/');
+const rel = (abs: string) => relative(ROOT, abs).replace(/\\/g, '/').replace(/\.test\.fixture\.ts$/, '.test.ts');
const TEST_PATH = /\btest\/[A-Za-z0-9_./-]+\.test\.ts\b/g;
function isDatabaseUrlRead(node: ts.Node): boolean {
@@ -143,8 +146,8 @@ function postgresLanes(): Map<string, string> {
for (const [path] of run.matchAll(TEST_PATH)) add(path, `${rel(workflow)} › ${jobName} › ${step.name ?? 'run'}`);
}
}
- for (const wrapper of files(join(ROOT, 'test', 'e2e'), name => name.endsWith('.test.ts'))) {
- for (const [, spec] of readFileSync(wrapper, 'utf8').matchAll(/(?:\bimport\s*\(\s*|\bfrom\s+)['"](\.{1,2}\/[^'"]+\.test\.ts)['"]/g)) {
+ for (const wrapper of files(join(ROOT, 'test', 'e2e'), name => TEST_FILE.test(name))) {
+ for (const [, spec] of readFileSync(wrapper, 'utf8').matchAll(/(?:\bimport\s*\(\s*|\bfrom\s+)['"](\.{1,2}\/[^'"]+\.test(?:\.fixture)?\.ts)['"]/g)) {
add(rel(resolve(dirname(wrapper), spec)), rel(wrapper));
}
}
@@ -161,9 +164,9 @@ function postgresLanes(): Map<string, string> {
const laned = postgresLanes();
const failures: string[] = [];
const armed = new Set<string>();
-for (const abs of files(join(ROOT, 'test'), name => name.endsWith('.test.ts'))) {
+for (const abs of files(join(ROOT, 'test'), name => TEST_FILE.test(name))) {
const path = rel(abs);
- if (path.startsWith('test/e2e/')) continue;
+ if (path.startsWith('test/e2e/') || path.startsWith('test/fixtures/')) continue;
const arm = postgresArm(abs);
if (!arm) continue;
armed.add(path);
@@ -174,7 +177,7 @@ for (const abs of files(join(ROOT, 'test'), name => name.endsWith('.test.ts')))
+ ` Docs: ${DOCS}`);
}
for (const [path, reason] of Object.entries(ALLOWLIST)) {
- const problem = !existsSync(join(ROOT, path)) ? 'names a missing file'
+ 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;
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index 7bedbce93c..e6667d1f56 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -272,6 +272,7 @@ test/scripts/e2e-wiring.test.ts selected-e2e job wiring 6 readFileSync
test/scripts/heavy-door-workflow.test.ts heavy door supply chain and coverage gates 4 readFileSync
test/scripts/native-lock-prebuilds.test.ts native lock distribution integrity 2 readFileSync
test/scripts/nightly-e2e.test.ts nightly E2E scheduling 4 readFileSync
+test/scripts/postgres-lane-coverage.test.ts check-postgres-lane-coverage.ts 6 readFileSync
test/scripts/run-verify-parallel.test.ts guard registration ⇒ execution coverage 1 readFileSync
test/scripts/test-shard.slow.test.ts test-shard.sh — LPT balance contract 5 readFileSync
test/scripts/test-shard.slow.test.ts test-shard.sh — exclusion contract 7 readFileSync
diff --git a/test/autopilot-operator-pause.test.ts b/test/autopilot-operator-pause.test.ts
index 158310d956..16a660a0cd 100644
--- a/test/autopilot-operator-pause.test.ts
+++ b/test/autopilot-operator-pause.test.ts
@@ -4,7 +4,7 @@
* `autopilot --install` (which `gbrain upgrade` runs) keeps it, and resume
* clears only it — never a migration or restore hold.
*/
-import { describe, expect, test } from 'bun:test';
+import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
@@ -83,10 +83,39 @@ describe('autopilot operator pause', () => {
});
});
+ test('the daemon loop skips cycles while the operator pause holds and resumes when it clears', async () => {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-operator-pause-daemon-'));
+ const env = { PATH: process.env.PATH, HOME: home, GBRAIN_HOME: home, GBRAIN_DISABLE_UPDATE_CHECK: '1', GBRAIN_MODEL_DISCOVERY: 'off' };
+ const cli = (...args: string[]) => Bun.spawn([process.execPath, join(import.meta.dir, '..', 'src', 'cli.ts'), ...args],
+ { cwd: home, env, stdout: 'pipe', stderr: 'pipe', stdin: 'ignore' });
+ try {
+ expect(await cli('init', '--pglite', '--no-embedding').exited).toBe(0);
+ mkdirSync(join(home, 'repo'));
+ expect(await cli('autopilot', 'pause', '--reason', 'upgrade window').exited).toBe(0);
+ const daemon = cli('autopilot', '--repo', join(home, 'repo'), '--interval', '1', '--inline');
+ let stdout = '';
+ const reader = (async () => { for await (const chunk of daemon.stdout) stdout += new TextDecoder().decode(chunk); })();
+ try {
+ await waitFor(() => stdout.includes('[autopilot] paused'), { timeoutMs: 30_000, label: 'daemon reports the pause' });
+ expect(stdout).not.toContain('[autopilot] resumed');
+ expect(await cli('autopilot', 'resume').exited).toBe(0);
+ await waitFor(() => stdout.includes('[autopilot] resumed'), { timeoutMs: 30_000, label: 'daemon resumes' });
+ } finally {
+ daemon.kill('SIGTERM');
+ await daemon.exited; await reader;
+ }
+ } finally { rmSync(home, { recursive: true, force: true }); }
+ }, 120_000);
+});
+
+describe('job workers honor the operator pause', () => {
+ let engine: PGLiteEngine;
+ beforeAll(async () => { engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); });
+ afterAll(async () => { await engine.disconnect(); });
+ beforeEach(async () => { await engine.executeRaw('DELETE FROM minion_jobs'); });
+
test('a job worker claims nothing while the operator pause holds and runs the job after resume', async () => {
await withEnv({ GBRAIN_HOME: emptyHome() }, async () => {
- const engine = new PGLiteEngine();
- await engine.connect({}); await engine.initSchema();
const worker = new MinionWorker(engine, { pollInterval: 25, lockDuration: 30_000 });
worker.register('operator-pause-probe', async () => 'ran');
let running: Promise<void> | undefined;
@@ -105,15 +134,13 @@ describe('autopilot operator pause', () => {
out(() => runAutopilotPauseCommand(['--resume']));
await waitFor(async () => (await queue.getJob(job.id))?.status === 'completed', { timeoutMs: 15_000, label: 'job completes after resume' });
} finally {
- worker.stop(); await running; await engine.disconnect();
+ worker.stop(); await running;
}
});
}, 60_000);
test('a job claimed as the operator pause lands is released back to the queue un-run', async () => {
await withEnv({ GBRAIN_HOME: emptyHome() }, async () => {
- const engine = new PGLiteEngine();
- await engine.connect({}); await engine.initSchema();
const worker = new MinionWorker(engine, { pollInterval: 25, lockDuration: 30_000 });
let runs = 0;
worker.register('operator-pause-probe', async () => { runs++; return 'ran'; });
@@ -137,32 +164,8 @@ describe('autopilot operator pause', () => {
expect(runs).toBe(0);
expect(await queue.getJob(job.id)).toMatchObject({ status: 'delayed', lock_token: null });
} finally {
- worker.stop(); await running; await engine.disconnect();
+ worker.stop(); await running;
}
});
}, 60_000);
-
- test('the daemon loop skips cycles while the operator pause holds and resumes when it clears', async () => {
- const home = mkdtempSync(join(tmpdir(), 'gbrain-operator-pause-daemon-'));
- const env = { PATH: process.env.PATH, HOME: home, GBRAIN_HOME: home, GBRAIN_DISABLE_UPDATE_CHECK: '1', GBRAIN_MODEL_DISCOVERY: 'off' };
- const cli = (...args: string[]) => Bun.spawn([process.execPath, join(import.meta.dir, '..', 'src', 'cli.ts'), ...args],
- { cwd: home, env, stdout: 'pipe', stderr: 'pipe', stdin: 'ignore' });
- try {
- expect(await cli('init', '--pglite', '--no-embedding').exited).toBe(0);
- mkdirSync(join(home, 'repo'));
- expect(await cli('autopilot', 'pause', '--reason', 'upgrade window').exited).toBe(0);
- const daemon = cli('autopilot', '--repo', join(home, 'repo'), '--interval', '1', '--inline');
- let stdout = '';
- const reader = (async () => { for await (const chunk of daemon.stdout) stdout += new TextDecoder().decode(chunk); })();
- try {
- await waitFor(() => stdout.includes('[autopilot] paused'), { timeoutMs: 30_000, label: 'daemon reports the pause' });
- expect(stdout).not.toContain('[autopilot] resumed');
- expect(await cli('autopilot', 'resume').exited).toBe(0);
- await waitFor(() => stdout.includes('[autopilot] resumed'), { timeoutMs: 30_000, label: 'daemon resumes' });
- } finally {
- daemon.kill('SIGTERM');
- await daemon.exited; await reader;
- }
- } finally { rmSync(home, { recursive: true, force: true }); }
- }, 120_000);
});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/export-scale.slow.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/export-scale.slow.test.fixture.ts
new file mode 100644
index 0000000000..778f0f9de2
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/export-scale.slow.test.fixture.ts
@@ -0,0 +1,4 @@
+import { describe } from 'bun:test';
+import { testBackends } from '../../../../../helpers/test-backends.ts';
+
+for (const backend of testBackends()) describe(backend, () => {});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/unlaned.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/unlaned.test.fixture.ts
new file mode 100644
index 0000000000..73053582e5
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/bad/test/unlaned.test.fixture.ts
@@ -0,0 +1,4 @@
+import { test } from 'bun:test';
+
+// A DATABASE_URL-gated Postgres arm that no Postgres lane names.
+test.skipIf(!process.env.DATABASE_URL)('postgres arm', () => {});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/.github/workflows/lane.yml b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/.github/workflows/lane.yml
new file mode 100644
index 0000000000..b0b2fcfe61
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/.github/workflows/lane.yml
@@ -0,0 +1,10 @@
+name: lane
+on: workflow_dispatch
+jobs:
+ pg:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Postgres arms
+ env:
+ DATABASE_URL: postgres://u:[email protected]:5432/gbrain_test
+ run: bun test test/stepped.test.ts
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/e2e/wrapped-postgres.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/e2e/wrapped-postgres.test.fixture.ts
new file mode 100644
index 0000000000..85d729c3e3
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/e2e/wrapped-postgres.test.fixture.ts
@@ -0,0 +1,3 @@
+import { registerPostgresTests } from '../../../../../../helpers/test-backends.ts';
+
+await registerPostgresTests(() => import('../wrapped.test.fixture.ts'));
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/export-scale.slow.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/export-scale.slow.test.fixture.ts
new file mode 100644
index 0000000000..778f0f9de2
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/export-scale.slow.test.fixture.ts
@@ -0,0 +1,4 @@
+import { describe } from 'bun:test';
+import { testBackends } from '../../../../../helpers/test-backends.ts';
+
+for (const backend of testBackends()) describe(backend, () => {});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/heavy.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/heavy.test.fixture.ts
new file mode 100644
index 0000000000..3957218f7e
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/heavy.test.fixture.ts
@@ -0,0 +1,4 @@
+import { beforeAll } from 'bun:test';
+import { isolatedPersistencePostgres } from '../../../../../helpers/persistence-postgres.ts';
+
+beforeAll(async () => { if (process.env.DATABASE_URL) await isolatedPersistencePostgres(process.env.DATABASE_URL); });
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/restore.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/restore.test.fixture.ts
new file mode 100644
index 0000000000..22aff05953
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/restore.test.fixture.ts
@@ -0,0 +1,7 @@
+import { expect } from 'bun:test';
+
+// Save-and-restore reads and assertions are not Postgres arms.
+const prev = process.env.DATABASE_URL;
+delete process.env.DATABASE_URL;
+if (prev !== undefined) process.env.DATABASE_URL = prev;
+expect(process.env.DATABASE_URL).toBeUndefined();
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/stepped.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/stepped.test.fixture.ts
new file mode 100644
index 0000000000..3370b95f01
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/stepped.test.fixture.ts
@@ -0,0 +1,4 @@
+import { describe } from 'bun:test';
+
+const url = process.env.DATABASE_URL;
+describe.skipIf(!url)('postgres arm named by a DATABASE_URL workflow step', () => {});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/wrapped.test.fixture.ts b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/wrapped.test.fixture.ts
new file mode 100644
index 0000000000..6abec72ccd
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/test/wrapped.test.fixture.ts
@@ -0,0 +1,4 @@
+import { describe } from 'bun:test';
+import { testBackends } from '../../../../../helpers/test-backends.ts';
+
+for (const backend of testBackends()) describe(`wrapped by an e2e file: ${backend}`, () => {});
diff --git a/test/fixtures/guards/check-postgres-lane-coverage.ts/good/tests/heavy/arm.sh b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/tests/heavy/arm.sh
new file mode 100644
index 0000000000..6ae5cf7010
--- /dev/null
+++ b/test/fixtures/guards/check-postgres-lane-coverage.ts/good/tests/heavy/arm.sh
@@ -0,0 +1 @@
+bun test test/heavy.test.ts
diff --git a/test/post-upgrade-banner.test.ts b/test/post-upgrade-banner.test.ts
index a968fe6f2a..02e8c16478 100644
--- a/test/post-upgrade-banner.test.ts
+++ b/test/post-upgrade-banner.test.ts
@@ -4,7 +4,7 @@
* and the read-only preview; nothing on a clean brain; never an applying
* command. The banner runs the full wave checks, not doctor --fast.
*/
-import { describe, expect, test } from 'bun:test';
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
@@ -80,39 +80,45 @@ describe('post-upgrade recovery banner', () => {
});
}, 180_000);
- test('gbrain post-upgrade relays the banner for a brain with findings and never an applying advisory', async () => {
- const home = mkdtempSync(join(tmpdir(), 'gbrain-banner-cli-'));
- const claude = selfCaptureHost();
- const cli = async (...args: string[]) => {
- const child = Bun.spawn([process.execPath, join(import.meta.dir, '..', 'src', 'cli.ts'), ...args], {
- cwd: home, stdout: 'pipe', stderr: 'pipe', stdin: 'ignore',
- env: { PATH: process.env.PATH, HOME: home, GBRAIN_HOME: home, CLAUDE_CONFIG_DIR: claude, GBRAIN_DISABLE_UPDATE_CHECK: '1', GBRAIN_SKIP_REFERENCE_SWEEP: '1' },
- });
- const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);
- return { stdout, stderr, code };
- };
- try {
- const init = await cli('init', '--pglite', '--no-embedding');
- expect(init.code, init.stderr).toBe(0);
- const { database_path } = JSON.parse(readFileSync(join(home, '.gbrain', 'config.json'), 'utf8'));
- await withEnv({ GBRAIN_HOME: home, CLAUDE_CONFIG_DIR: claude }, async () => {
- const engine = new PGLiteEngine();
- await engine.connect({ database_path });
- try {
- for (const fact of ['Alice Example prefers Rust for systems work', 'Alice Example ships on Fridays']) {
- await writeSingleFact(engine, 'default', { fact, entity: 'people/alice-example', provenance: 'hook:writeback', sessionId: 'sess-self' });
- }
- } finally { await disposePersistenceConsumer(engine); await engine.disconnect(); }
- });
- const upgraded = await cli('post-upgrade', '--no-autopilot-install');
- expect(upgraded.code, upgraded.stderr).toBe(0);
- expect(upgraded.stdout).toContain('[AGENT] Relay this to your operator');
- expect(upgraded.stdout).toContain('[AGENT] captured_facts_active: 2 (explicit_kind_required; preview with: gbrain repair captured-facts)');
- expect(`${upgraded.stdout}${upgraded.stderr}`).not.toMatch(/safe[- ]chunk/i);
- expect(upgraded.stdout).not.toContain('--apply');
- } finally {
- rmSync(home, { recursive: true, force: true });
- rmSync(claude, { recursive: true, force: true });
- }
+});
+
+describe('gbrain post-upgrade', () => {
+ const home = mkdtempSync(join(tmpdir(), 'gbrain-banner-cli-'));
+ const claude = selfCaptureHost();
+ const cli = async (...args: string[]) => {
+ const child = Bun.spawn([process.execPath, join(import.meta.dir, '..', 'src', 'cli.ts'), ...args], {
+ cwd: home, stdout: 'pipe', stderr: 'pipe', stdin: 'ignore',
+ env: { PATH: process.env.PATH, HOME: home, GBRAIN_HOME: home, CLAUDE_CONFIG_DIR: claude, GBRAIN_DISABLE_UPDATE_CHECK: '1', GBRAIN_SKIP_REFERENCE_SWEEP: '1' },
+ });
+ const [stdout, stderr, code] = await Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]);
+ return { stdout, stderr, code };
+ };
+
+ beforeAll(async () => {
+ const init = await cli('init', '--pglite', '--no-embedding');
+ expect(init.code, init.stderr).toBe(0);
+ const { database_path } = JSON.parse(readFileSync(join(home, '.gbrain', 'config.json'), 'utf8'));
+ await withEnv({ GBRAIN_HOME: home, CLAUDE_CONFIG_DIR: claude }, async () => {
+ const engine = new PGLiteEngine();
+ await engine.connect({ database_path });
+ try {
+ for (const fact of ['Alice Example prefers Rust for systems work', 'Alice Example ships on Fridays']) {
+ await writeSingleFact(engine, 'default', { fact, entity: 'people/alice-example', provenance: 'hook:writeback', sessionId: 'sess-self' });
+ }
+ } finally { await disposePersistenceConsumer(engine); await engine.disconnect(); }
+ });
+ }, 180_000);
+ afterAll(() => {
+ rmSync(home, { recursive: true, force: true });
+ rmSync(claude, { recursive: true, force: true });
+ });
+
+ test('relays the recovery banner for a brain with findings and never an applying advisory', async () => {
+ const upgraded = await cli('post-upgrade', '--no-autopilot-install');
+ expect(upgraded.code, upgraded.stderr).toBe(0);
+ expect(upgraded.stdout).toContain('[AGENT] Relay this to your operator');
+ expect(upgraded.stdout).toContain('[AGENT] captured_facts_active: 2 (explicit_kind_required; preview with: gbrain repair captured-facts)');
+ expect(`${upgraded.stdout}${upgraded.stderr}`).not.toMatch(/safe[- ]chunk/i);
+ expect(upgraded.stdout).not.toContain('--apply');
}, 180_000);
});
diff --git a/test/scripts/postgres-lane-coverage.test.ts b/test/scripts/postgres-lane-coverage.test.ts
index 229f67d5a4..056f3ebc97 100644
--- a/test/scripts/postgres-lane-coverage.test.ts
+++ b/test/scripts/postgres-lane-coverage.test.ts
@@ -11,6 +11,7 @@ import { join, resolve } from 'node:path';
const REPO = resolve(import.meta.dir, '..', '..');
const GUARD = join(REPO, 'scripts', 'check-postgres-lane-coverage.ts');
+const FIXTURES = join(REPO, 'test', 'fixtures', 'guards', 'check-postgres-lane-coverage.ts');
const ALLOWLISTED = { 'test/export-scale.slow.test.ts': "for (const backend of testBackends()) describe(backend, () => {});\n" };
const dirs: string[] = [];
afterEach(() => { for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true }); });
@@ -64,7 +65,7 @@ describe('check-postgres-lane-coverage.ts', () => {
test('save-and-restore reads, assertions and a self-supplied DATABASE_URL are not arms', () => {
const r = run({
- 'test/restore.test.ts': "const prev = process.env.DATABASE_URL;\ndelete process.env.DATABASE_URL;\nif (prev !== undefined) process.env.DATABASE_URL = prev;\nexpect(process.env.DATABASE_URL).toBeUndefined();\n",
+ 'test/restore.test.ts': readFileSync(join(FIXTURES, 'good', 'test', 'restore.test.fixture.ts'), 'utf8'),
'test/own-url.test.ts': "test('helper', () => withEnv({ DATABASE_URL: 'postgresql://localhost/gbrain_test' }, () => { expect(testBackends()).toEqual(['pglite', 'postgres']); }));\n",
'test/strings.test.ts': "const fixture = `await engine.connect({ database_url: process.env.DATABASE_URL });`;\n",
});
@@ -79,7 +80,9 @@ describe('check-postgres-lane-coverage.ts', () => {
});
test('every DATABASE_URL-gated arm in this repository runs in a Postgres lane or is allowlisted', () => {
- const r = spawnSync(process.execPath, [GUARD], { encoding: 'utf8', env: { ...process.env, GBRAIN_GUARD_ROOT: REPO } });
+ const env = { ...process.env };
+ delete env.GBRAIN_GUARD_ROOT;
+ const r = spawnSync(process.execPath, [GUARD], { encoding: 'utf8', cwd: REPO, env });
expect(r.status, `${r.stdout}\n${r.stderr}`).toBe(0);
});