|
8 | 8 | installJsonClient, |
9 | 9 | installTomlClient, |
10 | 10 | getMcpClientNames, |
| 11 | + getOpenCodeConfigPath, |
11 | 12 | } from "../src/utils/install-mcp.js"; |
12 | 13 |
|
13 | 14 | let tempDir: string; |
@@ -185,6 +186,50 @@ describe("upsertIntoJsonc", () => { |
185 | 186 | }); |
186 | 187 | }); |
187 | 188 |
|
| 189 | +describe("getOpenCodeConfigPath", () => { |
| 190 | + let originalXdgConfigHome: string | undefined; |
| 191 | + |
| 192 | + beforeEach(() => { |
| 193 | + originalXdgConfigHome = process.env.XDG_CONFIG_HOME; |
| 194 | + process.env.XDG_CONFIG_HOME = tempDir; |
| 195 | + }); |
| 196 | + |
| 197 | + afterEach(() => { |
| 198 | + if (originalXdgConfigHome === undefined) { |
| 199 | + delete process.env.XDG_CONFIG_HOME; |
| 200 | + } else { |
| 201 | + process.env.XDG_CONFIG_HOME = originalXdgConfigHome; |
| 202 | + } |
| 203 | + }); |
| 204 | + |
| 205 | + it("should prefer opencode.jsonc when both files exist", () => { |
| 206 | + const opencodeDir = path.join(tempDir, "opencode"); |
| 207 | + fs.mkdirSync(opencodeDir, { recursive: true }); |
| 208 | + fs.writeFileSync(path.join(opencodeDir, "opencode.json"), "{}"); |
| 209 | + fs.writeFileSync(path.join(opencodeDir, "opencode.jsonc"), "{}"); |
| 210 | + |
| 211 | + const result = getOpenCodeConfigPath(); |
| 212 | + |
| 213 | + expect(result).toBe(path.join(opencodeDir, "opencode.jsonc")); |
| 214 | + }); |
| 215 | + |
| 216 | + it("should use opencode.json when only it exists", () => { |
| 217 | + const opencodeDir = path.join(tempDir, "opencode"); |
| 218 | + fs.mkdirSync(opencodeDir, { recursive: true }); |
| 219 | + fs.writeFileSync(path.join(opencodeDir, "opencode.json"), "{}"); |
| 220 | + |
| 221 | + const result = getOpenCodeConfigPath(); |
| 222 | + |
| 223 | + expect(result).toBe(path.join(opencodeDir, "opencode.json")); |
| 224 | + }); |
| 225 | + |
| 226 | + it("should default to opencode.jsonc when neither file exists", () => { |
| 227 | + const result = getOpenCodeConfigPath(); |
| 228 | + |
| 229 | + expect(result).toBe(path.join(tempDir, "opencode", "opencode.jsonc")); |
| 230 | + }); |
| 231 | +}); |
| 232 | + |
188 | 233 | describe("installTomlClient", () => { |
189 | 234 | it("should create a new TOML file when none exists", () => { |
190 | 235 | const client = makeTomlClient(); |
|
0 commit comments