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
Check · Review · Land · Live done — Landed and live in production.
trevato/comment-wrap-never-stops → main 1 commit
14 files
changed +229
−54
CLAUDE.md +3 −1
| @@ -73,7 +73,9 @@ bun run src/main.ts # boots on :3000, data in ./data | ||
| 73 | 73 | your change touches, every comment line over 100 columns |
| 74 | 74 | (`src/kernel/comment_wrap.ts`, the repository's only formatter; `--all` for |
| 75 | 75 | 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`). | |
| 77 | 79 | - **`git push` is blocked at the shell level.** In tests and scripts that need a |
| 78 | 80 | git _client_, drive it through `Bun.spawn(["git", ...])`, never a shell push. |
| 79 | 81 | 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 | ||
| 73 | 73 | The check's first step is the gate-list audit (`bun scripts/gate.ts`), so an |
| 74 | 74 | `EXCLUDED` entry for a file that is gone, or one with no reason or issue, |
| 75 | 75 | 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, | |
| 82 | 83 | its build info in `.forge-cache/` (made first with `mkdir -p`: tsc will not |
| 83 | 84 | create the directory, and a checkout with no restored cache failed on it, |
| 84 | 85 | #1881). It is TypeScript 7, the native compiler (a |
docs/features/nightly.md +3 −2
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | # Nightly jobs |
| 2 | 2 | |
| 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`): | |
| 4 | 4 | |
| 5 | 5 | - **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>`. |
| 6 | 6 | - **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. | |
| 7 | 8 | |
| 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`. | |
| 9 | 10 | |
| 10 | 11 | ## Seeing it |
| 11 | 12 |
scripts/gate.ts +8 −6
| @@ -526,12 +526,12 @@ function wrapSources(root: string, all: boolean, working = false): { path: strin | ||
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | /** |
| 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. | |
| 531 | 531 | */ |
| 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))); | |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /** |
| @@ -678,7 +678,9 @@ if (import.meta.main) { | ||
| 678 | 678 | const fixed = wrapFix(".", process.argv.includes("--all")); |
| 679 | 679 | if (fixed.length) console.error(`gate: rewrapped comments in ${fixed.length === 1 ? "1 file" : `${fixed.length} files`}; commit them`); |
| 680 | 680 | } |
| 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}`); | |
| 682 | 684 | for (const line of refusal) console.error(`gate: ${line}`); |
| 683 | 685 | process.exit(refusal.length === 0 ? 0 : 2); |
| 684 | 686 | } |
src/checks/tiers.ts −1
| @@ -43,7 +43,6 @@ export const RULE_TESTS: readonly string[] = [ | ||
| 43 | 43 | // Scans of the whole tree that no import map can tie to a diff: a new |
| 44 | 44 | // module, a long comment line or a file read at import landed green on |
| 45 | 45 | // the fast tier and turned every later pull red (#10252). |
| 46 | "test/comment-wrap.test.ts", | |
| 47 | 46 | "test/unreached.test.ts", |
| 48 | 47 | "test/spawn-pipes.test.ts", |
| 49 | 48 | "test/hollow.test.ts", |
src/kernel/comment_wrap.ts +6 −4
| @@ -21,7 +21,6 @@ | ||
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | 23 | export const WRAP = 100; |
| 24 | export const WRAP_RULE = `rule "comments are wrapped at ${WRAP} columns"`; | |
| 25 | 24 | /** The one command that fixes every such line. */ |
| 26 | 25 | export const WRAP_FIX = "bun scripts/gate.ts --fix"; |
| 27 | 26 | |
| @@ -366,9 +365,12 @@ export function unwrapped(sources: readonly { path: string; text: string }[]): s | ||
| 366 | 365 | return sources.filter(({ path, text }) => WRAPPED_FILE.test(path) && rewrap(text) !== text).map(({ path }) => path); |
| 367 | 366 | } |
| 368 | 367 | |
| 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[] { | |
| 371 | 373 | if (paths.length === 0) return []; |
| 372 | 374 | 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)`]; | |
| 374 | 376 | } |
src/nightly/jobs.ts +8 −1
| @@ -17,11 +17,16 @@ export interface Step { | ||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | export interface Job { |
| 20 | readonly name: "outside-gate" | "flake-hunt" | "pack-compat"; | |
| 20 | readonly name: "outside-gate" | "flake-hunt" | "pack-compat" | "rewrap"; | |
| 21 | 21 | readonly slot: Slot; |
| 22 | 22 | readonly steps: readonly Step[]; |
| 23 | 23 | /** After the steps: the file whose quarantined edit is proposed as a pull. */ |
| 24 | 24 | 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; | |
| 25 | 30 | } |
| 26 | 31 | |
| 27 | 32 | /** The gate is cut into this many slices, each hunted on its own. */ |
| @@ -111,4 +116,6 @@ export const JOBS: readonly Job[] = [ | ||
| 111 | 116 | }, |
| 112 | 117 | ], |
| 113 | 118 | }, |
| 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 }, | |
| 114 | 121 | ]; |
src/nightly/propose.ts +64
| @@ -11,8 +11,11 @@ import type { App } from "../app.ts"; | ||
| 11 | 11 | import { proposeEdit } from "../actions/propose_edit.ts"; |
| 12 | 12 | import { readFileAt } from "../apps/checkout.ts"; |
| 13 | 13 | import type { Repo } from "../core/repos.ts"; |
| 14 | import { listOpenPulls } from "../core/pulls.ts"; | |
| 14 | 15 | import { getUserById } from "../core/users.ts"; |
| 16 | import { runGit } from "../git/env.ts"; | |
| 15 | 17 | import { repoDir } from "../git/repos.ts"; |
| 18 | import { rewrap, WRAPPED_FILE } from "../kernel/comment_wrap.ts"; | |
| 16 | 19 | import { createLog } from "../kernel/log.ts"; |
| 17 | 20 | |
| 18 | 21 | const log = createLog("nightly"); |
| @@ -45,3 +48,64 @@ export async function proposeQuarantine( | ||
| 45 | 48 | } |
| 46 | 49 | return branch; |
| 47 | 50 | } |
| 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( | ||
| 62 | 62 | const oid = await refTip(bare, `refs/heads/${repo.defaultBranch}`); |
| 63 | 63 | if (oid === undefined) return refuse(`no ${repo.defaultBranch} to check out`); |
| 64 | 64 | 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: [] }; | |
| 65 | 67 | const dir = join(app.config.dataDir, "nightly", `${job.name}-checkout`); |
| 66 | 68 | mkdirSync(join(app.config.dataDir, "nightly"), { recursive: true }); |
| 67 | 69 | const exported = await exportTree(bare, oid, dir); |
src/nightly/service.ts +11 −7
| @@ -17,7 +17,7 @@ import { createLog } from "../kernel/log.ts"; | ||
| 17 | 17 | import { ownRepoPath } from "../kernel/own_repo.ts"; |
| 18 | 18 | import { JOBS, type Job } from "./jobs.ts"; |
| 19 | 19 | import { radarNight, RADAR_NAME, RADAR_SLOT } from "./radar.ts"; |
| 20 | import { proposeQuarantine } from "./propose.ts"; | |
| 20 | import { proposeQuarantine, proposeRewrap } from "./propose.ts"; | |
| 21 | 21 | import { type Ran, runJob } from "./run.ts"; |
| 22 | 22 | import { lastSlot, owed, untilNext } from "./slots.ts"; |
| 23 | 23 | import { readLast, writeLast } from "./stamps.ts"; |
| @@ -54,17 +54,19 @@ function doing(app: App, options: { readonly forgeUrl: string; readonly token: s | ||
| 54 | 54 | }, |
| 55 | 55 | propose: async (job, ran, now) => { |
| 56 | 56 | 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; | |
| 58 | 60 | return proposeQuarantine(app, repo, ran, job.proposes.path, job.proposes.branchPrefix, now); |
| 59 | 61 | }, |
| 60 | 62 | }; |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | /** 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 => | |
| 65 | 67 | (ran.failed.length === 0 ? "every step finished" : `failed: ${ran.failed.join(", ")}`) + |
| 66 | 68 | (ran.filed.length === 0 ? "; filed nothing" : `; ${ran.filed.join(", ")}`) + |
| 67 | (branch === undefined ? "." : `; quarantine pull on ${branch}.`); | |
| 69 | (branch === undefined ? "." : `; ${pull} pull on ${branch}.`); | |
| 68 | 70 | |
| 69 | 71 | export function startNightly( |
| 70 | 72 | app: App, |
| @@ -106,17 +108,19 @@ export function startNightly( | ||
| 106 | 108 | return end(`not run: ${ran.error}.`); |
| 107 | 109 | } |
| 108 | 110 | const branch = |
| 109 | job.proposes !== undefined && !ran.failed.includes("quarantine") | |
| 111 | (job.proposes !== undefined || job.rewraps) && !ran.failed.includes("quarantine") | |
| 110 | 112 | ? await does.propose(job, ran, now()) |
| 111 | 113 | : undefined; |
| 112 | 114 | 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); | |
| 114 | 117 | }); |
| 115 | 118 | going = turn.catch((error) => log.error("failed", { job: job.name, error: String(error) })); |
| 116 | 119 | return going as Promise<void>; |
| 117 | 120 | }; |
| 118 | 121 | |
| 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. | |
| 120 | 124 | const radar = options.radar ?? ((signal: AbortSignal) => radarNight(app, undefined, signal)); |
| 121 | 125 | const runRadarNight = (): Promise<void> => { |
| 122 | 126 | const slot = lastSlot(RADAR_SLOT, now()); |
test/comment-wrap.test.ts +16 −18
| @@ -1,15 +1,15 @@ | ||
| 1 | 1 | /** |
| 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. | |
| 4 | 4 | * |
| 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. | |
| 6 | 6 | */ |
| 7 | 7 | import { expect, test } from "bun:test"; |
| 8 | 8 | import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; |
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | 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"; | |
| 13 | 13 | |
| 14 | 14 | const words = (n: number, word = "word") => Array.from({ length: n }, (_, i) => `${word}${i}`).join(" "); |
| 15 | 15 | 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", ( | ||
| 111 | 111 | expect(rewrap(`${line}\nf();\n`)).toBe(`${line}\nf();\n`); |
| 112 | 112 | }); |
| 113 | 113 | |
| 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", () => { | |
| 115 | 115 | const root = mkdtempSync(join(tmpdir(), "forge-wrap-")); |
| 116 | 116 | for (const dir of ["src/web/render/vendor", "test"]) mkdirSync(join(root, dir), { recursive: true }); |
| 117 | 117 | 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 | ||
| 120 | 120 | writeFileSync(join(root, "src/web/render/vendor/v.ts"), long); |
| 121 | 121 | writeFileSync(join(root, "src/b.ts"), "// short\n"); |
| 122 | 122 | |
| 123 | const refusal = wrapRefusal(root, true); | |
| 123 | const refusal = wrapNote(root, true); | |
| 124 | 124 | 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"); | |
| 126 | 128 | expect(refusal[0]).toContain(`\`${WRAP_FIX}\``); |
| 127 | 129 | expect(refusal[0]).toContain("2 files"); |
| 128 | 130 | // It names files, never a line to edit by hand. |
| 129 | 131 | 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"); | |
| 131 | 133 | |
| 132 | 134 | expect(wrapFix(root, true)).toEqual(["src/a.ts", "test/a.test.ts"]); |
| 133 | expect(wrapRefusal(root, true)).toEqual([]); | |
| 135 | expect(wrapNote(root, true)).toEqual([]); | |
| 134 | 136 | expect(wrapFix(root, true)).toEqual([]); |
| 135 | 137 | // Vendored code is not ours to reformat. |
| 136 | 138 | expect(readFileSync(join(root, "src/web/render/vendor/v.ts"), "utf8")).toBe(long); |
| 137 | 139 | expect(unwrapped([{ path: "docs/a.md", text: long }])).toEqual([]); |
| 138 | 140 | }); |
| 139 | 141 | |
| 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", () => { | |
| 141 | 143 | const root = mkdtempSync(join(tmpdir(), "forge-wrap-git-")); |
| 142 | 144 | const saved = process.env.FORGE_CHECK_BASE; |
| 143 | 145 | 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 | ||
| 154 | 156 | sh("add", "-A"); |
| 155 | 157 | sh("commit", "-q", "-m", "base"); |
| 156 | 158 | process.env.FORGE_CHECK_BASE = sh("rev-parse", "HEAD"); |
| 157 | expect(wrapRefusal(root)).toEqual([]); | |
| 159 | expect(wrapNote(root)).toEqual([]); | |
| 158 | 160 | |
| 159 | 161 | // One committed, one only in the working tree, one git does not hold yet. |
| 160 | 162 | 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 | ||
| 162 | 164 | writeFileSync(join(root, "src/touched.ts"), `${long}// more\n`); |
| 163 | 165 | writeFileSync(join(root, "src/new.ts"), long); |
| 164 | 166 | // 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); | |
| 166 | 168 | expect(rest).toEqual([]); |
| 167 | 169 | expect(line).toContain("1 file has"); |
| 168 | 170 | expect(line).toContain("(src/touched.ts)"); |
| 169 | 171 | expect(wrapFix(root)).toEqual(["src/new.ts", "src/touched.ts"]); |
| 170 | 172 | sh("add", "-A"); |
| 171 | 173 | sh("commit", "-q", "-m", "rewrapped"); |
| 172 | expect(wrapRefusal(root)).toEqual([]); | |
| 174 | expect(wrapNote(root)).toEqual([]); | |
| 173 | 175 | expect(readFileSync(join(root, "src/old.ts"), "utf8")).toBe(long); |
| 174 | 176 | // The whole tree, when asked. |
| 175 | 177 | 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 | ||
| 179 | 181 | rmSync(root, { recursive: true, force: true }); |
| 180 | 182 | } |
| 181 | 183 | }); |
| 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 () => { | ||
| 14 | 14 | try { |
| 15 | 15 | const now = at("2026-11-10T12:00:00Z"); |
| 16 | 16 | 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"]); | |
| 18 | 18 | expect(never.every((d) => d.lastRun === "never" && !d.overdue)).toBe(true); |
| 19 | 19 | expect(never[0]!.says).toBe("flake-hunt: never run; its slot is 02:17 UTC each night."); |
| 20 | 20 | |
| @@ -22,15 +22,15 @@ test("never run, fresh and overdue, with a fake clock", async () => { | ||
| 22 | 22 | writeLast(dir, "radar", { slot, startedAt: slot + 1000, finishedAt: slot + 5000, says: "read 3 repositories; filed nothing." }); |
| 23 | 23 | 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." }); |
| 24 | 24 | 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."); | |
| 26 | 26 | 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); | |
| 28 | 28 | |
| 29 | 29 | const later = slot + DAY + GRACE_MS + 1; |
| 30 | 30 | 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); | |
| 34 | 34 | } finally { |
| 35 | 35 | await rm(dir, { recursive: true, force: true }); |
| 36 | 36 | } |
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", () => { | ||
| 54 | 54 | expect(fast.files).toContain("test/x.test.ts"); |
| 55 | 55 | }); |
| 56 | 56 | |
| 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)", () => { | |
| 58 | 58 | 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"]) | |
| 60 | 60 | expect(fast.why.get(rule)).toBe("repo-wide rule"); |
| 61 | 61 | }); |
| 62 | 62 |
new above
offline