Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix(installer): reject invalid claude settings roots

Affaan Mustafad7e6bb242aed
diff --git a/scripts/lib/install/apply.js b/scripts/lib/install/apply.js
index 26fce135c..857a16172 100644
--- a/scripts/lib/install/apply.js
+++ b/scripts/lib/install/apply.js
@@ -49,6 +49,9 @@ function mergeHooksIntoSettings(plan) {
if (fs.existsSync(settingsPath)) {
try {
settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
+ if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
+ throw new Error('root value must be a JSON object');
+ }
} catch (error) {
throw new Error(`Failed to parse existing settings at ${settingsPath}: ${error.message}`);
}
diff --git a/tests/scripts/install-apply.test.js b/tests/scripts/install-apply.test.js
index 13b9d7fab..b82d67aae 100644
--- a/tests/scripts/install-apply.test.js
+++ b/tests/scripts/install-apply.test.js
@@ -441,6 +441,27 @@ function runTests() {
}
})) passed++; else failed++;
+ if (test('fails when existing settings.json root is not an object', () => {
+ const homeDir = createTempDir('install-apply-home-');
+ const projectDir = createTempDir('install-apply-project-');
+
+ try {
+ const claudeRoot = path.join(homeDir, '.claude');
+ fs.mkdirSync(claudeRoot, { recursive: true });
+ const settingsPath = path.join(claudeRoot, 'settings.json');
+ fs.writeFileSync(settingsPath, '[]\n');
+
+ const result = run(['--profile', 'core'], { cwd: projectDir, homeDir });
+ assert.strictEqual(result.code, 1);
+ assert.ok(result.stderr.includes('Failed to parse existing settings at'));
+ assert.ok(result.stderr.includes('root value must be a JSON object'));
+ assert.strictEqual(fs.readFileSync(settingsPath, 'utf8'), '[]\n');
+ } finally {
+ cleanup(homeDir);
+ cleanup(projectDir);
+ }
+ })) passed++; else failed++;
+
if (test('installs from ecc-install.json and persists component selections', () => {
const homeDir = createTempDir('install-apply-home-');
const projectDir = createTempDir('install-apply-project-');