Skip to content

Commit a1c4ebc

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(fork-sync): a landed hook retirement exempts no later sync (#1892)
## Problem The #1891 hook gate exempts any key with a `Fork-Hook-Retired` trailer above the merge base. A rebased tip copies every landed fork commit, so a trailer that landed on a plain commit exempts its key in every later sync. ## Change - **Exempt only new trailers:** the tip must carry more per key than the trunk - **Landed trailers:** cancel against their rebased copies ## Scope and approval Found while auditing the #1886 proof run's 36 retirements. Refs #1886 ## Verification - `fork-sync.test.ts`: a landed trailer's rebased copy no longer exempts the key - Fails before the fix, passes after (80/80) - `vp run fork:ci` → exit 0 Claude Opus 5.5 via Claude Code. ## Fork trailers Squashes: - b9d7679 fix(fork-sync): a landed hook retirement exempts no later sync (#1892) (#1892) - 7ba75a7 fixup! fix(fork-sync): a landed hook retirement exempts no later sync (#1892) (#1892) Fork-Domain: fork-meta Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 7f8dad0 commit a1c4ebc

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎scripts/fork-sync.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ it("names a hook the tip carries fewer marked lines of, unless a tip commit reti
646646
assert.deepStrictEqual(lostHooks(realRunner, f.root, trunk, tip), ["d/call (2→1)"]);
647647
const retired = write(["a();"], "retire\n\nFork-Hook-Retired: d/call");
648648
assert.deepStrictEqual(lostHooks(realRunner, f.root, trunk, retired), []);
649+
650+
// A landed trailer's rebased copy retires nothing in a later sync.
651+
const kept = ["a(); // fork-hook: d/call"];
652+
const message = "keep one\n\nFork-Hook-Retired: d/call";
653+
const landed = write(kept, message);
654+
f.git(["checkout", "--quiet", "--detach", retired], f.root);
655+
write(kept, message);
656+
const rebased = write(["a();"], "drop the last");
657+
assert.deepStrictEqual(lostHooks(realRunner, f.root, landed, rebased), ["d/call (1→0)"]);
649658
});
650659
});
651660

‎scripts/fork-sync.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,10 @@ const hookLineCounts = (
11551155
};
11561156

11571157
/**
1158-
* The hook keys whose marked lines the tip carries fewer of than the trunk:
1159-
* a resolution that silently dropped fork behaviour, which typecheck and tests
1160-
* miss. A key a commit above the merge base retires with a
1161-
* `Fork-Hook-Retired: domain/name` trailer is exempt.
1158+
* Hook keys whose marked lines the tip carries fewer of than the trunk: a resolution that silently
1159+
* dropped fork behaviour, which typecheck and tests miss. A key is exempt only when the tip's
1160+
* commits carry more `Fork-Hook-Retired: domain/name` trailers for it than the trunk's, so a
1161+
* landed retirement's rebased copy never exempts the key again.
11621162
*/
11631163
export const lostHooks = (
11641164
runner: CommandRunner,
@@ -1169,17 +1169,21 @@ export const lostHooks = (
11691169
const before = hookLineCounts(runner, root, trunk);
11701170
const after = hookLineCounts(runner, root, tip);
11711171
const since = git(runner, root, ["merge-base", trunk, tip]);
1172-
const retired = new Set(
1173-
lines(
1174-
git(runner, root, [
1175-
"log",
1176-
`--format=%(trailers:key=${HOOK_RETIRED_TRAILER},valueonly)`,
1177-
`${since}..${tip}`,
1178-
]),
1179-
),
1180-
);
1172+
const retirements = (ref: string): ReadonlyMap<string, number> => {
1173+
const counts = new Map<string, number>();
1174+
const log = git(runner, root, [
1175+
"log",
1176+
`--format=%(trailers:key=${HOOK_RETIRED_TRAILER},valueonly)`,
1177+
`${since}..${ref}`,
1178+
]);
1179+
for (const key of lines(log)) counts.set(key, (counts.get(key) ?? 0) + 1);
1180+
return counts;
1181+
};
1182+
const landed = retirements(trunk);
1183+
const declared = retirements(tip);
1184+
const retired = (key: string): boolean => (declared.get(key) ?? 0) > (landed.get(key) ?? 0);
11811185
return [...before]
1182-
.filter(([key, count]) => (after.get(key) ?? 0) < count && !retired.has(key))
1186+
.filter(([key, count]) => (after.get(key) ?? 0) < count && !retired(key))
11831187
.map(([key, count]) => `${key} (${count}→${after.get(key) ?? 0})`)
11841188
.toSorted();
11851189
};

0 commit comments

Comments
 (0)