mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 22:16:41 +00:00
- Simplify test files by removing custom TestRunner class - Use standard Node.js assert module across all unit tests - Update CLAUDE.md with streamlined development instructions - Update tests/README.md with current testing approach - Reduce boilerplate in delegation and GLMT test suites (652 lines removed)
124 lines
3.8 KiB
JavaScript
124 lines
3.8 KiB
JavaScript
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { SettingsParser } = require('../../../dist/delegation/settings-parser');
|
|
|
|
describe('SettingsParser', () => {
|
|
const testDir = path.join(os.tmpdir(), 'ccs-test-settings');
|
|
const claudeDir = path.join(testDir, '.claude');
|
|
|
|
function setupTestDir() {
|
|
if (fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true });
|
|
}
|
|
fs.mkdirSync(claudeDir, { recursive: true });
|
|
}
|
|
|
|
function cleanupTestDir() {
|
|
if (fs.existsSync(testDir)) {
|
|
fs.rmSync(testDir, { recursive: true });
|
|
}
|
|
}
|
|
|
|
beforeEach(() => {
|
|
setupTestDir();
|
|
});
|
|
|
|
after(() => {
|
|
cleanupTestDir();
|
|
});
|
|
|
|
describe('No settings files', () => {
|
|
it('returns empty arrays when no settings files', () => {
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 0);
|
|
assert.strictEqual(restrictions.disallowedTools.length, 0);
|
|
});
|
|
});
|
|
|
|
describe('Parse shared settings', () => {
|
|
it('parses shared settings.json', () => {
|
|
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
fs.writeFileSync(settingsPath, JSON.stringify({
|
|
permissions: {
|
|
allow: ['Bash(git:*)', 'Read'],
|
|
deny: ['Bash(rm:*)']
|
|
}
|
|
}));
|
|
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 2);
|
|
assert.strictEqual(restrictions.disallowedTools.length, 1);
|
|
assert.ok(restrictions.allowedTools.includes('Bash(git:*)'));
|
|
assert.ok(restrictions.disallowedTools.includes('Bash(rm:*)'));
|
|
});
|
|
});
|
|
|
|
describe('Local settings override', () => {
|
|
it('local settings override shared', () => {
|
|
fs.writeFileSync(path.join(claudeDir, 'settings.json'), JSON.stringify({
|
|
permissions: {
|
|
allow: ['Read'],
|
|
deny: []
|
|
}
|
|
}));
|
|
|
|
fs.writeFileSync(path.join(claudeDir, 'settings.local.json'), JSON.stringify({
|
|
permissions: {
|
|
allow: ['Bash(git:*)'],
|
|
deny: ['Bash(rm:*)']
|
|
}
|
|
}));
|
|
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 2);
|
|
assert.ok(restrictions.allowedTools.includes('Read'));
|
|
assert.ok(restrictions.allowedTools.includes('Bash(git:*)'));
|
|
assert.strictEqual(restrictions.disallowedTools.length, 1);
|
|
});
|
|
});
|
|
|
|
describe('Error handling', () => {
|
|
it('handles malformed JSON gracefully', () => {
|
|
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
fs.writeFileSync(settingsPath, '{ invalid json }');
|
|
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 0);
|
|
assert.strictEqual(restrictions.disallowedTools.length, 0);
|
|
});
|
|
|
|
it('handles settings without permissions key', () => {
|
|
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
fs.writeFileSync(settingsPath, JSON.stringify({
|
|
someOtherKey: 'value'
|
|
}));
|
|
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 0);
|
|
assert.strictEqual(restrictions.disallowedTools.length, 0);
|
|
});
|
|
|
|
it('handles empty permissions arrays', () => {
|
|
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
fs.writeFileSync(settingsPath, JSON.stringify({
|
|
permissions: {
|
|
allow: [],
|
|
deny: []
|
|
}
|
|
}));
|
|
|
|
const restrictions = SettingsParser.parseToolRestrictions(testDir);
|
|
|
|
assert.strictEqual(restrictions.allowedTools.length, 0);
|
|
assert.strictEqual(restrictions.disallowedTools.length, 0);
|
|
});
|
|
});
|
|
});
|