a695730891
Previously, when websearch was configured with Tavily provider and the TAVILY_API_KEY environment variable was not set, the entire plugin would fail to load with no visible error to the user. Changes: 1. createWebsearchConfig now returns undefined when Tavily key is missing 2. Added warning log: '[websearch] Tavily API key not found, skipping websearch MCP' 3. createBuiltinMcps now skips undefined configs instead of adding them 4. Added tests for both missing and present Tavily API key scenarios Fixes #2996
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
/// <reference types="bun-types" />
|
|
|
|
import { describe, test, expect, spyOn, beforeEach, afterEach } from "bun:test"
|
|
import { createWebsearchConfig } from "./websearch"
|
|
import * as shared from "../shared"
|
|
|
|
let logSpy: ReturnType<typeof spyOn>
|
|
|
|
beforeEach(() => {
|
|
logSpy = spyOn(shared, "log").mockImplementation(() => {})
|
|
})
|
|
|
|
afterEach(() => {
|
|
logSpy.mockRestore()
|
|
})
|
|
|
|
describe("createWebsearchConfig Tavily handling", () => {
|
|
test("returns undefined when Tavily API key is missing", () => {
|
|
const originalEnv = process.env.TAVILY_API_KEY
|
|
delete process.env.TAVILY_API_KEY
|
|
|
|
const config = createWebsearchConfig({ provider: "tavily" })
|
|
|
|
expect(config).toBeUndefined()
|
|
expect(logSpy).toHaveBeenCalledWith("[websearch] Tavily API key not found, skipping websearch MCP")
|
|
|
|
if (originalEnv) {
|
|
process.env.TAVILY_API_KEY = originalEnv
|
|
}
|
|
})
|
|
|
|
test("returns valid config when Tavily API key is present", () => {
|
|
const originalEnv = process.env.TAVILY_API_KEY
|
|
process.env.TAVILY_API_KEY = "test-key"
|
|
|
|
const config = createWebsearchConfig({ provider: "tavily" })
|
|
|
|
expect(config).toBeDefined()
|
|
expect(config?.type).toBe("remote")
|
|
expect(config?.url).toBe("https://mcp.tavily.com/mcp/")
|
|
|
|
if (originalEnv) {
|
|
process.env.TAVILY_API_KEY = originalEnv
|
|
} else {
|
|
delete process.env.TAVILY_API_KEY
|
|
}
|
|
})
|
|
})
|