2026-04-02 13:32:44 +09:00
|
|
|
/// <reference types="bun-types" />
|
2026-02-02 03:36:55 +08:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
import { describe, test, expect, spyOn, beforeEach, afterEach } from "bun:test"
|
|
|
|
|
import { createWebsearchConfig } from "./websearch"
|
|
|
|
|
import * as shared from "../shared"
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
let logSpy: ReturnType<typeof spyOn>
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
beforeEach(() => {
|
|
|
|
|
logSpy = spyOn(shared, "log").mockImplementation(() => {})
|
|
|
|
|
})
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
afterEach(() => {
|
|
|
|
|
logSpy.mockRestore()
|
|
|
|
|
})
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
describe("createWebsearchConfig Tavily handling", () => {
|
|
|
|
|
test("returns undefined when Tavily API key is missing", () => {
|
|
|
|
|
const originalEnv = process.env.TAVILY_API_KEY
|
2026-02-08 15:28:31 +09:00
|
|
|
delete process.env.TAVILY_API_KEY
|
|
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
const config = createWebsearchConfig({ provider: "tavily" })
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
expect(config).toBeUndefined()
|
|
|
|
|
expect(logSpy).toHaveBeenCalledWith("[websearch] Tavily API key not found, skipping websearch MCP")
|
2026-02-08 14:19:50 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
if (originalEnv) {
|
|
|
|
|
process.env.TAVILY_API_KEY = originalEnv
|
|
|
|
|
}
|
2026-02-08 15:28:31 +09:00
|
|
|
})
|
|
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
test("returns valid config when Tavily API key is present", () => {
|
|
|
|
|
const originalEnv = process.env.TAVILY_API_KEY
|
|
|
|
|
process.env.TAVILY_API_KEY = "test-key"
|
2026-02-02 03:36:55 +08:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
const config = createWebsearchConfig({ provider: "tavily" })
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
expect(config).toBeDefined()
|
|
|
|
|
expect(config?.type).toBe("remote")
|
|
|
|
|
expect(config?.url).toBe("https://mcp.tavily.com/mcp/")
|
2026-02-08 15:28:31 +09:00
|
|
|
|
2026-04-02 13:32:44 +09:00
|
|
|
if (originalEnv) {
|
|
|
|
|
process.env.TAVILY_API_KEY = originalEnv
|
|
|
|
|
} else {
|
|
|
|
|
delete process.env.TAVILY_API_KEY
|
|
|
|
|
}
|
2026-02-02 03:36:55 +08:00
|
|
|
})
|
|
|
|
|
})
|