T-191: M2.1u — Real Node/Bun adapters for the notebook snapshot exporter: createNodeNotebookCommandRunner() + createNodeNotebookSnapshotFs() in libs/research/src/notebook-snapshot-node.ts (argv-only node:child_process.spawn, kill-then-settle ETIMEDOUT, O_EXCL create, real-subprocess + temp-dir tests with a fake marimo script; no new deps, no real marimo, no bin)

This commit is contained in:
Studio 2026-12-02 22:17:32 -05:00 • committed by Boki
parent 825aa5f6ae
commit 394d15a81d
2 changed files with 38 additions and 11 deletions

View file

@ -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);
});
});
});

View file

@ -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,
[