From a3d378012c8d3968f20feeea0bdfa907ed8f2aec Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 17:44:22 +0100 Subject: [PATCH] test: tighten tool schema assertions --- src/agents/pi-tools.schema.test.ts | 41 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/agents/pi-tools.schema.test.ts b/src/agents/pi-tools.schema.test.ts index c6df2698802..d9590d736a0 100644 --- a/src/agents/pi-tools.schema.test.ts +++ b/src/agents/pi-tools.schema.test.ts @@ -86,13 +86,13 @@ describe("normalizeToolParameterSchema", () => { }; expect(cleaned.$defs).toBeUndefined(); - expect(cleaned.properties).toMatchObject({ + expect(cleaned.properties).toEqual({ foo: { type: "string", enum: ["a", "b"], }, }); - expect(cleaned.properties?.foo).toMatchObject({ + expect(cleaned.properties?.foo).toEqual({ type: "string", enum: ["a", "b"], }); @@ -428,22 +428,31 @@ describe("normalizeToolParameters", () => { ); expect(streamCalls).toBe(2); - expect(execute).toHaveBeenCalledWith("call-null-args", {}, undefined, expect.any(Function)); + const executeCall = execute.mock.calls[0]; + expect(executeCall?.[0]).toBe("call-null-args"); + expect(executeCall?.[1]).toEqual({}); + expect(executeCall?.[2]).toBeUndefined(); + expect(typeof executeCall?.[3]).toBe("function"); const toolResult = messages.find((message) => message.role === "toolResult"); - expect(toolResult).toMatchObject({ - role: "toolResult", - toolCallId: "call-null-args", - toolName: "wiki_lint", - isError: false, - content: [{ type: "text", text: "wiki ok" }], - }); + const toolResultRecord = toolResult as + | { + role?: string; + toolCallId?: string; + toolName?: string; + isError?: boolean; + content?: unknown; + } + | undefined; + expect(toolResultRecord?.role).toBe("toolResult"); + expect(toolResultRecord?.toolCallId).toBe("call-null-args"); + expect(toolResultRecord?.toolName).toBe("wiki_lint"); + expect(toolResultRecord?.isError).toBe(false); + expect(toolResultRecord?.content).toEqual([{ type: "text", text: "wiki ok" }]); const endedToolCall = events.find((event) => event.type === "tool_execution_end"); - expect(endedToolCall).toMatchObject({ - type: "tool_execution_end", - toolCallId: "call-null-args", - toolName: "wiki_lint", - isError: false, - }); + expect(endedToolCall?.type).toBe("tool_execution_end"); + expect(endedToolCall?.toolCallId).toBe("call-null-args"); + expect(endedToolCall?.toolName).toBe("wiki_lint"); + expect(endedToolCall?.isError).toBe(false); expect(JSON.stringify(messages)).not.toContain("Validation failed for tool"); });