1import { describe, test, expect } from "bun:test";
2import { FetchError, ToolInputError } from "../src/util/errors.js";
3import { createWebSearchTool } from "../src/agent/tools/web-search.js";
4
5describe("web_search error handling (issue #11)", () => {
6 test("missing session token throws ToolInputError", async () => {
7 const tool = createWebSearchTool("");
8 await expect(tool.execute("id", { query: "test" })).rejects.toThrow(ToolInputError);
9 });
10
11 test("search API failure is wrapped as FetchError", async () => {
12 // Use a bogus token so the kagi API call fails
13 const tool = createWebSearchTool("invalid-token-xxx");
14 try {
15 await tool.execute("id", { query: "test query" });
16 // If it somehow succeeds (unlikely), that's fine
17 } catch (e: any) {
18 // After fix, errors from the search API should be wrapped as FetchError
19 expect(e).toBeInstanceOf(FetchError);
20 }
21 });
22});