|
|
@@ -1446,159 +1446,131 @@ test("config parser preserves permission order while rejecting unknown top-level
|
|
|
|
|
|
// MCP config merging tests
|
|
|
|
|
|
-test("project config can override MCP server enabled status", async () => {
|
|
|
- await using tmp = await tmpdir({
|
|
|
- init: async (dir) => {
|
|
|
- // Simulates a base config (like from remote .well-known) with disabled MCP
|
|
|
- await Filesystem.write(
|
|
|
- path.join(dir, "opencode.json"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- jira: {
|
|
|
- type: "remote",
|
|
|
- url: "https://jira.example.com/mcp",
|
|
|
- enabled: false,
|
|
|
- },
|
|
|
- wiki: {
|
|
|
- type: "remote",
|
|
|
- url: "https://wiki.example.com/mcp",
|
|
|
- enabled: false,
|
|
|
- },
|
|
|
- },
|
|
|
- }),
|
|
|
- )
|
|
|
- // Project config enables just jira
|
|
|
- await Filesystem.write(
|
|
|
- path.join(dir, "opencode.jsonc"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- jira: {
|
|
|
- type: "remote",
|
|
|
- url: "https://jira.example.com/mcp",
|
|
|
- enabled: true,
|
|
|
- },
|
|
|
+it.instance("project config can override MCP server enabled status", () =>
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const test = yield* TestInstance
|
|
|
+ // Simulates a base config (like from remote .well-known) with disabled MCP.
|
|
|
+ yield* writeConfigEffect(test.directory, {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ jira: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://jira.example.com/mcp",
|
|
|
+ enabled: false,
|
|
|
+ },
|
|
|
+ wiki: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://wiki.example.com/mcp",
|
|
|
+ enabled: false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ // Project config enables just jira.
|
|
|
+ yield* writeConfigEffect(
|
|
|
+ test.directory,
|
|
|
+ {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ jira: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://jira.example.com/mcp",
|
|
|
+ enabled: true,
|
|
|
},
|
|
|
- }),
|
|
|
- )
|
|
|
- },
|
|
|
- })
|
|
|
- await withTestInstance({
|
|
|
- directory: tmp.path,
|
|
|
- fn: async (ctx) => {
|
|
|
- const config = await load(ctx)
|
|
|
- // jira should be enabled (overridden by project config)
|
|
|
- expect(config.mcp?.jira).toEqual({
|
|
|
- type: "remote",
|
|
|
- url: "https://jira.example.com/mcp",
|
|
|
- enabled: true,
|
|
|
- })
|
|
|
- // wiki should still be disabled (not overridden)
|
|
|
- expect(config.mcp?.wiki).toEqual({
|
|
|
- type: "remote",
|
|
|
- url: "https://wiki.example.com/mcp",
|
|
|
- enabled: false,
|
|
|
- })
|
|
|
- },
|
|
|
- })
|
|
|
-})
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "opencode.jsonc",
|
|
|
+ )
|
|
|
|
|
|
-test("MCP config deep merges preserving base config properties", async () => {
|
|
|
- await using tmp = await tmpdir({
|
|
|
- init: async (dir) => {
|
|
|
- // Base config with full MCP definition
|
|
|
- await Filesystem.write(
|
|
|
- path.join(dir, "opencode.json"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- myserver: {
|
|
|
- type: "remote",
|
|
|
- url: "https://myserver.example.com/mcp",
|
|
|
- enabled: false,
|
|
|
- headers: {
|
|
|
- "X-Custom-Header": "value",
|
|
|
- },
|
|
|
- },
|
|
|
+ const config = yield* Config.Service.use((svc) => svc.get())
|
|
|
+ expect(config.mcp?.jira).toEqual({
|
|
|
+ type: "remote",
|
|
|
+ url: "https://jira.example.com/mcp",
|
|
|
+ enabled: true,
|
|
|
+ })
|
|
|
+ expect(config.mcp?.wiki).toEqual({
|
|
|
+ type: "remote",
|
|
|
+ url: "https://wiki.example.com/mcp",
|
|
|
+ enabled: false,
|
|
|
+ })
|
|
|
+ }),
|
|
|
+)
|
|
|
+
|
|
|
+it.instance("MCP config deep merges preserving base config properties", () =>
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const test = yield* TestInstance
|
|
|
+ yield* writeConfigEffect(test.directory, {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ myserver: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://myserver.example.com/mcp",
|
|
|
+ enabled: false,
|
|
|
+ headers: {
|
|
|
+ "X-Custom-Header": "value",
|
|
|
},
|
|
|
- }),
|
|
|
- )
|
|
|
- // Override just enables it, should preserve other properties
|
|
|
- await Filesystem.write(
|
|
|
- path.join(dir, "opencode.jsonc"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- myserver: {
|
|
|
- type: "remote",
|
|
|
- url: "https://myserver.example.com/mcp",
|
|
|
- enabled: true,
|
|
|
- },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ yield* writeConfigEffect(
|
|
|
+ test.directory,
|
|
|
+ {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ myserver: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://myserver.example.com/mcp",
|
|
|
+ enabled: true,
|
|
|
},
|
|
|
- }),
|
|
|
- )
|
|
|
- },
|
|
|
- })
|
|
|
- await withTestInstance({
|
|
|
- directory: tmp.path,
|
|
|
- fn: async (ctx) => {
|
|
|
- const config = await load(ctx)
|
|
|
- expect(config.mcp?.myserver).toEqual({
|
|
|
- type: "remote",
|
|
|
- url: "https://myserver.example.com/mcp",
|
|
|
- enabled: true,
|
|
|
- headers: {
|
|
|
- "X-Custom-Header": "value",
|
|
|
},
|
|
|
- })
|
|
|
- },
|
|
|
- })
|
|
|
-})
|
|
|
+ },
|
|
|
+ "opencode.jsonc",
|
|
|
+ )
|
|
|
|
|
|
-test("local .opencode config can override MCP from project config", async () => {
|
|
|
- await using tmp = await tmpdir({
|
|
|
- init: async (dir) => {
|
|
|
- // Project config with disabled MCP
|
|
|
- await Filesystem.write(
|
|
|
- path.join(dir, "opencode.json"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- docs: {
|
|
|
- type: "remote",
|
|
|
- url: "https://docs.example.com/mcp",
|
|
|
- enabled: false,
|
|
|
- },
|
|
|
- },
|
|
|
- }),
|
|
|
- )
|
|
|
- // Local .opencode directory config enables it
|
|
|
- const opencodeDir = path.join(dir, ".opencode")
|
|
|
- await fs.mkdir(opencodeDir, { recursive: true })
|
|
|
- await Filesystem.write(
|
|
|
- path.join(opencodeDir, "opencode.json"),
|
|
|
- JSON.stringify({
|
|
|
- $schema: "https://opencode.ai/config.json",
|
|
|
- mcp: {
|
|
|
- docs: {
|
|
|
- type: "remote",
|
|
|
- url: "https://docs.example.com/mcp",
|
|
|
- enabled: true,
|
|
|
- },
|
|
|
+ const config = yield* Config.Service.use((svc) => svc.get())
|
|
|
+ expect(config.mcp?.myserver).toEqual({
|
|
|
+ type: "remote",
|
|
|
+ url: "https://myserver.example.com/mcp",
|
|
|
+ enabled: true,
|
|
|
+ headers: {
|
|
|
+ "X-Custom-Header": "value",
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }),
|
|
|
+)
|
|
|
+
|
|
|
+it.instance("local .opencode config can override MCP from project config", () =>
|
|
|
+ Effect.gen(function* () {
|
|
|
+ const test = yield* TestInstance
|
|
|
+ yield* writeConfigEffect(test.directory, {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ docs: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://docs.example.com/mcp",
|
|
|
+ enabled: false,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+ yield* mkdirEffect(path.join(test.directory, ".opencode"))
|
|
|
+ yield* writeConfigEffect(
|
|
|
+ path.join(test.directory, ".opencode"),
|
|
|
+ {
|
|
|
+ $schema: "https://opencode.ai/config.json",
|
|
|
+ mcp: {
|
|
|
+ docs: {
|
|
|
+ type: "remote",
|
|
|
+ url: "https://docs.example.com/mcp",
|
|
|
+ enabled: true,
|
|
|
},
|
|
|
- }),
|
|
|
- )
|
|
|
- },
|
|
|
- })
|
|
|
- await withTestInstance({
|
|
|
- directory: tmp.path,
|
|
|
- fn: async (ctx) => {
|
|
|
- const config = await load(ctx)
|
|
|
- expect(config.mcp?.docs?.enabled).toBe(true)
|
|
|
- },
|
|
|
- })
|
|
|
-})
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "opencode.json",
|
|
|
+ )
|
|
|
+
|
|
|
+ const config = yield* Config.Service.use((svc) => svc.get())
|
|
|
+ expect(config.mcp?.docs?.enabled).toBe(true)
|
|
|
+ }),
|
|
|
+)
|
|
|
|
|
|
test("project config overrides remote well-known config", async () => {
|
|
|
const originalFetch = globalThis.fetch
|