refactor(test): share internal hook and npm pack assertions

This commit is contained in:
Peter Steinberger
2026-02-18 16:59:38 +00:00
parent 72a4d83334
commit f05395ae00
6 changed files with 57 additions and 48 deletions

View File

@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { createInternalHookEventPayload } from "../../test-utils/internal-hook-event-payload.js";
import type { MsgContext } from "../templating.js";
import type { GetReplyOptions, ReplyPayload } from "../types.js";
import type { ReplyDispatcher } from "./reply-dispatcher.js";
@@ -26,16 +27,7 @@ const hookMocks = vi.hoisted(() => ({
},
}));
const internalHookMocks = vi.hoisted(() => ({
createInternalHookEvent: vi.fn(
(type: string, action: string, sessionKey: string, context: Record<string, unknown>) => ({
type,
action,
sessionKey,
context,
timestamp: new Date(),
messages: [],
}),
),
createInternalHookEvent: vi.fn(),
triggerInternalHook: vi.fn(async () => {}),
}));
@@ -121,7 +113,8 @@ describe("dispatchReplyFromConfig", () => {
hookMocks.runner.hasHooks.mockReset();
hookMocks.runner.hasHooks.mockReturnValue(false);
hookMocks.runner.runMessageReceived.mockReset();
internalHookMocks.createInternalHookEvent.mockClear();
internalHookMocks.createInternalHookEvent.mockReset();
internalHookMocks.createInternalHookEvent.mockImplementation(createInternalHookEventPayload);
internalHookMocks.triggerInternalHook.mockClear();
});
it("does not route when Provider matches OriginatingChannel (even if Surface is missing)", async () => {