test(opencode): reproduce ambient config leakage

This commit is contained in:
haelyra
2026-08-25 12:14:58 -04:00
parent c6cee0f3e2
commit 2331afbfd3
2 changed files with 47 additions and 0 deletions
+21
View File
@@ -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');
+26
View File
@@ -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