feat: allow disabled_mcps to accept any MCP name (#513)
This commit is contained in:
136
src/config/schema.test.ts
Normal file
136
src/config/schema.test.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import { OhMyOpenCodeConfigSchema } from "./schema"
|
||||
|
||||
describe("disabled_mcps schema", () => {
|
||||
test("should accept built-in MCP names", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: ["context7", "grep_app"],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toEqual(["context7", "grep_app"])
|
||||
}
|
||||
})
|
||||
|
||||
test("should accept custom MCP names", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: ["playwright", "sqlite", "custom-mcp"],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toEqual(["playwright", "sqlite", "custom-mcp"])
|
||||
}
|
||||
})
|
||||
|
||||
test("should accept mixed built-in and custom names", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: ["context7", "playwright", "custom-server"],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toEqual(["context7", "playwright", "custom-server"])
|
||||
}
|
||||
})
|
||||
|
||||
test("should accept empty array", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: [],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toEqual([])
|
||||
}
|
||||
})
|
||||
|
||||
test("should reject non-string values", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: [123, true, null],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
test("should accept undefined (optional field)", () => {
|
||||
//#given
|
||||
const config = {}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toBeUndefined()
|
||||
}
|
||||
})
|
||||
|
||||
test("should reject empty strings", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: [""],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(false)
|
||||
})
|
||||
|
||||
test("should accept MCP names with various naming patterns", () => {
|
||||
//#given
|
||||
const config = {
|
||||
disabled_mcps: [
|
||||
"my-custom-mcp",
|
||||
"my_custom_mcp",
|
||||
"myCustomMcp",
|
||||
"my.custom.mcp",
|
||||
"my-custom-mcp-123",
|
||||
],
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = OhMyOpenCodeConfigSchema.safeParse(config)
|
||||
|
||||
//#then
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data.disabled_mcps).toEqual([
|
||||
"my-custom-mcp",
|
||||
"my_custom_mcp",
|
||||
"myCustomMcp",
|
||||
"my.custom.mcp",
|
||||
"my-custom-mcp-123",
|
||||
])
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import { z } from "zod"
|
||||
import { McpNameSchema } from "../mcp/types"
|
||||
import { AnyMcpNameSchema, McpNameSchema } from "../mcp/types"
|
||||
|
||||
const PermissionValue = z.enum(["ask", "allow", "deny"])
|
||||
|
||||
@@ -234,7 +234,7 @@ export const RalphLoopConfigSchema = z.object({
|
||||
|
||||
export const OhMyOpenCodeConfigSchema = z.object({
|
||||
$schema: z.string().optional(),
|
||||
disabled_mcps: z.array(McpNameSchema).optional(),
|
||||
disabled_mcps: z.array(AnyMcpNameSchema).optional(),
|
||||
disabled_agents: z.array(BuiltinAgentNameSchema).optional(),
|
||||
disabled_skills: z.array(BuiltinSkillNameSchema).optional(),
|
||||
disabled_hooks: z.array(HookNameSchema).optional(),
|
||||
@@ -265,4 +265,4 @@ export type SkillsConfig = z.infer<typeof SkillsConfigSchema>
|
||||
export type SkillDefinition = z.infer<typeof SkillDefinitionSchema>
|
||||
export type RalphLoopConfig = z.infer<typeof RalphLoopConfigSchema>
|
||||
|
||||
export { McpNameSchema, type McpName } from "../mcp/types"
|
||||
export { AnyMcpNameSchema, type AnyMcpName, McpNameSchema, type McpName } from "../mcp/types"
|
||||
|
||||
Reference in New Issue
Block a user