fix(test/session-recovery): replace mock.calls[0][0] with typed accessor
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -21,8 +21,25 @@ const failedAssistantMsg: MessageData = {
|
|||||||
parts: [],
|
parts: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PromptAsyncInput {
|
||||||
|
readonly path: { readonly id: string }
|
||||||
|
readonly body: {
|
||||||
|
readonly agent?: string
|
||||||
|
readonly model?: { readonly providerID: string; readonly modelID: string }
|
||||||
|
readonly variant?: string
|
||||||
|
readonly parts: ReadonlyArray<{
|
||||||
|
readonly toolUseId: string
|
||||||
|
readonly content?: ReadonlyArray<{ readonly text: string }>
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createMockClient(messages: MessageData[] = []) {
|
function createMockClient(messages: MessageData[] = []) {
|
||||||
const promptAsync = mock(() => Promise.resolve({}))
|
const promptAsyncCalls: PromptAsyncInput[] = []
|
||||||
|
const promptAsync = mock((input: PromptAsyncInput) => {
|
||||||
|
promptAsyncCalls.push(input)
|
||||||
|
return Promise.resolve({})
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
client: {
|
client: {
|
||||||
@@ -32,9 +49,18 @@ function createMockClient(messages: MessageData[] = []) {
|
|||||||
},
|
},
|
||||||
} as never,
|
} as never,
|
||||||
promptAsync,
|
promptAsync,
|
||||||
|
promptAsyncCalls,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function firstPromptAsyncCall(calls: readonly PromptAsyncInput[]): PromptAsyncInput {
|
||||||
|
const call = calls[0]
|
||||||
|
if (!call) {
|
||||||
|
throw new Error("expected promptAsync to be called at least once")
|
||||||
|
}
|
||||||
|
return call
|
||||||
|
}
|
||||||
|
|
||||||
describe("recoverToolResultMissing", () => {
|
describe("recoverToolResultMissing", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sqliteBackend = false
|
sqliteBackend = false
|
||||||
@@ -94,7 +120,7 @@ describe("recoverToolResultMissing", () => {
|
|||||||
|
|
||||||
it("falls back to a valid id when callID is malformed", async () => {
|
it("falls back to a valid id when callID is malformed", async () => {
|
||||||
//#given
|
//#given
|
||||||
const { client, promptAsync } = createMockClient()
|
const { client, promptAsync, promptAsyncCalls } = createMockClient()
|
||||||
const failedAssistantWithMalformedCallID: MessageData = {
|
const failedAssistantWithMalformedCallID: MessageData = {
|
||||||
info: { id: "msg_failed", role: "assistant" },
|
info: { id: "msg_failed", role: "assistant" },
|
||||||
parts: [{
|
parts: [{
|
||||||
@@ -113,18 +139,14 @@ describe("recoverToolResultMissing", () => {
|
|||||||
//#then
|
//#then
|
||||||
expect(result).toBe(true)
|
expect(result).toBe(true)
|
||||||
expect(promptAsync).toHaveBeenCalledTimes(1)
|
expect(promptAsync).toHaveBeenCalledTimes(1)
|
||||||
const call = promptAsync.mock.calls[0]?.[0] as {
|
const call = firstPromptAsyncCall(promptAsyncCalls)
|
||||||
body: {
|
|
||||||
parts: Array<{ toolUseId: string }>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(call.body.parts.map((part) => part.toolUseId)).toEqual(["toolu_recovered_from_id"])
|
expect(call.body.parts.map((part) => part.toolUseId)).toEqual(["toolu_recovered_from_id"])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("sends only interrupted sqlite tool results when recoverStatuses is provided", async () => {
|
it("sends only interrupted sqlite tool results when recoverStatuses is provided", async () => {
|
||||||
//#given
|
//#given
|
||||||
sqliteBackend = true
|
sqliteBackend = true
|
||||||
const { client, promptAsync } = createMockClient([
|
const { client, promptAsync, promptAsyncCalls } = createMockClient([
|
||||||
{
|
{
|
||||||
info: { id: "msg_failed", role: "assistant" },
|
info: { id: "msg_failed", role: "assistant" },
|
||||||
parts: [
|
parts: [
|
||||||
@@ -166,13 +188,9 @@ describe("recoverToolResultMissing", () => {
|
|||||||
//#then
|
//#then
|
||||||
expect(result).toBe(true)
|
expect(result).toBe(true)
|
||||||
expect(promptAsync).toHaveBeenCalledTimes(1)
|
expect(promptAsync).toHaveBeenCalledTimes(1)
|
||||||
const call = promptAsync.mock.calls[0]?.[0] as {
|
const call = firstPromptAsyncCall(promptAsyncCalls)
|
||||||
body: {
|
|
||||||
parts: Array<{ toolUseId: string; content: Array<{ text: string }> }>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(call.body.parts.map((part) => part.toolUseId)).toEqual(["call_running", "toolu_pending"])
|
expect(call.body.parts.map((part) => part.toolUseId)).toEqual(["call_running", "toolu_pending"])
|
||||||
expect(call.body.parts[0]?.content[0]?.text).toBe("Tool execution was interrupted before producing a result.")
|
expect(call.body.parts[0]?.content?.[0]?.text).toBe("Tool execution was interrupted before producing a result.")
|
||||||
})
|
})
|
||||||
|
|
||||||
it("returns false for stored parts when tool part has no valid callID", async () => {
|
it("returns false for stored parts when tool part has no valid callID", async () => {
|
||||||
@@ -227,7 +245,7 @@ describe("recoverToolResultMissing", () => {
|
|||||||
tool: "bash",
|
tool: "bash",
|
||||||
state: { input: {} },
|
state: { input: {} },
|
||||||
}]
|
}]
|
||||||
const { client, promptAsync } = createMockClient()
|
const { client, promptAsync, promptAsyncCalls } = createMockClient()
|
||||||
const resumeConfig = {
|
const resumeConfig = {
|
||||||
sessionID: "ses_pin",
|
sessionID: "ses_pin",
|
||||||
agent: "Hephaestus",
|
agent: "Hephaestus",
|
||||||
@@ -240,14 +258,7 @@ describe("recoverToolResultMissing", () => {
|
|||||||
// then
|
// then
|
||||||
expect(result).toBe(true)
|
expect(result).toBe(true)
|
||||||
expect(promptAsync).toHaveBeenCalledTimes(1)
|
expect(promptAsync).toHaveBeenCalledTimes(1)
|
||||||
const call = promptAsync.mock.calls[0]?.[0] as {
|
const call = firstPromptAsyncCall(promptAsyncCalls)
|
||||||
body: {
|
|
||||||
agent?: string
|
|
||||||
model?: { providerID: string; modelID: string }
|
|
||||||
variant?: string
|
|
||||||
parts: unknown[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(call.body.agent).toBe("Hephaestus")
|
expect(call.body.agent).toBe("Hephaestus")
|
||||||
expect(call.body.model).toEqual({ providerID: "openai", modelID: "gpt-5.3-codex" })
|
expect(call.body.model).toEqual({ providerID: "openai", modelID: "gpt-5.3-codex" })
|
||||||
expect(call.body.variant).toBe("max")
|
expect(call.body.variant).toBe("max")
|
||||||
@@ -262,14 +273,15 @@ describe("recoverToolResultMissing", () => {
|
|||||||
tool: "bash",
|
tool: "bash",
|
||||||
state: { input: {} },
|
state: { input: {} },
|
||||||
}]
|
}]
|
||||||
const { client, promptAsync } = createMockClient()
|
const { client, promptAsync, promptAsyncCalls } = createMockClient()
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const result = await recoverToolResultMissing(client, "ses_nopin", failedAssistantMsg)
|
const result = await recoverToolResultMissing(client, "ses_nopin", failedAssistantMsg)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result).toBe(true)
|
expect(result).toBe(true)
|
||||||
const call = promptAsync.mock.calls[0]?.[0] as { body: Record<string, unknown> }
|
expect(promptAsync).toHaveBeenCalledTimes(1)
|
||||||
|
const call = firstPromptAsyncCall(promptAsyncCalls)
|
||||||
expect(call.body).not.toHaveProperty("agent")
|
expect(call.body).not.toHaveProperty("agent")
|
||||||
expect(call.body).not.toHaveProperty("model")
|
expect(call.body).not.toHaveProperty("model")
|
||||||
expect(call.body).not.toHaveProperty("variant")
|
expect(call.body).not.toHaveProperty("variant")
|
||||||
|
|||||||
Reference in New Issue
Block a user