test: guard active memory hook mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 00:17:45 +01:00
parent 3b44dfc367
commit 00453a9607

View File

@@ -229,6 +229,13 @@ describe("active-memory plugin", () => {
expect(params.messageChannel).toBe(messageChannel);
expect(params.messageProvider).toBe(messageProvider);
};
const firstHookRegistration = () => {
const [call] = api.on.mock.calls as Array<[string, Function, Record<string, unknown>?]>;
if (!call) {
throw new Error("expected before_prompt_build hook registration");
}
return call;
};
beforeEach(async () => {
vi.clearAllMocks();
@@ -294,9 +301,10 @@ describe("active-memory plugin", () => {
});
it("registers a before_prompt_build hook", () => {
expect(api.on.mock.calls[0]?.[0]).toBe("before_prompt_build");
expect(typeof api.on.mock.calls[0]?.[1]).toBe("function");
expect(api.on.mock.calls[0]?.[2]).toEqual({ timeoutMs: 15_000 });
const [hookName, handler, options] = firstHookRegistration();
expect(hookName).toBe("before_prompt_build");
expect(typeof handler).toBe("function");
expect(options).toEqual({ timeoutMs: 15_000 });
expect(hookOptions.before_prompt_build?.timeoutMs).toBe(15_000);
});