test(tools): update MCP, delegate-task, skill, and slashcommand tests
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
+24
-16
@@ -1,36 +1,50 @@
|
||||
/// <reference types="bun-types" />
|
||||
|
||||
import { describe, test, expect, spyOn, beforeEach, afterEach } from "bun:test"
|
||||
import { createWebsearchConfig } from "./websearch"
|
||||
import * as shared from "../shared"
|
||||
import * as logger from "../shared/logger"
|
||||
|
||||
let logSpy: ReturnType<typeof spyOn>
|
||||
let createWebsearchConfig: (typeof import("./websearch"))["createWebsearchConfig"]
|
||||
let originalEnv: Record<"EXA_API_KEY" | "TAVILY_API_KEY", string | undefined>
|
||||
|
||||
beforeEach(() => {
|
||||
logSpy = spyOn(shared, "log").mockImplementation(() => {})
|
||||
async function importFreshWebsearchModule(): Promise<typeof import("./websearch")> {
|
||||
return import(`./websearch?test=${Date.now()}-${Math.random()}`)
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
originalEnv = {
|
||||
EXA_API_KEY: process.env.EXA_API_KEY,
|
||||
TAVILY_API_KEY: process.env.TAVILY_API_KEY,
|
||||
}
|
||||
delete process.env.EXA_API_KEY
|
||||
delete process.env.TAVILY_API_KEY
|
||||
logSpy = spyOn(logger, "log").mockImplementation(() => {})
|
||||
;({ createWebsearchConfig } = await importFreshWebsearchModule())
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
logSpy.mockRestore()
|
||||
for (const [key, value] of Object.entries(originalEnv)) {
|
||||
if (value === undefined) {
|
||||
delete process.env[key]
|
||||
continue
|
||||
}
|
||||
|
||||
process.env[key] = value
|
||||
}
|
||||
})
|
||||
|
||||
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" })
|
||||
@@ -38,11 +52,5 @@ describe("createWebsearchConfig Tavily handling", () => {
|
||||
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
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user