test: isolate skill-tools and mcp-index tests to prevent mock contamination
Moves test files with mock.module() calls into zauc-mocks-* directories to prevent process-global mock pollution affecting subsequent tests. - src/tools/skill/tools.test.ts -> zauc-mocks-skill-tools/ - src/mcp/index.test.ts -> zauc-mocks-mcp-index/ Fixes remaining 21 CI failures (resolveSubagentExecution + slashcommand).
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { createBuiltinMcps } from "./index"
|
||||
|
||||
describe("createBuiltinMcps", () => {
|
||||
test("should return all MCPs when disabled_mcps is empty", () => {
|
||||
// given
|
||||
const disabledMcps: string[] = []
|
||||
|
||||
// when
|
||||
const result = createBuiltinMcps(disabledMcps)
|
||||
|
||||
// then
|
||||
expect(result).toHaveProperty("websearch")
|
||||
expect(result).toHaveProperty("context7")
|
||||
expect(result).toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(3)
|
||||
})
|
||||
|
||||
test("should filter out disabled built-in MCPs", () => {
|
||||
// given
|
||||
const disabledMcps = ["context7"]
|
||||
|
||||
// when
|
||||
const result = createBuiltinMcps(disabledMcps)
|
||||
|
||||
// then
|
||||
expect(result).toHaveProperty("websearch")
|
||||
expect(result).not.toHaveProperty("context7")
|
||||
expect(result).toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(2)
|
||||
})
|
||||
|
||||
test("should filter out all built-in MCPs when all disabled", () => {
|
||||
// given
|
||||
const disabledMcps = ["websearch", "context7", "grep_app"]
|
||||
|
||||
// when
|
||||
const result = createBuiltinMcps(disabledMcps)
|
||||
|
||||
// then
|
||||
expect(result).not.toHaveProperty("websearch")
|
||||
expect(result).not.toHaveProperty("context7")
|
||||
expect(result).not.toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(0)
|
||||
})
|
||||
|
||||
test("should ignore custom MCP names in disabled_mcps", () => {
|
||||
// given
|
||||
const disabledMcps = ["context7", "playwright", "custom"]
|
||||
|
||||
// when
|
||||
const result = createBuiltinMcps(disabledMcps)
|
||||
|
||||
// then
|
||||
expect(result).toHaveProperty("websearch")
|
||||
expect(result).not.toHaveProperty("context7")
|
||||
expect(result).toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(2)
|
||||
})
|
||||
|
||||
test("should handle empty disabled_mcps by default", () => {
|
||||
// given
|
||||
// when
|
||||
const result = createBuiltinMcps()
|
||||
|
||||
// then
|
||||
expect(result).toHaveProperty("websearch")
|
||||
expect(result).toHaveProperty("context7")
|
||||
expect(result).toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(3)
|
||||
})
|
||||
|
||||
test("should only filter built-in MCPs, ignoring unknown names", () => {
|
||||
// given
|
||||
const disabledMcps = ["playwright", "sqlite", "unknown-mcp"]
|
||||
|
||||
// when
|
||||
const result = createBuiltinMcps(disabledMcps)
|
||||
|
||||
// then
|
||||
expect(result).toHaveProperty("websearch")
|
||||
expect(result).toHaveProperty("context7")
|
||||
expect(result).toHaveProperty("grep_app")
|
||||
expect(Object.keys(result)).toHaveLength(3)
|
||||
})
|
||||
|
||||
test("should not throw when websearch disabled even if tavily configured without API key", () => {
|
||||
// given
|
||||
const originalTavilyKey = process.env.TAVILY_API_KEY
|
||||
delete process.env.TAVILY_API_KEY
|
||||
const disabledMcps = ["websearch"]
|
||||
const config = { websearch: { provider: "tavily" as const } }
|
||||
|
||||
try {
|
||||
// when
|
||||
const createMcps = () => createBuiltinMcps(disabledMcps, config)
|
||||
|
||||
// then
|
||||
expect(createMcps).not.toThrow()
|
||||
const result = createMcps()
|
||||
expect(result).not.toHaveProperty("websearch")
|
||||
} finally {
|
||||
if (originalTavilyKey) process.env.TAVILY_API_KEY = originalTavilyKey
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user