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

A long comment line never fails a check or holds a landing: the gate notes it, a nightly job rewraps main #13238

Merged opened this

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

Merged

trevato/comment-wrap-never-stops → main 1 commit

  • Merged. trevato/comment-wrap-never-stops was merged into main as 7ebb182.

Review

Sign in to review this change.
14 files changed +229 −54
CLAUDE.md +3 −1
@@ -73,7 +73,9 @@ bun run src/main.ts # boots on :3000, data in ./data
7373 your change touches, every comment line over 100 columns
7474 (`src/kernel/comment_wrap.ts`, the repository's only formatter; `--all` for
7575 the whole tree) and then runs the gate; run it before a push and commit what it
76 changes. Never rewrap a comment by hand.
76 changes. Never rewrap a comment by hand. A long comment line never fails a
77 check: the gate notes it, and the nightly `rewrap` job proposes main's
78 touched files rewrapped as one pull (`src/nightly/propose.ts`).
7779 - **`git push` is blocked at the shell level.** In tests and scripts that need a
7880 git _client_, drive it through `Bun.spawn(["git", ...])`, never a shell push.
7981 See `test/app.test.ts` / `test/onboarding.test.ts` for the pattern.
docs/DEVELOP.md +7 −6
@@ -73,12 +73,13 @@ adversarial suites are split by subject into `test/studio*.test.ts` and
7373 The check's first step is the gate-list audit (`bun scripts/gate.ts`), so an
7474 `EXCLUDED` entry for a file that is gone, or one with no reason or issue,
7575 fails in under a second,
76 before install-heavy work. Comment width is formatting, not review:
77 `bun scripts/gate.ts --fix` rewraps every comment line over 100 columns in
78 the files the pull changes (`src/kernel/comment_wrap.ts`; `--all` for the
79 whole tree) and then runs the same audit, and the gate's one line for an
80 unwrapped file names that command. A file the pull does not touch is never
81 judged, so nobody is stopped by a line they did not write. `tsc` then runs `--incremental` with a 2 GB heap,
76 before install-heavy work. Comment width is formatting, not review, and never
77 fails a check: `bun scripts/gate.ts --fix` rewraps every comment line over
78 100 columns in the files the pull changes (`src/kernel/comment_wrap.ts`;
79 `--all` for the whole tree) and then runs the same audit. A pull that skips
80 it gets one `gate: note:` line in its check log and lands as it is; the
81 nightly `rewrap` job (docs/features/nightly.md) proposes the files main
82 changed in the last two days, rewrapped, as one pull. `tsc` then runs `--incremental` with a 2 GB heap,
8283 its build info in `.forge-cache/` (made first with `mkdir -p`: tsc will not
8384 create the directory, and a checkout with no restored cache failed on it,
8485 #1881). It is TypeScript 7, the native compiler (a
docs/features/nightly.md +3 −2
@@ -1,11 +1,12 @@
11 # Nightly jobs
22
3 The forge runs two jobs itself, at a fixed UTC slot each (`src/nightly/jobs.ts`):
3 The forge runs these jobs itself, at a fixed UTC slot each (`src/nightly/jobs.ts`):
44
55 - **flake-hunt, 02:17.** The gate in 20 slices, five loaded runs each, then the quarantine. Files `Flaky:` issues and proposes the quarantine as a pull on `flake-hunt/<date>`.
66 - **outside-gate, 03:47.** Every file in `EXCLUDED` once. Opens, updates and closes `Red:` issues. Then the long runs the gate cuts short: the engine-split soak at 1000 round trips (`test/engine-split-soak.test.ts`; the gate runs 48), the landing simulator at 24 seeds (`test/landsim.test.ts`; the gate runs 4), and the dead-end near-miss and offered-action walks (`test/deadends.test.ts`; the gate crawls only).
7 - **rewrap, 06:07.** No steps and no cell: the forge reads the files main changed in the last two days and proposes those whose comment lines run past 100 columns, rewrapped by `src/kernel/comment_wrap.ts`, as one pull on `rewrap/<date>` (at most 200 files; none while an earlier rewrap pull is open). A comment's width never fails a check, so this is what keeps main wrapped.
78
8 Both are `scripts/flake-hunt.ts`, run in a cell on a checkout of the default branch that reaches only the forge and the registry. Only steps that file hold `FORGE_TOKEN`.
9 The first two are `scripts/flake-hunt.ts`, run in a cell on a checkout of the default branch that reaches only the forge and the registry. Only steps that file hold `FORGE_TOKEN`.
910
1011 ## Seeing it
1112
scripts/gate.ts +8 −6
@@ -526,12 +526,12 @@ function wrapSources(root: string, all: boolean, working = false): { path: strin
526526 }
527527
528528 /**
529 * The files this pull changes are what the comment rewrapper returns (#12968): one line naming the
530 * command that fixes it, never a list of lines to rewrap by hand.
529 * What the comment rewrapper would change among the files this pull changes (#12968): one line,
530 * a note in the check's log. It is never a refusal: the nightly rewrap wraps them on main.
531531 */
532 export function wrapRefusal(root = ".", all = false): string[] {
533 const { unwrapped, wrapProblems } = require("../src/kernel/comment_wrap.ts") as typeof import("../src/kernel/comment_wrap.ts");
534 return wrapProblems(unwrapped(wrapSources(root, all)));
532 export function wrapNote(root = ".", all = false): string[] {
533 const { unwrapped, wrapNotes } = require("../src/kernel/comment_wrap.ts") as typeof import("../src/kernel/comment_wrap.ts");
534 return wrapNotes(unwrapped(wrapSources(root, all)));
535535 }
536536
537537 /**
@@ -678,7 +678,9 @@ if (import.meta.main) {
678678 const fixed = wrapFix(".", process.argv.includes("--all"));
679679 if (fixed.length) console.error(`gate: rewrapped comments in ${fixed.length === 1 ? "1 file" : `${fixed.length} files`}; commit them`);
680680 }
681 const refusal = [...gateRefusal(presentTests()), ...slowRefusal(presentTests()), ...(await pinRefusal()), ...(await tryItRefusal()), ...(await bothDoorsRefusal()), ...(await lookRefusal()), ...(await directionRefusal()), ...strayTestRefusal(), ...reviewRefusal(), ...wrapRefusal(), ...(await addedRefusal()), ...(await dependencyRefusal()), ...(await readmeCapRefusal()), ...billingDeletesRefusal()];
681 const refusal = [...gateRefusal(presentTests()), ...slowRefusal(presentTests()), ...(await pinRefusal()), ...(await tryItRefusal()), ...(await bothDoorsRefusal()), ...(await lookRefusal()), ...(await directionRefusal()), ...strayTestRefusal(), ...reviewRefusal(), ...(await addedRefusal()), ...(await dependencyRefusal()), ...(await readmeCapRefusal()), ...billingDeletesRefusal()];
682 // Said, never refused: a comment's width stops no check (#12968).
683 for (const line of wrapNote()) console.error(`gate: ${line}`);
682684 for (const line of refusal) console.error(`gate: ${line}`);
683685 process.exit(refusal.length === 0 ? 0 : 2);
684686 }
src/checks/tiers.ts −1
@@ -43,7 +43,6 @@ export const RULE_TESTS: readonly string[] = [
4343 // Scans of the whole tree that no import map can tie to a diff: a new
4444 // module, a long comment line or a file read at import landed green on
4545 // the fast tier and turned every later pull red (#10252).
46 "test/comment-wrap.test.ts",
4746 "test/unreached.test.ts",
4847 "test/spawn-pipes.test.ts",
4948 "test/hollow.test.ts",
src/kernel/comment_wrap.ts +6 −4
@@ -21,7 +21,6 @@
2121 */
2222
2323 export const WRAP = 100;
24 export const WRAP_RULE = `rule "comments are wrapped at ${WRAP} columns"`;
2524 /** The one command that fixes every such line. */
2625 export const WRAP_FIX = "bun scripts/gate.ts --fix";
2726
@@ -366,9 +365,12 @@ export function unwrapped(sources: readonly { path: string; text: string }[]): s
366365 return sources.filter(({ path, text }) => WRAPPED_FILE.test(path) && rewrap(text) !== text).map(({ path }) => path);
367366 }
368367
369 /** The gate's one line for files `rewrap` would change: it names the command, not the lines. */
370 export function wrapProblems(paths: readonly string[]): string[] {
368 /**
369 * The gate's one line for files `rewrap` would change: a note, never a refusal. Width is
370 * formatting, so it stops no check and holds no landing; the nightly rewrap wraps them on main.
371 */
372 export function wrapNotes(paths: readonly string[]): string[] {
371373 if (paths.length === 0) return [];
372374 const named = paths.slice(0, 3).join(", ") + (paths.length > 3 ? ` and ${paths.length - 3} more` : "");
373 return [`${WRAP_RULE}: ${paths.length === 1 ? "1 file has" : `${paths.length} files have`} a longer comment line (${named}); run \`${WRAP_FIX}\` and commit what it rewraps`];
375 return [`note: ${paths.length === 1 ? "1 file has" : `${paths.length} files have`} a comment line over ${WRAP} columns (${named}); nothing to do, the nightly rewrap wraps them on main (\`${WRAP_FIX}\` does it now)`];
374376 }
src/nightly/jobs.ts +8 −1
@@ -17,11 +17,16 @@ export interface Step {
1717 }
1818
1919 export interface Job {
20 readonly name: "outside-gate" | "flake-hunt" | "pack-compat";
20 readonly name: "outside-gate" | "flake-hunt" | "pack-compat" | "rewrap";
2121 readonly slot: Slot;
2222 readonly steps: readonly Step[];
2323 /** After the steps: the file whose quarantined edit is proposed as a pull. */
2424 readonly proposes?: { readonly path: string; readonly branchPrefix: string };
25 /**
26 * No steps, nothing run in a cell: the forge reads the files main changed lately and proposes
27 * their comments rewrapped as one pull (`proposeRewrap`, #12968).
28 */
29 readonly rewraps?: true;
2530 }
2631
2732 /** The gate is cut into this many slices, each hunted on its own. */
@@ -111,4 +116,6 @@ export const JOBS: readonly Job[] = [
111116 },
112117 ],
113118 },
119 // A comment's width never stops a pull, so main is wrapped here, once a day, in one pull.
120 { name: "rewrap", slot: { hour: 6, minute: 7 }, steps: [], rewraps: true },
114121 ];
src/nightly/propose.ts +64
@@ -11,8 +11,11 @@ import type { App } from "../app.ts";
1111 import { proposeEdit } from "../actions/propose_edit.ts";
1212 import { readFileAt } from "../apps/checkout.ts";
1313 import type { Repo } from "../core/repos.ts";
14 import { listOpenPulls } from "../core/pulls.ts";
1415 import { getUserById } from "../core/users.ts";
16 import { runGit } from "../git/env.ts";
1517 import { repoDir } from "../git/repos.ts";
18 import { rewrap, WRAPPED_FILE } from "../kernel/comment_wrap.ts";
1619 import { createLog } from "../kernel/log.ts";
1720
1821 const log = createLog("nightly");
@@ -45,3 +48,64 @@ export async function proposeQuarantine(
4548 }
4649 return branch;
4750 }
51
52 /**
53 * How far back the nightly rewrap looks for files main changed: two nights, so a missed one is
54 * caught.
55 */
56 export const REWRAP_WINDOW_MS = 48 * 60 * 60_000;
57 /** The most files one rewrap pull carries; the rest wait for the next night. */
58 export const REWRAP_MAX_FILES = 200;
59 export const REWRAP_BRANCH = "rewrap";
60
61 /**
62 * The comment rewrap, as a pull (#12968): the files main changed in the last two days whose
63 * comments run past the width go up rewrapped (`kernel/comment_wrap.ts`) as one commit on a dated
64 * branch. A comment's width stops no check and holds no landing, so this is what keeps main
65 * wrapped. Nothing is proposed while an earlier rewrap pull is still open: two would clash.
66 */
67 export async function proposeRewrap(
68 app: App,
69 repo: Repo,
70 ran: { readonly oid: string },
71 now: number,
72 ): Promise<string | undefined> {
73 if (listOpenPulls(app.db, repo.id).some((p) => p.headBranch.startsWith(`${REWRAP_BRANCH}/`))) return undefined;
74 const bare = repoDir(app.reposRoot, repo.ownerName, repo.name);
75 const since = new Date(now - REWRAP_WINDOW_MS).toISOString();
76 const touched = await runGit(["log", `--since=${since}`, "--name-only", "--no-renames", "--format=", ran.oid, "--", "src", "test", "scripts"], { cwd: bare });
77 if (!touched.ok) return undefined;
78 const files: { path: string; content: string }[] = [];
79 for (const path of new Set(touched.value.split("\n").filter((p) => WRAPPED_FILE.test(p)))) {
80 const was = await readFileAt(bare, ran.oid, path);
81 if (was === undefined) continue;
82 const content = rewrap(was);
83 if (content !== was) files.push({ path, content });
84 if (files.length >= REWRAP_MAX_FILES) break;
85 }
86 if (files.length === 0) return undefined;
87 const owner = getUserById(app.db, repo.ownerId);
88 if (owner === undefined || owner.kind !== "user") return undefined;
89 const branch = `${REWRAP_BRANCH}/${new Date(now).toISOString().slice(0, 10)}`;
90 const proposed = await proposeEdit(app, owner, repo, {
91 base: repo.defaultBranch,
92 branch,
93 files,
94 message: [
95 `Rewrap the comments of ${files.length === 1 ? "1 file" : `${files.length} files`} changed since ${since.slice(0, 10)}`,
96 "",
97 "Formatting only, made by the comment rewrapper (bun scripts/gate.ts --fix), not by hand: no code changes.",
98 "",
99 "Direction: #12968",
100 "Try: open / on the preview; every page is as before, since only comments moved",
101 "No look: comments only; no markup, style or script changed, so no page looks different",
102 ].join("\n"),
103 title: `Rewrap comments (${branch})`,
104 body: "Direction: #12968\n\nMade by the nightly rewrap (`src/nightly/propose.ts`), not by hand: the comment lines over 100 columns in the files main changed in the last two days, folded by `src/kernel/comment_wrap.ts`. Comments only; no code token moves. A comment's width never stops a pull, so this pull is what keeps main wrapped.",
105 });
106 if (!proposed.ok) {
107 log.warn("could not propose the rewrap", { branch, step: proposed.error.step, reason: proposed.error.reason });
108 return undefined;
109 }
110 return branch;
111 }
src/nightly/run.ts +2
@@ -62,6 +62,8 @@ async function runSteps(
6262 const oid = await refTip(bare, `refs/heads/${repo.defaultBranch}`);
6363 if (oid === undefined) return refuse(`no ${repo.defaultBranch} to check out`);
6464 keep(`${job.name} on ${repo.ownerName}/${repo.name} ${repo.defaultBranch} at ${oid}`);
65 // A job of no steps runs nothing: no checkout, no cell.
66 if (job.steps.length === 0) return { dir: "", oid, failed: [], filed: [] };
6567 const dir = join(app.config.dataDir, "nightly", `${job.name}-checkout`);
6668 mkdirSync(join(app.config.dataDir, "nightly"), { recursive: true });
6769 const exported = await exportTree(bare, oid, dir);
src/nightly/service.ts +11 −7
@@ -17,7 +17,7 @@ import { createLog } from "../kernel/log.ts";
1717 import { ownRepoPath } from "../kernel/own_repo.ts";
1818 import { JOBS, type Job } from "./jobs.ts";
1919 import { radarNight, RADAR_NAME, RADAR_SLOT } from "./radar.ts";
20 import { proposeQuarantine } from "./propose.ts";
20 import { proposeQuarantine, proposeRewrap } from "./propose.ts";
2121 import { type Ran, runJob } from "./run.ts";
2222 import { lastSlot, owed, untilNext } from "./slots.ts";
2323 import { readLast, writeLast } from "./stamps.ts";
@@ -54,17 +54,19 @@ function doing(app: App, options: { readonly forgeUrl: string; readonly token: s
5454 },
5555 propose: async (job, ran, now) => {
5656 const repo = repoOf();
57 if (repo === undefined || job.proposes === undefined) return undefined;
57 if (repo === undefined) return undefined;
58 if (job.rewraps) return proposeRewrap(app, repo, ran, now);
59 if (job.proposes === undefined) return undefined;
5860 return proposeQuarantine(app, repo, ran, job.proposes.path, job.proposes.branchPrefix, now);
5961 },
6062 };
6163 }
6264
6365 /** One sentence: whether the steps finished, what they filed, and the pull. */
64 export const says = (ran: Ran, branch: string | undefined): string =>
66 export const says = (ran: Ran, branch: string | undefined, pull = "quarantine"): string =>
6567 (ran.failed.length === 0 ? "every step finished" : `failed: ${ran.failed.join(", ")}`) +
6668 (ran.filed.length === 0 ? "; filed nothing" : `; ${ran.filed.join(", ")}`) +
67 (branch === undefined ? "." : `; quarantine pull on ${branch}.`);
69 (branch === undefined ? "." : `; ${pull} pull on ${branch}.`);
6870
6971 export function startNightly(
7072 app: App,
@@ -106,17 +108,19 @@ export function startNightly(
106108 return end(`not run: ${ran.error}.`);
107109 }
108110 const branch =
109 job.proposes !== undefined && !ran.failed.includes("quarantine")
111 (job.proposes !== undefined || job.rewraps) && !ran.failed.includes("quarantine")
110112 ? await does.propose(job, ran, now())
111113 : undefined;
112114 log.info("finished", { job: job.name, failed: ran.failed.join(", "), pull: branch ?? "" });
113 end(abort.signal.aborted ? `stopped by a restart; ${says(ran, branch)}` : says(ran, branch));
115 const said = says(ran, branch, job.rewraps ? "rewrap" : "quarantine");
116 end(abort.signal.aborted ? `stopped by a restart; ${said}` : said);
114117 });
115118 going = turn.catch((error) => log.error("failed", { job: job.name, error: String(error) }));
116119 return going as Promise<void>;
117120 };
118121
119 // The radar is in-process, so it needs no job of steps; it keeps a slot and a record like the others.
122 // The radar is in-process, so it needs no job of steps; it keeps a slot and a record like the
123 // others.
120124 const radar = options.radar ?? ((signal: AbortSignal) => radarNight(app, undefined, signal));
121125 const runRadarNight = (): Promise<void> => {
122126 const slot = lastSlot(RADAR_SLOT, now());
test/comment-wrap.test.ts +16 −18
@@ -1,15 +1,15 @@
11 /**
2 * Comment width is formatting (#12968): one rewrapper decides it and fixes it,
3 * and the gate's rule is that the files a pull changes are what the rewrapper returns.
2 * Comment width is formatting (#12968): one rewrapper decides it and fixes it. It is idempotent
3 * and touches comments alone; the gate says what it would change as a note and never refuses.
44 *
5 * @tree-scan: the last test reads the files this pull changes under src/, test/ and scripts/.
5 * @not-a-tree-scan: every file it reads is in a temp directory of its own.
66 */
77 import { expect, test } from "bun:test";
88 import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
11 import { wrapFix, wrapRefusal } from "../scripts/gate.ts";
12 import { comments, rewrap, unwrapped, WRAP, WRAP_FIX, wrapProblems } from "../src/kernel/comment_wrap.ts";
11 import { wrapFix, wrapNote } from "../scripts/gate.ts";
12 import { comments, rewrap, unwrapped, WRAP, WRAP_FIX, wrapNotes } from "../src/kernel/comment_wrap.ts";
1313
1414 const words = (n: number, word = "word") => Array.from({ length: n }, (_, i) => `${word}${i}`).join(" ");
1515 const widest = (text: string) => Math.max(...text.split("\n").map((line) => line.length));
@@ -111,7 +111,7 @@ test("directives, indented code and a word that fits nowhere stay as written", (
111111 expect(rewrap(`${line}\nf();\n`)).toBe(`${line}\nf();\n`);
112112 });
113113
114 test("the gate's failure is one line that names the command, and the command fixes it", () => {
114 test("the gate's line is one note that names the command, never a refusal, and the command fixes it", () => {
115115 const root = mkdtempSync(join(tmpdir(), "forge-wrap-"));
116116 for (const dir of ["src/web/render/vendor", "test"]) mkdirSync(join(root, dir), { recursive: true });
117117 const long = `// ${words(40)}\nexport const x = 1;\n`;
@@ -120,24 +120,26 @@ test("the gate's failure is one line that names the command, and the command fix
120120 writeFileSync(join(root, "src/web/render/vendor/v.ts"), long);
121121 writeFileSync(join(root, "src/b.ts"), "// short\n");
122122
123 const refusal = wrapRefusal(root, true);
123 const refusal = wrapNote(root, true);
124124 expect(refusal).toHaveLength(1);
125 expect(refusal[0]).toContain(`rule "comments are wrapped at ${WRAP} columns"`);
125 expect(refusal[0]!.startsWith("note: ")).toBe(true);
126 expect(refusal[0]).not.toContain("rule ");
127 expect(refusal[0]).toContain("nothing to do");
126128 expect(refusal[0]).toContain(`\`${WRAP_FIX}\``);
127129 expect(refusal[0]).toContain("2 files");
128130 // It names files, never a line to edit by hand.
129131 expect(refusal[0]).not.toMatch(/\.ts:\d/);
130 expect(wrapProblems(["a.ts", "b.ts", "c.ts", "d.ts", "e.ts"])[0]).toContain("a.ts, b.ts, c.ts and 2 more");
132 expect(wrapNotes(["a.ts", "b.ts", "c.ts", "d.ts", "e.ts"])[0]).toContain("a.ts, b.ts, c.ts and 2 more");
131133
132134 expect(wrapFix(root, true)).toEqual(["src/a.ts", "test/a.test.ts"]);
133 expect(wrapRefusal(root, true)).toEqual([]);
135 expect(wrapNote(root, true)).toEqual([]);
134136 expect(wrapFix(root, true)).toEqual([]);
135137 // Vendored code is not ours to reformat.
136138 expect(readFileSync(join(root, "src/web/render/vendor/v.ts"), "utf8")).toBe(long);
137139 expect(unwrapped([{ path: "docs/a.md", text: long }])).toEqual([]);
138140 });
139141
140 test("a pull is judged, and fixed, only in the files it changes: main's old lines never stop it", () => {
142 test("a pull is read, and fixed, only in the files it changes", () => {
141143 const root = mkdtempSync(join(tmpdir(), "forge-wrap-git-"));
142144 const saved = process.env.FORGE_CHECK_BASE;
143145 const sh = (...a: string[]) => {
@@ -154,7 +156,7 @@ test("a pull is judged, and fixed, only in the files it changes: main's old line
154156 sh("add", "-A");
155157 sh("commit", "-q", "-m", "base");
156158 process.env.FORGE_CHECK_BASE = sh("rev-parse", "HEAD");
157 expect(wrapRefusal(root)).toEqual([]);
159 expect(wrapNote(root)).toEqual([]);
158160
159161 // One committed, one only in the working tree, one git does not hold yet.
160162 writeFileSync(join(root, "src/touched.ts"), long);
@@ -162,14 +164,14 @@ test("a pull is judged, and fixed, only in the files it changes: main's old line
162164 writeFileSync(join(root, "src/touched.ts"), `${long}// more\n`);
163165 writeFileSync(join(root, "src/new.ts"), long);
164166 // The check judges what is committed; the fix also takes what is not yet.
165 const [line, ...rest] = wrapRefusal(root);
167 const [line, ...rest] = wrapNote(root);
166168 expect(rest).toEqual([]);
167169 expect(line).toContain("1 file has");
168170 expect(line).toContain("(src/touched.ts)");
169171 expect(wrapFix(root)).toEqual(["src/new.ts", "src/touched.ts"]);
170172 sh("add", "-A");
171173 sh("commit", "-q", "-m", "rewrapped");
172 expect(wrapRefusal(root)).toEqual([]);
174 expect(wrapNote(root)).toEqual([]);
173175 expect(readFileSync(join(root, "src/old.ts"), "utf8")).toBe(long);
174176 // The whole tree, when asked.
175177 expect(wrapFix(root, true)).toEqual(["src/old.ts"]);
@@ -179,7 +181,3 @@ test("a pull is judged, and fixed, only in the files it changes: main's old line
179181 rmSync(root, { recursive: true, force: true });
180182 }
181183 });
182
183 test(`rule: what this pull changes is unchanged by the comment rewrapper; \`${WRAP_FIX}\` fixes it`, () => {
184 expect(wrapRefusal()).toEqual([]);
185 });
test/maintenance-duties.test.ts +6 −6
@@ -14,7 +14,7 @@ test("never run, fresh and overdue, with a fake clock", async () => {
1414 try {
1515 const now = at("2026-11-10T12:00:00Z");
1616 const never = duties(dir, now);
17 expect(never.map((d) => d.name)).toEqual(["flake-hunt", "outside-gate", "pack-compat", "radar"]);
17 expect(never.map((d) => d.name)).toEqual(["flake-hunt", "outside-gate", "pack-compat", "rewrap", "radar"]);
1818 expect(never.every((d) => d.lastRun === "never" && !d.overdue)).toBe(true);
1919 expect(never[0]!.says).toBe("flake-hunt: never run; its slot is 02:17 UTC each night.");
2020
@@ -22,15 +22,15 @@ test("never run, fresh and overdue, with a fake clock", async () => {
2222 writeLast(dir, "radar", { slot, startedAt: slot + 1000, finishedAt: slot + 5000, says: "read 3 repositories; filed nothing." });
2323 writeLast(dir, "flake-hunt", { slot: at("2026-11-10T02:17:00Z"), startedAt: at("2026-11-10T02:17:30Z"), finishedAt: at("2026-11-10T04:00:00Z"), says: "filed 2 flakes." });
2424 const fresh = duties(dir, now);
25 expect(fresh[3]!.says).toBe("radar: last ran 2026-11-10 05:07 UTC; nothing found.");
25 expect(fresh[4]!.says).toBe("radar: last ran 2026-11-10 05:07 UTC; nothing found.");
2626 expect(fresh[0]!.says).toBe("flake-hunt: last ran 2026-11-10 02:17 UTC; filed 2 flakes.");
27 expect(fresh[3]!.overdue).toBe(false);
27 expect(fresh[4]!.overdue).toBe(false);
2828
2929 const later = slot + DAY + GRACE_MS + 1;
3030 const late = duties(dir, later);
31 expect(late[3]!.overdue).toBe(true);
32 expect(late[3]!.says).toBe("radar: last ran 2026-11-10 05:07 UTC; nothing found; overdue.");
33 expect(duties(dir, slot + DAY + GRACE_MS)[3]!.overdue).toBe(false);
31 expect(late[4]!.overdue).toBe(true);
32 expect(late[4]!.says).toBe("radar: last ran 2026-11-10 05:07 UTC; nothing found; overdue.");
33 expect(duties(dir, slot + DAY + GRACE_MS)[4]!.overdue).toBe(false);
3434 } finally {
3535 await rm(dir, { recursive: true, force: true });
3636 }
test/nightly-rewrap.test.ts added +93
@@ -0,0 +1,93 @@
1 /**
2 * The nightly rewrap (#12968): a comment's width stops no pull, so once a day the forge proposes
3 * the files main changed lately with their comments rewrapped, as one pull.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtempSync, rmSync } from "node:fs";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
10 import { readFileAt } from "../src/apps/checkout.ts";
11 import { createApp, type App } from "../src/app.ts";
12 import { listPulls } from "../src/core/pulls.ts";
13 import type { Repo } from "../src/core/repos.ts";
14 import type { User } from "../src/core/users.ts";
15 import { refTip } from "../src/git/read.ts";
16 import { rewrap } from "../src/kernel/comment_wrap.ts";
17 import { JOBS } from "../src/nightly/jobs.ts";
18 import { proposeRewrap, REWRAP_WINDOW_MS } from "../src/nightly/propose.ts";
19 import { says } from "../src/nightly/service.ts";
20 import { seedAdmin } from "./helpers/admin.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22
23 quietLogs();
24
25 const LONG = `// ${Array.from({ length: 40 }, (_, i) => `word${i}`).join(" ")}\nexport const x = 1;\n`;
26 let dir: string;
27 let app: App;
28 let repo: Repo;
29 let owner: User;
30 const bare = () => join(app.reposRoot, "alice", "forge.git");
31 const tip = async () => (await refTip(bare(), `refs/heads/${repo.defaultBranch}`))!;
32
33 beforeAll(async () => {
34 dir = mkdtempSync(join(tmpdir(), "nightly-rewrap-"));
35 app = createApp({ dataDir: dir, port: 0 });
36 const seeded = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-long-passphrase" });
37 if (!seeded.ok) throw new Error("no owner");
38 owner = seeded.value;
39 const made = await createRepo(app, owner, { name: "forge", visibility: "public" });
40 if (!made.ok) throw new Error("no repo");
41 repo = made.value;
42 });
43 afterAll(() => {
44 app.close();
45 rmSync(dir, { recursive: true, force: true });
46 });
47
48 test("the job has a slot, no steps and nothing to run in a cell", () => {
49 const job = JOBS.find((j) => j.name === "rewrap")!;
50 expect(job.steps).toEqual([]);
51 expect(job.rewraps).toBe(true);
52 expect(says({ dir: "", oid: "", failed: [], filed: [] }, "rewrap/2026-11-16", "rewrap")).toContain("rewrap pull on rewrap/2026-11-16.");
53 });
54
55 test("a main whose changed files are wrapped proposes nothing", async () => {
56 const seeded = await commitToBranch(app, owner, repo, { message: "seed", files: [{ path: "src/short.ts", content: "// short\nexport const s = 1;\n" }] });
57 if (!seeded.ok) throw new Error("no seed");
58 expect(await proposeRewrap(app, repo, { oid: await tip() }, Date.now())).toBeUndefined();
59 expect(listPulls(app.db, repo.id, {})).toHaveLength(0);
60 });
61
62 test("files main changed with long comments go up rewrapped as one pull; an old change and other files are left", async () => {
63 const landed = await commitToBranch(app, owner, repo, {
64 message: "a pull landed unwrapped",
65 files: [
66 { path: "src/a.ts", content: LONG },
67 { path: "test/a.test.ts", content: LONG },
68 { path: "src/web/render/vendor/v.ts", content: LONG },
69 { path: "docs/a.md", content: LONG },
70 ],
71 });
72 if (!landed.ok) throw new Error("no landing");
73 const oid = await tip();
74 const now = Date.now();
75 // Looked at from past the window, nothing was changed lately.
76 expect(await proposeRewrap(app, repo, { oid }, now + REWRAP_WINDOW_MS + 60 * 60_000)).toBeUndefined();
77
78 const branch = await proposeRewrap(app, repo, { oid }, now);
79 expect(branch).toBe(`rewrap/${new Date(now).toISOString().slice(0, 10)}`);
80 const pulls = listPulls(app.db, repo.id, {});
81 expect(pulls).toHaveLength(1);
82 expect(pulls[0]?.title).toBe(`Rewrap comments (${branch})`);
83 const head = (await refTip(bare(), `refs/heads/${branch}`))!;
84 for (const path of ["src/a.ts", "test/a.test.ts"]) expect(await readFileAt(bare(), head, path)).toBe(rewrap(LONG));
85 for (const path of ["src/web/render/vendor/v.ts", "docs/a.md"]) expect(await readFileAt(bare(), head, path)).toBe(LONG);
86 // What the gate reads in the commit message of a pull that changes src/.
87 const message = Bun.spawnSync(["git", "log", "-1", "--format=%B", head], { cwd: bare() }).stdout.toString();
88 for (const line of ["Direction: #12968", "Try: ", "No look: "]) expect(message).toContain(line);
89
90 // While that pull is open, the next night proposes no second one to clash with it.
91 expect(await proposeRewrap(app, repo, { oid }, now + 24 * 60 * 60_000)).toBeUndefined();
92 expect(listPulls(app.db, repo.id, {})).toHaveLength(1);
93 });
test/rule-tests-always.test.ts +2 −2
@@ -54,9 +54,9 @@ describe("the repo-wide rule tests in the fast tier", () => {
5454 expect(fast.files).toContain("test/x.test.ts");
5555 });
5656
57 test("a pull adding only a new module runs the tree scans: unreached, comment width, boot (#10252)", () => {
57 test("a pull adding only a new module runs the tree scans: unreached, boot (#10252)", () => {
5858 const fast = plan(["src/spawn/new.ts"]);
59 for (const rule of ["test/unreached.test.ts", "test/comment-wrap.test.ts", "test/release-boot.test.ts", "test/hollow.test.ts"])
59 for (const rule of ["test/unreached.test.ts", "test/release-boot.test.ts", "test/hollow.test.ts"])
6060 expect(fast.why.get(rule)).toBe("repo-wide rule");
6161 });
6262

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs