Previously, pollRunningTasks() and checkAndInterruptStaleTasks() treated
any non-"idle" session status as "still running", which caused tasks with
terminal statuses like "interrupted" to be skipped indefinitely — both
for completion detection AND stale timeout. This made the parent session
hang forever waiting for an ALL COMPLETE notification that never came.
Extract isActiveSessionStatus() and isTerminalSessionStatus() that
classify session statuses explicitly. Only known active statuses
("busy", "retry", "running") protect tasks from completion/stale checks.
Known terminal statuses ("interrupted") trigger immediate completion.
Unknown statuses fall through to the standard idle/gone path with output
validation as a conservative default.
Introduced by: a0c93816 (2026-02-14), dc370f7f (2026-03-08)
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { describe, test, expect, mock } from "bun:test"
|
|
import { isActiveSessionStatus, isTerminalSessionStatus } from "./session-status-classifier"
|
|
|
|
const mockLog = mock()
|
|
mock.module("../../shared", () => ({ log: mockLog }))
|
|
|
|
describe("isActiveSessionStatus", () => {
|
|
describe("#given a known active session status", () => {
|
|
test('#when type is "busy" #then returns true', () => {
|
|
expect(isActiveSessionStatus("busy")).toBe(true)
|
|
})
|
|
|
|
test('#when type is "retry" #then returns true', () => {
|
|
expect(isActiveSessionStatus("retry")).toBe(true)
|
|
})
|
|
|
|
test('#when type is "running" #then returns true', () => {
|
|
expect(isActiveSessionStatus("running")).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe("#given a known terminal session status", () => {
|
|
test('#when type is "idle" #then returns false', () => {
|
|
expect(isActiveSessionStatus("idle")).toBe(false)
|
|
})
|
|
|
|
test('#when type is "interrupted" #then returns false and does not log', () => {
|
|
mockLog.mockClear()
|
|
expect(isActiveSessionStatus("interrupted")).toBe(false)
|
|
expect(mockLog).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe("#given an unknown session status", () => {
|
|
test('#when type is an arbitrary unknown string #then returns false and logs warning', () => {
|
|
mockLog.mockClear()
|
|
expect(isActiveSessionStatus("some-unknown-status")).toBe(false)
|
|
expect(mockLog).toHaveBeenCalledWith(
|
|
"[background-agent] Unknown session status type encountered:",
|
|
"some-unknown-status",
|
|
)
|
|
})
|
|
|
|
test('#when type is empty string #then returns false', () => {
|
|
expect(isActiveSessionStatus("")).toBe(false)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("isTerminalSessionStatus", () => {
|
|
test('#when type is "interrupted" #then returns true', () => {
|
|
expect(isTerminalSessionStatus("interrupted")).toBe(true)
|
|
})
|
|
|
|
test('#when type is "idle" #then returns false (idle is handled separately)', () => {
|
|
expect(isTerminalSessionStatus("idle")).toBe(false)
|
|
})
|
|
|
|
test('#when type is "busy" #then returns false', () => {
|
|
expect(isTerminalSessionStatus("busy")).toBe(false)
|
|
})
|
|
|
|
test('#when type is an unknown string #then returns false', () => {
|
|
expect(isTerminalSessionStatus("some-unknown")).toBe(false)
|
|
})
|
|
})
|