mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 08:15:29 +00:00
fix(openspec): query history for literal anchor paths
This commit is contained in:
1 parent
3f14a103a8
commit
59bf23876f
2 files changed
+38
-2
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user