Skip to content

Commit 00453a9

Browse files
committed
test: guard active memory hook mock calls
1 parent 3b44dfc commit 00453a9

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

extensions/active-memory/index.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ describe("active-memory plugin", () => {
229229
expect(params.messageChannel).toBe(messageChannel);
230230
expect(params.messageProvider).toBe(messageProvider);
231231
};
232+
const firstHookRegistration = () => {
233+
const [call] = api.on.mock.calls as Array<[string, Function, Record<string, unknown>?]>;
234+
if (!call) {
235+
throw new Error("expected before_prompt_build hook registration");
236+
}
237+
return call;
238+
};
232239

233240
beforeEach(async () => {
234241
vi.clearAllMocks();
@@ -294,9 +301,10 @@ describe("active-memory plugin", () => {
294301
});
295302

296303
it("registers a before_prompt_build hook", () => {
297-
expect(api.on.mock.calls[0]?.[0]).toBe("before_prompt_build");
298-
expect(typeof api.on.mock.calls[0]?.[1]).toBe("function");
299-
expect(api.on.mock.calls[0]?.[2]).toEqual({ timeoutMs: 15_000 });
304+
const [hookName, handler, options] = firstHookRegistration();
305+
expect(hookName).toBe("before_prompt_build");
306+
expect(typeof handler).toBe("function");
307+
expect(options).toEqual({ timeoutMs: 15_000 });
300308
expect(hookOptions.before_prompt_build?.timeoutMs).toBe(15_000);
301309
});
302310

0 commit comments

Comments
 (0)