92 lines
2.1 KiB
TypeScript
92 lines
2.1 KiB
TypeScript
|
|
const { describe, test, expect, mock } = require("bun:test")
|
||
|
|
|
||
|
|
mock.module("./session-creator", () => ({
|
||
|
|
createOrGetSession: mock(async () => ({ sessionID: "ses-test-123" })),
|
||
|
|
}))
|
||
|
|
|
||
|
|
mock.module("./completion-poller", () => ({
|
||
|
|
waitForCompletion: mock(async () => {}),
|
||
|
|
}))
|
||
|
|
|
||
|
|
mock.module("./message-processor", () => ({
|
||
|
|
processMessages: mock(async () => "agent response"),
|
||
|
|
}))
|
||
|
|
|
||
|
|
describe("executeSync", () => {
|
||
|
|
test("passes question=false via tools parameter to block question tool", async () => {
|
||
|
|
//#given
|
||
|
|
const { executeSync } = require("./sync-executor")
|
||
|
|
|
||
|
|
let promptArgs: any
|
||
|
|
const promptAsync = mock(async (input: any) => {
|
||
|
|
promptArgs = input
|
||
|
|
return { data: {} }
|
||
|
|
})
|
||
|
|
|
||
|
|
const args = {
|
||
|
|
subagent_type: "explore",
|
||
|
|
description: "test task",
|
||
|
|
prompt: "find something",
|
||
|
|
}
|
||
|
|
|
||
|
|
const toolContext = {
|
||
|
|
sessionID: "parent-session",
|
||
|
|
messageID: "msg-1",
|
||
|
|
agent: "sisyphus",
|
||
|
|
abort: new AbortController().signal,
|
||
|
|
metadata: mock(async () => {}),
|
||
|
|
}
|
||
|
|
|
||
|
|
const ctx = {
|
||
|
|
client: {
|
||
|
|
session: { promptAsync },
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
//#when
|
||
|
|
await executeSync(args, toolContext, ctx as any)
|
||
|
|
|
||
|
|
//#then
|
||
|
|
expect(promptAsync).toHaveBeenCalled()
|
||
|
|
expect(promptArgs.body.tools.question).toBe(false)
|
||
|
|
})
|
||
|
|
|
||
|
|
test("passes task=false via tools parameter", async () => {
|
||
|
|
//#given
|
||
|
|
const { executeSync } = require("./sync-executor")
|
||
|
|
|
||
|
|
let promptArgs: any
|
||
|
|
const promptAsync = mock(async (input: any) => {
|
||
|
|
promptArgs = input
|
||
|
|
return { data: {} }
|
||
|
|
})
|
||
|
|
|
||
|
|
const args = {
|
||
|
|
subagent_type: "librarian",
|
||
|
|
description: "search docs",
|
||
|
|
prompt: "find docs",
|
||
|
|
}
|
||
|
|
|
||
|
|
const toolContext = {
|
||
|
|
sessionID: "parent-session",
|
||
|
|
messageID: "msg-2",
|
||
|
|
agent: "sisyphus",
|
||
|
|
abort: new AbortController().signal,
|
||
|
|
metadata: mock(async () => {}),
|
||
|
|
}
|
||
|
|
|
||
|
|
const ctx = {
|
||
|
|
client: {
|
||
|
|
session: { promptAsync },
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
//#when
|
||
|
|
await executeSync(args, toolContext, ctx as any)
|
||
|
|
|
||
|
|
//#then
|
||
|
|
expect(promptAsync).toHaveBeenCalled()
|
||
|
|
expect(promptArgs.body.tools.task).toBe(false)
|
||
|
|
})
|
||
|
|
})
|