From aa41e23519cf020e85bc4748dc450120c54af44a Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 9 May 2026 17:41:12 +0100 Subject: [PATCH] test: tighten tool adapter logging assertions --- ...pi-tool-definition-adapter.logging.test.ts | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/src/agents/pi-tool-definition-adapter.logging.test.ts b/src/agents/pi-tool-definition-adapter.logging.test.ts index 5dff8c87dd8..b259d14c792 100644 --- a/src/agents/pi-tool-definition-adapter.logging.test.ts +++ b/src/agents/pi-tool-definition-adapter.logging.test.ts @@ -64,10 +64,8 @@ describe("pi tool definition adapter logging", () => { await def.execute("call-edit-1", { path: "notes.txt" }, undefined, undefined, extensionContext); - expect(logError).toHaveBeenCalledWith( - expect.stringContaining( - '[tools] edit failed: Missing required parameter: edits (received: path). Supply correct parameters before retrying. raw_params={"path":"notes.txt"}', - ), + expect(vi.mocked(logError).mock.calls[0]?.[0]).toContain( + '[tools] edit failed: Missing required parameter: edits (received: path). Supply correct parameters before retrying. raw_params={"path":"notes.txt"}', ); }); @@ -96,15 +94,12 @@ describe("pi tool definition adapter logging", () => { extensionContext, ); - expect(result).toEqual( - expect.objectContaining({ - details: expect.objectContaining({ - status: "blocked", - deniedReason: "plugin-before-tool-call", - reason: "blocked by policy", - }), - }), - ); + const details = result.details as + | { status?: string; deniedReason?: string; reason?: string } + | undefined; + expect(details?.status).toBe("blocked"); + expect(details?.deniedReason).toBe("plugin-before-tool-call"); + expect(details?.reason).toBe("blocked by policy"); expect(logError).not.toHaveBeenCalled(); expect(mocks.logDebug).toHaveBeenCalledWith( "tools: exec blocked by before_tool_call: blocked by policy", @@ -138,17 +133,14 @@ describe("pi tool definition adapter logging", () => { extensionContext, ); - expect(result).toEqual( - expect.objectContaining({ - details: expect.objectContaining({ - status: "error", - tool: "web_search", - error: "This operation was aborted", - }), - }), - ); - expect(logError).toHaveBeenCalledWith( - expect.stringContaining("[tools] web_search failed: This operation was aborted"), + const details = result.details as + | { status?: string; tool?: string; error?: string } + | undefined; + expect(details?.status).toBe("error"); + expect(details?.tool).toBe("web_search"); + expect(details?.error).toBe("This operation was aborted"); + expect(vi.mocked(logError).mock.calls[0]?.[0]).toContain( + "[tools] web_search failed: This operation was aborted", ); }); @@ -173,18 +165,21 @@ describe("pi tool definition adapter logging", () => { const controller = new AbortController(); controller.abort(); - await expect( - def.execute( + let thrown: unknown; + try { + await def.execute( "call-web-search-agent-abort", { query: "OpenClaw" }, controller.signal, undefined, extensionContext, - ), - ).rejects.toMatchObject({ - name: "AbortError", - message: "This operation was aborted", - }); + ); + } catch (error) { + thrown = error; + } + expect(thrown).toBeInstanceOf(Error); + expect((thrown as Error).name).toBe("AbortError"); + expect((thrown as Error).message).toBe("This operation was aborted"); expect(logError).not.toHaveBeenCalled(); });