fix(background): Wave 2 - fix interrupt status checks, display text, error recovery grace, LSP JSONC
- fix(background): include "interrupt" status in all terminal status checks (3 files) - fix(background): display "INTERRUPTED" instead of "CANCELLED" for interrupted tasks - fix(cli): add error recovery grace period in poll-for-completion - fix(lsp): use JSONC parser for config loading to support comments All changes verified with tests and typecheck.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { describe, test, expect, mock } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { executeBackgroundAgent } from "./background-agent-executor"
|
||||
|
||||
describe("executeBackgroundAgent", () => {
|
||||
const mockManager = {
|
||||
launch: mock(() => Promise.resolve({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})),
|
||||
getTask: mock(),
|
||||
} as unknown as BackgroundManager
|
||||
|
||||
const testContext = {
|
||||
sessionID: "test-session",
|
||||
messageID: "test-message",
|
||||
agent: "test-agent",
|
||||
abort: new AbortController().signal,
|
||||
}
|
||||
|
||||
const testArgs = {
|
||||
description: "Test background task",
|
||||
prompt: "Test prompt",
|
||||
subagent_type: "test-agent",
|
||||
}
|
||||
|
||||
test("detects interrupted task as failure", async () => {
|
||||
//#given
|
||||
mockManager.launch.mockResolvedValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})
|
||||
mockManager.getTask.mockReturnValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "interrupt",
|
||||
})
|
||||
|
||||
//#when
|
||||
const result = await executeBackgroundAgent(testArgs, testContext, mockManager)
|
||||
|
||||
//#then
|
||||
expect(result).toContain("Task failed to start")
|
||||
expect(result).toContain("interrupt")
|
||||
expect(result).toContain("test-task-id")
|
||||
})
|
||||
})
|
||||
@@ -48,7 +48,7 @@ export async function executeBackgroundAgent(
|
||||
return `Task aborted while waiting for session to start.\n\nTask ID: ${task.id}`
|
||||
}
|
||||
const updated = manager.getTask(task.id)
|
||||
if (updated?.status === "error" || updated?.status === "cancelled") {
|
||||
if (updated?.status === "error" || updated?.status === "cancelled" || updated?.status === "interrupt") {
|
||||
return `Task failed to start (status: ${updated.status}).\n\nTask ID: ${task.id}`
|
||||
}
|
||||
await new Promise<void>((resolve) => {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, test, expect, mock } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { executeBackground } from "./background-executor"
|
||||
|
||||
describe("executeBackground", () => {
|
||||
const mockManager = {
|
||||
launch: mock(() => Promise.resolve({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})),
|
||||
getTask: mock(),
|
||||
} as unknown as BackgroundManager
|
||||
|
||||
const testContext = {
|
||||
sessionID: "test-session",
|
||||
messageID: "test-message",
|
||||
agent: "test-agent",
|
||||
abort: new AbortController().signal,
|
||||
}
|
||||
|
||||
const testArgs = {
|
||||
description: "Test background task",
|
||||
prompt: "Test prompt",
|
||||
subagent_type: "test-agent",
|
||||
}
|
||||
|
||||
test("detects interrupted task as failure", async () => {
|
||||
//#given
|
||||
mockManager.launch.mockResolvedValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})
|
||||
mockManager.getTask.mockReturnValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "interrupt",
|
||||
})
|
||||
|
||||
//#when
|
||||
const result = await executeBackground(testArgs, testContext, mockManager)
|
||||
|
||||
//#then
|
||||
expect(result).toContain("Task failed to start")
|
||||
expect(result).toContain("interrupt")
|
||||
expect(result).toContain("test-task-id")
|
||||
})
|
||||
})
|
||||
@@ -52,7 +52,7 @@ export async function executeBackground(
|
||||
return `Task aborted while waiting for session to start.\n\nTask ID: ${task.id}`
|
||||
}
|
||||
const updated = manager.getTask(task.id)
|
||||
if (updated?.status === "error" || updated?.status === "cancelled") {
|
||||
if (updated?.status === "error" || updated?.status === "cancelled" || updated?.status === "interrupt") {
|
||||
return `Task failed to start (status: ${updated.status}).\n\nTask ID: ${task.id}`
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, WAIT_FOR_SESSION_INTERVAL_MS))
|
||||
|
||||
Reference in New Issue
Block a user