GeezerVison is showing github.com — fork seams: after a rebase, exclude an upstream file named like a for… · scuttletoby/t3code@42571f7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .github/scripts/fork-follow.sh +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -195,7 +195,8 @@ schema_check "$base" "The series" | 195 | 195 | # is a fork with a list of its own). After a rebase (--after-rebase), a "pending" ceiling or "lost" | 196 | 196 | # count above the file's lines is only a note: upstream taking a fork line drops it in the rebase, | 197 | 197 | # and the next run (from the new base) would refuse it. So the series gets a commit that lowers each | 198 | | -# one (#325); a count that rose is still refused, as raising one is the owner's review. | | 198 | +# one (#325), and excludes in "forkFiles" each upstream file a pull request's run would take for the | | 199 | +# fork's own (#432); a count that rose is still refused, as raising one is the owner's review. | 199 | 200 | seam_refusal="Fork changes to upstream files must stay within the seam lines" | 200 | 201 | # What a lowering commit changed, for the run's summary: written only once the plan has finished, | 201 | 202 | # as a later check can still stop it and then nothing is pushed. | @@ -218,7 +219,7 @@ seam_check() { # seam_check BASE WHAT [--after-rebase] | 218 | 219 | as_fork commit -q -m "fork seams: lower counts after the rebase onto $target_tag" -m "$lowered" | 219 | 220 | printf '%s\n' "$2 lowered the seam list (.github/fork-seams.json) in a commit of its own:" "$lowered" >&2 | 220 | 221 | lowered_summary=("### Seam list lowered: $2" "" "$lowered" "" \ | 221 | | - "Committed on top of the rebased series (the candidate); the fork lines or upstream lines these counted are gone." "") | | 222 | + "Committed on top of the rebased series (the candidate); the fork lines or upstream lines these counted are gone, and each excluded file is upstream's." "") | 222 | 223 | # The lowered list is judged again: it must pass and lower nothing more. | 223 | 224 | status=0 | 224 | 225 | seam_run "$1" ${3:+"$3"} || status=$? | |
Collapse file Copy file name to clipboardExpand all lines: .github/scripts/fork-follow.test.sh +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -693,6 +693,24 @@ plan | 693 | 693 | check "plan: re-run of a rebase that lowered the list -> the same files, advance to the earlier release" \ | 694 | 694 | eval 'action_is advance && [[ "$(out candidate)" == "$released" ]] && grep -q "lowered the seam list" "$root/out"' | 695 | 695 |
| | 696 | +# #432: upstream adds a file named like the fork's (upstream's own "fork" feature names files so). | | 697 | +# A pull request's run would take it for the fork's own, so the run from upstream refused it and | | 698 | +# every fork-follow stopped until a pull request excluded it. After the rebase the plan excludes | | 699 | +# it itself, in the lowering commit, and the next run passes. | | 700 | +new_upstream | | 701 | +new_fork v0.1.10 | | 702 | +up_release v0.1.11 'echo up > fork-up.txt' | | 703 | +plan | | 704 | +check "plan: an upstream file named like a fork file is excluded in the lowered list, not a stop" \ | | 705 | + eval 'action_is rebase && [[ ! -e "$root/refused" ]] \ | | 706 | + && [[ "$(lowered_list | jq -c .forkFiles)" == "[\"!fork-up.txt\"]" ]] \ | | 707 | + && grep -qx -- "- fork-up.txt: \"forkFiles\" \"!fork-up.txt\" added (upstream has it; a pull request'"'"'s run took it for a fork file)" <<< "$(git -C "$root/work" log -1 --format=%b "$(out candidate)")"' | | 708 | +work git reset -q --hard "$(out candidate)" | | 709 | +work git push -q --force origin HEAD:main | | 710 | +plan | | 711 | +check "plan: the next run from the new base passes the list with the exclusion" \ | | 712 | + eval 'action_is release && [[ ! -e "$root/report.md" ]] && hasnt "lowered the seam list" "$root/out"' | | 713 | + | 696 | 714 | # The lowered list is checked again and must lower nothing more. A seam check that always lowers | 697 | 715 | # (in the fork's series, which the plan runs) stops the plan: the report says what was lowered, and | 698 | 716 | # the run's summary claims no commit, as nothing goes on from here. | |
Collapse file Copy file name to clipboardExpand all lines: .github/scripts/fork-seam-check.cjs +48-15Lines changed: 48 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -555,16 +555,20 @@ function findListedGone(config, { atBase, atHead }) { | 555 | 555 | } | 556 | 556 |
| 557 | 557 | /** | 558 | | - * Upstream's files the head still has that a pull request's run would take for the fork's own (a | 559 | | - * hole in that run). `upstreamFiles`: every path upstream has; `atHead`: a path's text in head. | | 558 | + * Upstream files in head that a pull request's run would take for the fork's own. Refused, except | | 559 | + * right after a rebase that writes a lowered list: there each goes to `lowered.hidden` and lowerList | | 560 | + * excludes it in "forkFiles", which only narrows what a pull request's run takes for the fork's own. | 560 | 561 | */ | 561 | | -function findHiddenUpstreamFiles(upstreamFiles, isForkFile, atHead) { | 562 | | - return upstreamFiles | 563 | | - .filter((file) => isForkFile(file) && atHead(file) !== undefined) | 564 | | - .map( | 565 | | - (file) => | 566 | | - `${file}: upstream has it, but a pull request's run takes it for a fork file (its name or "forkFiles"); exclude it with "!${file}".`, | 567 | | - ); | | 562 | +function findHiddenUpstreamFiles(upstreamFiles, isForkFile, atHead, lowered) { | | 563 | + const hidden = upstreamFiles.filter((file) => isForkFile(file) && atHead(file) !== undefined); | | 564 | + if (lowered !== undefined) { | | 565 | + for (const file of hidden) lowered.hidden.add(file); | | 566 | + return []; | | 567 | + } | | 568 | + return hidden.map( | | 569 | + (file) => | | 570 | + `${file}: upstream has it, but a pull request's run takes it for a fork file (its name or "forkFiles"); exclude it with "!${file}".`, | | 571 | + ); | 568 | 572 | } | 569 | 573 |
| 570 | 574 | /** | @@ -877,10 +881,10 @@ const MOVED_WHY = | 877 | 881 | 'Was "pending": fork-follow moved it here once it had no fork line left, as its "lost" entry still counts upstream lines it loses. No seam line: a fork line goes in a file of the fork\'s own.'; | 878 | 882 |
| 879 | 883 | /** | 880 | | - * `text` with the counts in `lowered` ({ pending, lost }: Maps of file to count) lowered, as { text, changes }, | 881 | | - * or undefined when nothing changes. Only lowers; a count at 0 removes the entry. A "pending" file with no fork | 882 | | - * line left that "lost" still names moves to "files" with no seam line (no fork line may come back, no line may | 883 | | - * be lost). Two-space JSON, parsed again before it is returned, so a lowered list is never one the check refuses. | | 884 | + * `text` with `lowered` ({ pending, lost } Maps of counts, `hidden` Set of upstream files) applied, as | | 885 | + * { text, changes }, or undefined when nothing changes. Only lowers; a count at 0 removes the entry; a | | 886 | + * "pending" file with no fork line left moves to "files"; each hidden file stops being a fork file | | 887 | + * (its own "forkFiles" entry goes, or a `!` entry excludes it). Parsed again before it is returned. | 884 | 888 | */ | 885 | 889 | function lowerList(text, lowered) { | 886 | 890 | const raw = JSON.parse(text); | @@ -927,6 +931,21 @@ function lowerList(text, lowered) { | 927 | 931 | }), | 928 | 932 | ); | 929 | 933 | } | | 934 | + for (const file of lowered.hidden ?? []) { | | 935 | + const patterns = raw.forkFiles ?? []; | | 936 | + const kept = patterns.filter((pattern) => pattern !== file); | | 937 | + const named = forkFileTest(kept)(file); | | 938 | + if (named) kept.push(`!${file}`); | | 939 | + raw.forkFiles = kept; | | 940 | + const what = !named | | 941 | + ? "entry removed" | | 942 | + : kept.length === patterns.length | | 943 | + ? `entry replaced by "!${file}"` | | 944 | + : `"!${file}" added`; | | 945 | + changes.push( | | 946 | + `${file}: "forkFiles" ${what} (upstream has it; a pull request's run took it for a fork file)`, | | 947 | + ); | | 948 | + } | 930 | 949 | // Appended through defineProperty: a file named `__proto__` stays an own key. | 931 | 950 | for (const file of moved) { | 932 | 951 | Object.defineProperty(raw.files, file, { | @@ -1038,7 +1057,9 @@ function main(argv) { | 1038 | 1057 | } | 1039 | 1058 | } | 1040 | 1059 | const lowered = | 1041 | | - parsed.loweredList === undefined ? undefined : { pending: new Map(), lost: new Map() }; | | 1060 | + parsed.loweredList === undefined | | 1061 | + ? undefined | | 1062 | + : { pending: new Map(), lost: new Map(), hidden: new Set() }; | 1042 | 1063 | const unlisted = findUnlistedChanges(config, { | 1043 | 1064 | changed, | 1044 | 1065 | atBase, | @@ -1087,6 +1108,7 @@ function main(argv) { | 1087 | 1108 | git(["ls-tree", "-r", "-z", "--name-only", mergeBase]).split("\0").filter(Boolean), | 1088 | 1109 | isForkFile, | 1089 | 1110 | atHead, | | 1111 | + lowered, | 1090 | 1112 | ) | 1091 | 1113 | : []), | 1092 | 1114 | ]; | @@ -1127,7 +1149,18 @@ function main(argv) { | 1127 | 1149 | if (listProblem !== undefined) return 1; | 1128 | 1150 | if (lowered !== undefined) { | 1129 | 1151 | // After a rebase only: fork-follow commits the lowered list into the rebased series. | 1130 | | - const lower = lowerList(textAt(configRef, CONFIG), lowered); | | 1152 | + const listText = textAt(configRef, CONFIG); | | 1153 | + const lower = lowerList(listText, lowered); | | 1154 | + const isStillFork = forkFileTest(parseConfig(lower?.text ?? listText).forkFiles); | | 1155 | + const still = [...lowered.hidden].filter((file) => isStillFork(file)); | | 1156 | + if (still.length > 0) { | | 1157 | + for (const file of still) { | | 1158 | + console.error( | | 1159 | + printable(`${file}: the lowered list still takes this upstream file for a fork file.`), | | 1160 | + ); | | 1161 | + } | | 1162 | + return 1; | | 1163 | + } | 1131 | 1164 | if (lower !== undefined) { | 1132 | 1165 | fs.writeFileSync(parsed.loweredList, lower.text); | 1133 | 1166 | for (const change of lower.changes) console.log(printable(`Lowered: ${change}`)); | |
Collapse file Copy file name to clipboardExpand all lines: .github/scripts/fork-seam-check.test.cjs +84Lines changed: 84 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -913,6 +913,90 @@ test("from upstream, an upstream file named like a fork file fails on the comman | 913 | 913 | }); | 914 | 914 | }); | 915 | 915 |
| | 916 | +// A file upstream names like a fork file stopped every fork-follow after the rebase until a pull | | 917 | +// request excluded it. Right after a rebase that writes a lowered list, the list excludes it. | | 918 | +test("after a rebase, the lowered list excludes an upstream file a pull request's run takes for a fork file", () => { | | 919 | + withRepo(({ dir, commit, fromUpstream }) => { | | 920 | + const upstream = commit( | | 921 | + { "src/exact.ts": UP, "src/forkJoin.ts": UP, "src/usage/Up.ts": UP, ...BASE }, | | 922 | + "upstream", | | 923 | + ); | | 924 | + // Old state: a list with no "forkFiles" key, and one whose entries take upstream's files. | | 925 | + const forkFiles = ["src/usage/", "src/exact.ts", "src/fork-own.ts"]; | | 926 | + const series = commit( | | 927 | + { ...seams({ files: SEAM, forkFiles }), "src/fork-own.ts": UP }, | | 928 | + "fork series", | | 929 | + ); | | 930 | + const out = path.join(dir, "..", `${path.basename(dir)}-lowered.json`); | | 931 | + try { | | 932 | + // Before the rebase, or after it with no list to write, it is still refused: nothing would | | 933 | + // commit the exclusion, and main's pull request runs would keep the hole. | | 934 | + for (const args of [[], ["--after-rebase"]]) { | | 935 | + const refused = fromUpstream(...args, upstream, series); | | 936 | + assert.equal(refused.status, 1, args.join(" ")); | | 937 | + assert.match(refused.stderr, /- src\/forkJoin\.ts: upstream has it/); | | 938 | + } | | 939 | + const result = fromUpstream("--after-rebase", "--lowered-list", out, upstream, series); | | 940 | + assert.equal(result.status, 0, result.stderr); | | 941 | + const why = "(upstream has it; a pull request's run took it for a fork file)"; | | 942 | + assert.deepEqual(result.stdout.match(/^Lowered: .*$/gm), [ | | 943 | + `Lowered: src/exact.ts: "forkFiles" entry removed ${why}`, | | 944 | + `Lowered: src/forkJoin.ts: "forkFiles" "!src/forkJoin.ts" added ${why}`, | | 945 | + `Lowered: src/usage/Up.ts: "forkFiles" "!src/usage/Up.ts" added ${why}`, | | 946 | + ]); | | 947 | + const lowered = parseConfig(fs.readFileSync(out, "utf8")); | | 948 | + assert.deepEqual(lowered.forkFiles, [ | | 949 | + "src/usage/", | | 950 | + "src/fork-own.ts", | | 951 | + "!src/forkJoin.ts", | | 952 | + "!src/usage/Up.ts", | | 953 | + ]); | | 954 | + // Main's pull request runs judge upstream's three as upstream's; the fork's own stay its own. | | 955 | + const isForkFile = forkFileTest(lowered.forkFiles); | | 956 | + for (const file of ["src/exact.ts", "src/forkJoin.ts", "src/usage/Up.ts"]) { | | 957 | + assert.equal(isForkFile(file), false, file); | | 958 | + } | | 959 | + assert.equal(isForkFile("src/fork-own.ts"), true); | | 960 | + assert.equal(isForkFile("src/usage/Own.ts"), true); | | 961 | + // Runs again with the lowered list committed: nothing more to lower or refuse. | | 962 | + fs.rmSync(out); | | 963 | + const committed = commit({ [CONFIG]: JSON.stringify(lowered) }, "lowered"); | | 964 | + for (const args of [["--after-rebase", "--lowered-list", out], ["--after-rebase"], []]) { | | 965 | + const again = fromUpstream(...args, upstream, committed); | | 966 | + assert.equal(again.status, 0, `${args.join(" ")}: ${again.stderr}`); | | 967 | + assert.doesNotMatch(again.stdout, /Lowered/); | | 968 | + } | | 969 | + assert.equal(fs.existsSync(out), false); | | 970 | + // A fork change in such a file is refused, never excluded away, and nothing is written. | | 971 | + const changed = commit( | | 972 | + { [CONFIG]: JSON.stringify({ files: SEAM, forkFiles }), "src/forkJoin.ts": `${UP}x();\n` }, | | 973 | + "fork line", | | 974 | + ); | | 975 | + const stopped = fromUpstream("--after-rebase", "--lowered-list", out, upstream, changed); | | 976 | + assert.equal(stopped.status, 1); | | 977 | + assert.match(stopped.stderr, /- src\/forkJoin\.ts: upstream file with 1 fork line/); | | 978 | + assert.equal(fs.existsSync(out), false); | | 979 | + } finally { | | 980 | + fs.rmSync(out, { force: true }); | | 981 | + } | | 982 | + }); | | 983 | +}); | | 984 | + | | 985 | +test("lowerList excludes a hidden upstream file in a list with no forkFiles, or replaces its own entry", () => { | | 986 | + const none = `${JSON.stringify({ files: {} }, null, 2)}\n`; | | 987 | + const hidden = (...files) => ({ pending: new Map(), lost: new Map(), hidden: new Set(files) }); | | 988 | + assert.deepEqual(JSON.parse(lowerList(none, hidden("src/forkJoin.ts")).text), { | | 989 | + files: {}, | | 990 | + forkFiles: ["!src/forkJoin.ts"], | | 991 | + }); | | 992 | + // Named like the fork's and listed: the entry alone would not exclude it, so a `!` replaces it. | | 993 | + const listed = `${JSON.stringify({ files: {}, forkFiles: ["fork/up.ts"] }, null, 2)}\n`; | | 994 | + const result = lowerList(listed, hidden("fork/up.ts")); | | 995 | + assert.deepEqual(JSON.parse(result.text).forkFiles, ["!fork/up.ts"]); | | 996 | + assert.match(result.changes[0], /^fork\/up\.ts: "forkFiles" entry replaced by "!fork\/up\.ts"/); | | 997 | + assert.equal(lowerList(none, hidden()), undefined); | | 998 | +}); | | 999 | + | 916 | 1000 | // Both cases passed in both modes before. | 917 | 1001 | test("a rename or delete cannot hide an upstream file, from upstream or on a pull request", () => { | 918 | 1002 | withRepo(({ dir, git, commit, run, fromUpstream }) => { | |
Collapse file Copy file name to clipboardExpand all lines: docs/fork/updates.md +6-3Lines changed: 6 additions & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -122,9 +122,12 @@ watches; it changes nothing on the machine, and `0` turns it off. | 122 | 122 | (the runbook below), regenerate the tree and commit it into the rebased series before pushing; a | 123 | 123 | pull request that changes only the tree is judged line by line and refused. A pull request's run has no upstream commit, | 124 | 124 | so it takes files named as the fork's (`fork`, `fork-*`, `forkName*`, `FORK_*`) and `forkFiles` | 125 | | - for the fork's own; from upstream, a pattern that matches an upstream file fails. Then remove the | 126 | | - entry (or exclude a fork-named path with `!path`): from then on a pull request's run judges the | 127 | | - file as upstream's, also before the rebase that brings upstream's copy. For the same | | 125 | + for the fork's own; from upstream, a pattern that matches an upstream file fails. Right after a | | 126 | + rebase it is not refused: fork-follow excludes the file itself in its lowering commit (the | | 127 | + file's own `forkFiles` entry goes; a fork-named path or one another pattern takes gets `!path`), | | 128 | + which only narrows what a pull request's run takes for the fork's own. Before a rebase (a list | | 129 | + on main that lets one through) it still fails: remove the entry or add the `!path` with a pull | | 130 | + request. Either way a pull request's run then judges the file as upstream's. For the same | 128 | 131 | reason a pull request's run counts upstream's copies of a seam line against its allowance: a | 129 | 132 | seam line upstream also has (`}`, `/**`) cannot be added by a pull request, only checked by | 130 | 133 | fork-follow, so keep seam lines specific. A listed copy main's tip already has is spent too, not | |
|