From 2da56b385b10cda952a9d63d1d8850a7991bcedb Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 18 Oct 2026 16:34:53 +0200 Subject: [PATCH 1/3] =?UTF-8?q?test:=20reproduce=20#673=20=E2=80=94=20a=20?= =?UTF-8?q?failed=20console-lane=20daemon=20start=20names=20no=20cause?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/console/daemon-start-failure.spec.ts | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 e2e/console/daemon-start-failure.spec.ts diff --git a/e2e/console/daemon-start-failure.spec.ts b/e2e/console/daemon-start-failure.spec.ts new file mode 100644 index 000000000..5dafbdf48 --- /dev/null +++ b/e2e/console/daemon-start-failure.spec.ts @@ -0,0 +1,63 @@ +import { createServer } from "node:net"; + +import { expect, startDaemon, test } from "./fixtures.js"; + +/** + * why: reproduces #673. A failed daemon start reports only what the CLI guessed at while it polled + * for a socket (`Timed out starting simlock daemon: connect ENOENT /daemon.sock`, or + * `Daemon connection closed` once the daemon answered and then tore itself down), never the reason + * it wrote to `daemon.log` -- and `startDaemon`'s catch deletes that log with the rest of the home, + * so the cause cannot be read afterwards either. The conflict below is the EADDRINUSE family of + * #553, staged by holding the HTTP port the daemon is about to bind. + */ + +function reported(error: unknown): string { + if (!(error instanceof Error)) return String(error); + return error.cause === undefined + ? error.message + : `${error.message}\ncause: ${String(error.cause)}`; +} + +async function hold(port: number): Promise<() => Promise> { + const holder = createServer(); + await new Promise((resolve, reject) => { + holder.once("error", (error: Error) => + reject(new Error(`premise: could not hold port ${String(port)}: ${error.message}`)), + ); + holder.listen(port, "127.0.0.1", () => resolve()); + }); + return () => new Promise((resolve) => holder.close(() => resolve())); +} + +test("a daemon start that cannot bind its HTTP port reports the port conflict", async () => { + const daemon = await startDaemon("worker"); + try { + // why: restarting on its own home and port first shows that same start is accepted, so the + // refused one below can only be about the port this test comes to hold. + await daemon.stop(); + await daemon.start(); + + await daemon.stop(); + const release = await hold(daemon.port); + let failure: unknown; + let started = false; + try { + await daemon.start(); + started = true; + } catch (error: unknown) { + failure = error; + } finally { + await release(); + } + + if (started) { + throw new Error( + `premise: the daemon bound port ${String(daemon.port)}, which this test holds`, + ); + } + expect(reported(failure)).toContain("EADDRINUSE"); + expect(reported(failure)).toContain(String(daemon.port)); + } finally { + await daemon.dispose(); + } +}); From 799352194acc895132689cdd84f89c32b176d26b Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 18 Oct 2026 17:04:01 +0200 Subject: [PATCH 2/3] fix(e2e/console): a failed daemon start reports the daemon's own cause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit why: #673 — the lane judged a start by its exit code alone, and the catch in startDaemon deleted the home with daemon.log, the only record of why the daemon gave up; every console test then failed with only what the CLI saw polling the socket. Read that log's tail at the failure point, before any caller disposes. Co-authored-by: Claude --- e2e/console/fixtures.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/e2e/console/fixtures.ts b/e2e/console/fixtures.ts index c6319be77..0ebcf8aa5 100644 --- a/e2e/console/fixtures.ts +++ b/e2e/console/fixtures.ts @@ -1,5 +1,5 @@ import { existsSync } from "node:fs"; -import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; @@ -107,7 +107,15 @@ export async function startDaemon( }; const start = async () => { const started = await cli(["daemon", "start"], env, { timeout: 30_000 }); - expect(started.code, started.stderr).toBe(0); + if (started.code === 0) return; + // why: a failed start reports only what the CLI saw while polling the socket, and `dispose` + // deletes this home with `daemon.log` — the only record of the cause the daemon itself wrote. + // Read the tail here, before any caller's catch reaches `dispose`, and fail with both. + const log = await readFile(join(home, "daemon.log"), "utf8").catch(() => ""); + const tail = log.split("\n").slice(-20).join("\n"); + throw new Error( + `daemon start failed (exit ${String(started.code)}): ${started.stderr}\n${tail}`, + ); }; const dispose = async () => { for (const handle of background) handle.kill("SIGTERM"); From 84b64b4286828be0ae51f3f5c16687e6c2ac40b2 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sun, 18 Oct 2026 17:38:24 +0200 Subject: [PATCH 3/3] fix(e2e/console): append the log tail to the expect message, as the triage proposes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit why: #673 review F1 — the Simplest fix reads the daemon.log tail into the message given to expect on the exit-code check, not a separate thrown error; same failure point, one assertion, nothing else changed. Co-authored-by: Claude --- e2e/console/fixtures.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/e2e/console/fixtures.ts b/e2e/console/fixtures.ts index 0ebcf8aa5..1cba00273 100644 --- a/e2e/console/fixtures.ts +++ b/e2e/console/fixtures.ts @@ -113,9 +113,7 @@ export async function startDaemon( // Read the tail here, before any caller's catch reaches `dispose`, and fail with both. const log = await readFile(join(home, "daemon.log"), "utf8").catch(() => ""); const tail = log.split("\n").slice(-20).join("\n"); - throw new Error( - `daemon start failed (exit ${String(started.code)}): ${started.stderr}\n${tail}`, - ); + expect(started.code, `daemon start failed: ${started.stderr}\n${tail}`).toBe(0); }; const dispose = async () => { for (const handle of background) handle.kill("SIGTERM");