* fix(#934): reapply verifier handles missing pristine baseline post-rename Gap 1 (verify-reapply-patches.cjs): when backup-meta.json records a pristine_hash for a file but gsd-pristine/ has no corresponding snapshot on disk, the verifier fell to over-broad mode and produced false FAIL_USER_LINES_MISSING. Fix: return advisory OK_NO_BASELINE (non-blocking, exit 0) so the verifier does not block on files it cannot reason about. Gap 2 (new migration 004): migration 003 removed legacy get-shit-done/ runtime files but left gsd-pristine/get-shit-done/ orphan snapshots in place. Those stale snapshots referenced get-shit-done/... key paths that no longer match the active gsd-core/... layout. Fix: add migration 004-prune-stale-pristine-get-shit-done (NOT editing 003, preserving its checksum — ref #670 guard) to remove all files under gsd-pristine/get-shit-done/ as GSD-managed pristine snapshots. Includes tests: bug-934 OK_NO_BASELINE assertions in the verifier test, new installer-migration-prune-stale-pristine.test.cjs, updated installer-migrations baseline-lock checksum for 004. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#934): rename migration to satisfy legacy-name guard + mark intentional path refs Rename src/installer-migrations/004-prune-stale-pristine-get-shit-done.cts → 004-prune-stale-pristine-snapshots.cts so the filename no longer contains the forbidden token. Update .gitignore and eslint.config.mjs to track the new built path. Add gsd-allow-legacy-name markers to the remaining intentional uses of the legacy path string in the migration body (lines 3 and 100) and in tests (installer-migration-prune-stale-pristine.test.cjs lines 202 and 226; and the baseline-lock key in installer-migrations.test.cjs:1469). Update the baseline checksum for migration 2026-06-09-prune-stale-pristine-get-shit-done to reflect the two new marker comments added to its body. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
249 lines
10 KiB
JavaScript
249 lines
10 KiB
JavaScript
'use strict';
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
/**
|
|
* Bug #2969: /gsd-reapply-patches Step 5 hunk verification gate reports
|
|
* success on lost content because the LLM-driven workflow fills in
|
|
* "verified: yes" without actually checking content presence.
|
|
*
|
|
* Fix: deterministic verifier script (scripts/verify-reapply-patches.cjs)
|
|
* that the workflow calls.
|
|
*
|
|
* Per the repo's no-source-grep testing standard (CONTRIBUTING.md):
|
|
* tests must assert on TYPED structured fields — not regex/substring
|
|
* matching against script output, formatter prose, or file content.
|
|
*
|
|
* The script's --json mode emits a structured report whose `reason`
|
|
* field is a stable enum (exposed as REASON), and whose `missing` field
|
|
* is an array of typed strings (exact set membership, not substring).
|
|
* Every assertion below is a deepEqual / equal / Array.includes against
|
|
* those typed fields. Zero regex, zero String#includes on text.
|
|
*/
|
|
|
|
const { test, describe, before, after } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const cp = require('node:child_process');
|
|
const { cleanup } = require('./helpers.cjs');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
// Script lives at gsd-core/bin/ so the installer ships it under
|
|
// `${GSD_HOME}/gsd-core/bin/` (issue #2994). The top-level scripts/
|
|
// directory is not copied to user installs.
|
|
const SCRIPT = path.join(ROOT, 'gsd-core', 'bin', 'verify-reapply-patches.cjs');
|
|
const { REASON } = require(SCRIPT);
|
|
|
|
let tmpRoot;
|
|
let patchesDir;
|
|
let configDir;
|
|
let pristineDir;
|
|
|
|
function writeFile(absPath, content) {
|
|
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
fs.writeFileSync(absPath, content);
|
|
}
|
|
|
|
function resetFixture({ withPristine = true } = {}) {
|
|
for (const dir of [patchesDir, configDir, pristineDir]) {
|
|
cleanup(dir);
|
|
}
|
|
fs.mkdirSync(patchesDir);
|
|
fs.mkdirSync(configDir);
|
|
if (withPristine) fs.mkdirSync(pristineDir);
|
|
}
|
|
|
|
/** Runs the verifier with --json. Returns parsed structured report. */
|
|
function runVerifier({ includePristine = true } = {}) {
|
|
const args = [
|
|
SCRIPT,
|
|
'--patches-dir', patchesDir,
|
|
'--config-dir', configDir,
|
|
...(includePristine ? ['--pristine-dir', pristineDir] : []),
|
|
'--json',
|
|
];
|
|
const r = cp.spawnSync(process.execPath, args, { encoding: 'utf8' });
|
|
return {
|
|
status: r.status,
|
|
report: r.stdout && r.stdout.length ? JSON.parse(r.stdout) : null,
|
|
};
|
|
}
|
|
|
|
before(() => {
|
|
tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-2969-'));
|
|
patchesDir = path.join(tmpRoot, 'patches');
|
|
configDir = path.join(tmpRoot, 'installed');
|
|
pristineDir = path.join(tmpRoot, 'pristine');
|
|
resetFixture();
|
|
});
|
|
|
|
after(() => {
|
|
cleanup(tmpRoot);
|
|
});
|
|
|
|
describe('Bug #2969: deterministic Step 5 verification gate', () => {
|
|
test('REASON enum exposes the documented set of stable codes', () => {
|
|
// Locks the public diagnostic surface — adding a code requires updating
|
|
// this assertion, removing one breaks consumers that switch on the enum.
|
|
// Bug #3657 added OK_PRISTINE_DRIFT_DETECTED.
|
|
// Bug #934 added OK_NO_BASELINE.
|
|
assert.deepEqual(
|
|
Object.keys(REASON).sort(),
|
|
[
|
|
'FAIL_INSTALLED_MISSING',
|
|
'FAIL_INSTALLED_NOT_REGULAR_FILE',
|
|
'FAIL_READ_ERROR',
|
|
'FAIL_USER_LINES_MISSING',
|
|
'OK_NO_BASELINE',
|
|
'OK_NO_SIGNIFICANT_BACKUP_LINES',
|
|
'OK_NO_USER_LINES_VS_PRISTINE',
|
|
'OK_PRISTINE_DRIFT_DETECTED',
|
|
],
|
|
);
|
|
});
|
|
|
|
test('exits 0 with status=ok when every user-added line is present in the merged file', () => {
|
|
resetFixture();
|
|
const pristine = 'line one of stock content here\nline two of stock content here\nline three of stock content here\n';
|
|
const userAdded = 'a custom line the user added for behavior X\nanother substantial line that the user inserted\n';
|
|
|
|
writeFile(path.join(pristineDir, 'skills', 'foo', 'SKILL.md'), pristine);
|
|
writeFile(path.join(patchesDir, 'skills', 'foo', 'SKILL.md'), pristine + userAdded);
|
|
writeFile(path.join(configDir, 'skills', 'foo', 'SKILL.md'), pristine + userAdded);
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 0);
|
|
assert.equal(report.failures, 0);
|
|
assert.equal(report.checked, 1);
|
|
assert.equal(report.results[0].status, 'ok');
|
|
assert.deepEqual(report.results[0].missing, []);
|
|
});
|
|
|
|
test('reason=FAIL_USER_LINES_MISSING with the exact dropped line in .missing[]', () => {
|
|
resetFixture();
|
|
const pristine = 'first stock line in the original file here\nsecond stock line in the original file here\n';
|
|
const lostLine = 'this is the visual companion block that must survive';
|
|
writeFile(path.join(pristineDir, 'skills', 'discuss-phase', 'SKILL.md'), pristine);
|
|
writeFile(path.join(patchesDir, 'skills', 'discuss-phase', 'SKILL.md'), `${pristine}${lostLine}\n`);
|
|
writeFile(path.join(configDir, 'skills', 'discuss-phase', 'SKILL.md'), pristine);
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 1);
|
|
assert.equal(report.failures, 1);
|
|
const r0 = report.results[0];
|
|
// Normalize separators: on Windows the SUT emits 'skills\discuss-phase\SKILL.md'.
|
|
assert.equal(r0.file.replace(/\\/g, '/'), 'skills/discuss-phase/SKILL.md');
|
|
assert.equal(r0.status, 'fail');
|
|
assert.equal(r0.reason, REASON.FAIL_USER_LINES_MISSING);
|
|
assert.ok(
|
|
r0.missing.includes(lostLine),
|
|
`dropped line should be in .missing[]; got ${JSON.stringify(r0.missing)}`,
|
|
);
|
|
});
|
|
|
|
test('reason=FAIL_INSTALLED_NOT_REGULAR_FILE when installed path is a directory', () => {
|
|
resetFixture();
|
|
writeFile(path.join(pristineDir, 'a.md'), 'pristine line of substantial content here\n');
|
|
writeFile(path.join(patchesDir, 'a.md'), 'pristine line of substantial content here\nuser added line that is substantial\n');
|
|
fs.mkdirSync(path.join(configDir, 'a.md')); // EISDIR trap
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 1);
|
|
assert.equal(report.results[0].status, 'fail');
|
|
assert.equal(report.results[0].reason, REASON.FAIL_INSTALLED_NOT_REGULAR_FILE);
|
|
});
|
|
|
|
test('reason=FAIL_INSTALLED_MISSING when the merged file has been deleted', () => {
|
|
resetFixture();
|
|
const pristine = 'stock line one with substantial content for the test\n';
|
|
writeFile(path.join(pristineDir, 'workflow.md'), pristine);
|
|
writeFile(path.join(patchesDir, 'workflow.md'), `${pristine}user line that should survive but does not\n`);
|
|
// configDir intentionally missing the file.
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 1);
|
|
assert.equal(report.results[0].status, 'fail');
|
|
assert.equal(report.results[0].reason, REASON.FAIL_INSTALLED_MISSING);
|
|
});
|
|
|
|
test('--json report has the documented shape: { checked, failures, results: [{ file, status, missing, reason }] }', () => {
|
|
resetFixture();
|
|
const pristine = 'pristine line that is sufficiently long to be significant\n';
|
|
const userAdded = 'extra line the user wrote for their workflow customisation';
|
|
writeFile(path.join(pristineDir, 'a.md'), pristine);
|
|
writeFile(path.join(patchesDir, 'a.md'), `${pristine}${userAdded}\n`);
|
|
writeFile(path.join(configDir, 'a.md'), pristine);
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 1);
|
|
// Bug #3657 (Finding 1): drifted + drifted_files are additive fields added to surface
|
|
// pristine-drift skips distinctly from failures. Shape-lock updated to include them.
|
|
// Bug #934: no_baseline + no_baseline_files are additive fields for missing-pristine advisory.
|
|
assert.deepEqual(Object.keys(report).sort(), ['checked', 'drifted', 'drifted_files', 'failures', 'no_baseline', 'no_baseline_files', 'results']);
|
|
const r0 = report.results[0];
|
|
assert.deepEqual(Object.keys(r0).sort(), ['file', 'missing', 'reason', 'status']);
|
|
assert.equal(typeof r0.file, 'string');
|
|
assert.equal(typeof r0.status, 'string');
|
|
assert.equal(typeof r0.reason, 'string');
|
|
assert.ok(Array.isArray(r0.missing));
|
|
});
|
|
|
|
test('ignores backup-meta.json — it is metadata, not a patched file', () => {
|
|
resetFixture();
|
|
writeFile(path.join(patchesDir, 'backup-meta.json'), JSON.stringify({ files: [] }));
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 0);
|
|
assert.equal(report.checked, 0);
|
|
assert.equal(report.failures, 0);
|
|
assert.deepEqual(report.results, []);
|
|
});
|
|
|
|
test('without --pristine-dir, treats every significant backup line as required (safe over-broad fallback)', () => {
|
|
resetFixture({ withPristine: false });
|
|
const presentLine = 'this is a substantial line of user content here';
|
|
const droppedLine = 'another substantial line that should survive';
|
|
writeFile(path.join(patchesDir, 'b.md'), `${presentLine}\n${droppedLine}\n`);
|
|
writeFile(path.join(configDir, 'b.md'), `${presentLine}\n`);
|
|
|
|
const { status, report } = runVerifier({ includePristine: false });
|
|
assert.equal(status, 1);
|
|
assert.equal(report.results[0].reason, REASON.FAIL_USER_LINES_MISSING);
|
|
assert.ok(report.results[0].missing.includes(droppedLine));
|
|
assert.ok(!report.results[0].missing.includes(presentLine));
|
|
});
|
|
|
|
test('treats gsd-hook-version install-time substitution as upstream-owned, not missing user content (#229)', () => {
|
|
resetFixture();
|
|
const rel = path.join('hooks', 'gsd-statusline.js');
|
|
const pristine = [
|
|
'// gsd-hook-version: {{GSD_VERSION}}',
|
|
'console.log("statusline hook");',
|
|
'',
|
|
].join('\n');
|
|
const backup = [
|
|
'// gsd-hook-version: 1.41.0',
|
|
'console.log("statusline hook");',
|
|
'',
|
|
].join('\n');
|
|
const installed = [
|
|
'// gsd-hook-version: 1.42.3',
|
|
'console.log("statusline hook");',
|
|
'',
|
|
].join('\n');
|
|
|
|
writeFile(path.join(pristineDir, rel), pristine);
|
|
writeFile(path.join(patchesDir, rel), backup);
|
|
writeFile(path.join(configDir, rel), installed);
|
|
|
|
const { status, report } = runVerifier();
|
|
assert.equal(status, 0, `expected pass for upstream-owned version substitution; report=${JSON.stringify(report)}`);
|
|
assert.equal(report.failures, 0);
|
|
assert.equal(report.checked, 1);
|
|
assert.equal(report.results[0].status, 'ok');
|
|
assert.deepStrictEqual(report.results[0].missing, []);
|
|
});
|
|
});
|