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 21:51:03 -05:00 • committed by Boki
parent 309f442d5e
commit 5d238ce32c
2 changed files with 116 additions and 37 deletions

View file

@ -134,28 +134,13 @@ export function createNodeNotebookCommandRunner(
// Child may have already exited before kill was delivered.
}
}
// Tear down our read ends of stdout/stderr so a descendant that
// inherited either pipe cannot prevent `child`'s `close` event from
// firing once the direct child exits.
child.stdout?.destroy();
child.stderr?.destroy();
};
const deadlineMs = performance.now() + timeoutMs;
const scheduleTimeout = (): void => {
if (settled || terminalFailure !== null) {
return;
}
const remainingMs = deadlineMs - performance.now();
if (remainingMs <= 0) {
triggerTerminalFailure(
createCodedError(
'ETIMEDOUT',
`Command '${commandName}' timed out after ${timeoutMs}ms.`
)
);
return;
}
const delayMs = Math.min(Math.ceil(remainingMs), MAX_TIMER_DELAY_MS);
timeoutHandle = setTimeout(scheduleTimeout, delayMs);
};
scheduleTimeout();
const attachStreamCollector = (
stream: NodeJS.ReadableStream | null,
streamName: 'stdout' | 'stderr',
@ -209,6 +194,26 @@ export function createNodeNotebookCommandRunner(
}
);
const deadlineMs = performance.now() + timeoutMs;
const scheduleTimeout = (): void => {
if (settled || terminalFailure !== null) {
return;
}
const remainingMs = deadlineMs - performance.now();
if (remainingMs <= 0) {
triggerTerminalFailure(
createCodedError(
'ETIMEDOUT',
`Command '${commandName}' timed out after ${timeoutMs}ms.`
)
);
return;
}
const delayMs = Math.min(Math.ceil(remainingMs), MAX_TIMER_DELAY_MS);
timeoutHandle = setTimeout(scheduleTimeout, delayMs);
};
scheduleTimeout();
child.once('error', err => {
clearTimeoutHandle();
if (settled) {