test: guard agent web mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 08:29:19 +01:00
parent 815af80363
commit 808ce04cc1
5 changed files with 15 additions and 10 deletions
+2 -2
View File
@@ -810,7 +810,7 @@ describe("createMusicGenerateTool", () => {
});
expect(webMedia.loadWebMedia).toHaveBeenCalledTimes(1);
const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls[0];
const loadCall = vi.mocked(webMedia.loadWebMedia).mock.calls.at(0);
expect(loadCall?.[0]).toBe("http://198.18.0.153/reference.png");
const loadOptions = loadCall?.[1] as {
requestInit?: { signal?: unknown };
@@ -820,7 +820,7 @@ describe("createMusicGenerateTool", () => {
expect(loadOptions.ssrfPolicy).toEqual({ allowRfc2544BenchmarkRange: true });
expect(generateMusicOptions().timeoutMs).toBe(180_000);
expect(fetchTimeout.buildTimeoutAbortSignal).toHaveBeenCalledTimes(1);
expect(vi.mocked(fetchTimeout.buildTimeoutAbortSignal).mock.calls[0]?.[0]).toEqual({
expect(vi.mocked(fetchTimeout.buildTimeoutAbortSignal).mock.calls.at(0)?.[0]).toEqual({
operation: "music-generate.reference-fetch",
timeoutMs: 30_000,
url: "http://198.18.0.153/reference.png",
@@ -57,7 +57,11 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
await tool?.execute?.("call", { url: "https://example.com/page" });
expect(fetchSpy).toHaveBeenCalledTimes(1);
const [, init] = fetchSpy.mock.calls[0];
const fetchCall = fetchSpy.mock.calls.at(0);
if (!fetchCall) {
throw new Error("expected fetch to be called");
}
const [, init] = fetchCall;
expect(init.headers.Accept).toBe("text/markdown, text/html;q=0.9, */*;q=0.1");
});
@@ -141,7 +145,7 @@ describe("web_fetch Cloudflare Markdown for Agents", () => {
await tool?.execute?.("call", { url: "https://example.com/runtime-firecrawl-off" });
expect(fetchSpy).toHaveBeenCalledTimes(1);
expect(fetchSpy.mock.calls[0]?.[0]).toBe("https://example.com/runtime-firecrawl-off");
expect(fetchSpy.mock.calls.at(0)?.[0]).toBe("https://example.com/runtime-firecrawl-off");
});
it("logs x-markdown-tokens when header is present", async () => {
@@ -38,11 +38,11 @@ type ProviderResolutionParams = {
};
function firstRunWebSearchParams(): RunWebSearchParams | undefined {
return mocks.runWebSearch.mock.calls[0]?.[0] as RunWebSearchParams | undefined;
return mocks.runWebSearch.mock.calls.at(0)?.[0] as RunWebSearchParams | undefined;
}
function firstProviderResolutionParams(): ProviderResolutionParams | undefined {
return mocks.resolveManifestContractOwnerPluginId.mock.calls[0]?.[0] as
return mocks.resolveManifestContractOwnerPluginId.mock.calls.at(0)?.[0] as
| ProviderResolutionParams
| undefined;
}
+3 -2
View File
@@ -26,7 +26,8 @@ describe("web_search signal plumbing", () => {
await tool?.execute("call-search", { query: "openclaw" }, controller.signal);
expect(mocks.runWebSearch).toHaveBeenCalledTimes(1);
expect(mocks.runWebSearch.mock.calls[0]?.[0]?.args).toEqual({ query: "openclaw" });
expect(mocks.runWebSearch.mock.calls[0]?.[0]?.signal).toBe(controller.signal);
const params = mocks.runWebSearch.mock.calls.at(0)?.[0];
expect(params?.args).toEqual({ query: "openclaw" });
expect(params?.signal).toBe(controller.signal);
});
});
+2 -2
View File
@@ -344,7 +344,7 @@ describe("web_fetch extraction fallbacks", () => {
await tool?.execute?.("call", { url: "https://example.com/proxy" });
const requestInit = mockFetch.mock.calls[0]?.[1] as
const requestInit = mockFetch.mock.calls.at(0)?.[1] as
| (RequestInit & { dispatcher?: unknown })
| undefined;
const dispatcher = requestInit?.dispatcher;
@@ -372,7 +372,7 @@ describe("web_fetch extraction fallbacks", () => {
await tool?.execute?.("call", { url: "https://example.com/proxy" });
const requestInit = mockFetch.mock.calls[0]?.[1] as
const requestInit = mockFetch.mock.calls.at(0)?.[1] as
| (RequestInit & { dispatcher?: unknown })
| undefined;
const dispatcher = requestInit?.dispatcher;