fix: resolve JSON parse error in Oracle after promptAsync refactor (#1681)
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
const { describe, test, expect, mock } = require("bun:test")
|
||||
const {
|
||||
describe: bunDescribe,
|
||||
test: bunTest,
|
||||
expect: bunExpect,
|
||||
mock: bunMock,
|
||||
} = require("bun:test")
|
||||
|
||||
describe("sendSyncPrompt", () => {
|
||||
test("passes question=false via tools parameter", async () => {
|
||||
bunDescribe("sendSyncPrompt", () => {
|
||||
bunTest("passes question=false via tools parameter", async () => {
|
||||
//#given
|
||||
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
||||
|
||||
let promptArgs: any
|
||||
const promptAsync = mock(async (input: any) => {
|
||||
const promptAsync = bunMock(async (input: any) => {
|
||||
promptArgs = input
|
||||
return { data: {} }
|
||||
})
|
||||
@@ -33,19 +38,19 @@ describe("sendSyncPrompt", () => {
|
||||
}
|
||||
|
||||
//#when
|
||||
await sendSyncPrompt(mockClient as any, input)
|
||||
await sendSyncPrompt(mockClient, input)
|
||||
|
||||
//#then
|
||||
expect(promptAsync).toHaveBeenCalled()
|
||||
expect(promptArgs.body.tools.question).toBe(false)
|
||||
bunExpect(promptAsync).toHaveBeenCalled()
|
||||
bunExpect(promptArgs.body.tools.question).toBe(false)
|
||||
})
|
||||
|
||||
test("applies agent tool restrictions for explore agent", async () => {
|
||||
bunTest("applies agent tool restrictions for explore agent", async () => {
|
||||
//#given
|
||||
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
||||
|
||||
let promptArgs: any
|
||||
const promptAsync = mock(async (input: any) => {
|
||||
const promptAsync = bunMock(async (input: any) => {
|
||||
promptArgs = input
|
||||
return { data: {} }
|
||||
})
|
||||
@@ -73,19 +78,19 @@ describe("sendSyncPrompt", () => {
|
||||
}
|
||||
|
||||
//#when
|
||||
await sendSyncPrompt(mockClient as any, input)
|
||||
await sendSyncPrompt(mockClient, input)
|
||||
|
||||
//#then
|
||||
expect(promptAsync).toHaveBeenCalled()
|
||||
expect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
||||
bunExpect(promptAsync).toHaveBeenCalled()
|
||||
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
||||
})
|
||||
|
||||
test("applies agent tool restrictions for librarian agent", async () => {
|
||||
bunTest("applies agent tool restrictions for librarian agent", async () => {
|
||||
//#given
|
||||
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
||||
|
||||
let promptArgs: any
|
||||
const promptAsync = mock(async (input: any) => {
|
||||
const promptAsync = bunMock(async (input: any) => {
|
||||
promptArgs = input
|
||||
return { data: {} }
|
||||
})
|
||||
@@ -113,19 +118,19 @@ describe("sendSyncPrompt", () => {
|
||||
}
|
||||
|
||||
//#when
|
||||
await sendSyncPrompt(mockClient as any, input)
|
||||
await sendSyncPrompt(mockClient, input)
|
||||
|
||||
//#then
|
||||
expect(promptAsync).toHaveBeenCalled()
|
||||
expect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
||||
bunExpect(promptAsync).toHaveBeenCalled()
|
||||
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
||||
})
|
||||
|
||||
test("does not restrict call_omo_agent for sisyphus agent", async () => {
|
||||
bunTest("does not restrict call_omo_agent for sisyphus agent", async () => {
|
||||
//#given
|
||||
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
||||
|
||||
let promptArgs: any
|
||||
const promptAsync = mock(async (input: any) => {
|
||||
const promptAsync = bunMock(async (input: any) => {
|
||||
promptArgs = input
|
||||
return { data: {} }
|
||||
})
|
||||
@@ -153,10 +158,90 @@ describe("sendSyncPrompt", () => {
|
||||
}
|
||||
|
||||
//#when
|
||||
await sendSyncPrompt(mockClient as any, input)
|
||||
await sendSyncPrompt(mockClient, input)
|
||||
|
||||
//#then
|
||||
expect(promptAsync).toHaveBeenCalled()
|
||||
expect(promptArgs.body.tools.call_omo_agent).toBe(true)
|
||||
bunExpect(promptAsync).toHaveBeenCalled()
|
||||
bunExpect(promptArgs.body.tools.call_omo_agent).toBe(true)
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user