From 59bf23876faac34df6d4c97c18b796dc0cc8ebc6 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Wed, 18 Nov 2026 00:55:05 -0500 Subject: [PATCH] fix(openspec): query history for literal anchor paths --- scripts/ci/check-spec-freshness.js | 5 ++-- tests/ci/check-spec-freshness.test.js | 35 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/scripts/ci/check-spec-freshness.js b/scripts/ci/check-spec-freshness.js index cb74b3507..b3c12b2ca 100644 --- a/scripts/ci/check-spec-freshness.js +++ b/scripts/ci/check-spec-freshness.js @@ -25,6 +25,7 @@ * - git is always invoked through execFileSync with an argv array. Paths are * passed after `--`; the date is validated to YYYY-MM-DD first and passed * as a single argument. Nothing from spec Markdown reaches a shell. + * Literal pathspecs ensure Git looks at the same target we validated. * - the project root must not be a symlink; every enforced target is resolved * through fs.realpathSync and must stay inside the real project root. * - shallow clones report UNVERIFIED — incomplete history is never @@ -207,7 +208,7 @@ function gitProbe() { function gitHashesAfter(date, anchorPath) { const out = execFileSync( 'git', - ['log', '--format=%H', `--after=${date}`, '--', anchorPath], + ['--literal-pathspecs', 'log', '--format=%H', `--after=${date}`, '--', anchorPath], { encoding: 'utf8', cwd: projectRoot, stdio: ['pipe', 'pipe', 'pipe'] } ); return out.trim().split('\n').filter(Boolean); @@ -216,7 +217,7 @@ function gitHashesAfter(date, anchorPath) { function gitAllHashes(anchorPath) { const out = execFileSync( 'git', - ['log', '--format=%H', '--', anchorPath], + ['--literal-pathspecs', 'log', '--format=%H', '--', anchorPath], { encoding: 'utf8', cwd: projectRoot, stdio: ['pipe', 'pipe', 'pipe'] } ); return out.trim().split('\n').filter(Boolean); diff --git a/tests/ci/check-spec-freshness.test.js b/tests/ci/check-spec-freshness.test.js index 927b0db72..95eb3f483 100644 --- a/tests/ci/check-spec-freshness.test.js +++ b/tests/ci/check-spec-freshness.test.js @@ -190,6 +190,41 @@ describe('check-spec-freshness (v1, file-level)', () => { }); }); + describe('literal enforced paths', () => { + it('finds changes to a tracked file with brackets in its name', () => { + const repo = track(initRepo()); + commitFile(repo, 'src/[id].js', 'v1\n', daysAgo(5)); + commitFile(repo, 'src/[id].js', 'v2\n', daysAgo(1)); + writeSpec(repo, 'route', { lastVerified: daysAgo(3), anchors: ['src/[id].js::run'] }); + + const result = runChecker(repo); + assert.strictEqual(result.exitCode, 1); + assert.strictEqual(parseJson(result).specs[0].status, 'STALE'); + }); + + it('ignores decoy changes when the literal bracketed path is unchanged', () => { + const repo = track(initRepo()); + commitFile(repo, 'src/[id].js', 'unchanged\n', daysAgo(5)); + commitFile(repo, 'src/i.js', 'unrelated\n', daysAgo(1)); + writeSpec(repo, 'route', { lastVerified: daysAgo(3), anchors: ['src/[id].js::run'] }); + + const result = runChecker(repo); + assert.strictEqual(result.exitCode, 0); + assert.strictEqual(parseJson(result).specs[0].status, 'FRESH'); + }); + + it('does not use another file as evidence for an uncommitted bracketed path', () => { + const repo = track(initRepo()); + commitFile(repo, 'src/i.js', 'unrelated\n', daysAgo(5)); + fs.writeFileSync(path.join(repo, 'src/[id].js'), 'uncommitted\n'); + writeSpec(repo, 'route', { lastVerified: daysAgo(3), anchors: ['src/[id].js::run'] }); + + const result = runChecker(repo); + assert.strictEqual(result.exitCode, 0); + assert.strictEqual(parseJson(result).specs[0].status, 'UNVERIFIED'); + }); + }); + describe('verdicts on a real repo with history', () => { // Timeline: src/lib.js committed 300 days ago (v1) and 50 days ago (v2). let repo;