























@@ -22,6 +22,17 @@ vi.mock("playwright-core", () => ({
2222},
2323}));
242425+function firstMockCall(
26+mock: { mock: { calls: Array<readonly unknown[]> } },
27+label: string,
28+): readonly unknown[] {
29+const call = mock.mock.calls[0];
30+if (!call) {
31+throw new Error(`expected ${label} call`);
32+}
33+return call;
34+}
35+2536afterAll(() => {
2637vi.doUnmock("playwright-core");
2738vi.resetModules();
@@ -128,7 +139,9 @@ describe("PlaywrightDiffScreenshotter", () => {
128139expect(launchMock).toHaveBeenCalledTimes(1);
129140expect(pages).toHaveLength(1);
130141expect(pages[0]?.pdf).toHaveBeenCalledTimes(1);
131-const pdfCall = pages[0]?.pdf.mock.calls.at(0)?.[0] as Record<string, unknown> | undefined;
142+const pdfCall = firstMockCall(pages[0]?.pdf, "PDF render")[0] as
143+| Record<string, unknown>
144+| undefined;
132145if (!pdfCall) {
133146throw new Error("expected PDF render call");
134147}
@@ -404,9 +417,12 @@ describe("diffs plugin registration", () => {
404417registerDiffsPlugin(api as unknown as OpenClawPluginApi);
405418406419expect(on).toHaveBeenCalledTimes(1);
407-expect(on.mock.calls.at(0)?.[0]).toBe("before_prompt_build");
408-const beforePromptBuild = on.mock.calls.at(0)?.[1];
409-const promptResult = await beforePromptBuild?.({}, {});
420+const [hookName, beforePromptBuild] = firstMockCall(on, "plugin hook registration");
421+expect(hookName).toBe("before_prompt_build");
422+if (typeof beforePromptBuild !== "function") {
423+throw new Error("expected before_prompt_build callback");
424+}
425+const promptResult = await beforePromptBuild({}, {});
410426expect(promptResult?.prependSystemContext).toBe(
411427[
412428"When you need to show edits as a real diff, prefer the `diffs` tool instead of writing a manual summary.",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。