refactor(cleanup): simplify pass on the R-a diff

engine-compare imports the coordinator's title limit and trim instead
of a copy whose reason went with Arm B; the autonomy gate exports one
parser and its test runs in-process with two CLI runs; one import
scanner in lib-imports; the fenced-section walker shared from
tests/helpers/md-section.mjs instead of six copies; plan-gate hash
in-process; living-paths scans once; routing drops the orchestrator
filter whose files are gone; small leftovers removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-07 13:31:30 +01:00
commit efe981f7bc
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
18 changed files with 161 additions and 358 deletions

View file

@ -41,7 +41,7 @@ const SCOPE_DIRS = ['agents/', 'commands/', 'skills/', 'templates/', 'docs/'];
const SCOPE_ROOT = new Set(['README.md', 'CLAUDE.md', 'CONTRIBUTING.md', 'SECURITY.md']);
// Living tracked text in scope (see the header).
export function inScope(rel) {
function inScope(rel) {
if (!rel.endsWith('.md') || /\.local\./.test(rel)) return false;
if (rel === 'CHANGELOG.md') return false;
return SCOPE_ROOT.has(rel) || SCOPE_DIRS.some(d => rel.startsWith(d));
@ -49,7 +49,7 @@ export function inScope(rel) {
// Every plugin path a text names, as { line, path } with path relative to the
// repository root. `rel` is the text's own path, for relative links.
export function extractPaths(text, rel) {
function extractPaths(text, rel) {
const out = [];
const lines = text.split('\n');
lines.forEach((line, i) => {
@ -78,7 +78,7 @@ export function extractPaths(text, rel) {
}
// "file:line path" for every named path that does not exist under root.
export function deadPaths(root, files) {
function deadPaths(root, files) {
const dead = [];
for (const rel of files) {
const text = readFileSync(join(root, rel), 'utf-8');
@ -89,9 +89,15 @@ export function deadPaths(root, files) {
return dead;
}
function trackedFiles(root) {
const out = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf-8' });
return out.split('\0').filter(Boolean);
let scan = null;
/** The tracked files and every dead hit in the in-scope ones (EXEMPT not applied), computed once. */
function repoScan() {
if (!scan) {
const files = execFileSync('git', ['ls-files', '-z'], { cwd: ROOT, encoding: 'utf-8' }).split('\0').filter(Boolean);
scan = { files, dead: deadPaths(ROOT, files.filter(inScope)) };
}
return scan;
}
// Named exceptions: "file path" -> reason. Each must still be dead (a stale
@ -156,19 +162,19 @@ test('scope keeps living docs and drops history and target-repo text', () => {
});
test('living tracked text names only paths that exist', () => {
const files = trackedFiles(ROOT);
const { files, dead } = repoScan();
assert.ok(files.length > 100, `git ls-files returned ${files.length} files; refusing to pass on an empty scan`);
const hits = deadPaths(ROOT, files.filter(inScope)).filter(h => !EXEMPT.has(exemptKey(h)));
const hits = dead.filter(h => !EXEMPT.has(exemptKey(h)));
assert.deepEqual(hits, [], `${hits.length} dead path reference(s):\n${hits.join('\n')}`);
});
test('every EXEMPT entry is still a dead reference in a tracked file', () => {
const tracked = new Set(trackedFiles(ROOT));
const { files, dead } = repoScan();
const tracked = new Set(files);
const deadKeys = new Set(dead.map(exemptKey));
for (const key of EXEMPT.keys()) {
const [rel, path] = key.split(' ');
const rel = key.split(' ')[0];
assert.ok(tracked.has(rel), `EXEMPT names untracked ${rel}`);
const dead = deadPaths(ROOT, [rel]).map(exemptKey);
assert.ok(dead.includes(key), `EXEMPT entry "${key}" is no longer dead; remove it`);
assert.ok(!existsSync(join(ROOT, path)), `EXEMPT path ${path} exists`);
assert.ok(deadKeys.has(key), `EXEMPT entry "${key}" is no longer dead; remove it`);
}
});