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(install): surface Claude settings failures

wellkilo26d3e0038b22
diff --git a/scripts/lib/install-lifecycle.js b/scripts/lib/install-lifecycle.js
index c5ece3504..5da0cd8b1 100644
--- a/scripts/lib/install-lifecycle.js
+++ b/scripts/lib/install-lifecycle.js
@@ -1300,11 +1300,12 @@ function inspectManagedOperation(repoRoot, trustedRoot, operation, linkIndex = n
destinationPath,
managedHookInspection: inspection
};
- } catch (_error) {
+ } catch (error) {
return {
- status: 'drifted',
+ status: 'invalid-settings',
operation,
- destinationPath
+ destinationPath,
+ error: `Failed to inspect Claude settings at ${destinationPath}: ${error.message}`
};
}
}
@@ -1337,6 +1338,8 @@ function summarizeManagedOperationHealth(repoRoot, trustedRoot, operations, targ
summary.unsafeSource.push(inspection);
} else if (inspection.status === 'unsafe-destination') {
summary.unsafeDestination.push(inspection);
+ } else if (inspection.status === 'invalid-settings') {
+ summary.invalidSettings.push(inspection);
} else if (inspection.status === 'unverified' || inspection.status === 'invalid-destination') {
summary.unverified.push(inspection);
}
@@ -1348,6 +1351,7 @@ function summarizeManagedOperationHealth(repoRoot, trustedRoot, operations, targ
missingSource: [],
unsafeSource: [],
unsafeDestination: [],
+ invalidSettings: [],
unverified: []
}
);
@@ -1374,7 +1378,9 @@ function getUnsafeOperationResult(record, operationHealth) {
? getUnsafeManagedDestinationError(operationHealth)
: operationHealth.unsafeSource.length > 0
? createUnsafeRepairSourceError().message
- : null;
+ : operationHealth.invalidSettings.length > 0
+ ? operationHealth.invalidSettings[0].error
+ : null;
if (!error) {
return null;
}
@@ -1666,6 +1672,17 @@ function analyzeRecord(record, context) {
);
}
+ if (operationHealth.invalidSettings.length > 0) {
+ issues.push(
+ buildIssue(
+ 'error',
+ 'invalid-claude-settings',
+ operationHealth.invalidSettings[0].error,
+ { paths: operationHealth.invalidSettings.map(entry => entry.destinationPath) }
+ )
+ );
+ }
+
if (missingManagedOperations.length > 0) {
issues.push(
buildIssue('error', 'missing-managed-files', `${missingManagedOperations.length} managed file(s) are missing`, {
diff --git a/scripts/lib/install/apply.js b/scripts/lib/install/apply.js
index 1c5d4900d..015b1e128 100644
--- a/scripts/lib/install/apply.js
+++ b/scripts/lib/install/apply.js
@@ -209,20 +209,27 @@ function shouldSetClaudeCommitAttributionPreference(plan) {
}
function writeClaudeCommitAttributionPreference(settingsPath, options = {}) {
+ let settings;
try {
- let changed = false;
- updateSettingsAtomic(settingsPath, settings => {
- if (hasExplicitCommitAttributionPreference(settings)) {
- return { settings };
- }
- changed = true;
- return { settings: withCommitAttributionDisabled(settings) };
- }, options);
- return changed;
+ settings = readSettings(settingsPath);
} catch (_error) {
// Unreadable or malformed settings belong to the user; leave them untouched.
return false;
}
+
+ if (hasExplicitCommitAttributionPreference(settings)) {
+ return false;
+ }
+
+ let changed = false;
+ updateSettingsAtomic(settingsPath, latestSettings => {
+ if (hasExplicitCommitAttributionPreference(latestSettings)) {
+ return { settings: latestSettings };
+ }
+ changed = true;
+ return { settings: withCommitAttributionDisabled(latestSettings) };
+ }, options);
+ return changed;
}
function isMcpConfigPath(filePath) {
diff --git a/tests/lib/install-executor.test.js b/tests/lib/install-executor.test.js
index d0acad15a..0f9c656f6 100644
--- a/tests/lib/install-executor.test.js
+++ b/tests/lib/install-executor.test.js
@@ -498,8 +498,9 @@ function runTests() {
const tempDir = createTempDir('install-executor-claude-hooks-');
try {
for (const target of ['claude', 'claude-project']) {
- const homeDir = path.join(tempDir, `${target} home "quoted" $dollar %percent%`);
- const projectRoot = path.join(tempDir, `${target} project "quoted" $dollar %percent%`);
+ const quoted = process.platform === 'win32' ? 'quoted' : '"quoted"';
+ const homeDir = path.join(tempDir, `${target} home ${quoted} $dollar %percent%`);
+ const projectRoot = path.join(tempDir, `${target} project ${quoted} $dollar %percent%`);
fs.mkdirSync(homeDir, { recursive: true });
fs.mkdirSync(projectRoot, { recursive: true });
@@ -568,6 +569,54 @@ function runTests() {
}
})) passed++; else failed++;
+ if (test('Claude commit-attribution atomic write failures abort installation', () => {
+ const tempDir = createTempDir('install-executor-attribution-failure-');
+ const originalRenameSync = fs.renameSync;
+ try {
+ const homeDir = path.join(tempDir, 'home');
+ const projectRoot = path.join(tempDir, 'project');
+ fs.mkdirSync(homeDir, { recursive: true });
+ fs.mkdirSync(projectRoot, { recursive: true });
+ const rawPlan = createManifestInstallPlan({
+ sourceRoot: REPO_ROOT,
+ homeDir,
+ projectRoot,
+ target: 'claude',
+ moduleIds: ['hooks-runtime'],
+ });
+ const plan = {
+ ...rawPlan,
+ hookConsent: 'enabled',
+ statePreview: {
+ ...rawPlan.statePreview,
+ request: { ...rawPlan.statePreview.request, hookConsent: 'enabled' },
+ },
+ };
+ const settingsPath = path.join(homeDir, '.claude', 'settings.json');
+ let settingsCommitCount = 0;
+ fs.renameSync = function failAttributionCommit(sourcePath, destinationPath) {
+ if (path.resolve(String(destinationPath)) === path.resolve(settingsPath)) {
+ settingsCommitCount += 1;
+ if (settingsCommitCount === 2) {
+ throw new Error('injected attribution rename failure');
+ }
+ }
+ return originalRenameSync.call(fs, sourcePath, destinationPath);
+ };
+
+ assert.throws(
+ () => applyInstallPlanDirect(plan),
+ /injected attribution rename failure/
+ );
+ const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
+ assert.ok(settings.hooks.SessionStart.some(entry => entry.id === 'session:start'));
+ assert.strictEqual(Object.hasOwn(settings, 'includeCoAuthoredBy'), false);
+ } finally {
+ fs.renameSync = originalRenameSync;
+ cleanup(tempDir);
+ }
+ })) passed++; else failed++;
+
if (test('creates legacy compatibility manifest plans from language selections', () => {
const projectRoot = createTempDir('install-executor-project-');
const homeDir = createTempDir('install-executor-home-');
diff --git a/tests/lib/install-lifecycle.test.js b/tests/lib/install-lifecycle.test.js
index 4e45c9597..b086ef2bf 100644
--- a/tests/lib/install-lifecycle.test.js
+++ b/tests/lib/install-lifecycle.test.js
@@ -3372,6 +3372,54 @@ function runTests() {
}
})) passed++; else failed++;
+ if (test('doctor and repair surface malformed Claude settings errors', () => {
+ const homeDir = createTempDir('install-lifecycle-claude-home-');
+ const projectRoot = createTempDir('install-lifecycle-project-');
+
+ try {
+ const targetRoot = path.join(homeDir, '.claude');
+ const settingsPath = path.join(targetRoot, 'settings.json');
+ const managedHooks = currentManagedHooks(targetRoot);
+ fs.mkdirSync(targetRoot, { recursive: true });
+ fs.writeFileSync(settingsPath, '{ invalid json\n');
+ writeClaudeState(homeDir, {
+ operations: [
+ managedOperation('update-claude-settings', settingsPath, {
+ sourceRelativePath: 'hooks/hooks.json',
+ strategy: 'update-claude-settings',
+ managedHooks,
+ }),
+ ],
+ });
+
+ const report = buildDoctorReport({
+ repoRoot: REPO_ROOT,
+ homeDir,
+ projectRoot,
+ targets: ['claude'],
+ });
+ const issue = report.results[0].issues.find(candidate => (
+ candidate.code === 'invalid-claude-settings'
+ ));
+ assert.strictEqual(report.results[0].status, 'error');
+ assert.ok(issue, 'doctor should report an invalid Claude settings issue');
+ assert.match(issue.message, /Failed to inspect Claude settings/);
+
+ const repair = repairInstalledStates({
+ repoRoot: REPO_ROOT,
+ homeDir,
+ projectRoot,
+ targets: ['claude'],
+ });
+ assert.strictEqual(repair.results[0].status, 'error');
+ assert.match(repair.results[0].error, /Failed to inspect Claude settings/);
+ assert.strictEqual(fs.readFileSync(settingsPath, 'utf8'), '{ invalid json\n');
+ } finally {
+ cleanup(homeDir);
+ cleanup(projectRoot);
+ }
+ })) passed++; else failed++;
+
if (test('repair restores managed Claude hooks while preserving user settings and hooks', () => {
const homeDir = createTempDir('install-lifecycle-claude-home-');
const projectRoot = createTempDir('install-lifecycle-project-');