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,56 @@
|
||||
import { describe, test, expect, mock } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import { createBackgroundTask } from "./create-background-task"
|
||||
|
||||
describe("createBackgroundTask", () => {
|
||||
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 tool = createBackgroundTask(mockManager)
|
||||
|
||||
const testContext = {
|
||||
sessionID: "test-session",
|
||||
messageID: "test-message",
|
||||
agent: "test-agent",
|
||||
abort: new AbortController().signal,
|
||||
}
|
||||
|
||||
const testArgs = {
|
||||
description: "Test background task",
|
||||
prompt: "Test prompt",
|
||||
agent: "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 tool.execute(testArgs, testContext)
|
||||
|
||||
//#then
|
||||
expect(result).toContain("Task entered error state")
|
||||
expect(result).toContain("test-task-id")
|
||||
})
|
||||
})
|
||||
@@ -79,7 +79,7 @@ export function createBackgroundTask(manager: BackgroundManager): ToolDefinition
|
||||
}
|
||||
await delay(WAIT_FOR_SESSION_INTERVAL_MS)
|
||||
const updated = manager.getTask(task.id)
|
||||
if (!updated || updated.status === "error") {
|
||||
if (!updated || updated.status === "error" || updated.status === "cancelled" || updated.status === "interrupt") {
|
||||
return `Task ${!updated ? "was deleted" : `entered error state`}\.\n\nTask ID: ${task.id}`
|
||||
}
|
||||
sessionId = updated?.sessionID
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, it, expect } from "bun:test"
|
||||
import { writeFileSync, unlinkSync } from "fs"
|
||||
import { join } from "path"
|
||||
import { tmpdir } from "os"
|
||||
import { loadJsonFile } from "./server-config-loader"
|
||||
|
||||
describe("loadJsonFile", () => {
|
||||
it("parses JSONC config files with comments correctly", () => {
|
||||
// given
|
||||
const testData = {
|
||||
lsp: {
|
||||
typescript: {
|
||||
command: ["tsserver"],
|
||||
extensions: [".ts", ".tsx"]
|
||||
}
|
||||
}
|
||||
}
|
||||
const jsoncContent = `{
|
||||
// LSP configuration for TypeScript
|
||||
"lsp": {
|
||||
"typescript": {
|
||||
"command": ["tsserver"],
|
||||
"extensions": [".ts", ".tsx"] // TypeScript extensions
|
||||
}
|
||||
}
|
||||
}`
|
||||
const tempPath = join(tmpdir(), "test-config.jsonc")
|
||||
writeFileSync(tempPath, jsoncContent, "utf-8")
|
||||
|
||||
// when
|
||||
const result = loadJsonFile<typeof testData>(tempPath)
|
||||
|
||||
// then
|
||||
expect(result).toEqual(testData)
|
||||
|
||||
// cleanup
|
||||
unlinkSync(tempPath)
|
||||
})
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { join } from "path"
|
||||
import { BUILTIN_SERVERS } from "./constants"
|
||||
import type { ResolvedServer } from "./types"
|
||||
import { getOpenCodeConfigDir } from "../../shared"
|
||||
import { parseJsonc } from "../../shared/jsonc-parser"
|
||||
|
||||
interface LspEntry {
|
||||
disabled?: boolean
|
||||
@@ -24,10 +25,10 @@ interface ServerWithSource extends ResolvedServer {
|
||||
source: ConfigSource
|
||||
}
|
||||
|
||||
function loadJsonFile<T>(path: string): T | null {
|
||||
export function loadJsonFile<T>(path: string): T | null {
|
||||
if (!existsSync(path)) return null
|
||||
try {
|
||||
return JSON.parse(readFileSync(path, "utf-8")) as T
|
||||
return parseJsonc(readFileSync(path, "utf-8")) as T
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user