From f078d9022622a0a885f79cf5bf0fdf216792a3b1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 00:23:11 +0100 Subject: [PATCH] test: guard thread ownership mock calls --- extensions/thread-ownership/index.test.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/thread-ownership/index.test.ts b/extensions/thread-ownership/index.test.ts index 41233a742b1..04f493762bb 100644 --- a/extensions/thread-ownership/index.test.ts +++ b/extensions/thread-ownership/index.test.ts @@ -39,6 +39,14 @@ describe("thread-ownership plugin", () => { expect(init?.body).toBe(JSON.stringify({ agent_id: agentId })); } + function requireFirstLogMessage(mock: ReturnType, label: string): string { + const [call] = mock.mock.calls; + if (!call || typeof call[0] !== "string") { + throw new Error(`expected ${label}`); + } + return call[0]; + } + beforeEach(() => { vi.clearAllMocks(); for (const key of Object.keys(hooks)) { @@ -256,8 +264,7 @@ describe("thread-ownership plugin", () => { const result = await sendSlackThreadMessage(); expect(result).toEqual({ cancel: true }); - const infoMessage = vi.mocked(api.logger.info).mock.calls[0]?.[0]; - expect(typeof infoMessage).toBe("string"); + const infoMessage = requireFirstLogMessage(api.logger.info, "ownership cancel info log"); expect(infoMessage).toContain("cancelled send"); }); @@ -267,8 +274,7 @@ describe("thread-ownership plugin", () => { const result = await sendSlackThreadMessage(); expect(result).toBeUndefined(); - const warningMessage = vi.mocked(api.logger.warn).mock.calls[0]?.[0]; - expect(typeof warningMessage).toBe("string"); + const warningMessage = requireFirstLogMessage(api.logger.warn, "ownership check warning log"); expect(warningMessage).toContain("ownership check failed"); }); });