test: add promptAsync mocks to all test files for promptAsync migration

This commit is contained in:
Peïo Thibault 2026-02-07 14:32:47 +01:00
parent fa77be0daf
commit 414cecd7df
4 changed files with 1168 additions and 1067 deletions

View File

@ -171,6 +171,7 @@ function createBackgroundManager(): BackgroundManager {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -880,12 +881,14 @@ describe("BackgroundManager.notifyParentSession - aborted parent", () => {
test("should skip notification when parent session is aborted", async () => { test("should skip notification when parent session is aborted", async () => {
//#given //#given
let promptCalled = false let promptCalled = false
const client = { const promptMock = async () => {
session: {
prompt: async () => {
promptCalled = true promptCalled = true
return {} return {}
}, }
const client = {
session: {
prompt: promptMock,
promptAsync: promptMock,
abort: async () => ({}), abort: async () => ({}),
messages: async () => { messages: async () => {
const error = new Error("User aborted") const error = new Error("User aborted")
@ -922,14 +925,16 @@ describe("BackgroundManager.notifyParentSession - aborted parent", () => {
test("should swallow aborted error from prompt", async () => { test("should swallow aborted error from prompt", async () => {
//#given //#given
let promptCalled = false let promptCalled = false
const client = { const promptMock = async () => {
session: {
prompt: async () => {
promptCalled = true promptCalled = true
const error = new Error("User aborted") const error = new Error("User aborted")
error.name = "MessageAbortedError" error.name = "MessageAbortedError"
throw error throw error
}, }
const client = {
session: {
prompt: promptMock,
promptAsync: promptMock,
abort: async () => ({}), abort: async () => ({}),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
@ -1060,6 +1065,7 @@ describe("BackgroundManager.tryCompleteTask", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async (args: { path: { id: string } }) => { abort: async (args: { path: { id: string } }) => {
abortedSessionIDs.push(args.path.id) abortedSessionIDs.push(args.path.id)
return {} return {}
@ -1202,12 +1208,14 @@ describe("BackgroundManager.resume model persistence", () => {
beforeEach(() => { beforeEach(() => {
// given // given
promptCalls = [] promptCalls = []
const client = { const promptMock = async (args: { path: { id: string }; body: Record<string, unknown> }) => {
session: {
prompt: async (args: { path: { id: string }; body: Record<string, unknown> }) => {
promptCalls.push(args) promptCalls.push(args)
return {} return {}
}, }
const client = {
session: {
prompt: promptMock,
promptAsync: promptMock,
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -1317,6 +1325,7 @@ describe("BackgroundManager - Non-blocking Queue Integration", () => {
create: async () => ({ data: { id: `ses_${crypto.randomUUID()}` } }), create: async () => ({ data: { id: `ses_${crypto.randomUUID()}` } }),
get: async () => ({ data: { directory: "/test/dir" } }), get: async () => ({ data: { directory: "/test/dir" } }),
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
todo: async () => ({ data: [] }), todo: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
@ -1875,6 +1884,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -1907,6 +1917,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -1939,6 +1950,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -1975,6 +1987,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2009,6 +2022,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2044,6 +2058,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2095,6 +2110,7 @@ describe("BackgroundManager.checkAndInterruptStaleTasks", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2132,6 +2148,7 @@ describe("BackgroundManager.shutdown session abort", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async (args: { path: { id: string } }) => { abort: async (args: { path: { id: string } }) => {
abortedSessionIDs.push(args.path.id) abortedSessionIDs.push(args.path.id)
return {} return {}
@ -2181,6 +2198,7 @@ describe("BackgroundManager.shutdown session abort", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async (args: { path: { id: string } }) => { abort: async (args: { path: { id: string } }) => {
abortedSessionIDs.push(args.path.id) abortedSessionIDs.push(args.path.id)
return {} return {}
@ -2241,6 +2259,7 @@ describe("BackgroundManager.shutdown session abort", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2266,6 +2285,7 @@ describe("BackgroundManager.shutdown session abort", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
}, },
} }
@ -2512,6 +2532,7 @@ describe("BackgroundManager.handleEvent - early session.idle deferral", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
messages: async (args: { path: { id: string } }) => { messages: async (args: { path: { id: string } }) => {
messagesCalls.push(args.path.id) messagesCalls.push(args.path.id)
@ -2571,6 +2592,7 @@ describe("BackgroundManager.handleEvent - early session.idle deferral", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
messages: async () => ({ messages: async () => ({
data: [ data: [
@ -2621,6 +2643,7 @@ describe("BackgroundManager.handleEvent - early session.idle deferral", () => {
const client = { const client = {
session: { session: {
prompt: async () => ({}), prompt: async () => ({}),
promptAsync: async () => ({}),
abort: async () => ({}), abort: async () => ({}),
messages: async () => { messages: async () => {
messagesCallCount += 1 messagesCallCount += 1

View File

@ -34,6 +34,7 @@ describe("atlas hook", () => {
client: { client: {
session: { session: {
prompt: promptMock, prompt: promptMock,
promptAsync: promptMock,
}, },
}, },
_promptMock: promptMock, _promptMock: promptMock,

View File

@ -229,6 +229,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -281,6 +282,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -326,6 +328,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -391,6 +394,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -679,6 +683,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -743,6 +748,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -787,6 +793,11 @@ describe("sisyphus-task", () => {
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
@ -794,10 +805,8 @@ describe("sisyphus-task", () => {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_sync_default_variant" } }), create: async () => ({ data: { id: "ses_sync_default_variant" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "done" }] }]
}), }),
@ -851,6 +860,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -891,6 +901,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -927,16 +938,20 @@ describe("sisyphus-task", () => {
let promptBody: any let promptBody: any
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }]
}), }),
@ -995,6 +1010,7 @@ describe("sisyphus-task", () => {
const mockClient = { const mockClient = {
session: { session: {
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ {
@ -1058,6 +1074,7 @@ describe("sisyphus-task", () => {
const mockClient = { const mockClient = {
session: { session: {
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [], data: [],
}), }),
@ -1104,13 +1121,16 @@ describe("sisyphus-task", () => {
launch: async () => ({}), launch: async () => ({}),
} }
const promptMock = async () => {
throw new Error("JSON Parse error: Unexpected EOF")
}
const mockClient = { const mockClient = {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_sync_error_test" } }), create: async () => ({ data: { id: "ses_sync_error_test" } }),
prompt: async () => { prompt: promptMock,
throw new Error("JSON Parse error: Unexpected EOF") promptAsync: promptMock,
},
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -1164,6 +1184,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_sync_success" } }), create: async () => ({ data: { id: "ses_sync_success" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ {
@ -1217,13 +1238,16 @@ describe("sisyphus-task", () => {
launch: async () => ({}), launch: async () => ({}),
} }
const promptMock = async () => {
throw new Error("Cannot read property 'name' of undefined agent.name")
}
const mockClient = { const mockClient = {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_agent_notfound" } }), create: async () => ({ data: { id: "ses_agent_notfound" } }),
prompt: async () => { prompt: promptMock,
throw new Error("Cannot read property 'name' of undefined agent.name") promptAsync: promptMock,
},
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -1268,14 +1292,18 @@ describe("sisyphus-task", () => {
let promptBody: any let promptBody: any
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_sync_model" } }), create: async () => ({ data: { id: "ses_sync_model" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }]
}), }),
@ -1344,6 +1372,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_unstable_gemini" } }), create: async () => ({ data: { id: "ses_unstable_gemini" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Gemini task completed successfully" }] } { info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Gemini task completed successfully" }] }
@ -1407,6 +1436,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -1466,6 +1496,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_unstable_minimax" } }), create: async () => ({ data: { id: "ses_unstable_minimax" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Minimax task completed successfully" }] } { info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Minimax task completed successfully" }] }
@ -1523,16 +1554,19 @@ describe("sisyphus-task", () => {
}, },
} }
const promptMock = async () => {
promptCalled = true
return { data: {} }
}
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_sync_non_gemini" } }), create: async () => ({ data: { id: "ses_sync_non_gemini" } }),
prompt: async () => { prompt: promptMock,
promptCalled = true promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done sync" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done sync" }] }]
}), }),
@ -1597,6 +1631,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_artistry_gemini" } }), create: async () => ({ data: { id: "ses_artistry_gemini" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Artistry result here" }] } { info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Artistry result here" }] }
@ -1662,6 +1697,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_writing_gemini" } }), create: async () => ({ data: { id: "ses_writing_gemini" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Writing result here" }] } { info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Writing result here" }] }
@ -1726,6 +1762,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_custom_unstable" } }), create: async () => ({ data: { id: "ses_custom_unstable" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Custom unstable result" }] } { info: { role: "assistant", time: { created: Date.now() } }, parts: [{ type: "text", text: "Custom unstable result" }] }
@ -1858,11 +1895,12 @@ describe("sisyphus-task", () => {
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: "opencode/kimi-k2.5-free" } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
model: { list: async () => [] }, model: { list: async () => [] },
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -1870,6 +1908,9 @@ describe("sisyphus-task", () => {
const tool = createDelegateTask({ const tool = createDelegateTask({
manager: mockManager, manager: mockManager,
client: mockClient, client: mockClient,
userCategories: {
"fallback-test": { model: "anthropic/claude-opus-4-6" },
},
}) })
const toolContext = { const toolContext = {
@ -1980,6 +2021,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -2025,16 +2067,20 @@ describe("sisyphus-task", () => {
let promptBody: any let promptBody: any
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_browser_provider" } }), create: async () => ({ data: { id: "ses_browser_provider" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }]
}), }),
@ -2086,6 +2132,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_no_browser_provider" } }), create: async () => ({ data: { id: "ses_no_browser_provider" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }]
}), }),
@ -2531,6 +2578,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -2577,6 +2625,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_prometheus_allowed" } }), create: async () => ({ data: { id: "ses_prometheus_allowed" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Plan created successfully" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Plan created successfully" }] }]
}), }),
@ -2625,6 +2674,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "test-session" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
status: async () => ({ data: {} }), status: async () => ({ data: {} }),
}, },
@ -2691,6 +2741,7 @@ describe("sisyphus-task", () => {
session: { session: {
create: async () => ({ data: { id: "ses_explore_model" } }), create: async () => ({ data: { id: "ses_explore_model" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -2733,6 +2784,11 @@ describe("sisyphus-task", () => {
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { app: {
agents: async () => ({ agents: async () => ({
@ -2745,10 +2801,8 @@ describe("sisyphus-task", () => {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_oracle_model" } }), create: async () => ({ data: { id: "ses_oracle_model" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Consultation done" }] }], data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Consultation done" }] }],
}), }),
@ -2794,6 +2848,11 @@ describe("sisyphus-task", () => {
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { app: {
agents: async () => ({ agents: async () => ({
@ -2806,10 +2865,8 @@ describe("sisyphus-task", () => {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_no_model_agent" } }), create: async () => ({ data: { id: "ses_no_model_agent" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }], data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Done" }] }],
}), }),
@ -2853,16 +2910,20 @@ describe("sisyphus-task", () => {
let promptBody: any let promptBody: any
const mockManager = { launch: async () => ({}) } const mockManager = { launch: async () => ({}) }
const promptMock = async (input: any) => {
promptBody = input.body
return { data: {} }
}
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [{ name: "prometheus", mode: "subagent" }] }) }, app: { agents: async () => ({ data: [{ name: "prometheus", mode: "subagent" }] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_prometheus_delegate" } }), create: async () => ({ data: { id: "ses_prometheus_delegate" } }),
prompt: async (input: any) => { prompt: promptMock,
promptBody = input.body promptAsync: promptMock,
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Plan created" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Plan created" }] }]
}), }),
@ -2914,6 +2975,10 @@ describe("sisyphus-task", () => {
promptBody = input.body promptBody = input.body
return { data: {} } return { data: {} }
}, },
promptAsync: async (input: any) => {
promptBody = input.body
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Consultation done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Consultation done" }] }]
}), }),
@ -2968,6 +3033,7 @@ describe("sisyphus-task", () => {
return { data: { id: "ses_title_test" } } return { data: { id: "ses_title_test" } }
}, },
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "done" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "done" }] }]
}), }),
@ -3016,6 +3082,7 @@ describe("sisyphus-task", () => {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_metadata_test" } }), create: async () => ({ data: { id: "ses_metadata_test" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ messages: async () => ({
data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Task completed" }] }] data: [{ info: { role: "assistant" }, parts: [{ type: "text", text: "Task completed" }] }]
}), }),
@ -3069,10 +3136,11 @@ describe("sisyphus-task", () => {
const mockClient = { const mockClient = {
app: { agents: async () => ({ data: [] }) }, app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) }, config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
model: { list: async () => [{ id: SYSTEM_DEFAULT_MODEL }] }, model: { list: async () => [] },
session: { session: {
create: async () => ({ data: { id: "ses_bg_metadata" } }), create: async () => ({ data: { id: "test-session" } }),
prompt: async () => ({ data: {} }), prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -3080,6 +3148,9 @@ describe("sisyphus-task", () => {
const tool = createDelegateTask({ const tool = createDelegateTask({
manager: mockManager, manager: mockManager,
client: mockClient, client: mockClient,
userCategories: {
"sisyphus-junior": { model: "anthropic/claude-sonnet-4-5" },
},
}) })
const toolContext = { const toolContext = {

View File

@ -111,17 +111,19 @@ describe("look-at tool", () => {
}) })
describe("createLookAt error handling", () => { describe("createLookAt error handling", () => {
// given JSON parse error occurs in session.prompt // given JSON parse error occurs in session.promptAsync
// when LookAt tool executed // when LookAt tool executed
// then return user-friendly error message // then error propagates (band-aid removed since root cause fixed by promptAsync migration)
test("handles JSON parse error from session.prompt gracefully", async () => { test("propagates JSON parse error from session.promptAsync", async () => {
const throwingMock = async () => {
throw new Error("JSON Parse error: Unexpected EOF")
}
const mockClient = { const mockClient = {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_test_json_error" } }), create: async () => ({ data: { id: "ses_test_json_error" } }),
prompt: async () => { prompt: throwingMock,
throw new Error("JSON Parse error: Unexpected EOF") promptAsync: throwingMock,
},
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -142,28 +144,24 @@ describe("look-at tool", () => {
ask: async () => {}, ask: async () => {},
} }
const result = await tool.execute( await expect(
{ file_path: "/test/file.png", goal: "analyze image" }, tool.execute({ file_path: "/test/file.png", goal: "analyze image" }, toolContext)
toolContext ).rejects.toThrow("JSON Parse error: Unexpected EOF")
)
expect(result).toContain("Error: Failed to analyze")
expect(result).toContain("malformed response")
expect(result).toContain("multimodal-looker")
expect(result).toContain("image/png")
}) })
// given generic error occurs in session.prompt // given generic error occurs in session.promptAsync
// when LookAt tool executed // when LookAt tool executed
// then return error including original error message // then error propagates
test("handles generic prompt error gracefully", async () => { test("propagates generic prompt error", async () => {
const throwingMock = async () => {
throw new Error("Network connection failed")
}
const mockClient = { const mockClient = {
session: { session: {
get: async () => ({ data: { directory: "/project" } }), get: async () => ({ data: { directory: "/project" } }),
create: async () => ({ data: { id: "ses_test_generic_error" } }), create: async () => ({ data: { id: "ses_test_generic_error" } }),
prompt: async () => { prompt: throwingMock,
throw new Error("Network connection failed") promptAsync: throwingMock,
},
messages: async () => ({ data: [] }), messages: async () => ({ data: [] }),
}, },
} }
@ -184,13 +182,9 @@ describe("look-at tool", () => {
ask: async () => {}, ask: async () => {},
} }
const result = await tool.execute( await expect(
{ file_path: "/test/file.pdf", goal: "extract text" }, tool.execute({ file_path: "/test/file.pdf", goal: "extract text" }, toolContext)
toolContext ).rejects.toThrow("Network connection failed")
)
expect(result).toContain("Error: Failed to send prompt")
expect(result).toContain("Network connection failed")
}) })
}) })
@ -220,6 +214,10 @@ describe("look-at tool", () => {
promptBody = input.body promptBody = input.body
return { data: {} } return { data: {} }
}, },
promptAsync: async (input: any) => {
promptBody = input.body
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "done" }] }, { info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "done" }] },
@ -274,6 +272,10 @@ describe("look-at tool", () => {
promptBody = input.body promptBody = input.body
return { data: {} } return { data: {} }
}, },
promptAsync: async (input: any) => {
promptBody = input.body
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "analyzed" }] }, { info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "analyzed" }] },
@ -327,6 +329,10 @@ describe("look-at tool", () => {
promptBody = input.body promptBody = input.body
return { data: {} } return { data: {} }
}, },
promptAsync: async (input: any) => {
promptBody = input.body
return { data: {} }
},
messages: async () => ({ messages: async () => ({
data: [ data: [
{ info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "analyzed" }] }, { info: { role: "assistant", time: { created: 1 } }, parts: [{ type: "text", text: "analyzed" }] },