test: guard agent web mock calls · openclaw/openclaw@808ce04
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -810,7 +810,7 @@ describe("createMusicGenerateTool", () => {
|
810 | 810 | }); |
811 | 811 | |
812 | 812 | expect(webMedia.loadWebMedia).toHaveBeenCalledTimes(1); |
813 | | -const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls[0]; |
| 813 | +const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls.at(0); |
814 | 814 | expect(loadCall?.[0]).toBe("http://198.18.0.153/reference.png"); |
815 | 815 | const loadOptions = loadCall?.[1] as { |
816 | 816 | requestInit?: { signal?: unknown }; |
@@ -820,7 +820,7 @@ describe("createMusicGenerateTool", () => {
|
820 | 820 | expect(loadOptions.ssrfPolicy).toEqual({ allowRfc2544BenchmarkRange: true }); |
821 | 821 | expect(generateMusicOptions().timeoutMs).toBe(180_000); |
822 | 822 | expect(fetchTimeout.buildTimeoutAbortSignal).toHaveBeenCalledTimes(1); |
823 | | -expect(vi.mocked(fetchTimeout.buildTimeoutAbortSignal).mock.calls[0]?.[0]).toEqual({ |
| 823 | +expect(vi.mocked(fetchTimeout.buildTimeoutAbortSignal).mock.calls.at(0)?.[0]).toEqual({ |
824 | 824 | operation: "music-generate.reference-fetch", |
825 | 825 | timeoutMs: 30_000, |
826 | 826 | url: "http://198.18.0.153/reference.png", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,11 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
57 | 57 | await tool?.execute?.("call", { url: "https://example.com/page" }); |
58 | 58 | |
59 | 59 | expect(fetchSpy).toHaveBeenCalledTimes(1); |
60 | | -const [, init] = fetchSpy.mock.calls[0]; |
| 60 | +const fetchCall = fetchSpy.mock.calls.at(0); |
| 61 | +if (!fetchCall) { |
| 62 | +throw new Error("expected fetch to be called"); |
| 63 | +} |
| 64 | +const [, init] = fetchCall; |
61 | 65 | expect(init.headers.Accept).toBe("text/markdown, text/html;q=0.9, */*;q=0.1"); |
62 | 66 | }); |
63 | 67 | |
@@ -141,7 +145,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
|
141 | 145 | await tool?.execute?.("call", { url: "https://example.com/runtime-firecrawl-off" }); |
142 | 146 | |
143 | 147 | expect(fetchSpy).toHaveBeenCalledTimes(1); |
144 | | -expect(fetchSpy.mock.calls[0]?.[0]).toBe("https://example.com/runtime-firecrawl-off"); |
| 148 | +expect(fetchSpy.mock.calls.at(0)?.[0]).toBe("https://example.com/runtime-firecrawl-off"); |
145 | 149 | }); |
146 | 150 | |
147 | 151 | it("logs x-markdown-tokens when header is present", async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -38,11 +38,11 @@ type ProviderResolutionParams = {
|
38 | 38 | }; |
39 | 39 | |
40 | 40 | function firstRunWebSearchParams(): RunWebSearchParams | undefined { |
41 | | -return mocks.runWebSearch.mock.calls[0]?.[0] as RunWebSearchParams | undefined; |
| 41 | +return mocks.runWebSearch.mock.calls.at(0)?.[0] as RunWebSearchParams | undefined; |
42 | 42 | } |
43 | 43 | |
44 | 44 | function firstProviderResolutionParams(): ProviderResolutionParams | undefined { |
45 | | -return mocks.resolveManifestContractOwnerPluginId.mock.calls[0]?.[0] as |
| 45 | +return mocks.resolveManifestContractOwnerPluginId.mock.calls.at(0)?.[0] as |
46 | 46 | | ProviderResolutionParams |
47 | 47 | | undefined; |
48 | 48 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,8 @@ describe("web_search signal plumbing", () => {
|
26 | 26 | await tool?.execute("call-search", { query: "openclaw" }, controller.signal); |
27 | 27 | |
28 | 28 | expect(mocks.runWebSearch).toHaveBeenCalledTimes(1); |
29 | | -expect(mocks.runWebSearch.mock.calls[0]?.[0]?.args).toEqual({ query: "openclaw" }); |
30 | | -expect(mocks.runWebSearch.mock.calls[0]?.[0]?.signal).toBe(controller.signal); |
| 29 | +const params = mocks.runWebSearch.mock.calls.at(0)?.[0]; |
| 30 | +expect(params?.args).toEqual({ query: "openclaw" }); |
| 31 | +expect(params?.signal).toBe(controller.signal); |
31 | 32 | }); |
32 | 33 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -344,7 +344,7 @@ describe("web_fetch extraction fallbacks", () => {
|
344 | 344 | |
345 | 345 | await tool?.execute?.("call", { url: "https://example.com/proxy" }); |
346 | 346 | |
347 | | -const requestInit = mockFetch.mock.calls[0]?.[1] as |
| 347 | +const requestInit = mockFetch.mock.calls.at(0)?.[1] as |
348 | 348 | | (RequestInit & { dispatcher?: unknown }) |
349 | 349 | | undefined; |
350 | 350 | const dispatcher = requestInit?.dispatcher; |
@@ -372,7 +372,7 @@ describe("web_fetch extraction fallbacks", () => {
|
372 | 372 | |
373 | 373 | await tool?.execute?.("call", { url: "https://example.com/proxy" }); |
374 | 374 | |
375 | | -const requestInit = mockFetch.mock.calls[0]?.[1] as |
| 375 | +const requestInit = mockFetch.mock.calls.at(0)?.[1] as |
376 | 376 | | (RequestInit & { dispatcher?: unknown }) |
377 | 377 | | undefined; |
378 | 378 | const dispatcher = requestInit?.dispatcher; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。