merge: sync Kilo runtime branch with latest main
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
/**
|
||||
* GSD Tools Tests - OpenCode permission config
|
||||
* Regression tests for OpenCode permission config handling.
|
||||
*
|
||||
* Regression tests for OpenCode permission handling, including the valid
|
||||
* top-level string form: "permission": "allow".
|
||||
* Ensures the installer does not crash when opencode.json uses the valid
|
||||
* top-level string form: "permission": "allow", and that path-specific
|
||||
* permissions are written against the actual resolved install directory.
|
||||
*/
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
@@ -17,6 +18,19 @@ const { configureOpencodePermissions } = require('../bin/install.js');
|
||||
|
||||
const installSrc = fs.readFileSync(path.join(__dirname, '..', 'bin', 'install.js'), 'utf8');
|
||||
|
||||
const envKeys = ['OPENCODE_CONFIG_DIR', 'OPENCODE_CONFIG', 'XDG_CONFIG_HOME'];
|
||||
const originalEnv = Object.fromEntries(envKeys.map((key) => [key, process.env[key]]));
|
||||
|
||||
function restoreEnv(snapshot) {
|
||||
for (const key of envKeys) {
|
||||
if (snapshot[key] === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = snapshot[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('configureOpencodePermissions', () => {
|
||||
let configDir;
|
||||
|
||||
@@ -26,9 +40,10 @@ describe('configureOpencodePermissions', () => {
|
||||
|
||||
afterEach(() => {
|
||||
cleanup(configDir);
|
||||
restoreEnv(originalEnv);
|
||||
});
|
||||
|
||||
test('does not rewrite top-level string permissions', () => {
|
||||
test('does not crash or rewrite top-level string permissions', () => {
|
||||
const configPath = path.join(configDir, 'opencode.json');
|
||||
const original = JSON.stringify({
|
||||
$schema: 'https://opencode.ai/config.json',
|
||||
@@ -37,6 +52,7 @@ describe('configureOpencodePermissions', () => {
|
||||
}, null, 2) + '\n';
|
||||
|
||||
fs.writeFileSync(configPath, original);
|
||||
process.env.OPENCODE_CONFIG_DIR = configDir;
|
||||
|
||||
assert.doesNotThrow(() => configureOpencodePermissions(true, configDir));
|
||||
assert.strictEqual(fs.readFileSync(configPath, 'utf8'), original);
|
||||
@@ -45,6 +61,7 @@ describe('configureOpencodePermissions', () => {
|
||||
test('adds path-specific read and external_directory permissions for object configs', () => {
|
||||
const configPath = path.join(configDir, 'opencode.json');
|
||||
fs.writeFileSync(configPath, JSON.stringify({ permission: {} }, null, 2) + '\n');
|
||||
process.env.OPENCODE_CONFIG_DIR = configDir;
|
||||
|
||||
configureOpencodePermissions(true, configDir);
|
||||
|
||||
@@ -56,6 +73,9 @@ describe('configureOpencodePermissions', () => {
|
||||
});
|
||||
|
||||
test('finishInstall passes the actual config dir to OpenCode permissions', () => {
|
||||
assert.ok(installSrc.includes('configureOpencodePermissions(isGlobal, configDir);'), 'OpenCode permission config uses actual install dir');
|
||||
assert.ok(
|
||||
installSrc.includes('configureOpencodePermissions(isGlobal, configDir);'),
|
||||
'OpenCode permission config uses actual install dir'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user