Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions __tests__/installer-targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ function setHome(dir: string): { restore: () => void } {
};
}

function setPlatform(platform: NodeJS.Platform): { restore: () => void } {
const previous = Object.getOwnPropertyDescriptor(process, 'platform');
Object.defineProperty(process, 'platform', { value: platform });
return {
restore() {
if (previous) Object.defineProperty(process, 'platform', previous);
},
};
}

describe('Installer targets — contract', () => {
let tmpHome: string;
let tmpCwd: string;
Expand Down Expand Up @@ -233,6 +243,33 @@ describe('Installer targets — partial-state idempotency', () => {
expect(result.files[0].action).toBe('created');
});

it('opencode: Windows global install uses ~/.config/opencode instead of APPDATA', () => {
const platform = setPlatform('win32');
const appData = path.join(tmpHome, 'AppData', 'Roaming');
const prevAppData = process.env.APPDATA;
const prevXdgConfigHome = process.env.XDG_CONFIG_HOME;
process.env.APPDATA = appData;
delete process.env.XDG_CONFIG_HOME;

try {
const opencode = getTarget('opencode')!;
const result = opencode.install('global', { autoAllow: true });
const configFile = path.join(tmpHome, '.config', 'opencode', 'opencode.jsonc');
const instructionsFile = path.join(tmpHome, '.config', 'opencode', 'AGENTS.md');
const appDataConfigFile = path.join(appData, 'opencode', 'opencode.jsonc');

expect(result.files.map((f) => f.path)).toContain(configFile);
expect(result.files.map((f) => f.path)).toContain(instructionsFile);
expect(fs.existsSync(configFile)).toBe(true);
expect(fs.existsSync(instructionsFile)).toBe(true);
expect(fs.existsSync(appDataConfigFile)).toBe(false);
} finally {
platform.restore();
if (prevAppData === undefined) delete process.env.APPDATA; else process.env.APPDATA = prevAppData;
if (prevXdgConfigHome === undefined) delete process.env.XDG_CONFIG_HOME; else process.env.XDG_CONFIG_HOME = prevXdgConfigHome;
}
});

it('opencode: preserves line and block comments through install + idempotent re-run', () => {
const opencode = getTarget('opencode')!;
const dir = path.join(tmpHome, '.config', 'opencode');
Expand Down Expand Up @@ -311,10 +348,10 @@ describe('Installer targets — partial-state idempotency', () => {
it('opencode: local install writes ./opencode.jsonc and ./AGENTS.md in cwd', () => {
const opencode = getTarget('opencode')!;
const result = opencode.install('local', { autoAllow: true });
const paths = result.files.map((f) => f.path.replace(/\\/g, '/'));
// macOS realpath shenanigans (/var vs /private/var) — suffix match.
expect(paths.some((p) => p.endsWith('/opencode.jsonc'))).toBe(true);
expect(paths.some((p) => p.endsWith('/AGENTS.md'))).toBe(true);
const paths = result.files.map((f) => f.path);
// Avoid absolute-path quirks (/var vs /private/var, or \ vs /).
expect(paths.some((p) => path.basename(p) === 'opencode.jsonc')).toBe(true);
expect(paths.some((p) => path.basename(p) === 'AGENTS.md')).toBe(true);
});

it('hermes: install adds codegraph MCP server and cli toolset, preserving existing yaml', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/installer/targets/opencode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* opencode target.
*
* - MCP server entry to `~/.config/opencode/opencode.jsonc` (global,
* XDG-style; `%APPDATA%/opencode/opencode.jsonc` on Windows) or
* XDG-style, including on Windows) or
* `./opencode.jsonc` (local). Falls back to `opencode.json` when a
* `.json` file already exists; defaults new installs to `.jsonc`
* because that's what opencode itself creates on first run.
Expand Down Expand Up @@ -50,11 +50,8 @@ import {
} from '../instructions-template';

function globalConfigDir(): string {
if (process.platform === 'win32') {
const appData = process.env.APPDATA ?? path.join(os.homedir(), 'AppData', 'Roaming');
return path.join(appData, 'opencode');
}
// XDG_CONFIG_HOME if set, else ~/.config — matches opencode's docs.
// OpenCode documents the same ~/.config/opencode global config path
// on Windows too; do not route Windows installs through APPDATA.
const xdg = process.env.XDG_CONFIG_HOME && process.env.XDG_CONFIG_HOME.trim().length > 0
? process.env.XDG_CONFIG_HOME
: path.join(os.homedir(), '.config');
Expand Down