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

A red main more than 256 commits past its last green still names the landing that broke it #15326

Merged opened this

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

Merged

scout/forge:scout/15322-a-red-main-more-than-256-commits-past-it → main 0 commits fork

  • Merged. scout/15322-a-red-main-more-than-256-commits-past-it was merged into main as 6f8692b.

Review

Sign in to review this change.
3 files changed +65 −6
src/checks/culprit.ts +18 −5
@@ -199,20 +199,33 @@ export async function afterVerify(app: App, repo: Repo, run: Run, ask: Ask): Pro
199199 const range = await rangeOf(app, repo, green.commitOid, red.commitOid);
200200 if (range === undefined || range.length === 0)
201201 return [unbisected(app, repo, red, `git could not list ${short(green.commitOid)}..${short(red.commitOid)}`)];
202 if (range.length > MAX_RANGE)
203 return [unbisected(app, repo, red, `${range.length} commits since the last green is over ${MAX_RANGE}`)];
202 // A range longer than MAX_RANGE is bisected over its newest MAX_RANGE
203 // commits (#15322): the steps stay at ⌈log₂ MAX_RANGE⌉, and a window whose
204 // oldest commit is already red says so rather than name a wrong culprit.
205 const window = range.length > MAX_RANGE ? range.slice(-MAX_RANGE) : range;
206 const cut = window.length < range.length;
204207 const { green: tried, vague } = stepsOf(app, repo.id, red.id);
205208 if (vague !== undefined)
206209 return [unbisected(app, repo, red, `the step at ${short(vague.commitOid)} failed without naming a test`)];
207 const step = nextStep(range, tried);
210 const step = nextStep(window, tried);
208211 if (step === undefined) return [];
212 if (step.kind === "culprit" && cut && step.commit === window[0])
213 return [
214 unbisected(
215 app,
216 repo,
217 red,
218 `the break is older than the newest ${window.length - 1} commits: ${short(step.commit)}, the oldest of the ` +
219 `newest ${window.length} of ${range.length} since the last green at ${short(green.commitOid)}, is already red`,
220 ),
221 ];
209222 if (step.kind === "culprit") return [await name(app, repo, red, step.commit, green.commitOid, tried.size)];
210223 const asked = await ask(repo, BISECT_ENV, step.commit, `${BISECT_PREFIX}${red.id}`);
211224 return asked === undefined
212225 ? [`bisect: ${short(step.commit)} could not be asked for`]
213226 : [
214 `bisect: trying ${short(step.commit)}, ${range.length} commit(s) since ${short(green.commitOid)}, ` +
215 `at most ${maxSteps(range.length)} step(s); run ${asked.id}`,
227 `bisect: trying ${short(step.commit)}, ${range.length} commit(s) since ${short(green.commitOid)}` +
228 `${cut ? `, the newest ${window.length} bisected` : ""}, at most ${maxSteps(window.length)} step(s); run ${asked.id}`,
216229 ];
217230 }
218231
src/checks/verify.ts +1 −1
@@ -30,7 +30,7 @@ export const VERIFY_REASON = "schedule";
3030 export const VERIFY_EVERY_MS = 30 * 60_000;
3131 /** How often the forge looks for a verification that is due. */
3232 export const VERIFY_SWEEP_MS = 60_000;
33 /** A range wider than this is not bisected: it is named in one issue. */
33 /** A range wider than this is bisected over its newest this many commits (#15322). */
3434 export const MAX_RANGE = 256;
3535 /** At most this many failed files are carried into a bisection. */
3636 export const MAX_FILES = 20;
test/verify-after-landing.test.ts +46
@@ -21,6 +21,7 @@ import {
2121 bisectOrigin,
2222 FLAKY_ALONE,
2323 failedFiles,
24 MAX_RANGE,
2425 maxSteps,
2526 nextStep,
2627 onlyEnv,
@@ -35,6 +36,7 @@ import type { Repo } from "../src/core/repos.ts";
3536 import { createRun, getRun, type Run } from "../src/core/runs.ts";
3637 import { createUser, type User } from "../src/core/users.ts";
3738 import { readVerified, spanWords, verifiedSays } from "../src/flow/verified.ts";
39 import { runGit } from "../src/git/env.ts";
3840 import { resolveOid } from "../src/git/merge.ts";
3941 import { repoDir } from "../src/git/repos.ts";
4042 import { flowPanel } from "../src/web/pages/flow-panel.ts";
@@ -266,6 +268,50 @@ describe("a red verification names its culprit", () => {
266268 expect(app.db.query("SELECT COUNT(*) AS n FROM issue WHERE repo_id = ?1 AND kind = 'issue'").get(repo.id)).toEqual({ n: 1 });
267269 });
268270
271 /** `n` commits straight onto main in one fast-import, oldest first: their oids. */
272 const pushMany = async (n: number): Promise<string[]> => {
273 const cwd = repoDir(app.reposRoot, repo.ownerName, repo.name);
274 let stream = "";
275 for (let i = 0; i < n; i++) {
276 const msg = `c${i}\n`;
277 stream += `commit refs/heads/main\ncommitter a <[email protected]> ${1_700_000_000 + i} +0000\ndata ${msg.length}\n${msg}`;
278 if (i === 0) stream += `from ${await tip()}\n`;
279 stream += "\n";
280 }
281 const imported = await runGit(["fast-import", "--quiet"], { cwd, stdin: new TextEncoder().encode(stream) });
282 if (!imported.ok) throw new Error(JSON.stringify(imported.error));
283 const log = await runGit(["rev-list", "--first-parent", "--reverse", `-${n}`, "refs/heads/main"], { cwd });
284 if (!log.ok) throw new Error(JSON.stringify(log.error));
285 return log.value.split("\n");
286 };
287
288 test("300 commits since the green, the break inside the newest 256: named in at most 8 steps", async () => {
289 await verification("ok");
290 const oids = await pushMany(300);
291 const red = await verification("failed");
292 const { lines, steps } = await bisect(red, oids[200]!, oids);
293 expect(steps).toBeLessThanOrEqual(maxSteps(MAX_RANGE));
294 expect(lines[0]).toContain(`the newest ${MAX_RANGE} bisected, at most 8 step(s)`);
295 expect(lines.at(-1)).toContain(`culprit ${oids[200]!.slice(0, 7)}, landed by no pull`);
296 const issue = app.db.query<{ body: string }, [string]>("SELECT body FROM issue WHERE repo_id = ?1").get(repo.id)!;
297 expect(issue.body).toContain(`Commit ${oids[200]}`);
298 });
299
300 test("300 commits since the green, the break older than the window: said plainly, no culprit named", async () => {
301 await verification("ok");
302 const oids = await pushMany(300);
303 const red = await verification("failed");
304 const { lines, steps } = await bisect(red, oids[10]!, oids);
305 expect(steps).toBeLessThanOrEqual(maxSteps(MAX_RANGE));
306 const oldest = oids[300 - MAX_RANGE]!;
307 expect(lines.at(-1)).toContain(`the break is older than the newest ${MAX_RANGE - 1} commits: ${oldest.slice(0, 7)}`);
308 expect(lines.join("\n")).not.toContain("culprit");
309 const issue = app.db.query<{ body: string }, [string]>("SELECT body FROM issue WHERE repo_id = ?1").get(repo.id)!;
310 expect(issue.body).toContain("the break is older than the newest");
311 expect(issue.body).toContain(oldest.slice(0, 7));
312 expect(issue.body).not.toContain(oids[10]!.slice(0, 7));
313 });
314
269315 test("a red whose files were already red at the verification before starts nothing", async () => {
270316 await verification("ok");
271317 await land("one");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs