Skip to content

Commit 5d5f3eb

Browse files
donjor-agent[bot]donjor
authored andcommitted
refactor(fork-meta): fork scan refuses every finding; the replay baseline is gone (#1826)
## Problem Whole-series scans with `--replay-of` grandfathered findings already on the replay ref as advisory, so old findings never failed again. The fold that published `ce6be6ea42` brought that inventory to 0, so the baseline only hides new debt now. ## Change Removed from `scripts/fork-scan.ts`: - `resolveBaselineKeys`, `BaselineKeys` - `partitionBaseline`, finding-key normalisation - the `historical: … advisory` report section Kept `--replay-of`: it still maps replayed commits to their counterparts. The baseline fixture now proves a pre-existing finding fails the scan. No docs or skills described the baseline. ## Scope and approval Closes #1493 ## Close conditions - [x] Inventory: the scan reports 0 findings - [x] Baseline: `resolveBaselineKeys` removed - [x] Guard: a pre-existing finding fails the scan - [x] In-place edits: 0 on the next walk Inventory on `ce6be6ea42`, against merge base `680152e27b`: ```text node scripts/fork-scan.ts --head ce6be6e --target 680152e --since 680152e --replay-of ce6be6e --no-typecheck historical findings: 0 ``` ## Verification ```text vp test run scripts/fork-scan.test.ts scripts/fork-scan-gates.test.ts → exit 0 (38 passed) scripts: vp exec tsc-rs --noEmit → exit 0 vp run fork:ci → exit 0 (587 tests passed) ``` Claude Opus 5.5 (host) and GPT Sol (peer), via Claude Code and Pi. ## Fork trailers Fork-Domain: fork-meta Fork-Tier: qol Co-authored-by: donjor <[email protected]>
1 parent a9230b5 commit 5d5f3eb

2 files changed

Lines changed: 17 additions & 188 deletions

File tree

‎scripts/fork-scan-gates.test.ts‎

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { assert, it } from "@effect/vitest";
99

1010
import {
1111
buildScanResult,
12-
normaliseFindingDetail,
1312
readScan,
1413
renderScanReport,
1514
scanFailures,
@@ -207,21 +206,6 @@ it("exempts a replay addition re-indented by an upstream restructure", () => {
207206
assert.match(warnings[0] ?? "", /1 added line.*const introduced = true;/);
208207
});
209208

210-
it("keys a finding without its sha or count, keeping path digits", () => {
211-
assert.strictEqual(
212-
normaliseFindingDetail("apps/web/src/a.test.ts gains 4 fork test block(s)"),
213-
normaliseFindingDetail("apps/web/src/a.test.ts gains 12 fork test block(s)"),
214-
);
215-
assert.notStrictEqual(
216-
normaliseFindingDetail("docs/02-bug.md gains 1 block"),
217-
normaliseFindingDetail("docs/03-bug.md gains 1 block"),
218-
);
219-
assert.strictEqual(
220-
normaliseFindingDetail("moved in 9f318b69a9 and 3 more"),
221-
"moved in <sha> and <n> more",
222-
);
223-
});
224-
225209
it("fails an upstream-test addition in the since range", () => {
226210
const raw = [
227211
"abc1234",
@@ -908,19 +892,13 @@ it("passes a declared replacement: upstream case removed, fork sibling carries i
908892
}
909893
});
910894

911-
/**
912-
* Whole-series rehearsal fixture: `landed` (`replayOf`) already carries one
913-
* in-place upstream rewrite as legacy debt. `replay` rehearses the same
914-
* rewrite (a different sha, identical resulting text) plus one brand-new
915-
* rewrite the replay itself introduces.
916-
*/
917-
const baselineFixture = (): {
895+
const replayFixture = (): {
918896
root: string;
919897
base: string;
920898
landed: string;
921899
replay: string;
922900
} => {
923-
const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "fork-scan-baseline-"));
901+
const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "fork-scan-replay-"));
924902
const env = {
925903
...process.env,
926904
GIT_AUTHOR_NAME: "fixture",
@@ -947,7 +925,6 @@ const baselineFixture = (): {
947925
git("commit", "-m", "upstream: base");
948926
const base = git("rev-parse", "HEAD");
949927

950-
// Legacy debt: `landed` already carries the in-place rewrite.
951928
git("checkout", "--quiet", "-b", "landed", base);
952929
write(thingPath, thingCase.replace("expect(keep).toBe(1);", "expect(keep).toBe(2);"));
953930
git("add", "-A");
@@ -967,7 +944,7 @@ const baselineFixture = (): {
967944
return { root, base, landed, replay };
968945
};
969946

970-
const baselineLedger = `# Fork delta
947+
const replayLedger = `# Fork delta
971948
972949
## fork-meta
973950
@@ -978,44 +955,8 @@ const baselineLedger = `# Fork delta
978955
| \`apps/web/src/*.test.ts\` | The seam. |
979956
`;
980957

981-
it("makes only the replay-introduced rewrite fatal against a --replay-of baseline", () => {
982-
const f = baselineFixture();
983-
try {
984-
const git = new SystemGit(f.root);
985-
const commandRunner = new SystemCommandRunner();
986-
const additiveRunner = { worktree: f.root, run: commandRunner.run.bind(commandRunner) };
987-
const result = readScan(
988-
git,
989-
{
990-
base: null,
991-
head: f.replay,
992-
target: f.base,
993-
typecheck: false,
994-
since: f.base,
995-
replayOf: f.landed,
996-
},
997-
baselineLedger,
998-
additiveRunner,
999-
);
1000-
const failures = scanFailures(result);
1001-
assert.isTrue(
1002-
failures.some((failure) => failure.includes("apps/web/src/other.test.ts")),
1003-
`the replay-introduced rewrite must stay fatal: ${JSON.stringify(failures)}`,
1004-
);
1005-
assert.isFalse(
1006-
failures.some((failure) => failure.includes("apps/web/src/thing.test.ts")),
1007-
`the rewrite already on ${f.landed} must be advisory, not fatal: ${JSON.stringify(failures)}`,
1008-
);
1009-
assert.lengthOf(result.historicalWarnings, 1);
1010-
assert.lengthOf(result.historicalAdditive, 1);
1011-
assert.match(renderScanReport(result), /historical: 2 finding\(s\) already on/);
1012-
} finally {
1013-
NodeFS.rmSync(f.root, { recursive: true, force: true });
1014-
}
1015-
});
1016-
1017-
it("keeps both findings fatal without --replay-of on the same inputs", () => {
1018-
const f = baselineFixture();
958+
it("refuses pre-existing and new findings with --replay-of", () => {
959+
const f = replayFixture();
1019960
try {
1020961
const git = new SystemGit(f.root);
1021962
const commandRunner = new SystemCommandRunner();
@@ -1029,14 +970,20 @@ it("keeps both findings fatal without --replay-of on the same inputs", () => {
1029970
target: f.base,
1030971
typecheck: false,
1031972
since: f.base,
1032-
replayOf: null,
973+
replayOf: f.landed,
1033974
},
1034-
baselineLedger,
975+
replayLedger,
1035976
additiveRunner,
1036977
),
1037978
);
1038-
assert.isTrue(failures.some((failure) => failure.includes("apps/web/src/thing.test.ts")));
1039-
assert.isTrue(failures.some((failure) => failure.includes("apps/web/src/other.test.ts")));
979+
for (const rule of ["upstream-test:", "additive:tests:"]) {
980+
for (const path of ["apps/web/src/thing.test.ts", "apps/web/src/other.test.ts"]) {
981+
assert.isTrue(
982+
failures.some((failure) => failure.startsWith(rule) && failure.includes(path)),
983+
`${rule} ${path} must fail: ${JSON.stringify(failures)}`,
984+
);
985+
}
986+
}
1040987
} finally {
1041988
NodeFS.rmSync(f.root, { recursive: true, force: true });
1042989
}

‎scripts/fork-scan.ts‎

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,6 @@ export interface ScanResult {
107107
// reads as superseded rather than contradictory; the additive gate consumes that reading.
108108
readonly supersedes: ReadonlyArray<string>;
109109
readonly retireCandidates: ReadonlyArray<SituatedDeclaration>;
110-
// Whole-series rehearsal only (`--replay-of` with `--since == --target`):
111-
// `upstream-test`/`replaced-export` warnings and `additive:*` findings
112-
// whose normalised key already exists on `replayOf` against its own base —
113-
// legacy debt, not something this replay introduced. Kept out of
114-
// `warnings`/`additive` (and so out of `scanFailures`) but rendered
115-
// separately, advisory-only. Empty and null outside that mode.
116-
readonly historicalWarnings: ReadonlyArray<ScanAuthoringWarning>;
117-
readonly historicalAdditive: ReadonlyArray<AdditiveFinding>;
118-
readonly historicalBase: string | null;
119-
readonly replayOf: string | null;
120110
}
121111

122112
export { UsageError } from "./lib/fork-cli.ts";
@@ -132,8 +122,6 @@ Options:
132122
--since <ref> Guard only commits in <ref>..head; the overlap report covers the whole range
133123
--replay-of <ref>
134124
Guard only commits whose added lines differ from the same-subject commit on this ref.
135-
When --since equals --target, upstream-test/replaced-export/additive findings already
136-
present on <ref> against its own base are advisory, not fatal.
137125
--no-typecheck Skip the rehearsed-head typechecks
138126
-h, --help Show help
139127
@@ -275,51 +263,8 @@ export interface ScanInput extends ScanRange {
275263
// declaration refusals plus undeclared-contradiction findings.
276264
readonly supersedes?: ReadonlyArray<string>;
277265
readonly retireCandidates?: ReadonlyArray<SituatedDeclaration>;
278-
// Whole-series rehearsal baseline, computed by the runner from a second
279-
// scan of replayOf against its own base. Absent outside that mode.
280-
readonly baseline?: BaselineKeys | undefined;
281-
}
282-
283-
export interface BaselineKeys {
284-
readonly base: string;
285-
readonly replayOf: string;
286-
readonly warningKeys: ReadonlySet<string>;
287-
readonly additiveKeys: ReadonlySet<string>;
288266
}
289267

290-
const SHA_PATTERN = /\b[0-9a-f]{7,40}\b/g;
291-
// A whole-word integer between spaces is a count ("gains 4 fork test
292-
// block(s)"). A squash sums its members' counts, so the count leaves the key
293-
// too; a digit inside a path sits against a non-space and survives.
294-
const COUNT_PATTERN = /(?<=\s)\d+(?=\s)/g;
295-
export const normaliseFindingDetail = (text: string): string =>
296-
text.replace(SHA_PATTERN, "<sha>").replace(COUNT_PATTERN, "<n>");
297-
298-
// One key per finding shape, sha-free and count-free so a finding rebases or
299-
// squashes into an identical key on both scans. `warning.detail` always
300-
// carries its path (the messages `fork-scan-authoring.ts` builds all open on
301-
// it, or name it a sentence in), so folding it into the normalised detail is
302-
// enough for uniqueness without a separate path field on
303-
// `ScanAuthoringWarning`.
304-
const warningKey = (warning: ScanAuthoringWarning): string =>
305-
`${warning.rule}|${normaliseFindingDetail(warning.detail)}`;
306-
const additiveKey = (finding: AdditiveFinding): string =>
307-
`${finding.check}|${finding.path}|${normaliseFindingDetail(finding.detail)}`;
308-
309-
const partitionBaseline = <Finding>(
310-
findings: ReadonlyArray<Finding>,
311-
keyOf: (finding: Finding) => string,
312-
baselineKeys: ReadonlySet<string> | undefined,
313-
): { readonly fatal: ReadonlyArray<Finding>; readonly historical: ReadonlyArray<Finding> } => {
314-
if (baselineKeys === undefined) return { fatal: findings, historical: [] };
315-
const fatal: Array<Finding> = [];
316-
const historical: Array<Finding> = [];
317-
for (const finding of findings) {
318-
(baselineKeys.has(keyOf(finding)) ? historical : fatal).push(finding);
319-
}
320-
return { fatal, historical };
321-
};
322-
323268
export const buildScanResult = (input: ScanInput): ScanResult => {
324269
const touched = new Map<string, Set<string>>();
325270
const commitCounts = new Map<string, number>();
@@ -362,28 +307,15 @@ export const buildScanResult = (input: ScanInput): ScanResult => {
362307
for (const path of shared) overlaps.push({ path, domain, covered: covers(path) });
363308
}
364309

365-
const rawWarnings = input.guard === undefined ? [] : collectAuthoringWarnings(input.guard);
366-
const rawAdditive = input.additive ?? [];
367-
const warningPartition = partitionBaseline(rawWarnings, warningKey, input.baseline?.warningKeys);
368-
const additivePartition = partitionBaseline(
369-
rawAdditive,
370-
additiveKey,
371-
input.baseline?.additiveKeys,
372-
);
373-
374310
return {
375311
range: { base: input.base, head: input.head, target: input.target },
376312
domains,
377313
overlaps: overlaps.toSorted((left, right) => left.path.localeCompare(right.path)),
378314
typecheckGaps: [],
379315
undeclaredDomains,
380316
untaggedCommits,
381-
warnings: warningPartition.fatal,
382-
additive: additivePartition.fatal,
383-
historicalWarnings: warningPartition.historical,
384-
historicalAdditive: additivePartition.historical,
385-
historicalBase: input.baseline?.base ?? null,
386-
replayOf: input.baseline?.replayOf ?? null,
317+
warnings: input.guard === undefined ? [] : collectAuthoringWarnings(input.guard),
318+
additive: input.additive ?? [],
387319
supersedes: input.supersedes ?? [],
388320
retireCandidates: input.retireCandidates ?? [],
389321
hookDetails:
@@ -499,18 +431,6 @@ export const renderScanReport = (result: ScanResult): string => {
499431
lines.push("", `Hook guard, ${result.hookDetails.length} finding(s):`);
500432
for (const detail of result.hookDetails) lines.push(` HOOK ${detail}`);
501433
}
502-
const historicalCount = result.historicalWarnings.length + result.historicalAdditive.length;
503-
if (historicalCount > 0 && result.replayOf !== null && result.historicalBase !== null) {
504-
lines.push(
505-
"",
506-
`historical: ${historicalCount} finding(s) already on ${result.replayOf} against ${result.historicalBase}, advisory`,
507-
"Advisory, already on the replay baseline:",
508-
);
509-
lines.push(...renderAuthoringWarnings(result.historicalWarnings).map((line) => ` ${line}`));
510-
if (result.historicalAdditive.length > 0) {
511-
lines.push(...renderAdditiveFindings(result.historicalAdditive).map((line) => ` ${line}`));
512-
}
513-
}
514434
if (result.untaggedCommits.length > 0) {
515435
lines.push(
516436
`skipped ${result.untaggedCommits.length} commit(s) without Fork-Domain (vp run fork:delta --check owns them): ${result.untaggedCommits.join(", ")}`,
@@ -624,47 +544,9 @@ export const readScan = (
624544
{ head: range.head },
625545
),
626546
...readSupersedesAssessment(git, range),
627-
baseline: resolveBaselineKeys(git, options, range, ledger, additiveRunner),
628547
});
629548
};
630549

631-
// Whole-series rehearsal only: `--replay-of` scans every replayed commit, so
632-
// this second scan of `replayOf` against its own base (never live upstream —
633-
// `range.target` may already be pinned to a merge base by the caller) finds
634-
// the legacy debt the replay did not introduce. `--since != --target` means
635-
// the caller bounded the guard to a real commit range already, so the
636-
// baseline diff is a no-op there (recursing with replayOf: null never loops).
637-
const resolveBaselineKeys = (
638-
git: GitReader,
639-
options: ScanOptions,
640-
range: ScanRange,
641-
ledger: string,
642-
additiveRunner: AdditiveRunner | undefined,
643-
): BaselineKeys | undefined => {
644-
if (options.replayOf === null) return undefined;
645-
if (options.since === null || options.since !== options.target) return undefined;
646-
const historicalBase = git.run(["merge-base", range.target, options.replayOf]).trim();
647-
const baselineResult = readScan(
648-
git,
649-
{
650-
base: null,
651-
head: options.replayOf,
652-
target: historicalBase,
653-
typecheck: false,
654-
since: historicalBase,
655-
replayOf: null,
656-
},
657-
ledger,
658-
additiveRunner,
659-
);
660-
return {
661-
base: historicalBase,
662-
replayOf: options.replayOf,
663-
warningKeys: new Set(baselineResult.warnings.map(warningKey)),
664-
additiveKeys: new Set(baselineResult.additive.map(additiveKey)),
665-
};
666-
};
667-
668550
/** What `checkAdditive` needs beyond the git reads: the worktree the trees resolve in. */
669551
export interface AdditiveRunner extends CwdCommandRunner {
670552
readonly worktree: string;

0 commit comments

Comments
 (0)