test: guard thread ownership mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 00:23:11 +01:00
parent 9a9dc4a47b
commit f078d90226

View File

@@ -39,6 +39,14 @@ describe("thread-ownership plugin", () => {
expect(init?.body).toBe(JSON.stringify({ agent_id: agentId }));
}
function requireFirstLogMessage(mock: ReturnType<typeof vi.fn>, 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");
});
});