Merge pull request #2546 from acamq/fix/installer-paths

fix(installer): always use .config/opencode for CLI on Windows (#2502)
This commit is contained in:
acamq
2026-03-15 17:44:39 -06:00
committed by GitHub
2 changed files with 16 additions and 19 deletions

View File

@@ -183,6 +183,7 @@ describe("opencode-config-dir", () => {
// given opencode CLI binary detected, platform is Windows
Object.defineProperty(process, "platform", { value: "win32" })
delete process.env.APPDATA
delete process.env.XDG_CONFIG_HOME
delete process.env.OPENCODE_CONFIG_DIR
// when getOpenCodeConfigDir is called with binary="opencode"
@@ -191,6 +192,21 @@ describe("opencode-config-dir", () => {
// then returns ~/.config/opencode (cross-platform default)
expect(result).toBe(join(homedir(), ".config", "opencode"))
})
test("returns ~/.config/opencode on Windows even when APPDATA is set (#2502)", () => {
// given opencode CLI binary detected, platform is Windows with APPDATA set
// (regression test: previously would check AppData for existing config)
Object.defineProperty(process, "platform", { value: "win32" })
process.env.APPDATA = "C:\\Users\\TestUser\\AppData\\Roaming"
delete process.env.XDG_CONFIG_HOME
delete process.env.OPENCODE_CONFIG_DIR
// when getOpenCodeConfigDir is called with binary="opencode"
const result = getOpenCodeConfigDir({ binary: "opencode", version: "1.0.200", checkExisting: false })
// then returns ~/.config/opencode (ignores APPDATA entirely for CLI)
expect(result).toBe(join(homedir(), ".config", "opencode"))
})
})
describe("for opencode-desktop Tauri binary", () => {

View File

@@ -48,25 +48,6 @@ function getCliConfigDir(): string {
return resolve(envConfigDir)
}
if (process.platform === "win32") {
const crossPlatformDir = join(homedir(), ".config", "opencode")
const crossPlatformConfig = join(crossPlatformDir, "opencode.json")
if (existsSync(crossPlatformConfig)) {
return crossPlatformDir
}
const appData = process.env.APPDATA || join(homedir(), "AppData", "Roaming")
const appdataDir = join(appData, "opencode")
const appdataConfig = join(appdataDir, "opencode.json")
if (existsSync(appdataConfig)) {
return appdataDir
}
return crossPlatformDir
}
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config")
return join(xdgConfig, "opencode")
}