Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/hosts/daemon-update-safety.test.mjs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 }));
Expand Down Expand Up @@ -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) => {
Expand Down
Loading