Give never-updated background tasks a longer default window and keep the default-threshold regression coverage aligned with that behavior. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
declare const require: (name: string) => any
|
|
const { describe, expect, test, mock } = require("bun:test")
|
|
|
|
import { DEFAULT_MESSAGE_STALENESS_TIMEOUT_MS } from "./constants"
|
|
import { checkAndInterruptStaleTasks } from "./task-poller"
|
|
import type { BackgroundTask } from "./types"
|
|
|
|
function createRunningTask(startedAt: Date): BackgroundTask {
|
|
return {
|
|
id: "task-1",
|
|
sessionID: "ses-1",
|
|
parentSessionID: "parent-ses-1",
|
|
parentMessageID: "msg-1",
|
|
description: "test",
|
|
prompt: "test",
|
|
agent: "explore",
|
|
status: "running",
|
|
startedAt,
|
|
progress: undefined,
|
|
}
|
|
}
|
|
|
|
describe("DEFAULT_MESSAGE_STALENESS_TIMEOUT_MS", () => {
|
|
test("uses a 30 minute default", () => {
|
|
// #given
|
|
const expectedTimeout = 30 * 60 * 1000
|
|
|
|
// #when
|
|
const timeout = DEFAULT_MESSAGE_STALENESS_TIMEOUT_MS
|
|
|
|
// #then
|
|
expect(timeout).toBe(expectedTimeout)
|
|
})
|
|
|
|
test("does not interrupt a never-updated task after 15 minutes when config is omitted", async () => {
|
|
// #given
|
|
const task = createRunningTask(new Date(Date.now() - 15 * 60 * 1000))
|
|
const client = {
|
|
session: {
|
|
abort: mock(() => Promise.resolve()),
|
|
},
|
|
}
|
|
const concurrencyManager = {
|
|
release: mock(() => {}),
|
|
}
|
|
const notifyParentSession = mock(() => Promise.resolve())
|
|
|
|
// #when
|
|
await checkAndInterruptStaleTasks({
|
|
tasks: [task],
|
|
client: client as never,
|
|
config: undefined,
|
|
concurrencyManager: concurrencyManager as never,
|
|
notifyParentSession,
|
|
})
|
|
|
|
// #then
|
|
expect(task.status).toBe("running")
|
|
})
|
|
})
|