From cabe0b16ad8a7a61b6d7e9f329b230e59325d298 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 15:32:20 +0100 Subject: [PATCH 1/2] =?UTF-8?q?test:=20reproduce=20#1663=20=E2=80=94=20the?= =?UTF-8?q?=20daemon=20launch=20fails=20when=20the=20folder=20holding=20SI?= =?UTF-8?q?MLOCK=5FHOME=20refuses=20mkdir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ports/daemon-launcher.test.ts | 38 ++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/ports/daemon-launcher.test.ts b/src/ports/daemon-launcher.test.ts index c112ca2b0..984aebac0 100644 --- a/src/ports/daemon-launcher.test.ts +++ b/src/ports/daemon-launcher.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { spawn } from "node:child_process"; import { fileURLToPath } from "node:url"; import { chmod, mkdir, mkdtemp, readFile, readdir, rm, stat, writeFile } from "node:fs/promises"; @@ -9,6 +9,13 @@ import { FakeDaemonLauncher, NodeDaemonLauncher, startErrorFrom } from "./daemon import { launcherFor } from "./service-launcher.js"; import { FakeServiceManager, type ServiceState } from "./service-manager.js"; +// why: lets one test refuse a mkdir of one existing folder, as Windows does for a drive root; every +// other call goes to the real `mkdir`. +vi.mock("node:fs/promises", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, mkdir: vi.fn(actual.mkdir) }; +}); + describe("NodeDaemonLauncher", () => { it("rejects asynchronous spawn failures", async () => { const directory = await mkdtemp(join(tmpdir(), "simlock-launcher-")); @@ -103,6 +110,35 @@ describe("NodeDaemonLauncher", () => { } }); + it("starts the daemon when the folder holding SIMLOCK_HOME exists but refuses mkdir", async () => { + // why: #1663: on Windows `mkdir('D:\\')`, recursive or not, rejects EPERM though the root exists + // (Node 22.23.5, Windows 11). The temporary folder stands in for the drive root. + const driveRoot = await mkdtemp(join(tmpdir(), "simlock-launcher-")); + const home = join(driveRoot, "simlock"); + const logPath = join(home, "daemon.log"); + const actual = await vi.importActual("node:fs/promises"); + vi.mocked(mkdir).mockImplementation(async (path, options) => { + if (path === driveRoot) + throw Object.assign(new Error(`EPERM: operation not permitted, mkdir '${driveRoot}'`), { + code: "EPERM", + }); + return actual.mkdir(path, options); + }); + try { + const launch = new NodeDaemonLauncher({ + args: ["-e", "console.log('out')"], + command: process.execPath, + logPath, + simlockHome: home, + }).launch(); + await expect(launch).resolves.toHaveProperty("exited"); + await expect.poll(async () => (await readFile(logPath, "utf8")).trim()).toBe("out"); + } finally { + vi.mocked(mkdir).mockImplementation(actual.mkdir); + await rm(driveRoot, { force: true, recursive: true }); + } + }); + it("combines stdout and stderr in an append-only log", async () => { const directory = await mkdtemp(join(tmpdir(), "simlock-launcher-")); const logPath = join(directory, "daemon.log"); From 81aac6ae896989dd3d57027eecefa280894ed1d0 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 17 Nov 2026 15:35:42 +0100 Subject: [PATCH 2/2] fix(ports): the daemon launch leaves an existing parent of SIMLOCK_HOME alone (#1663) --- src/ports/daemon-launcher.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ports/daemon-launcher.ts b/src/ports/daemon-launcher.ts index 95814ea41..ce502092c 100644 --- a/src/ports/daemon-launcher.ts +++ b/src/ports/daemon-launcher.ts @@ -91,7 +91,16 @@ export interface NodeDaemonLauncherOptions { * import), their parents left to the default and an existing one left as it is. `chmod` because the umask can only take bits from `mkdir`'s mode. */ async function createDataDirectory(directory: string): Promise { - await mkdir(dirname(directory), { recursive: true }); + const parent = dirname(directory); + // why: Windows rejects even a recursive mkdir of a drive root (`D:\`) with EPERM though it + // exists, so a parent that is already a directory is left alone. + if ( + !(await stat(parent).then( + (info) => info.isDirectory(), + () => false, + )) + ) + await mkdir(parent, { recursive: true }); try { await mkdir(directory, { mode: 0o700 }); } catch (error: unknown) {