From 394d15a81d15901e1ba6ae22b89ffed580f38336 Mon Sep 17 00:00:00 2001 From: Studio Date: Wed, 2 Dec 2026 22:17:32 -0500 Subject: [PATCH] =?UTF-8?q?T-191:=20M2.1u=20=E2=80=94=20Real=20Node/Bun=20?= =?UTF-8?q?adapters=20for=20the=20notebook=20snapshot=20exporter:=20`creat?= =?UTF-8?q?eNodeNotebookCommandRunner()`=20+=20`createNodeNotebookSnapshot?= =?UTF-8?q?Fs()`=20in=20`libs/research/src/notebook-snapshot-node.ts`=20(a?= =?UTF-8?q?rgv-only=20`node:child=5Fprocess.spawn`,=20kill-then-settle=20`?= =?UTF-8?q?ETIMEDOUT`,=20`O=5FEXCL`=20create,=20real-subprocess=20+=20temp?= =?UTF-8?q?-dir=20tests=20with=20a=20fake=20marimo=20script;=20no=20new=20?= =?UTF-8?q?deps,=20no=20real=20marimo,=20no=20bin)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/notebook-snapshot-node-qa.test.ts | 45 ++++++++++++++----- .../test/notebook-snapshot-node.test.ts | 4 +- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/libs/research/test/notebook-snapshot-node-qa.test.ts b/libs/research/test/notebook-snapshot-node-qa.test.ts index 615637e2..9b1b317f 100644 --- a/libs/research/test/notebook-snapshot-node-qa.test.ts +++ b/libs/research/test/notebook-snapshot-node-qa.test.ts @@ -480,17 +480,42 @@ describe('notebook-snapshot-node QA', () => { expect(pkg.exports['./notebook-snapshot-node']).toBe('./src/notebook-snapshot-node.ts'); }); - test('browser bundle of the root entrypoint contains no adapter code or child_process', async () => { - const result = await Bun.build({ - entrypoints: [resolve(import.meta.dir, '../src/index.ts')], - target: 'browser', - }); + test('browser bundle of the root entrypoint contains no adapter code or child_process', () => { + const entry = resolve(import.meta.dir, '../src/index.ts'); + // Run Bun.build in a subprocess so Bun's in-process build/fd cache stays + // isolated from other bundling tests in the full workspace suite. + const child = Bun.spawnSync( + [ + process.execPath, + '--no-env-file', + '-e', + ` + const result = await Bun.build({ + entrypoints: [${JSON.stringify(entry)}], + target: 'browser', + }); + if (!result.success) { + console.error(result.logs); + process.exit(1); + } + const code = (await Promise.all(result.outputs.map(o => o.text()))).join('\\n'); + for (const forbidden of [ + 'createNodeNotebookCommandRunner', + 'createNodeNotebookSnapshotFs', + 'child_process', + ]) { + if (code.includes(forbidden)) { + console.error('Found forbidden symbol in browser bundle:', forbidden); + process.exit(2); + } + } + `, + ], + { env: { PATH: process.env.PATH } } + ); - expect(result.success).toBe(true); - const code = (await Promise.all(result.outputs.map(o => o.text()))).join('\n'); - expect(code).not.toContain('createNodeNotebookCommandRunner'); - expect(code).not.toContain('createNodeNotebookSnapshotFs'); - expect(code).not.toContain('child_process'); + expect(new TextDecoder().decode(child.stderr)).toBe(''); + expect(child.exitCode).toBe(0); }); }); }); diff --git a/libs/research/test/notebook-snapshot-node.test.ts b/libs/research/test/notebook-snapshot-node.test.ts index 67696aa7..32c32c5d 100644 --- a/libs/research/test/notebook-snapshot-node.test.ts +++ b/libs/research/test/notebook-snapshot-node.test.ts @@ -186,7 +186,9 @@ describe('notebook-snapshot-node adapters', () => { const grandchildScript = join(workDir, 'grandchild-sleeper.js'); const parentScript = join(workDir, 'spawn-grandchild.js'); - await writeFile(grandchildScript, 'setInterval(() => {}, 10_000);\n', 'utf8'); + // Bounded lifetime well beyond the runner's 800ms deadline so a regression + // cannot leak the fixture process indefinitely. + await writeFile(grandchildScript, 'setTimeout(() => process.exit(0), 30_000);\n', 'utf8'); await writeFile( parentScript, [