Skip to content

Commit ae15e93

Browse files
donjor-agent[bot]rsi-pr-agent
authored andcommitted
fix(fork): a sync fold keeps the squash-landed fixup's PR link (#1620)
> 🤖 claude/anthropic claude-opus-5-5 (high) ## Problem The sync rebase folds a squash-landed `fixup! <owner subject> (#N)` into its owner as git's `fixup`, which keeps only the owner's message. So `(#N)` is lost, breaking the #1491 rule that every PR link survives every fold. ## Change 1. Sync renders each folded owner's message first 2. Adds the `Squashes:` list `fork:fold` writes 3. Lists each fixup's PR link there 4. Keeps trailers verbatim, `Co-authored-by:` too 5. Sequence editor amends the owner with it 6. Link guard refuses a tip that lost a link A fixup citing no PR still folds as plain git `fixup`, its owner's message untouched. `fork-sync.md` now names this as the sync's only reword. **Guard scope:** it also refuses a sync where git silently drops a linked fork commit. That matches the sync's rule that it never drops a commit. ## Scope and approval Closes #1592. - [ ] **Sync:** a folded `fixup! <subject> (#N)` keeps RSI-Software/t3code-hyprws#N on the owner's message - [ ] **Guard:** the sync refuses a rebased tip that drops a PR link ## Verification | test | result | | --- | --- | | Fold of `fixup! … (#1600)` | link kept as member line, trailers verbatim | | Tip with the link dropped | refused | | Real rebased tip | passes the guard | | command | exit | | --- | --- | | `vp test run`, 3 touched test files, 127 tests | 0 | | scripts `tsc --noEmit` | 0 | | `vp run fork:ci`, scripts 739 tests | 0 | Not run: a real sync with a linked fixup on trunk; the next one proves it. Claude Opus 5.5 in Claude Code, inside T3 Code; implemented by a Pi child agent. ## Fork trailers Squashes: - d33a265 fix(fork): a sync fold keeps the squash-landed fixup's PR link (#1620) (#1620) - a42e986 fixup! fix(fork): a sync fold keeps the squash-landed fixup's PR link (#1620) (#1620) Fork-Domain: fork-meta Fork-Tier: core Fork-Upstreamable: no
1 parent 28b0f7a commit ae15e93

7 files changed

Lines changed: 347 additions & 47 deletions

File tree

‎docs/fork/operations/fork-sync.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ Discipline lives in [Fork development](../internals/fork-development.md); the pr
99

1010
`hyprws` is the single fork trunk.
1111
The sync driver runs one upstream release tag end to end: one run, one exit code, one report.
12-
It never merges upstream in, nor drops, reorders, or rewords a commit.
12+
It never merges upstream in, nor drops or reorders a commit.
1313
It folds each `fixup! <subject>` landing into the one fork commit it names, a squash landing's trailing ` (#N)` included, and refuses a fixup naming none or several.
14+
It rewords only an owner that absorbs a squash-landed fixup: the fixup's PR link joins its `Squashes:` list, rendered the way fork:fold renders one.
15+
The rebase refuses a rebased tip that dropped any PR link.
1416

1517
| Step | Does | Fails when |
1618
| ------- | ------------------------------------------------------------------------- | -------------------------------------------------- |

‎scripts/fork-fold.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,11 @@ export const foldTrailers = (members: ReadonlyArray<FoldCommit>): string => {
262262
return lines.join("\n");
263263
};
264264

265-
/** Drops an earlier fold's `Squashes:` list so fork:scan reads only this fold's members. */
266-
const withoutSquashes = (prose: string): string =>
265+
/**
266+
* Drops an earlier fold's `Squashes:` list so fork:scan reads only this fold's members.
267+
* The sync reuses it when it re-renders an owner that an earlier sync fold already listed.
268+
*/
269+
export const withoutSquashes = (prose: string): string =>
267270
prose
268271
.split("\n\n")
269272
.filter((paragraph) => {
@@ -312,7 +315,7 @@ const memberLineRefs = (line: string): ReadonlyArray<string> =>
312315
[...line.matchAll(MEMBER_LINE_REF)].map((match) => `${FORK_REPO}#${match[1] ?? match[2]}`);
313316

314317
/** The trimmed `- <sha> …` member lines under a message's first `Squashes:` heading. */
315-
const squashesLines = (message: string): ReadonlyArray<string> => {
318+
export const squashesLines = (message: string): ReadonlyArray<string> => {
316319
const lines = message.replace(/\r\n/g, "\n").split("\n");
317320
const start = lines.findIndex((line) => line.trim() === "Squashes:");
318321
if (start < 0) return [];
@@ -384,7 +387,7 @@ export const citeOld = (stack: FoldStack, old: FoldStack): FoldStack => {
384387
* its own, so it renders like any member and its pull request link survives.
385388
* A commit a split head replayed renders under its `<old>` sha.
386389
*/
387-
const memberLine = (member: FoldCommit): string => {
390+
export const memberLine = (member: FoldCommit): string => {
388391
if (member.subject.startsWith(FIXUP_SUBJECT)) {
389392
const repair = firstSquashesLine(member.message);
390393
if (repair !== undefined) return repair;

‎scripts/fork-sync.test.ts‎

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as NodePath from "node:path";
66

77
import { assert, it } from "@effect/vitest";
88

9+
import type { FoldCommit } from "./fork-fold.ts";
910
import {
1011
blockedIssueBody,
1112
checkCommands,
@@ -15,6 +16,8 @@ import {
1516
dependencySetChanged,
1617
failureIssueBody,
1718
failureMarker,
19+
foldSyncMessages,
20+
refuseDroppedLinks,
1821
resolveFixups,
1922
publishBlock,
2023
publishFailure,
@@ -35,7 +38,7 @@ import { deriveCiTestJobs, workflowJobIds } from "./lib/fork-ci-jobs.ts";
3538
import { FORK_CI_WORKFLOW_PATH } from "./lib/fork-ci-flags.ts";
3639
import { runCommand, type CommandResult } from "./lib/fork-command.ts";
3740
import { GENERATED_HOOK_PATH } from "./lib/fork-hook-guard.ts";
38-
import { placeFixups, sequenceEditor } from "./lib/fork-sync-todo.ts";
41+
import { FOLD_MESSAGES_ENV, placeFixups, sequenceEditor } from "./lib/fork-sync-todo.ts";
3942

4043
const ok = (stdout = ""): CommandResult => ({ status: 0, stdout, stderr: "" });
4144
const refused = (stderr: string): CommandResult => ({ status: 1, stdout: "", stderr });
@@ -1893,6 +1896,62 @@ it("resolves a squash-landed fixup to the owner it names, keeping an owner's own
18931896
);
18941897
});
18951898

1899+
/** A minimal stack member: foldSyncMessages reads subject, short, and message. */
1900+
const foldCommit = (sha: string, message: string): FoldCommit => ({
1901+
sha,
1902+
short: sha.slice(0, 7),
1903+
authorDate: "",
1904+
subject: message.split("\n")[0] ?? "",
1905+
message,
1906+
files: [],
1907+
});
1908+
1909+
it("folds a squash-landed fixup's link into the owner's message as a fold's Squashes section", () => {
1910+
const owner = foldCommit(
1911+
"aaaa1111111",
1912+
"feat: x\n\nFork-Domain: fork-meta\nFork-Tier: core\nCo-authored-by: a <[email protected]>",
1913+
);
1914+
const fixup = foldCommit("cccc2222222", "fixup! feat: x (#16)");
1915+
assert.deepStrictEqual(
1916+
[...foldSyncMessages([owner, fixup], [["cccc2222222", "aaaa1111111"]])],
1917+
[
1918+
[
1919+
"aaaa1111111",
1920+
[
1921+
"feat: x",
1922+
"",
1923+
"Squashes:",
1924+
"",
1925+
"- aaaa111 feat: x",
1926+
"- cccc222 fixup! feat: x (#16) (RSI-Software/t3code-hyprws#16)",
1927+
"",
1928+
"Fork-Domain: fork-meta",
1929+
"Fork-Tier: core",
1930+
"Co-authored-by: a <[email protected]>",
1931+
].join("\n"),
1932+
],
1933+
],
1934+
);
1935+
});
1936+
1937+
it("keeps an owner with no link-carrying fixup a plain git fold", () => {
1938+
const owner = foldCommit("aaaa1111111", "feat: x");
1939+
const fixup = foldCommit("cccc2222222", "fixup! feat: x");
1940+
assert.strictEqual(foldSyncMessages([owner, fixup], [["cccc2222222", "aaaa1111111"]]).size, 0);
1941+
});
1942+
1943+
it("separates a folded owner's subject from its existing prose", () => {
1944+
const owner = foldCommit(
1945+
"aaaa1111111",
1946+
"feat: x\n\nExisting behavior.\n\nFork-Domain: fork-meta\nFork-Tier: core",
1947+
);
1948+
const fixup = foldCommit("cccc2222222", "fixup! feat: x (#16)");
1949+
const folded = foldSyncMessages([owner, fixup], [[fixup.sha, owner.sha]]).get(owner.sha);
1950+
assert.isDefined(folded);
1951+
assert.strictEqual(folded?.split("\n\n")[0], owner.subject);
1952+
assert.include(folded, "\n\nExisting behavior.\n\nSquashes:");
1953+
});
1954+
18961955
it("places each resolved fixup under its owner in git's generated todo", () => {
18971956
const todo = [
18981957
"pick aaaa111 feat: a",
@@ -1924,6 +1983,40 @@ it("places each resolved fixup under its owner in git's generated todo", () => {
19241983
);
19251984
});
19261985

1986+
it("amends an owner with its folded message after the owner's last fixup", () => {
1987+
const todo = [
1988+
"pick aaaa111 feat: a",
1989+
"pick cccc333 fixup! feat: a (#9)",
1990+
"pick dddd444 fixup! feat: a (#10)",
1991+
"pick bbbb222 feat: b",
1992+
].join("\n");
1993+
assert.strictEqual(
1994+
placeFixups(
1995+
todo,
1996+
[
1997+
["cccc3333333", "aaaa1111111"],
1998+
["dddd4444444", "aaaa1111111"],
1999+
],
2000+
new Map([["aaaa1111111", "/sync/folds/aaaa1111111.msg"]]),
2001+
),
2002+
[
2003+
"pick aaaa111 feat: a",
2004+
"fixup cccc333 fixup! feat: a (#9)",
2005+
"fixup dddd444 fixup! feat: a (#10)",
2006+
"exec git commit --amend --no-verify -F '/sync/folds/aaaa1111111.msg'",
2007+
"pick bbbb222 feat: b",
2008+
].join("\n"),
2009+
);
2010+
});
2011+
2012+
it("writes no exec line when no owner carries a folded message", () => {
2013+
const todo = ["pick aaaa111 feat: a", "pick cccc333 fixup! feat: a (#9)"].join("\n");
2014+
assert.strictEqual(
2015+
placeFixups(todo, [["cccc3333333", "aaaa1111111"]]),
2016+
["pick aaaa111 feat: a", "fixup cccc333 fixup! feat: a (#9)"].join("\n"),
2017+
);
2018+
});
2019+
19272020
it("starts the sync rebase interactive with autosquash and the fixup-placing sequence editor", () => {
19282021
withFoldFixture((f) => {
19292022
const seen: Array<{
@@ -1951,10 +2044,11 @@ it("starts the sync rebase interactive with autosquash and the fixup-placing seq
19512044
assert.ok(initial!.args.includes("--autosquash"));
19522045
assert.strictEqual(initial!.env?.GIT_EDITOR, "true");
19532046
assert.strictEqual(initial!.env?.GIT_SEQUENCE_EDITOR, sequenceEditor());
2047+
assert.strictEqual(initial!.env?.[FOLD_MESSAGES_ENV], "[]");
19542048
});
19552049
});
19562050

1957-
it("folds a squash-landed fixup into its owner at the sync rebase", () => {
2051+
it("folds a squash-landed fixup into its owner, keeping its link above the trailers", () => {
19582052
withFoldFixture((f) => {
19592053
const target = { tag: "v1.0.0", sha: f.git(["rev-parse", "v1.0.0"], f.root) };
19602054
const outcome = rebaseOnto(realRunner, f.root, target, f.git(["rev-parse", "hyprws"], f.root));
@@ -1968,6 +2062,43 @@ it("folds a squash-landed fixup into its owner at the sync rebase", () => {
19682062
f.git(["show", `${outcome.newSha}:shared.txt`], f.root),
19692063
"fork line1 fixed\nline2\nline3 upstream",
19702064
);
2065+
// The pre-rebase shas the member lines cite: origin/hyprws still names
2066+
// them, since only the detached worktree moved.
2067+
const fixup = f.git(["rev-parse", "origin/hyprws"], f.root);
2068+
const fixupShort = f.git(["log", "-1", "--format=%h", fixup], f.root);
2069+
const ownerShort = f.git(["log", "-1", "--format=%h", "origin/hyprws^"], f.root);
2070+
const body = f.git(["log", "-1", "--format=%B", outcome.newSha], f.root);
2071+
const bodyLines = body.split("\n").map((line) => line.trim());
2072+
assert.ok(
2073+
bodyLines.includes(
2074+
`- ${fixupShort} fixup! feat(fork): owned change (#1600) (RSI-Software/t3code-hyprws#1600)`,
2075+
),
2076+
`the folded message keeps the fixup's PR link: ${body}`,
2077+
);
2078+
assert.ok(
2079+
bodyLines.includes(`- ${ownerShort} feat(fork): owned change`),
2080+
`the folded message lists its members: ${body}`,
2081+
);
2082+
// The owner's own trailers survive verbatim as the final block.
2083+
const trailers = f.git(["log", "-1", "--format=%(trailers)", outcome.newSha], f.root);
2084+
assert.match(trailers, /Fork-Domain: fork-meta/);
2085+
assert.match(trailers, /Co-authored-by: fork <fork@example\.invalid>/);
2086+
assert.strictEqual(body.trimEnd().endsWith(trailers.trimEnd()), true);
2087+
}, "fixup! feat(fork): owned change (#1600)");
2088+
});
2089+
2090+
it("refuses a rebased tip that drops a squash landing's pull request link", () => {
2091+
withFoldFixture((f) => {
2092+
const target = { tag: "v1.0.0", sha: f.git(["rev-parse", "v1.0.0"], f.root) };
2093+
const oldSha = f.git(["rev-parse", "hyprws"], f.root);
2094+
// A tip folded the old way: the fixup's changes land, its link does
2095+
// not. The cherry-picked owner keeps its own message and loses the link.
2096+
f.git(["checkout", "--quiet", "--detach", "v1.0.0"], f.root);
2097+
f.git(["cherry-pick", "--quiet", `${oldSha}^`], f.root);
2098+
const dropped = f.git(["rev-parse", "HEAD"], f.root);
2099+
assert.throws(() => refuseDroppedLinks(f.root, target, oldSha, dropped), /t3code-hyprws#1600/);
2100+
// The rebase that keeps the link passes the same guard.
2101+
assert.strictEqual(rebaseOnto(realRunner, f.root, target, oldSha).status, "applied");
19712102
}, "fixup! feat(fork): owned change (#1600)");
19722103
});
19732104

0 commit comments

Comments
 (0)