From 5c933ea8fd3ef6822c4bd0f579209fbfffa3ae8a Mon Sep 17 00:00:00 2001 From: K <61059522+kahme247@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:22:28 +0200 Subject: [PATCH] test(hosts): fix daemon-update-safety timeout flake blocking #569 --- lib/hosts/daemon-update-safety.test.mjs | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/hosts/daemon-update-safety.test.mjs b/lib/hosts/daemon-update-safety.test.mjs index c9e1800e0..0b2fe05dd 100644 --- a/lib/hosts/daemon-update-safety.test.mjs +++ b/lib/hosts/daemon-update-safety.test.mjs @@ -1,5 +1,5 @@ import assert from "node:assert/strict"; -import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, realpathSync, rmSync } from "node:fs"; +import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, realpathSync, rmSync, chmodSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import test, { after } from "node:test"; @@ -78,6 +78,9 @@ test("daemon refuses new sessions while a persisted daemon update is running", a function updatableInstall(t) { const install = join(scratch, "node_modules", "@kahme247", "ompweb"); mkdirSync(join(install, "bin"), { recursive: true }); + // The host refuses a group- or world-writable install directory, and mkdir honours the ambient umask: pin the + // fixture's mode so the update check is not decided by whatever umask the runner happens to use. + chmodSync(install, 0o755); const launcher = join(install, "bin", "omp-web-host.js"); writeFileSync(launcher, ""); writeFileSync(join(install, "package.json"), JSON.stringify({ name: "@kahme247/ompweb", version: packageJson.version })); @@ -107,15 +110,21 @@ test("a session still starting also blocks the update check, and stops blocking const realSpawn = localHost.spawnRpc; const gate = Promise.withResolvers(); localHost.spawnRpc = async () => { await gate.promise; throw new Error("spawn failed"); }; - t.after(() => { localHost.spawnRpc = realSpawn; }); - const starting = spawn("starting"); - const held = await checkUpdates(); - assert.equal(held.result.ompweb.canUpdate, false, "a spawn not yet registered as a channel must still count"); - assert.match(held.result.ompweb.blockedReason, /sessions|subagents/i); - gate.resolve(); - assert.equal((await starting).ok, false); - // Only the session reason must go: a suite running inside a systemd service is still blocked by that service. - assert.doesNotMatch((await checkUpdates()).result.ompweb.blockedReason ?? "", /sessions|subagents/i); + try { + const starting = spawn("starting"); + const held = await checkUpdates(); + assert.equal(held.result.ompweb.canUpdate, false, "a spawn not yet registered as a channel must still count"); + assert.match(held.result.ompweb.blockedReason, /sessions|subagents/i); + gate.resolve(); + assert.equal((await starting).ok, false); + // Only the session reason must go: a suite running inside a systemd service is still blocked by that service. + assert.doesNotMatch((await checkUpdates()).result.ompweb.blockedReason ?? "", /sessions|subagents/i); + } finally { + // A failed assertion must not leave the gate shut: the daemon's pending spawn would hang its stop, and the + // patched spawnRpc would leak into every later test (its open never answered, a 30s timeout each). + gate.resolve(); + localHost.spawnRpc = realSpawn; + } }); test("a daemon welcome writes the real updater health acknowledgement", async (t) => {