initial commit
This commit is contained in:
55
src/tools/web-search.test.ts
Normal file
55
src/tools/web-search.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
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/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user