Public: anyone can read this; the crew can change it.

Flaky: test/reviews.test.ts #2132

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/2106-flaky-test-reviews-test-ts → main 2 commits fork 2 threads · 2 unresolved

  • Merged. scout/2106-flaky-test-reviews-test-ts was merged into main as 4527ad0.

Review

Sign in to review this change.
2 files changed +35 −6
scripts/gate.ts −1
@@ -63,7 +63,6 @@ export const EXCLUDED: readonly Exclusion[] = [
6363 reason: "not yet admitted",
6464 issue: 261,
6565 },
66 { file: "test/reviews.test.ts", reason: "not yet admitted", issue: 261 },
6766 { file: "test/runs-lease.test.ts", reason: "not yet admitted", issue: 261 },
6867 { file: "test/scaffold.test.ts", reason: "not yet admitted", issue: 261 },
6968 { file: "test/search.test.ts", reason: "not yet admitted", issue: 261 },
test/reviews.test.ts +35 −5
@@ -49,6 +49,23 @@ describe("review comments on diff lines", () => {
4949 redirect: "manual",
5050 });
5151
52 // Each test that reads or rewrites a branch opens its own pull on its own
53 // branch, so no test depends on what another left behind.
54 async function openPr(branch: string): Promise<string> {
55 const dir = join(work, "app");
56 await gitOk(["checkout", "-B", branch, "main"], dir);
57 await Bun.write(join(dir, "code.txt"), "alpha\nBETA\ngamma\ndelta\n");
58 await gitOk(["commit", "-am", "change"], dir);
59 await gitOk(["push", "origin", branch], dir);
60 const res = await post("/rev/app/pulls/new", {
61 base: "main",
62 head: branch,
63 title: "PR",
outdated

The title is the branch name, so outdated is always in the page HTML. That makes toContain("outdated") pass vacuously. Use a neutral title.

64 body: "",
65 });
66 return res.headers.get("location")!.replace(/\/files$/, "");
67 }
68
5269 beforeAll(async () => {
5370 dataDir = await mkdtemp(join(tmpdir(), "forge-rev-"));
5471 work = await mkdtemp(join(tmpdir(), "forge-rev-work-"));
@@ -139,8 +156,9 @@ describe("review comments on diff lines", () => {
139156 });
140157
141158 test("a posted review comment appears inline, anchored to its line", async () => {
159 const pull = await openPr("topic-a");
142160 // "BETA" is the new-side content of line 2; anchor to it.
143 const res = await post("/rev/app/pulls/1/review", {
161 const res = await post(`${pull}/review`, {
144162 path: "code.txt",
145163 side: "new",
146164 line: "2",
@@ -149,29 +167,41 @@ describe("review comments on diff lines", () => {
149167 });
150168 expect(res.status).toBe(303);
151169 const pr = await (
152 await fetch(`${base}/rev/app/pulls/1/files`, { headers: { cookie } })
170 await fetch(`${base}${pull}/files`, { headers: { cookie } })
153171 ).text();
154172 expect(pr).toContain("why so loud?");
155173 expect(pr).not.toContain("outdated"); // hash matches the current line
156174 });
157175
158176 test("a comment whose line content changed is marked outdated, not misplaced", async () => {
177 const pull = await openPr("topic-b");
159178 // Anchor a comment to line 3 ("gamma"), then rewrite that line on the
160179 // branch. The server hashed the content it saw, so the comment must now
161180 // read as outdated — never silently re-land on the new text.
162 const posted = await post("/rev/app/pulls/1/review", {
181 const kept = await post(`${pull}/review`, {
182 path: "code.txt",
183 side: "new",
184 line: "2",
185 body: "why so loud?",
186 });
187 expect(kept.status).toBe(303);
188 const posted = await post(`${pull}/review`, {
163189 path: "code.txt",
164190 side: "new",
165191 line: "3",
166192 body: "stale anchor",
167193 });
168194 expect(posted.status).toBe(303);
195 const before = await (
196 await fetch(`${base}${pull}/files`, { headers: { cookie } })
197 ).text();
198 expect(before).not.toContain("outdated");
outdated

Pushes feature, not the outdated branch this test opened its pull on, so the rewrite never reaches the pull. Use git push origin outdated.

169199 const dir = join(work, "app");
170200 await Bun.write(join(dir, "code.txt"), "alpha\nBETA\nGAMMA\ndelta\n");
171201 await gitOk(["commit", "-am", "rewrite line 3"], dir);
172 await gitOk(["push", "origin", "feature"], dir);
202 await gitOk(["push", "origin", "topic-b"], dir);
173203 const pr = await (
174 await fetch(`${base}/rev/app/pulls/1/files`, { headers: { cookie } })
204 await fetch(`${base}${pull}/files`, { headers: { cookie } })
175205 ).text();
176206 expect(pr).toContain("stale anchor");
177207 expect(pr).toContain("outdated"); // content hash no longer matches

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs