Skip to content

Commit 9cdab26

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(fork): scan a fixup! landing as the commit it names (#1386)
Fork-Domain: fork-meta Fork-Tier: core Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 3c2bfa3 commit 9cdab26

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎scripts/fork-delta.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ export const parseSquashBody = (subject: string, body: string): ForkCommit => ({
149149
const isForkTier = (value: string | undefined): value is ForkTier =>
150150
value !== undefined && (ForkTier.literals as ReadonlyArray<string>).includes(value);
151151

152+
/** The subject prefix marking a fork landing that amends the commit it names. */
153+
export const FIXUP_PREFIX = "fixup! ";
154+
152155
/**
153156
* Walk-authored `fixup!` commits are transient: #861 makes them trailer-free by
154157
* design, and the sync rebase autosquashes them into their owners immediately
@@ -157,7 +160,8 @@ const isForkTier = (value: string | undefined): value is ForkTier =>
157160
*/
158161
export const dropTransientFixups = (
159162
commits: ReadonlyArray<ForkCommit>,
160-
): ReadonlyArray<ForkCommit> => commits.filter((commit) => !commit.subject.startsWith("fixup! "));
163+
): ReadonlyArray<ForkCommit> =>
164+
commits.filter((commit) => !commit.subject.startsWith(FIXUP_PREFIX));
161165

162166
export const collectFindings = (commits: ReadonlyArray<ForkCommit>): ReadonlyArray<ForkFinding> =>
163167
commits.flatMap((commit) => {

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
resolveGuardedCommits,
1717
scanFailures,
1818
squashedMembers,
19+
withFixupOwnerTrailers,
1920
type ScanInput,
2021
} from "./fork-scan.ts";
2122
import { SystemCommandRunner, SystemGit } from "./lib/fork-command.ts";
@@ -250,6 +251,44 @@ it("matches every squashed member by sha prefix and leaves the subject ordinal a
250251
);
251252
});
252253

254+
it("adds the fixups the sync folds into an owner to its replay match", () => {
255+
const matches = matchReplayCounterparts(
256+
[
257+
{ sha: "replayed-owner", subject: "fix: owner" },
258+
{ sha: "replayed-squash", subject: "fix: squash", squashes: ["aaaa111"] },
259+
],
260+
new Map([
261+
["fix: owner", ["original-owner"]],
262+
["fixup! fix: owner", ["original-fixup-1", "original-fixup-2"]],
263+
["fix: squash", ["aaaa1111111"]],
264+
["fixup! fix: squash", ["original-squash-fixup"]],
265+
]),
266+
["aaaa1111111"],
267+
);
268+
assert.deepStrictEqual(
269+
[...matches],
270+
[
271+
["replayed-owner", ["original-owner", "original-fixup-1", "original-fixup-2"]],
272+
["replayed-squash", ["aaaa1111111", "original-squash-fixup"]],
273+
],
274+
);
275+
});
276+
277+
it("scans a trailer-free fixup as the commit it names", () => {
278+
assert.deepStrictEqual(
279+
withFixupOwnerTrailers([
280+
{ sha: "owner", short: "owner", subject: "fix: owner", domain: "example", tier: "core" },
281+
{ sha: "fixup", short: "fixup", subject: "fixup! fix: owner" },
282+
{ sha: "orphan", short: "orphan", subject: "fixup! fix: missing" },
283+
]).map(({ sha, domain, tier }) => ({ sha, domain, tier })),
284+
[
285+
{ sha: "owner", domain: "example", tier: "core" },
286+
{ sha: "fixup", domain: "example", tier: "core" },
287+
{ sha: "orphan", domain: undefined, tier: undefined },
288+
],
289+
);
290+
});
291+
253292
it("keys a finding without its sha or count, keeping path digits", () => {
254293
assert.strictEqual(
255294
normaliseFindingDetail("apps/web/src/a.test.ts gains 4 fork test block(s)"),

‎scripts/fork-sync.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import * as NodePath from "node:path";
4242

4343
import * as Schema from "effect/Schema";
4444

45+
import { FIXUP_PREFIX } from "./fork-delta.ts";
4546
import { parseArgs, UsageError } from "./lib/fork-cli.ts";
4647
import {
4748
commandText,
@@ -467,9 +468,6 @@ export type RebaseOutcome =
467468
}
468469
| { readonly status: "blocked"; readonly conflicts: ReadonlyArray<ConflictRow> };
469470

470-
/** The subject prefix marking a fork landing that amends the commit it names. */
471-
export const FIXUP_PREFIX = "fixup! ";
472-
473471
/** Subjects of the fork commits above `target` that a `fixup!` commit may name. */
474472
export const forkSubjects = (
475473
runner: CommandRunner,

0 commit comments

Comments
 (0)