* fix(#2831): expand HOME in OpenCode skill/template paths OpenCode does not shell-expand $HOME in @file references on any platform — the literal `@$HOME/...` path is resolved relative to the config command/ dir, producing `command/$HOME/...` (file not found). The previous fix for #2376 only guarded Windows; extend to all platforms. Closes #2831 * test(#2831): assert behavior via exported computePathPrefix, not source grep Addresses CodeRabbit review on PR #2842: - Extracts pathPrefix logic into a named, test-exported computePathPrefix helper in bin/install.js (no behavior change at the call site). - Rewrites bug-2376 and bug-2831 regression tests to call the exported function directly instead of regex-matching install.js source text, per the repo's no-source-grep testing standard. - Wraps temp-dir test setup in try/finally so cleanup runs on assertion failures (no leaked tmp dirs).
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
/**
|
|
* Regression test for #2376: @$HOME not correctly mapped in OpenCode on Windows.
|
|
*
|
|
* On Windows, $HOME is not expanded by PowerShell/cmd.exe, so OpenCode cannot
|
|
* resolve @$HOME/... file references in installed command files.
|
|
*
|
|
* Fix: install.js must use the absolute path (not $HOME-relative) when installing
|
|
* for OpenCode. (Generalized to all platforms in #2831 — OpenCode `@file`
|
|
* references are not shell-expanded on any platform.)
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const { describe, test, before, after } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
let computePathPrefix;
|
|
|
|
before(() => {
|
|
process.env.GSD_TEST_MODE = '1';
|
|
// Re-require fresh in case other tests already loaded it.
|
|
delete require.cache[require.resolve('../bin/install.js')];
|
|
({ computePathPrefix } = require('../bin/install.js'));
|
|
});
|
|
|
|
after(() => {
|
|
delete process.env.GSD_TEST_MODE;
|
|
});
|
|
|
|
describe('bug-2376: OpenCode on Windows must use absolute path, not $HOME', () => {
|
|
test('computePathPrefix is exported by install.js', () => {
|
|
assert.equal(typeof computePathPrefix, 'function');
|
|
});
|
|
|
|
test('OpenCode on Windows: pathPrefix is absolute (no $HOME substitution)', () => {
|
|
const pathPrefix = computePathPrefix({
|
|
isGlobal: true,
|
|
isOpencode: true,
|
|
isWindowsHost: true,
|
|
resolvedTarget: 'C:/Users/user/.config/opencode',
|
|
homeDir: 'C:/Users/user',
|
|
});
|
|
assert.strictEqual(pathPrefix, 'C:/Users/user/.config/opencode/');
|
|
assert.ok(!pathPrefix.includes('$HOME'));
|
|
});
|
|
|
|
test('Claude Code on Windows: pathPrefix still uses $HOME (unaffected)', () => {
|
|
const pathPrefix = computePathPrefix({
|
|
isGlobal: true,
|
|
isOpencode: false,
|
|
isWindowsHost: true,
|
|
resolvedTarget: 'C:/Users/user/.claude',
|
|
homeDir: 'C:/Users/user',
|
|
});
|
|
assert.strictEqual(pathPrefix, '$HOME/.claude/');
|
|
});
|
|
});
|