feat: migrate tool callers to SDK message finders on SQLite backend
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
/// <reference types="bun-types" />
|
||||
import { describe, test, expect, mock } from "bun:test"
|
||||
import type { BackgroundManager } from "../../features/background-agent"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { executeBackgroundAgent } from "./background-agent-executor"
|
||||
|
||||
describe("executeBackgroundAgent", () => {
|
||||
const launchMock = mock(() => Promise.resolve({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
}))
|
||||
const getTaskMock = mock()
|
||||
|
||||
const mockManager = {
|
||||
launch: mock(() => Promise.resolve({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})),
|
||||
getTask: mock(),
|
||||
launch: launchMock,
|
||||
getTask: getTaskMock,
|
||||
} as unknown as BackgroundManager
|
||||
|
||||
const testContext = {
|
||||
@@ -25,18 +30,25 @@ describe("executeBackgroundAgent", () => {
|
||||
description: "Test background task",
|
||||
prompt: "Test prompt",
|
||||
subagent_type: "test-agent",
|
||||
run_in_background: true,
|
||||
}
|
||||
|
||||
const mockClient = {
|
||||
session: {
|
||||
messages: mock(() => Promise.resolve({ data: [] })),
|
||||
},
|
||||
} as unknown as PluginInput["client"]
|
||||
|
||||
test("detects interrupted task as failure", async () => {
|
||||
//#given
|
||||
mockManager.launch.mockResolvedValueOnce({
|
||||
launchMock.mockResolvedValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
agent: "test-agent",
|
||||
status: "pending",
|
||||
})
|
||||
mockManager.getTask.mockReturnValueOnce({
|
||||
getTaskMock.mockReturnValueOnce({
|
||||
id: "test-task-id",
|
||||
sessionID: null,
|
||||
description: "Test task",
|
||||
@@ -45,11 +57,11 @@ describe("executeBackgroundAgent", () => {
|
||||
})
|
||||
|
||||
//#when
|
||||
const result = await executeBackgroundAgent(testArgs, testContext, mockManager)
|
||||
const result = await executeBackgroundAgent(testArgs, testContext, mockManager, mockClient)
|
||||
|
||||
//#then
|
||||
expect(result).toContain("Task failed to start")
|
||||
expect(result).toContain("interrupt")
|
||||
expect(result).toContain("test-task-id")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user