feat(FN-3758): align web fetch test coverage and documentation
Aligns web fetch tool test coverage across multiple test suites and updates the agents documentation, with a patch changeset for `@runfusion/fusion`. Fusion-Task-Id: FN-3758
This commit is contained in:
43
packages/cli/src/__tests__/extension-web-fetch.test.ts
Normal file
43
packages/cli/src/__tests__/extension-web-fetch.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const fetchWebContentMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@fusion/engine", () => ({
|
||||
fetchWebContent: fetchWebContentMock,
|
||||
}));
|
||||
|
||||
import kbExtension from "../extension.js";
|
||||
|
||||
describe("extension fn_web_fetch", () => {
|
||||
it("registers and executes fn_web_fetch", async () => {
|
||||
const tools = new Map<string, any>();
|
||||
const api = {
|
||||
registerTool(def: any) {
|
||||
tools.set(def.name, def);
|
||||
},
|
||||
registerCommand: vi.fn(),
|
||||
registerShortcut: vi.fn(),
|
||||
registerFlag: vi.fn(),
|
||||
on: vi.fn(),
|
||||
} as any;
|
||||
|
||||
fetchWebContentMock.mockResolvedValue({
|
||||
finalUrl: "https://example.com/final",
|
||||
status: 200,
|
||||
contentType: "text/plain",
|
||||
title: "Example",
|
||||
content: "hello world",
|
||||
truncated: false,
|
||||
bytesRead: 11,
|
||||
});
|
||||
|
||||
kbExtension(api);
|
||||
const tool = tools.get("fn_web_fetch");
|
||||
expect(tool).toBeTruthy();
|
||||
|
||||
const result = await tool.execute("id", { url: "https://example.com" }, undefined, undefined, { cwd: process.cwd() });
|
||||
expect(fetchWebContentMock).toHaveBeenCalledWith("https://example.com", { timeoutMs: undefined, maxBytes: undefined });
|
||||
expect(result.content[0].text).toContain("https://example.com/final");
|
||||
expect(result.details.status).toBe(200);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user