Files
pi-web-search/src/tools/web-search.test.ts
2026-04-10 23:11:21 +01:00

56 lines
1.4 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { createWebSearchTool } from "./web-search.ts";
test("web_search forwards nested Tavily options to the runtime", async () => {
let capturedRequest: any;
const tool = createWebSearchTool({
executeSearch: async (request) => {
capturedRequest = request;
return {
providerName: "tavily-main",
results: [
{
title: "Docs",
url: "https://pi.dev",
},
],
execution: { actualProviderName: "tavily-main" },
};
},
});
const result = await tool.execute(
"tool-1",
{
query: "pi docs",
tavily: {
includeAnswer: true,
includeRawContent: true,
searchDepth: "advanced",
},
},
undefined,
undefined,
undefined,
);
assert.equal(capturedRequest.tavily.includeAnswer, true);
assert.equal(capturedRequest.tavily.searchDepth, "advanced");
assert.match((result.content[0] as { text: string }).text, /Docs/);
});
test("web_search rejects a blank query before resolving a provider", async () => {
const tool = createWebSearchTool({
executeSearch: async () => {
throw new Error("should not execute search for a blank query");
},
});
await assert.rejects(
() => tool.execute("tool-1", { query: " " }, undefined, undefined, undefined),
/non-empty query/,
);
});