mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-17 21:15:40 +02:00
Follow-up on the co-author default in this PR. - Remove the existsSync/writeFileSync race in the installer settings write (CodeQL js/file-system-race, high). A single guarded read now covers the fresh-install case, and unreadable or non-object settings are left untouched. - Respect `attribution` as an explicit user choice. It supersedes `includeCoAuthoredBy` in Claude Code 2.1.x, so a user who configured it would otherwise have had a dead key written into their settings. - Share one opt-out rule via scripts/lib/claude-commit-attribution.js instead of duplicating it across the installer and plugin setup. - Update the git-workflow rule and its nine mirrors and translations, which still told users ECC does not ship this setting. We keep writing the deprecated `includeCoAuthoredBy` key rather than `attribution`: unknown keys fail Claude Code settings validation, so writing `attribution` would break users on older versions.
78 lines
3.3 KiB
JavaScript
78 lines
3.3 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
hasExplicitCommitAttributionPreference,
|
|
withCommitAttributionDisabled,
|
|
} = require('../../scripts/lib/claude-commit-attribution');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
return true;
|
|
} catch (error) {
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` Error: ${error.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
console.log('\nClaude commit attribution preference');
|
|
|
|
if (test('treats absent settings as unconfigured', () => {
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference(undefined), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference(null), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({}), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ theme: 'dark' }), false);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('treats either includeCoAuthoredBy boolean as an explicit choice', () => {
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ includeCoAuthoredBy: true }), true);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ includeCoAuthoredBy: false }), true);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('treats a configured attribution as an explicit choice', () => {
|
|
// `attribution` supersedes `includeCoAuthoredBy` in Claude Code, so a user who
|
|
// set it has already decided and ECC must not write a key that loses to it.
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: { commit: '' } }), true);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: { pr: '' } }), true);
|
|
assert.strictEqual(
|
|
hasExplicitCommitAttributionPreference({ attribution: { commit: 'Co-Authored-By: Someone <a@b.c>' } }),
|
|
true
|
|
);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('ignores attribution values that carry no commit or pr choice', () => {
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: {} }), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: null }), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: [] }), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: 'off' }), false);
|
|
assert.strictEqual(hasExplicitCommitAttributionPreference({ attribution: { sessionUrl: false } }), false);
|
|
})) passed++; else failed++;
|
|
|
|
if (test('disables attribution while preserving unrelated settings', () => {
|
|
assert.deepStrictEqual(
|
|
withCommitAttributionDisabled({ theme: 'dark' }),
|
|
{ theme: 'dark', includeCoAuthoredBy: false }
|
|
);
|
|
assert.deepStrictEqual(withCommitAttributionDisabled({}), { includeCoAuthoredBy: false });
|
|
})) passed++; else failed++;
|
|
|
|
if (test('returns explicit settings unchanged', () => {
|
|
const optIn = { includeCoAuthoredBy: true };
|
|
assert.strictEqual(withCommitAttributionDisabled(optIn), optIn);
|
|
|
|
const alreadyOff = { includeCoAuthoredBy: false };
|
|
assert.strictEqual(withCommitAttributionDisabled(alreadyOff), alreadyOff);
|
|
|
|
const customAttribution = { attribution: { commit: 'Signed-off-by: Someone <a@b.c>' } };
|
|
assert.strictEqual(withCommitAttributionDisabled(customAttribution), customAttribution);
|
|
})) passed++; else failed++;
|
|
|
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
|
process.exit(failed > 0 ? 1 : 0);
|