From 9578e4332e38d516c769697437c66670332e9fc5 Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:18:43 +0000 Subject: [PATCH 1/6] fix(dms): retry the run.json rename while Windows holds the file open --- packages/dms/e2e/run-state.mjs | 42 ++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/dms/e2e/run-state.mjs b/packages/dms/e2e/run-state.mjs index a0f0db22f..63a7090d2 100644 --- a/packages/dms/e2e/run-state.mjs +++ b/packages/dms/e2e/run-state.mjs @@ -8,7 +8,7 @@ import { rmSync, writeFileSync, } from "node:fs"; -import { tmpdir } from "node:os"; +import { platform, tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { describeFailure } from "./failure.mjs"; import { assertSameNamespaces } from "./identity.mjs"; @@ -26,6 +26,9 @@ import { } from "./json.mjs"; const RUN_FILE = "run.json"; +const REPLACE_RETRY_MS = 2_000; +const REPLACE_POLL_MS = 5; +const REPLACE_PAUSE = new Int32Array(new SharedArrayBuffer(4)); const ID_BYTES = 3; const TIMESTAMP_LENGTH = 15; @@ -275,7 +278,42 @@ export function saveRun(state) { writeFileSync(`${file}.next`, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600, }); - renameSync(`${file}.next`, file); + replaceFile(`${file}.next`, file); +} + +/** + * Renames `from` over `to`. Windows refuses with EPERM to replace a file + * another process holds open, as a service loading the run does for a + * moment, so there the rename is tried again until that read is done. + * + * @param {string} from The new file + * @param {string} to The file it replaces + * @throws When the rename fails for another reason, or Windows still refuses it after {@link REPLACE_RETRY_MS} + */ +function replaceFile(from, to) { + const deadline = Date.now() + REPLACE_RETRY_MS; + for (;;) { + try { + renameSync(from, to); + return; + } catch (error) { + if (!isHeldOpen(error) || Date.now() >= deadline) throw error; + Atomics.wait(REPLACE_PAUSE, 0, 0, REPLACE_POLL_MS); + } + } +} + +/** + * @param {unknown} error + * @returns {boolean} + */ +function isHeldOpen(error) { + return ( + platform() === "win32" && + error instanceof Error && + "code" in error && + error.code === "EPERM" + ); } /** From 7d73728825d18ba0f8525c5086cfffba825632c6 Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:18:44 +0000 Subject: [PATCH 2/6] test(dms): compare builder diagnostic files in the platform's path form --- .../dms/src/test/unit/builder/declaration-refresh.test.ts | 6 +++--- .../dms/src/test/unit/builder/environment-refresh.test.ts | 4 +++- .../dms/src/test/unit/builder/importer-typecheck.test.ts | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/dms/src/test/unit/builder/declaration-refresh.test.ts b/packages/dms/src/test/unit/builder/declaration-refresh.test.ts index 22705e886..dcd96483c 100644 --- a/packages/dms/src/test/unit/builder/declaration-refresh.test.ts +++ b/packages/dms/src/test/unit/builder/declaration-refresh.test.ts @@ -84,9 +84,9 @@ describe("[unit] a declaration file edited between two builder operations", () = !result.ok && result.error.code === "typecheck_failed" ? result.error.diagnostics : []; - expect(diagnostics.map((diagnostic) => diagnostic.file)).to.deep.equal([ - path.join(app.root, "src", "labels.ts"), - ]); + expect( + diagnostics.map((diagnostic) => path.normalize(diagnostic.file)), + ).to.deep.equal([path.join(app.root, "src", "labels.ts")]); }); /** diff --git a/packages/dms/src/test/unit/builder/environment-refresh.test.ts b/packages/dms/src/test/unit/builder/environment-refresh.test.ts index 526691410..e8d9214a0 100644 --- a/packages/dms/src/test/unit/builder/environment-refresh.test.ts +++ b/packages/dms/src/test/unit/builder/environment-refresh.test.ts @@ -96,7 +96,9 @@ async function addBanner() { function failedFiles(result: Awaited>): string[] { return !result.ok && result.error.code === "typecheck_failed" - ? result.error.diagnostics.map((diagnostic) => diagnostic.file) + ? result.error.diagnostics.map((diagnostic) => + path.normalize(diagnostic.file), + ) : []; } diff --git a/packages/dms/src/test/unit/builder/importer-typecheck.test.ts b/packages/dms/src/test/unit/builder/importer-typecheck.test.ts index 9067c1a7c..fb778d91d 100644 --- a/packages/dms/src/test/unit/builder/importer-typecheck.test.ts +++ b/packages/dms/src/test/unit/builder/importer-typecheck.test.ts @@ -59,7 +59,9 @@ function installTone(tone: string): void { function failedFiles(result: OpResult): string[] { return !result.ok && result.error.code === "typecheck_failed" - ? result.error.diagnostics.map((diagnostic) => diagnostic.file) + ? result.error.diagnostics.map((diagnostic) => + path.normalize(diagnostic.file), + ) : []; } From 4ba1d49dce9da7946d2bf468750edcdd56eb2af9 Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:18:48 +0000 Subject: [PATCH 3/6] test(dms): expand the 8.3 short name of the e2e suite test's checkout --- packages/dms/e2e/suite.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/dms/e2e/suite.test.mjs b/packages/dms/e2e/suite.test.mjs index cf053afdf..482700035 100644 --- a/packages/dms/e2e/suite.test.mjs +++ b/packages/dms/e2e/suite.test.mjs @@ -27,7 +27,9 @@ const CONFIG = `export default ${JSON.stringify({ * @returns {string} The checkout root */ function twoSuiteCheckout(t) { - const root = realpathSync(mkdtempSync(join(tmpdir(), "dms-e2e-suite-"))); + const root = realpathSync.native( + mkdtempSync(join(tmpdir(), "dms-e2e-suite-")), + ); const cwd = process.cwd(); const recorded = process.env.DMS_E2E_SUITE; const prebuilt = process.env.DMS_E2E_PREBUILT; From b2671f1d9733ea5dd43f299b5c74b01a3b010979 Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:18:50 +0000 Subject: [PATCH 4/6] test(dms): skip the mail sink listener check where /proc is missing --- packages/dms/e2e/services.test.mjs | 47 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/dms/e2e/services.test.mjs b/packages/dms/e2e/services.test.mjs index e008766ad..875158933 100644 --- a/packages/dms/e2e/services.test.mjs +++ b/packages/dms/e2e/services.test.mjs @@ -6,6 +6,7 @@ import { join } from "node:path"; import test from "node:test"; import { pathToFileURL } from "node:url"; import { newRun } from "./helpers/fake-run.mjs"; +import { hasProc } from "./identity.mjs"; import { listenersOf, restartablePort } from "./processes.mjs"; import { readRun, saveRun } from "./run-state.mjs"; @@ -24,28 +25,34 @@ function kitWithoutBin(t) { return kit; } -await test("a copy of the kit with no bin/ beside it starts a run's mail sink (catches a stack that runs its services through a script outside the kit)", async (t) => { - const kit = kitWithoutBin(t); - const state = await newRun(t); - state.smtpPort = await restartablePort(); - saveRun(state); - const started = spawnSync( - process.execPath, - [ - "--input-type=module", - "--eval", - `const { ensureMail } = await import(${JSON.stringify(pathToFileURL(join(kit, "stack.mjs")).href)}); +await test( + "a copy of the kit with no bin/ beside it starts a run's mail sink (catches a stack that runs its services through a script outside the kit)", + { + skip: !hasProc() && "the process that listens on a port is read from /proc", + }, + async (t) => { + const kit = kitWithoutBin(t); + const state = await newRun(t); + state.smtpPort = await restartablePort(); + saveRun(state); + const started = spawnSync( + process.execPath, + [ + "--input-type=module", + "--eval", + `const { ensureMail } = await import(${JSON.stringify(pathToFileURL(join(kit, "stack.mjs")).href)}); const { loadRun } = await import(${JSON.stringify(pathToFileURL(join(kit, "run-state.mjs")).href)}); await ensureMail(loadRun(${JSON.stringify(state.dir)}));`, - ], - { encoding: "utf8" }, - ); - assert.equal(started.status, 0, started.stderr); - const mail = readRun(state.dir).processes.find( - (entry) => entry.name === "mail", - ); - assert.deepEqual(listenersOf(state.smtpPort), [mail?.pid]); -}); + ], + { encoding: "utf8" }, + ); + assert.equal(started.status, 0, started.stderr); + const mail = readRun(state.dir).processes.find( + (entry) => entry.name === "mail", + ); + assert.deepEqual(listenersOf(state.smtpPort), [mail?.pid]); + }, +); await test("the service entry refuses a name it does not serve and names those it does (catches an entry that exits 0 on a typo, leaving the stack to wait on a port nothing listens on)", () => { const entry = spawnSync( From aabd3eae50db7d3b04b8ae5c070d7ae69688ba97 Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:18:51 +0000 Subject: [PATCH 5/6] test(dms): check a stopped mongod with isRunning, which a zombie fails --- packages/dms/e2e/mongo-server.test.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dms/e2e/mongo-server.test.mjs b/packages/dms/e2e/mongo-server.test.mjs index 86cbf9d1f..d310d4d0a 100644 --- a/packages/dms/e2e/mongo-server.test.mjs +++ b/packages/dms/e2e/mongo-server.test.mjs @@ -12,7 +12,7 @@ import test from "node:test"; import { fileURLToPath } from "node:url"; import { MongoClient } from "mongodb"; import { pidIn } from "./helpers/pids.mjs"; -import { isAlive } from "./identity.mjs"; +import { isRunning } from "./identity.mjs"; import { mongodBinary, startMongod } from "./mongo.mjs"; import { stopRecorded } from "./processes.mjs"; @@ -107,7 +107,7 @@ await test("a mongod that cannot join the replica set is stopped", async (t) => await assert.rejects(startMongod(paths, [PACKAGE_ROOT]), { message: "This node was not started with replication enabled.", }); - assert.equal(isAlive(pidIn(spawned)), false); + assert.equal(isRunning(pidIn(spawned)), false); }); await test("a mongod restarted on its port and data folder serves a change stream again", async (t) => { From 82d96d253915c19c1415bd255c1ed8b72234208e Mon Sep 17 00:00:00 2001 From: Antony Rizzitelli Date: Fri, 20 Nov 2026 22:22:07 +0000 Subject: [PATCH 6/6] test(dms): check the mail sink's listener only where /proc tells it --- packages/dms/e2e/services.test.mjs | 47 +++++++++++++----------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/packages/dms/e2e/services.test.mjs b/packages/dms/e2e/services.test.mjs index 875158933..909fa0ac0 100644 --- a/packages/dms/e2e/services.test.mjs +++ b/packages/dms/e2e/services.test.mjs @@ -25,34 +25,29 @@ function kitWithoutBin(t) { return kit; } -await test( - "a copy of the kit with no bin/ beside it starts a run's mail sink (catches a stack that runs its services through a script outside the kit)", - { - skip: !hasProc() && "the process that listens on a port is read from /proc", - }, - async (t) => { - const kit = kitWithoutBin(t); - const state = await newRun(t); - state.smtpPort = await restartablePort(); - saveRun(state); - const started = spawnSync( - process.execPath, - [ - "--input-type=module", - "--eval", - `const { ensureMail } = await import(${JSON.stringify(pathToFileURL(join(kit, "stack.mjs")).href)}); +await test("a copy of the kit with no bin/ beside it starts a run's mail sink (catches a stack that runs its services through a script outside the kit)", async (t) => { + const kit = kitWithoutBin(t); + const state = await newRun(t); + state.smtpPort = await restartablePort(); + saveRun(state); + const started = spawnSync( + process.execPath, + [ + "--input-type=module", + "--eval", + `const { ensureMail } = await import(${JSON.stringify(pathToFileURL(join(kit, "stack.mjs")).href)}); const { loadRun } = await import(${JSON.stringify(pathToFileURL(join(kit, "run-state.mjs")).href)}); await ensureMail(loadRun(${JSON.stringify(state.dir)}));`, - ], - { encoding: "utf8" }, - ); - assert.equal(started.status, 0, started.stderr); - const mail = readRun(state.dir).processes.find( - (entry) => entry.name === "mail", - ); - assert.deepEqual(listenersOf(state.smtpPort), [mail?.pid]); - }, -); + ], + { encoding: "utf8" }, + ); + assert.equal(started.status, 0, started.stderr); + const mail = readRun(state.dir).processes.find( + (entry) => entry.name === "mail", + ); + assert.ok(mail, "the run records no mail sink"); + if (hasProc()) assert.deepEqual(listenersOf(state.smtpPort), [mail.pid]); +}); await test("the service entry refuses a name it does not serve and names those it does (catches an entry that exits 0 on a typo, leaving the stack to wait on a port nothing listens on)", () => { const entry = spawnSync(