diff --git a/tests/lib/install-targets.test.js b/tests/lib/install-targets.test.js index 7bd937733..e0ef595cc 100644 --- a/tests/lib/install-targets.test.js +++ b/tests/lib/install-targets.test.js @@ -668,6 +668,27 @@ function runTests() { ); })) passed++; else failed++; + if (test('opencode adapter isolates an explicit home from ambient config overrides', () => { + const adapter = getInstallTargetAdapter('opencode'); + const homeDir = '/Users/isolated'; + const originalRoot = process.env.OPENCODE_CONFIG_DIR; + const originalXdg = process.env.XDG_CONFIG_HOME; + + try { + process.env.OPENCODE_CONFIG_DIR = '/runner/global/opencode'; + process.env.XDG_CONFIG_HOME = '/runner/global/xdg'; + assert.strictEqual( + adapter.resolveRoot({ homeDir }), + path.join(homeDir, '.config', 'opencode') + ); + } finally { + if (originalRoot === undefined) delete process.env.OPENCODE_CONFIG_DIR; + else process.env.OPENCODE_CONFIG_DIR = originalRoot; + if (originalXdg === undefined) delete process.env.XDG_CONFIG_HOME; + else process.env.XDG_CONFIG_HOME = originalXdg; + } + })) passed++; else failed++; + if (test('qwen adapter supports lookup by target and adapter id', () => { const byTarget = getInstallTargetAdapter('qwen'); const byId = getInstallTargetAdapter('qwen-home'); diff --git a/tests/lib/mcp-inventory.test.js b/tests/lib/mcp-inventory.test.js index f6df78822..50a580432 100644 --- a/tests/lib/mcp-inventory.test.js +++ b/tests/lib/mcp-inventory.test.js @@ -216,6 +216,32 @@ test('opencode reader honors OPENCODE_CONFIG_DIR before XDG_CONFIG_HOME', () => assert.deepStrictEqual(xdg.map(record => record.name), ['xdg']); }); +test('opencode reader isolates an explicit home from ambient config overrides', () => { + const home = tmpHome(); + const configRoot = path.join(home, '.config', 'opencode'); + const ambientRoot = path.join(home, 'runner-global-opencode'); + fs.mkdirSync(configRoot, { recursive: true }); + fs.mkdirSync(ambientRoot, { recursive: true }); + fs.writeFileSync(path.join(configRoot, 'opencode.json'), JSON.stringify({ + mcp: { isolated: { type: 'local', command: ['node'] } }, + }), 'utf8'); + fs.writeFileSync(path.join(ambientRoot, 'opencode.json'), JSON.stringify({ + mcp: { leaked: { type: 'local', command: ['node'] } }, + }), 'utf8'); + const originalRoot = process.env.OPENCODE_CONFIG_DIR; + + try { + process.env.OPENCODE_CONFIG_DIR = ambientRoot; + assert.deepStrictEqual( + readOpencodeMcp({ homeDir: home }).map(record => record.name), + ['isolated'] + ); + } finally { + if (originalRoot === undefined) delete process.env.OPENCODE_CONFIG_DIR; + else process.env.OPENCODE_CONFIG_DIR = originalRoot; + } +}); + test('collectMcpInventory merges harnesses, detects fragmentation + drift, redacts secrets', () => { const home = tmpHome(); // claude + opencode agree on github (consistent); codex github uses a