From f1e7d4245abeb9f38682a78d19687626d51088c7 Mon Sep 17 00:00:00 2001 From: nntrivi2001 Date: Wed, 12 Aug 2026 11:08:21 +0700 Subject: [PATCH] test(lanes): add test for stale run_id clearing during healing Add missing test coverage for healRunId's core behavior: that a STALE run_id (tmux session gone) gets CLEARED to null with status: idle when read via GET. The existing test only verified the LIVE case (session still running). This test proves the release-on-gone path, simulating a session death via tmux mock. --- server/__tests__/lane-lifecycle.test.js | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/server/__tests__/lane-lifecycle.test.js b/server/__tests__/lane-lifecycle.test.js index d2d0053..d4403c2 100644 --- a/server/__tests__/lane-lifecycle.test.js +++ b/server/__tests__/lane-lifecycle.test.js @@ -1163,4 +1163,38 @@ describe("lane ensure, start mode, lane_id and releasing a finished run", () => tmux.__reset(); } }); + + it("clears a stale run_id and sets status to idle when the tmux session is gone", async () => { + const tmux = require("../lib/tmux"); + const lane = await adoptedLane("release-stale-run"); + + // Start a run for this lane. + const started = await request("POST", `/api/lanes/${lane.id}/start`, { prompt: "test" }); + assert.equal(started.status, 200, JSON.stringify(started.body)); + const runId = started.body.lane.run_id; + assert.equal(typeof runId, "string"); + assert.equal(started.body.lane.status, "running"); + + // Mock tmux so the session appears to be gone (has-session fails with status 1). + tmux.__setExecImpl((args) => { + if (args[0] === "has-session" && args[1] === "-t" && args[2] === runId) { + const e = new Error("no such session"); + e.status = 1; + throw e; + } + if (args[0] === "list-sessions") { + return ""; + } + return ""; + }); + + try { + // Read the lane — it should clear the run_id and set status to idle. + const after = (await request("GET", `/api/lanes/${lane.id}`)).body.lane; + assert.equal(after.run_id, null, "run_id should be cleared for stale session"); + assert.equal(after.status, "idle", "status should be idle after run is gone"); + } finally { + tmux.__reset(); + } + }); });