import test from "node:test"; import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { mkdtemp, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; // Run with: // pnpm -C editor exec tsx --test app/instrumentation.test.ts // // REVIEW-1 F3 (captions lane): on a Node without zstd the editor REFUSES TO // START — register() says which Node it needs and exits — instead of running // with every stored caption and chat unreadable. The check is the first thing // register() does in the Node runtime, before any runner is armed. const EDITOR = path.dirname(path.dirname(fileURLToPath(import.meta.url))); test("register() on a Node without zstd: the editor refuses to start, naming the Node it needs", async (t) => { const own = await mkdtemp(path.join(os.tmpdir(), "editor-no-zstd-")); t.after(() => rm(own, { recursive: true, force: true })); const preload = path.join(own, "no-zstd.mjs"); await writeFile(preload, 'import zlib from "node:zlib";\nfor (const k of ["zstdDecompress", "createZstdCompress", "createZstdDecompress"]) delete zlib[k];\n'); const tsx = path.join(EDITOR, "..", "node_modules", ".bin", "tsx"); const script = `import(${JSON.stringify(path.join(EDITOR, "instrumentation.ts"))}).then((m) => m.register()).then(() => console.log("BOOTED"));`; const r = spawnSync(tsx, ["-e", script], { cwd: EDITOR, encoding: "utf8", timeout: 60_000, env: { ...process.env, NODE_OPTIONS: `--import=${preload}`, NEXT_RUNTIME: "nodejs", TRANSCRIPTS_DIR: own, SETTINGS_FILE: path.join(own, "s.json") }, }); assert.equal(r.status, 1, r.stdout + r.stderr); assert.doesNotMatch(r.stdout, /BOOTED/); assert.match(r.stderr, /editor refuses to start: stored text .*needs node:zlib zstd — Node >= 22\.15/); });