
























@@ -317,7 +317,8 @@ function mockCallArg<T>(
317317argIndex: number,
318318_type?: (value: unknown) => value is T,
319319): T {
320-const call = callIndex < 0 ? mock.mock.calls.at(callIndex) : mock.mock.calls[callIndex];
320+const resolvedIndex = callIndex < 0 ? mock.mock.calls.length + callIndex : callIndex;
321+const call = mock.mock.calls[resolvedIndex];
321322if (!call) {
322323throw new Error(`Expected mock call at index ${callIndex}`);
323324}
@@ -460,9 +461,7 @@ describe("browser tool snapshot maxChars", () => {
460461});
461462462463expect(browserClientMocks.browserSnapshot).toHaveBeenCalled();
463-const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
464-| { maxChars?: number }
465-| undefined;
464+const opts = lastMockCallArg<{ maxChars?: number }>(browserClientMocks.browserSnapshot, 1);
466465expect(Object.hasOwn(opts ?? {}, "maxChars")).toBe(false);
467466});
468467@@ -566,10 +565,8 @@ describe("browser tool snapshot maxChars", () => {
566565await runSnapshotToolCall({ snapshotFormat: "ai" });
567566568567expect(browserClientMocks.browserSnapshot).toHaveBeenCalled();
569-const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
570-| { mode?: string }
571-| undefined;
572-expect(opts?.mode).toBeUndefined();
568+const opts = lastMockCallArg<{ mode?: string }>(browserClientMocks.browserSnapshot, 1);
569+expect(opts.mode).toBeUndefined();
573570});
574571575572it("does not apply config snapshot defaults to aria snapshots", async () => {
@@ -584,10 +581,8 @@ describe("browser tool snapshot maxChars", () => {
584581});
585582586583expect(browserClientMocks.browserSnapshot).toHaveBeenCalled();
587-const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
588-| { mode?: string }
589-| undefined;
590-expect(opts?.mode).toBeUndefined();
584+const opts = lastMockCallArg<{ mode?: string }>(browserClientMocks.browserSnapshot, 1);
585+expect(opts.mode).toBeUndefined();
591586});
592587593588it("keeps profile=user off the sandbox browser when no node is selected", async () => {
@@ -642,16 +637,14 @@ describe("browser tool snapshot maxChars", () => {
642637const tool = createBrowserTool();
643638await tool.execute?.("call-1", { action: "snapshot", target: "host", profile: "user" });
644639645-const snapshotOpts = lastMockCallArg<{ profile?: string }>(
646-browserClientMocks.browserSnapshot,
647-1,
648-);
640+const snapshotOpts = lastMockCallArg<{
641+format?: string;
642+maxChars?: number;
643+profile?: string;
644+}>(browserClientMocks.browserSnapshot, 1);
649645expect(snapshotOpts.profile).toBe("user");
650-const opts = browserClientMocks.browserSnapshot.mock.calls.at(-1)?.[1] as
651-| { format?: string; maxChars?: number }
652-| undefined;
653-expect(opts?.format).toBeUndefined();
654-expect(Object.hasOwn(opts ?? {}, "maxChars")).toBe(false);
646+expect(snapshotOpts.format).toBeUndefined();
647+expect(Object.hasOwn(snapshotOpts, "maxChars")).toBe(false);
655648});
656649657650it("routes to node proxy when target=node", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。