|
1 | 1 | import { describe, it, expect } from "bun:test"; |
2 | | -import { mkdtempSync, readFileSync, realpathSync, rmSync, mkdirSync, existsSync } from "fs"; |
| 2 | +import { mkdtempSync, readFileSync, realpathSync, rmSync, mkdirSync, existsSync, symlinkSync } from "fs"; |
3 | 3 | import { tmpdir } from "os"; |
4 | 4 | import { join } from "path"; |
5 | 5 | import { CursorPlugin } from "../../src/plugin"; |
@@ -197,4 +197,45 @@ describe("Plugin tool hook", () => { |
197 | 197 | rmSync(unexpectedDir, { recursive: true, force: true }); |
198 | 198 | } |
199 | 199 | }); |
| 200 | + |
| 201 | + it("treats config path aliases (symlink/case variants) as config and falls back to workspace", async () => { |
| 202 | + const projectDir = mkdtempSync(join(tmpdir(), "plugin-hook-config-alias-project-")); |
| 203 | + const xdgConfigHome = mkdtempSync(join(tmpdir(), "plugin-hook-config-alias-xdg-")); |
| 204 | + const aliasParentDir = mkdtempSync(join(tmpdir(), "plugin-hook-config-alias-parent-")); |
| 205 | + const aliasXdgHome = join(aliasParentDir, "xdg-home-alias"); |
| 206 | + const prevXdg = process.env.XDG_CONFIG_HOME; |
| 207 | + |
| 208 | + try { |
| 209 | + process.env.XDG_CONFIG_HOME = xdgConfigHome; |
| 210 | + symlinkSync(xdgConfigHome, aliasXdgHome); |
| 211 | + |
| 212 | + const configDir = join(xdgConfigHome, "opencode"); |
| 213 | + mkdirSync(configDir, { recursive: true }); |
| 214 | + |
| 215 | + const aliasConfigDir = join(aliasXdgHome, "opencode"); |
| 216 | + const filename = `symlink-alias-${Date.now()}.txt`; |
| 217 | + |
| 218 | + const hooks = await CursorPlugin(createMockInput(configDir, projectDir)); |
| 219 | + const out = await hooks.tool?.write?.execute( |
| 220 | + { path: `nested/${filename}`, content: "alias fallback" }, |
| 221 | + createToolContext(aliasConfigDir, undefined, "session-alias-1"), |
| 222 | + ); |
| 223 | + |
| 224 | + const expectedPath = join(projectDir, `nested/${filename}`); |
| 225 | + const unexpectedPath = join(configDir, `nested/${filename}`); |
| 226 | + |
| 227 | + expect(readFileSync(expectedPath, "utf-8")).toBe("alias fallback"); |
| 228 | + expect(out).toContain(expectedPath); |
| 229 | + expect(existsSync(unexpectedPath)).toBe(false); |
| 230 | + } finally { |
| 231 | + if (prevXdg === undefined) { |
| 232 | + delete process.env.XDG_CONFIG_HOME; |
| 233 | + } else { |
| 234 | + process.env.XDG_CONFIG_HOME = prevXdg; |
| 235 | + } |
| 236 | + rmSync(projectDir, { recursive: true, force: true }); |
| 237 | + rmSync(xdgConfigHome, { recursive: true, force: true }); |
| 238 | + rmSync(aliasParentDir, { recursive: true, force: true }); |
| 239 | + } |
| 240 | + }); |
200 | 241 | }); |
0 commit comments