42fb2548d6
Previously, when an explicit model was configured, the agent name was omitted to prevent opencode's built-in agent fallback chain from overriding the user-specified model. This removes that conditional logic and always passes the agent name alongside the model. Tests are updated to reflect this behavior change. 🤖 GENERATED WITH ASSISTANCE OF [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
297 lines
7.3 KiB
TypeScript
297 lines
7.3 KiB
TypeScript
const {
|
|
describe: bunDescribe,
|
|
test: bunTest,
|
|
expect: bunExpect,
|
|
mock: bunMock,
|
|
} = require("bun:test")
|
|
|
|
bunDescribe("sendSyncPrompt", () => {
|
|
bunTest("passes question=false via tools parameter", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = bunMock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "sisyphus-junior",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient, input)
|
|
|
|
//#then
|
|
bunExpect(promptAsync).toHaveBeenCalled()
|
|
bunExpect(promptArgs.body.tools.question).toBe(false)
|
|
})
|
|
|
|
bunTest("applies agent tool restrictions for explore agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = bunMock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "explore",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient, input)
|
|
|
|
//#then
|
|
bunExpect(promptAsync).toHaveBeenCalled()
|
|
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
|
})
|
|
|
|
bunTest("applies agent tool restrictions for librarian agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = bunMock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "librarian",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient, input)
|
|
|
|
//#then
|
|
bunExpect(promptAsync).toHaveBeenCalled()
|
|
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
|
})
|
|
|
|
bunTest("does not restrict call_omo_agent for sisyphus agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = bunMock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "sisyphus",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient, input)
|
|
|
|
//#then
|
|
bunExpect(promptAsync).toHaveBeenCalled()
|
|
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(true)
|
|
})
|
|
|
|
bunTest("includes agent alongside explicit category model", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = bunMock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "sisyphus-junior",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: {
|
|
providerID: "openai",
|
|
modelID: "gpt-5.4",
|
|
variant: "medium",
|
|
},
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient, input)
|
|
|
|
//#then
|
|
bunExpect(promptAsync).toHaveBeenCalled()
|
|
bunExpect(promptArgs.body.agent).toBe("sisyphus-junior")
|
|
bunExpect(promptArgs.body.model).toEqual({
|
|
providerID: "openai",
|
|
modelID: "gpt-5.4",
|
|
})
|
|
bunExpect(promptArgs.body.variant).toBe("medium")
|
|
})
|
|
|
|
bunTest("retries with promptSync for oracle when promptAsync fails with unexpected EOF", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
const promptWithModelSuggestionRetry = bunMock(async () => {
|
|
throw new Error("JSON Parse error: Unexpected EOF")
|
|
})
|
|
const promptSyncWithModelSuggestionRetry = bunMock(async () => {})
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "oracle",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
const result = await sendSyncPrompt(
|
|
{ session: { promptAsync: bunMock(async () => ({ data: {} })) } },
|
|
input,
|
|
{
|
|
promptWithModelSuggestionRetry,
|
|
promptSyncWithModelSuggestionRetry,
|
|
},
|
|
)
|
|
|
|
//#then
|
|
bunExpect(result).toBeNull()
|
|
bunExpect(promptWithModelSuggestionRetry).toHaveBeenCalledTimes(1)
|
|
bunExpect(promptSyncWithModelSuggestionRetry).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
bunTest("does not retry with promptSync for non-oracle on unexpected EOF", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
const promptWithModelSuggestionRetry = bunMock(async () => {
|
|
throw new Error("JSON Parse error: Unexpected EOF")
|
|
})
|
|
const promptSyncWithModelSuggestionRetry = bunMock(async () => {})
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "metis",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
const result = await sendSyncPrompt(
|
|
{ session: { promptAsync: bunMock(async () => ({ data: {} })) } },
|
|
input,
|
|
{
|
|
promptWithModelSuggestionRetry,
|
|
promptSyncWithModelSuggestionRetry,
|
|
},
|
|
)
|
|
|
|
//#then
|
|
bunExpect(result).toContain("JSON Parse error: Unexpected EOF")
|
|
bunExpect(promptWithModelSuggestionRetry).toHaveBeenCalledTimes(1)
|
|
bunExpect(promptSyncWithModelSuggestionRetry).toHaveBeenCalledTimes(0)
|
|
})
|
|
})
|