From 44112e4abff4268e37da01918e29b9e0e8d80c61 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Wed, 22 Jul 2026 10:51:37 -0700 Subject: [PATCH] test(files): route upload-raw env pinning through withEnv() (test-isolation R1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check:test-isolation flagged direct process.env.GBRAIN_SOURCE mutation in beforeAll/afterAll. Wrap each runFiles call in withEnv({ GBRAIN_SOURCE: undefined }, ...) instead — same pin, restore is try/finally-guaranteed. Co-Authored-By: Claude Fable 5 --- test/files-upload-raw.test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/files-upload-raw.test.ts b/test/files-upload-raw.test.ts index f334d805a..990bdd0d0 100644 --- a/test/files-upload-raw.test.ts +++ b/test/files-upload-raw.test.ts @@ -15,16 +15,17 @@ import { join } from 'path'; import { tmpdir } from 'os'; import { PGLiteEngine } from '../src/core/pglite-engine.ts'; import { runFiles } from '../src/commands/files.ts'; +import { withEnv } from './helpers/with-env.ts'; let engine: PGLiteEngine; let repoDir: string; let srcDir: string; -let savedEnvSource: string | undefined; + +// resolveSourceId env tier could leak from the harness — pin it off per call. +const runFilesNoEnvSource = (engine: PGLiteEngine, args: string[]) => + withEnv({ GBRAIN_SOURCE: undefined }, () => runFiles(engine, args)); beforeAll(async () => { - // resolveSourceId env tier could leak from the harness — pin it off. - savedEnvSource = process.env.GBRAIN_SOURCE; - delete process.env.GBRAIN_SOURCE; engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema(); @@ -38,7 +39,6 @@ afterAll(async () => { await engine.disconnect(); rmSync(repoDir, { recursive: true, force: true }); rmSync(srcDir, { recursive: true, force: true }); - if (savedEnvSource !== undefined) process.env.GBRAIN_SOURCE = savedEnvSource; }); describe('files upload-raw — small text file stays in git (#2297)', () => { @@ -46,7 +46,7 @@ describe('files upload-raw — small text file stays in git (#2297)', () => { const input = join(srcDir, 'notes.txt'); writeFileSync(input, 'raw provenance content'); - await runFiles(engine, ['upload-raw', input, '--page', 'people/alice-example', '--type', 'notes']); + await runFilesNoEnvSource(engine, ['upload-raw', input, '--page', 'people/alice-example', '--type', 'notes']); const dest = join(repoDir, 'people/alice-example/.raw/notes.txt'); expect(existsSync(dest)).toBe(true); @@ -65,7 +65,7 @@ describe('files upload-raw — small text file stays in git (#2297)', () => { const input = join(srcDir, 'loose.txt'); writeFileSync(input, 'loose content'); - await runFiles(engine, ['upload-raw', input]); + await runFilesNoEnvSource(engine, ['upload-raw', input]); expect(existsSync(join(repoDir, 'unsorted/.raw/loose.txt'))).toBe(true); const rows = await engine.executeRaw<{ storage_path: string }>( @@ -79,7 +79,7 @@ describe('files upload-raw — small text file stays in git (#2297)', () => { const input = join(srcDir, 'notes.txt'); writeFileSync(input, 'raw provenance content v2'); - await runFiles(engine, ['upload-raw', input, '--page', 'people/alice-example']); + await runFilesNoEnvSource(engine, ['upload-raw', input, '--page', 'people/alice-example']); const dest = join(repoDir, 'people/alice-example/.raw/notes.txt'); expect(readFileSync(dest, 'utf8')).toBe('raw provenance content v2');