Skip to content

Commit ca00d62

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(fork): forkSupersedes names wrapped and each-table upstream titles (#1532)
Replaces #1511, which GitHub closed when a host push briefly set its branch to trunk. Same commits, rebased onto `b98ba3ed105`; the combined fold proof of all B2 fixups was rerun there: no stops, tree-equal. ## Problem `forkSupersedes` cannot name an upstream case whose title prettier wrapped onto the next line (`it.effect(` then `"title"`), or an `.each` table case (`it.effect.each([...])(`). The scan refuses the declaration ("does not carry"), and the authoring guard excuses none of the removed lines. This blocks the #1493 B2 supersedes in `RepositoryIdentityResolver.test.ts` and `ProjectSetupScriptRunner.test.ts`. ## Change - `scripts/lib/fork-supersedes.ts` owns one case-opener parse, `caseOpeners`. - It reads a same-line title, a title on the line after a bare opener, and a one-line `.each(...)` table. - `caseSourceLines` returns one case's source lines. - `fork-scan-authoring.ts` and `fork-additive-gate.ts` drop their copies of the title regex and the case walk, and call `caseSourceLines`. - The authoring module doc had an import spliced into it; the doc is rejoined and the stale "kept local" note goes. ## Scope and approval Part of #1493 (batch B2 tooling prerequisite, host decision). B2 supersede PRs stack on this one. ## Verification ```text vp test run scripts/lib/fork-supersedes.test.ts scripts/fork-scan-gates.test.ts scripts/lib/fork-additive-gate.test.ts → exit 0 (57 passed) new guard case on the old parser → 1 failed (as expected) tsc --noEmit (scripts) → exit 0 vp lint <touched files> → exit 0 vp run fork:ci → exit 0 ``` Rebase scan (`--head HEAD --target <v0.0.45-nightly.20261002.2561> --since <same> --replay-of origin/hyprws --no-typecheck`): 95 historical findings before and after, none new. Model: Claude Opus 5.5, Claude Code (T3 Code thread). ## Fork trailers Squashes: - 62bcd0c fix(fork): forkSupersedes names wrapped and each-table upstream titles (#1532) (#1532) - cdac57a fixup! fix(fork): forkSupersedes names wrapped and each-table upstream titles (#1532) (#1532) Fork-Domain: fork-meta Fork-Tier: core Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent d76c5cc commit ca00d62

5 files changed

Lines changed: 185 additions & 130 deletions

File tree

‎scripts/fork-scan-authoring.ts‎

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
// @effect-diagnostics nodeBuiltinImport:off - Fork scripts need a synchronous bootstrap runner.
22

3-
// Authoring guards for `vp run fork:scan`. Each rule names a
4-
// shape a later rebase pays for, at the moment a fork commit creates it:
5-
//
6-
// - upstream-test: the commit adds a fork test block to an upstream-owned test
7-
// file instead of its `*.fork.test.ts` sibling, or rewrites an upstream
8-
// assertion in place (a same-size swap nets to zero added blocks, so the
9-
// removed side is the whole shape).
10-
// - replaced-export: the commit deletes an upstream-owned exported declaration
11-
import { enclosedSupersededTitles, supersededTitlesByPath } from "./lib/fork-supersedes.ts";
12-
13-
// A case title: the first string literal of an `it`/`test`/`effectIt`
14-
// opener, including the dotted effect forms (`it.effect`, `it.layer`).
15-
// Mirrors the additive gate's opener; kept local so this module stays
16-
// runnable without the gate's git runner.
17-
// and re-declares it, so every later upstream edit to it lands invisibly.
18-
//
19-
// (RSI-Software/t3code-hyprws#1190: smallest form of the old authoring-guard
20-
// cluster; footprint, lockfile, boundary, seam, and reshape rules do not come
21-
// back.) Warnings on commits in the `--since` range fail the scan; historical
22-
// range stays advisory.
3+
// Authoring guards for `vp run fork:scan`, each naming a shape a later rebase pays for:
4+
// upstream-test (a fork block added to an upstream test file instead of its `*.fork.test.ts`
5+
// sibling, or an upstream assertion rewritten in place) and replaced-export (an upstream export
6+
// deleted and re-declared). `--since` range warnings fail the scan; the historical range is advisory.
7+
8+
import {
9+
caseSourceLines,
10+
enclosedSupersededTitles,
11+
supersededTitlesByPath,
12+
} from "./lib/fork-supersedes.ts";
2313

2414
export type ScanAuthoringRule = "upstream-test" | "replaced-export";
2515

@@ -259,9 +249,6 @@ export const parseCommitPatches = (raw: string): ReadonlyMap<string, CommitPatch
259249
export const TEST_FILE = /\.test\.tsx?$/;
260250
const FORK_TEST_FILE = /\.fork\.test\.tsx?$/;
261251

262-
const TITLE_OF =
263-
/^\s*(?:it|test|effectIt)\s*(?:\.[\w$]+)*\s*(?:<[^>]*>)?\s*\(\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|`((?:\\.|[^`\\])*)`)/;
264-
265252
/** The paths whose target-tree text the upstream-test rule measures this patch against. */
266253
export const upstreamTestPaths = (patch: CommitPatch): ReadonlyArray<string> => [
267254
...patch.removedTestLines.keys(),
@@ -288,28 +275,8 @@ const significantLines = (text: string): ReadonlyArray<string> =>
288275
* that kept the body of the case it replaced exempts by its own case,
289276
* never by whole-file line membership (RSI-Software/t3code-hyprws#1208).
290277
*/
291-
const caseLines = (text: string, title: string): ReadonlySet<string> => {
292-
const lines = text.replace(/\r\n/g, "\n").split("\n");
293-
const started: Array<string> = [];
294-
let inside = false;
295-
for (const line of lines) {
296-
const current =
297-
TITLE_OF.exec(line)
298-
?.slice(1)
299-
.find((part) => part !== undefined) ?? null;
300-
if (current !== null) {
301-
if (current === title && !inside) {
302-
inside = true;
303-
started.push(line.trim());
304-
continue;
305-
}
306-
if (inside) break;
307-
continue;
308-
}
309-
if (inside) started.push(line);
310-
}
311-
return new Set(significantLines(started.join("\n")));
312-
};
278+
const caseLines = (text: string, title: string): ReadonlySet<string> =>
279+
new Set(significantLines(caseSourceLines(text, title).join("\n")));
313280

314281
/**
315282
* The target-tree lines of every case the scanned head's sibling declares

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,45 @@ it("passes a declared-superseded deletion and still fails an undeclared one", ()
544544
);
545545
});
546546

547+
it("passes a declared-superseded deletion of a wrapped case", () => {
548+
// Prettier wraps a long opener so its title sits on the next line; the
549+
// declaration still names that case and excuses its head and title lines.
550+
const removedCase = [
551+
"abc1234",
552+
"--- a/apps/web/src/thing.test.ts",
553+
"+++ b/apps/web/src/thing.test.ts",
554+
"@@ -1,4 +1,0 @@",
555+
"-it.effect(",
556+
'- "a title long enough that prettier wraps it",',
557+
"- () => Effect.sync(() => expect(keep).toBe(2)),",
558+
"-);",
559+
"",
560+
].join("\n");
561+
const upstreamText =
562+
'it.effect(\n "a title long enough that prettier wraps it",\n () => Effect.sync(() => expect(keep).toBe(2)),\n);\n';
563+
const sibling =
564+
'forkSupersedes({ upstream: "apps/web/src/thing.test.ts > a title long enough that prettier wraps it", reason: "the fork inverts it", commit: "abc1234" });\n' +
565+
'it("replacement", () => {\n expect(keep).toBe(3);\n});\n';
566+
const result = buildScanResult(
567+
baseInput({
568+
commits: [{ sha: "abc1234", short: "abc1234", domain: "example" }],
569+
filesBySha: new Map([["abc1234", ["apps/web/src/thing.test.ts"]]]),
570+
patchesBySha: parseCommitPatches(removedCase),
571+
upstreamFiles: new Set(["apps/web/src/thing.test.ts"]),
572+
upstreamTestFiles: new Set(["apps/web/src/thing.test.ts"]),
573+
upstreamTestLines: new Map([
574+
["apps/web/src/thing.test.ts", significantTestLines(upstreamText)],
575+
]),
576+
upstreamTestTexts: new Map([["apps/web/src/thing.test.ts", upstreamText]]),
577+
siblingTexts: new Map([["apps/web/src/thing.fork.test.ts", sibling]]),
578+
}),
579+
);
580+
assert.deepStrictEqual(
581+
scanFailures(result).filter((failure) => failure.startsWith("upstream-test:")),
582+
[],
583+
);
584+
});
585+
547586
it("fails a replaced export matched by name across files", () => {
548587
const raw = [
549588
"abc1234",

‎scripts/lib/fork-additive-gate.ts‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import * as NodePath from "node:path";
1111

1212
import type { CwdCommandRunner as CommandRunner } from "./fork-command.ts";
13-
import { enclosedSupersededTitles } from "./fork-supersedes.ts";
13+
import { caseSourceLines, enclosedSupersededTitles } from "./fork-supersedes.ts";
1414

1515
export type AdditiveCheck = "files" | "migrations" | "tests";
1616

@@ -264,31 +264,8 @@ export const upstreamTestPath = (sibling: string): string =>
264264
// The significant lines one upstream case carries: the opener line naming
265265
// the title through the next case opener. Line-based, the way
266266
// `significantLines` is — a case body is what the lost-line multiset counts.
267-
const TITLE_OF =
268-
/^\s*(?:it|test|effectIt)\s*(?:\.[\w$]+)*\s*(?:<[^>]*>)?\s*\(\s*(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)'|`((?:\\.|[^`\\])*)`)/;
269-
270-
const caseLines = (text: string, title: string): ReadonlyArray<string> => {
271-
const lines = text.replace(/\r\n/g, "\n").split("\n");
272-
const started: Array<string> = [];
273-
let inside = false;
274-
for (const line of lines) {
275-
const current =
276-
TITLE_OF.exec(line)
277-
?.slice(1)
278-
.find((part) => part !== undefined) ?? null;
279-
if (current !== null) {
280-
if (current === title && !inside) {
281-
inside = true;
282-
started.push(line.trim());
283-
continue;
284-
}
285-
if (inside) break;
286-
continue;
287-
}
288-
if (inside) started.push(line);
289-
}
290-
return significantLines(started.join("\n"));
291-
};
267+
const caseLines = (text: string, title: string): ReadonlyArray<string> =>
268+
significantLines(caseSourceLines(text, title).join("\n"));
292269

293270
const testFindings = (
294271
runner: CommandRunner,

‎scripts/lib/fork-supersedes.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { assert, it } from "@effect/vitest";
44

55
import {
66
assessForkSupersedes,
7+
caseSourceLines,
78
collectForkSupersedes,
89
contradictingTitles,
910
enclosedSupersededTitles,
1011
parseForkSupersedesCalls,
12+
siblingCaseOpenerLines,
1113
testCaseTitles,
1214
} from "./fork-supersedes.ts";
1315

@@ -94,6 +96,59 @@ it("reads case titles across the dotted effect forms", () => {
9496
assert.deepStrictEqual(testCaseTitles(text), ["plain", "dotted", "skipped"]);
9597
});
9698

99+
it("reads a title prettier wrapped onto the line after its opener", () => {
100+
const text = [
101+
`it.each([1, 2])("table %s", () => {});`,
102+
`it.effect(`,
103+
` "wrapped",`,
104+
` () => Effect.void,`,
105+
`);`,
106+
`it.effect.each(["add", "replace"] as const)(`,
107+
` "refreshes after %s",`,
108+
` (operation) => Effect.void,`,
109+
`);`,
110+
`it.effect(() => Effect.void);`,
111+
].join("\n");
112+
assert.deepStrictEqual(testCaseTitles(text), ["table %s", "wrapped", "refreshes after %s"]);
113+
assert.deepStrictEqual(siblingCaseOpenerLines(text), [1, 2, 6]);
114+
assert.deepStrictEqual(caseSourceLines(text, "refreshes after %s"), [
115+
`it.effect.each(["add", "replace"] as const)(`,
116+
` "refreshes after %s",`,
117+
` (operation) => Effect.void,`,
118+
`);`,
119+
`it.effect(() => Effect.void);`,
120+
]);
121+
assert.deepStrictEqual(caseSourceLines(text, "absent"), []);
122+
});
123+
124+
it("judges a declaration naming a wrapped each-table title", () => {
125+
const upstream = [
126+
`it.effect.each(["add", "replace"] as const)(`,
127+
` "refreshes after %s",`,
128+
` (operation) => expect(operation).toBe("upstream"),`,
129+
`);`,
130+
].join("\n");
131+
const sibling = [
132+
`forkSupersedes({ upstream: "thing.test.ts > refreshes after %s", reason: "why", commit: "abc" });`,
133+
`it.effect.each(["add", "replace"] as const)(`,
134+
` "prefers origin after %s",`,
135+
` (operation) => expect(operation).toBe("origin"),`,
136+
`);`,
137+
].join("\n");
138+
const assessed = assessForkSupersedes(
139+
new Map([["thing.fork.test.ts", sibling]]),
140+
new Map([["thing.test.ts", upstream]]),
141+
new Map(),
142+
);
143+
assert.isEmpty(assessed.refusals);
144+
assert.deepStrictEqual(assessed.superseded, [
145+
{ path: "thing.test.ts", title: "refreshes after %s" },
146+
]);
147+
assert.deepStrictEqual(enclosedSupersededTitles(sibling, "thing.test.ts"), [
148+
"refreshes after %s",
149+
]);
150+
});
151+
97152
it("refuses a declaration naming an absent file or title", () => {
98153
const sibling = `forkSupersedes({ upstream: "gone.test.ts > t", reason: "why", commit: "abc" });`;
99154
const absent = assessForkSupersedes(new Map([["a.fork.test.ts", sibling]]), new Map(), new Map());

0 commit comments

Comments
 (0)