initial commit
This commit is contained in:
70
src/tools/web-fetch.test.ts
Normal file
70
src/tools/web-fetch.test.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createWebFetchTool } from "./web-fetch.ts";
|
||||
|
||||
test("web_fetch prepareArguments folds a single url into urls", () => {
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async () => {
|
||||
throw new Error("not used");
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(tool.prepareArguments?.({ url: "https://exa.ai/docs" }), {
|
||||
url: "https://exa.ai/docs",
|
||||
urls: ["https://exa.ai/docs"],
|
||||
});
|
||||
});
|
||||
|
||||
test("web_fetch forwards nested Tavily extract options to the runtime", async () => {
|
||||
let capturedRequest: any;
|
||||
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async (request) => {
|
||||
capturedRequest = request;
|
||||
return {
|
||||
providerName: "tavily-main",
|
||||
results: [
|
||||
{
|
||||
url: "https://pi.dev",
|
||||
title: "Docs",
|
||||
text: "Body",
|
||||
},
|
||||
],
|
||||
execution: { actualProviderName: "tavily-main" },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tool.execute(
|
||||
"tool-1",
|
||||
{
|
||||
urls: ["https://pi.dev"],
|
||||
tavily: {
|
||||
query: "installation",
|
||||
extractDepth: "advanced",
|
||||
includeImages: true,
|
||||
},
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
|
||||
assert.equal(capturedRequest.tavily.query, "installation");
|
||||
assert.equal(capturedRequest.tavily.extractDepth, "advanced");
|
||||
assert.equal(capturedRequest.text, true);
|
||||
assert.match((result.content[0] as { text: string }).text, /Body/);
|
||||
});
|
||||
|
||||
test("web_fetch rejects malformed URLs", async () => {
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async () => {
|
||||
throw new Error("should not execute fetch for invalid URLs");
|
||||
},
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
() => tool.execute("tool-1", { urls: ["not-a-url"] }, undefined, undefined, undefined),
|
||||
/Invalid URL/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user