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.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user