Public: anyone can read this; the crew can change it.
One rule for a check's details, wherever they are read #17767
Its check is red, 16h 44m ago
check failed: 3 of 24420 tests — "on production's size > a cold /map answers within a few passes over the runs", "surfaces adversarial: web > N+1: a pull's crew activity does not cost more as its agent runs grow" …
sold/check-details → main 6 commits
34 files
changed +719
−173
- docs/features/run-logs.md
- src/actions/runs.ts
- src/apps/push_gate.ts
- src/checks/detail_pass.ts
- src/checks/doctor.ts
- src/checks/failure_names.ts
- src/checks/gate_run.ts
- src/checks/job_step.ts
- src/checks/queue_store.ts
- src/checks/report.ts
- src/checks/run_tier.ts
- src/checks/runner_step.ts
- src/checks/shared_red.ts
- src/checks/step_lines.ts
- src/checks/summary.ts
- src/checks/tier_flake.ts
- src/checks/tier_runner.ts
- src/checks/tiers.ts
- src/core/runs.ts
- src/crew/failure_quote.ts
- src/crew/no_change.ts
- src/crew/red_thrice.ts
- src/crew/sentinel.ts
- src/crew/unstick.ts
- src/http/api.ts
- src/main.ts
- test/check-details-pass.test.ts
- test/check-details.test.ts
- test/crew-red-thrice.test.ts
- test/doctor-culprit.test.ts
- test/full-suite-report.test.ts
- test/job-slices.test.ts
- test/no_change_recheck.test.ts
- test/sentinel-shared-evidence.test.ts
docs/features/run-logs.md +8
| @@ -18,6 +18,14 @@ Every one of these asks first whether the run is in this repository and the view | ||
| 18 | 18 | |
| 19 | 19 | When a run fails, the forge keeps the one line that says why (`findingsOf` in `src/logs/findings.ts`): the failing test its check named, at that test's own `(fail)` line; else the line the run's verdict quotes; else, for a deploy or an agent's run, the last line that states an error. The feed's post says it and links to it. `GET …/check.txt` says up to five failing tests with the end of each one's output, above the last 80 lines. A word in passing (`0 failed`, a passing test named for an error) is never taken for it. |
| 20 | 20 | |
| 21 | ## A check's kept details | |
| 22 | ||
| 23 | A failed check keeps its failing tests with their assertions and the end of their output (`checkDetail`). They are read and masked as its log is: each line is masked as it enters (`src/checks/step_lines.ts`), before any cut, and the runs API gives `checkDetail` only to who may read the run's log (null for anyone else). The summary, which names the first failing tests, is public with the run and masked too. A failed test is re-run by the name it printed, held in memory only. The merge queue's gate lines are masked as they enter too (`src/checks/gate_run.ts`). | |
| 24 | ||
| 25 | An issue or a comment about a failed check names the failing tests and links the run (`src/checks/failure_names.ts`); it carries no assertion and no output. So the full-suite report, the note after three reds, the builder's second "no change" and the sentinel's shared red lead to the run's page, and the batch doctor's hold to the gate's log. Both open for who may read the repository's logs. A crew builder sent back for a red gets the assertion and the output in its brief, read from the run (`src/crew/failure_brief.ts`). | |
| 26 | ||
| 27 | Kept details get one pass of the same mask (`src/checks/detail_pass.ts`). It starts five minutes after boot. A slice is at most 25 runs, 256 KiB of text or 20 ms, and the wait after it is at least 250 ms, longer while the event loop is late (twenty times its worst lateness of the last ten seconds, at most 30 s). `check-details-pass.json` under the data directory says how far it is, so a restart goes on and a finished pass is not run again. | |
| 28 | ||
| 21 | 29 | ## When the store is down |
| 22 | 30 | |
| 23 | 31 | A log that fails to archive stays local and the next sweep tries again. The seven-day prune never removes the log of a finished run the store does not hold, and one sweep runs at a time. |
src/actions/runs.ts +12 −6
| @@ -200,16 +200,22 @@ export function mayReadLogOfRun( | ||
| 200 | 200 | * facts (`canSeeOwnerFacts`), and so is the machinery under it: the agent |
| 201 | 201 | * session a follow-up resumes and the node it ran on (#2917). A reader who |
| 202 | 202 | * cannot write here gets what ran, why and how it ended, never those — on |
| 203 | * every door, since every door reads runs through here. | |
| 203 | * every door, since every door reads runs through here. A check's kept details | |
| 204 | * quote its log, so they are for the log's readers (`mayReadRunLog`). | |
| 204 | 205 | */ |
| 205 | 206 | export function runForReader( |
| 206 | 207 | app: App, |
| 207 | 208 | actor: User | undefined, |
| 208 | 209 | repo: Repo, |
| 209 | 210 | ): (run: Run) => Run { |
| 210 | return canSeeOwnerFacts(app.db, repo, actor) | |
| 211 | ? (run) => run | |
| 212 | : (run) => ({ ...run, costUsd: 0, turns: 0, sessionId: "", node: "" }); | |
| 211 | const facts = canSeeOwnerFacts(app.db, repo, actor); | |
| 212 | const details = mayReadRunLog(app, actor, repo); | |
| 213 | if (facts && details) return (run) => run; | |
| 214 | return (run) => ({ | |
| 215 | ...run, | |
| 216 | ...(facts ? {} : { costUsd: 0, turns: 0, sessionId: "", node: "" }), | |
| 217 | ...(details ? {} : { checkDetail: null }), | |
| 218 | }); | |
| 213 | 219 | } |
| 214 | 220 | |
| 215 | 221 | export function listRepoRuns( |
| @@ -244,12 +250,12 @@ export function workingNowCount(app: App, actor: User | undefined, repo: Repo): | ||
| 244 | 250 | |
| 245 | 251 | /** |
| 246 | 252 | * What the runs list shows this reader, before the list is built: whether |
| 247 | * they see cost and turns. Call it only for someone who may read runs. The | |
| 253 | * they see cost and turns, and a check's details. Call it only for someone who may read runs. The | |
| 248 | 254 | * owner and a stranger never share it. |
| 249 | 255 | */ |
| 250 | 256 | export function runsViewKey(app: App, actor: User | undefined, repo: Repo, options: ListRunsOptions): string { |
| 251 | 257 | const facts = canSeeOwnerFacts(app.db, repo, actor); |
| 252 | return `${facts ? "f" : "-"}\n${runsMarker(app.db, repo.id, options)}`; | |
| 258 | return `${facts ? "f" : "-"}${mayReadRunLog(app, actor, repo) ? "l" : "-"}\n${runsMarker(app.db, repo.id, options)}`; | |
| 253 | 259 | } |
| 254 | 260 | |
| 255 | 261 | /** |
src/apps/push_gate.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | |
| 8 | 8 | import { background } from "../perf/jobs.ts"; |
| 9 | 9 | import { parseBunTestFailure } from "../checks/bun-test.ts"; |
| 10 | import { redactHeld } from "../kernel/log.ts"; | |
| 10 | 11 | import { err, type Result } from "../kernel/result.ts"; |
| 11 | 12 | |
| 12 | 13 | /** Whether this deploy waits for its tests before it switches in. */ |
| @@ -19,7 +20,7 @@ export function gatesPush(env: string, reason: string, hasLive: boolean, declare | ||
| 19 | 20 | * `bun test`'s. |
| 20 | 21 | */ |
| 21 | 22 | export function nameFailingTests(error: string, lines: readonly string[]): string { |
| 22 | const names = parseBunTestFailure(lines)?.names.slice(0, 3) ?? []; | |
| 23 | const names = parseBunTestFailure(lines.map((l) => redactHeld(l)))?.names.slice(0, 3) ?? []; | |
| 23 | 24 | if (names.length === 0) return error; |
| 24 | 25 | const head = error.split("\n")[0] ?? error; |
| 25 | 26 | return `${head} — failing: ${names.map((n) => `"${n.slice(0, 80)}"`).join(", ")}`; |
src/checks/detail_pass.ts added +157
| @@ -0,0 +1,157 @@ | ||
| 1 | /** | |
| 2 | * One pass of the log's mask (`redactHeld`) over the check details, summaries and error lines runs | |
| 3 | * keep. It walks the runs there are when it starts, and `check-details-pass.json` under the data | |
| 4 | * directory holds how far it is, so a restart goes on and a later boot reads that one file. | |
| 5 | * | |
| 6 | * It yields to everything: it starts `FIRST_MS` after boot, a slice ends at `ROWS` runs, `BYTES` of | |
| 7 | * text or `SLICE_MS` of the thread, whichever is first, and the wait before the next is at least | |
| 8 | * `PAUSE_MS` and longer while the event loop is late. A slice that fails (a write lock held | |
| 9 | * elsewhere) is logged and tried again after `FAILED_MS`. | |
| 10 | */ | |
| 11 | ||
| 12 | import type { Database } from "bun:sqlite"; | |
| 13 | import { rename } from "node:fs/promises"; | |
| 14 | import { join } from "node:path"; | |
| 15 | import type { App } from "../app.ts"; | |
| 16 | import { SLICE_MS } from "../kernel/breathe.ts"; | |
| 17 | import { withoutWaiting } from "../kernel/db.ts"; | |
| 18 | import { redactHeld } from "../kernel/log.ts"; | |
| 19 | import { background } from "../perf/jobs.ts"; | |
| 20 | import { currentLoopLag } from "../perf/loop_worst.ts"; | |
| 21 | ||
| 22 | export interface Progress { | |
| 23 | /** The last run read, and the newest there was when the pass began. */ | |
| 24 | readonly at: string; | |
| 25 | readonly until: string; | |
| 26 | readonly done: boolean; | |
| 27 | readonly read: number; | |
| 28 | readonly masked: number; | |
| 29 | /** Details that are not JSON: left as they are. */ | |
| 30 | readonly unread: number; | |
| 31 | } | |
| 32 | ||
| 33 | export const FIRST_MS = 5 * 60_000; | |
| 34 | export const ROWS = 25; | |
| 35 | export const BYTES = 256 * 1024; | |
| 36 | export const PAUSE_MS = 250; | |
| 37 | const PAUSE_MAX_MS = 30_000; | |
| 38 | const FAILED_MS = 60_000; | |
| 39 | /** The wait is this many times the loop's worst lateness of the last ten seconds. */ | |
| 40 | const LATE_X = 20; | |
| 41 | ||
| 42 | /** The wait before the next slice, while the loop is `lagMs` late. */ | |
| 43 | export const pauseFor = (lagMs: number): number => Math.min(PAUSE_MAX_MS, Math.max(PAUSE_MS, Math.ceil(lagMs * LATE_X))); | |
| 44 | ||
| 45 | /** Every string in a value masked; its keys and shape stay. */ | |
| 46 | function maskDeep(value: unknown): unknown { | |
| 47 | if (typeof value === "string") return redactHeld(value); | |
| 48 | if (Array.isArray(value)) return value.map(maskDeep); | |
| 49 | if (value === null || typeof value !== "object") return value; | |
| 50 | return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, maskDeep(v)])); | |
| 51 | } | |
| 52 | ||
| 53 | interface Row { | |
| 54 | id: string; | |
| 55 | check_detail: string; | |
| 56 | summary: string; | |
| 57 | error_line: string; | |
| 58 | } | |
| 59 | ||
| 60 | export const passFrom = (db: Database): Progress => ({ | |
| 61 | at: "", | |
| 62 | until: db.query<{ id: string | null }, []>("SELECT MAX(id) AS id FROM run").get()?.id ?? "", | |
| 63 | done: false, | |
| 64 | read: 0, | |
| 65 | masked: 0, | |
| 66 | unread: 0, | |
| 67 | }); | |
| 68 | ||
| 69 | /** The next slice, its changes in one transaction; `done` once no run is left. */ | |
| 70 | export function maskSlice(db: Database, p: Progress, now: () => number = () => performance.now()): Progress { | |
| 71 | // One run a read: a slice never holds more text than it masks. | |
| 72 | const next = db.query<Row, [string, string]>( | |
| 73 | "SELECT id, check_detail, summary, error_line FROM run WHERE id > ?1 AND id <= ?2 ORDER BY id LIMIT 1", | |
| 74 | ); | |
| 75 | const from = now(); | |
| 76 | const changed: { was: Row; now: Row }[] = []; | |
| 77 | let { at, read, unread } = p; | |
| 78 | let done = false; | |
| 79 | for (let rows = 0, bytes = 0; rows < ROWS && bytes < BYTES && (rows === 0 || now() - from < SLICE_MS); rows++) { | |
| 80 | const r = next.get(at, p.until); | |
| 81 | if (r === null) { | |
| 82 | done = true; | |
| 83 | break; | |
| 84 | } | |
| 85 | at = r.id; | |
| 86 | read++; | |
| 87 | bytes += r.check_detail.length + r.summary.length + r.error_line.length; | |
| 88 | let detail = r.check_detail; | |
| 89 | if (detail !== "") | |
| 90 | try { | |
| 91 | const was = JSON.parse(detail) as unknown; | |
| 92 | const masks = JSON.stringify(maskDeep(was)); | |
| 93 | if (masks !== JSON.stringify(was)) detail = masks; | |
| 94 | } catch { | |
| 95 | unread++; | |
| 96 | } | |
| 97 | const summary = redactHeld(r.summary); | |
| 98 | const line = redactHeld(r.error_line); | |
| 99 | if (detail !== r.check_detail || summary !== r.summary || line !== r.error_line) | |
| 100 | changed.push({ was: r, now: { id: r.id, check_detail: detail, summary, error_line: line } }); | |
| 101 | } | |
| 102 | // The write lock is asked for only when there is something to write, once, and never waited for | |
| 103 | // (`.immediate`: no retry that spins). The engine's thread may have written a run since it was | |
| 104 | // read: that run is left as it wrote it, which is masked. | |
| 105 | let masked = p.masked; | |
| 106 | if (changed.length > 0) { | |
| 107 | const write = db.query( | |
| 108 | `UPDATE run SET check_detail = ?2, summary = ?3, error_line = ?4 | |
| 109 | WHERE id = ?1 AND check_detail = ?5 AND summary = ?6 AND error_line = ?7`, | |
| 110 | ); | |
| 111 | withoutWaiting(db, () => | |
| 112 | db.transaction(() => { | |
| 113 | for (const { was, now: n } of changed) | |
| 114 | masked += write.run(n.id, n.check_detail, n.summary, n.error_line, was.check_detail, was.summary, was.error_line).changes; | |
| 115 | }).immediate(), | |
| 116 | ); | |
| 117 | } | |
| 118 | return { at, until: p.until, done, read, masked, unread }; | |
| 119 | } | |
| 120 | ||
| 121 | /** Start the pass on its own timer; the returned function stops it. */ | |
| 122 | export function startDetailPass(app: App, firstMs = FIRST_MS, pause = pauseFor): () => void { | |
| 123 | const path = join(app.config.dataDir, "check-details-pass.json"); | |
| 124 | let stopped = false; | |
| 125 | let timer: ReturnType<typeof setTimeout> | undefined; | |
| 126 | let p: Progress | undefined; | |
| 127 | const step = async (): Promise<void> => { | |
| 128 | let wait: number | undefined = FAILED_MS; | |
| 129 | try { | |
| 130 | p ??= ((await Bun.file(path).json().catch(() => undefined)) as Progress | undefined) ?? passFrom(app.db); | |
| 131 | if (stopped || p.done) { | |
| 132 | wait = undefined; | |
| 133 | return; | |
| 134 | } | |
| 135 | p = maskSlice(app.db, p); | |
| 136 | await Bun.write(`${path}.tmp`, JSON.stringify(p)); | |
| 137 | await rename(`${path}.tmp`, path); | |
| 138 | wait = p.done ? undefined : pause(currentLoopLag()); | |
| 139 | if (p.done) app.log.info("kept check details masked", { read: p.read, masked: p.masked, unread: p.unread }); | |
| 140 | } finally { | |
| 141 | if (wait !== undefined) arm(wait); | |
| 142 | } | |
| 143 | }; | |
| 144 | const arm = (ms: number): void => { | |
| 145 | if (stopped) return; | |
| 146 | timer = setTimeout(() => { | |
| 147 | if (stopped) return; | |
| 148 | void background("kept-details", step, undefined, app); | |
| 149 | }, ms); | |
| 150 | timer.unref?.(); | |
| 151 | }; | |
| 152 | arm(firstMs); | |
| 153 | return () => { | |
| 154 | stopped = true; | |
| 155 | clearTimeout(timer); | |
| 156 | }; | |
| 157 | } |
src/checks/doctor.ts +5 −5
| @@ -2,7 +2,7 @@ | ||
| 2 | 2 | * The batch doctor (#7555): a merge-queue gate found one pull red. It classes |
| 3 | 3 | * the red (`doctor_classify.ts`), and only a functional red of a pull alone |
| 4 | 4 | * on its merge is held — out of the line, with a comment naming the exact |
| 5 | * test, its file, the error line and the command to reproduce, and the pull | |
| 5 | * test, its file, the gate's log and the command to reproduce, and the pull | |
| 6 | 6 | * handed back to its builder. The hold is "until green": the first check |
| 7 | 7 | * that passes on a new head lets it go (`actions/holds.ts` `releaseOnGreen`). |
| 8 | 8 | * A hold already on the pull — a person's above all — is never overwritten. |
| @@ -70,14 +70,14 @@ function whyLine(d: Diagnosis): string { | ||
| 70 | 70 | return `${HOLD_PREFIX} ${name} fails alone`; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | /** The comment a held pull gets: test, file, error line, command, what lifts it. */ | |
| 74 | export function holdComment(d: Diagnosis, builder: User | undefined): string { | |
| 73 | /** The comment a held pull gets: test, file, the gate's log, command, what lifts it. */ | |
| 74 | export function holdComment(d: Diagnosis, builder: User | undefined, log?: string): string { | |
| 75 | 75 | const lines = ["The batch doctor held this pull: it is red on its own merge with main, in a functional test."]; |
| 76 | 76 | if (d.test !== undefined) { |
| 77 | 77 | lines.push("", `- test: \`${d.test.name}\``); |
| 78 | 78 | if (d.test.file !== undefined) lines.push(`- file: \`${d.test.file}\``); |
| 79 | 79 | } |
| 80 | lines.push(`- error: \`${d.probe}\``); | |
| 80 | if (log !== undefined) lines.push(`- error: in [the gate's log](${log}), for who may read it`); | |
| 81 | 81 | const cmd = reproduce(d.test); |
| 82 | 82 | if (cmd !== undefined) lines.push(`- reproduce: \`${cmd}\``); |
| 83 | 83 | lines.push( |
| @@ -155,7 +155,7 @@ export function treatRed(app: App, repo: Repo, by: User, pull: Pull, red: Red, b | ||
| 155 | 155 | }); |
| 156 | 156 | if (issue !== undefined) { |
| 157 | 157 | const builder = builderOf(app.db, repo, issue); |
| 158 | addComment(app, by, repo, issue, holdComment(d, builder)); | |
| 158 | addComment(app, by, repo, issue, holdComment(d, builder, red.log)); | |
| 159 | 159 | if (builder && setAssignee(app.db, issue.id, builder.id)) |
| 160 | 160 | app.bus.append({ |
| 161 | 161 | kind: "pull.assigned", |
src/checks/failure_names.ts added +20
| @@ -0,0 +1,20 @@ | ||
| 1 | /** | |
| 2 | * What an issue or a comment says of a failed check: the failing tests by name and the way to the | |
| 3 | * run. The assertion and the output stay with the run, for who may read its log. | |
| 4 | */ | |
| 5 | ||
| 6 | import type { Run } from "../core/runs.ts"; | |
| 7 | ||
| 8 | /** The most names one comment says. */ | |
| 9 | const NAMES = 5; | |
| 10 | ||
| 11 | /** The failing tests by name; the summary's first line when the run named none. */ | |
| 12 | export function failureNames(run: Pick<Run, "checkDetail" | "summary">): string[] { | |
| 13 | const names = (run.checkDetail?.names ?? []).filter((n) => n !== ""); | |
| 14 | const said = names.length > 0 ? names : [run.summary.trim().split("\n")[0] || "the check failed"]; | |
| 15 | return [...said.slice(0, NAMES).map((n) => n.slice(0, 200)), ...(said.length > NAMES ? [`and ${said.length - NAMES} more`] : [])]; | |
| 16 | } | |
| 17 | ||
| 18 | /** The sentence that leads to a run's details. */ | |
| 19 | export const runDetails = (slug: string, runId: string): string => | |
| 20 | `The assertion and the output are with [the check run](/${slug}/runs/${runId}), for who may read its log.`; |
src/checks/gate_run.ts +2 −1
| @@ -8,6 +8,7 @@ import { JOB_VANISHED } from "./job_step.ts"; | ||
| 8 | 8 | import { gateRunId } from "./queue.ts"; |
| 9 | 9 | import type { LaneState } from "./lane_state.ts"; |
| 10 | 10 | import { runTier } from "./run_tier.ts"; |
| 11 | import { redactHeld } from "../kernel/log.ts"; | |
| 11 | 12 | |
| 12 | 13 | /** A gate this forge would not start, for it is stopping. */ |
| 13 | 14 | const INTERRUPTED = "this forge is stopping"; |
| @@ -35,7 +36,7 @@ async function gateOnce( | ||
| 35 | 36 | commitOid, |
| 36 | 37 | pull, |
| 37 | 38 | tier: "full", |
| 38 | write: (line) => lines.push(line), | |
| 39 | write: (line) => lines.push(redactHeld(line)), | |
| 39 | 40 | signal: controller.signal, |
| 40 | 41 | }); |
| 41 | 42 | if (done.ok) return { ok: true, error: "", lines }; |
src/checks/job_step.ts +2 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | import { JobVanished, runJob, type JobOptions, type JobSpec } from "../cluster/jobs.ts"; |
| 8 | 8 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 9 | import type { StepLines } from "./step_lines.ts"; | |
| 9 | 10 | import type { Placement } from "./placement.ts"; |
| 10 | 11 | |
| 11 | 12 | /** What a NetworkPolicy selects a check's pod by (docs/APPS.md, Placement). */ |
| @@ -26,7 +27,7 @@ export async function runJobStep( | ||
| 26 | 27 | timeoutMs: number; |
| 27 | 28 | limits: { memoryMiB: number; cpus: number; diskMiB: number }; |
| 28 | 29 | /** The Job's own output, apart from the echoed commands. */ |
| 29 | output: string[]; | |
| 30 | output: Pick<StepLines, "push">; | |
| 30 | 31 | onNode: (node: string) => void; |
| 31 | 32 | /** The proxy variables of this run's egress gate (`checks/job_gate.ts`). */ |
| 32 | 33 | proxy?: Record<string, string>; |
src/checks/queue_store.ts +2 −1
| @@ -140,7 +140,7 @@ function stepsOf(text: string): RecordedStep[] | undefined { | ||
| 140 | 140 | function verdictOf(text: string): Judged | undefined { |
| 141 | 141 | const v = parsed(text); |
| 142 | 142 | if (typeof v !== "object" || v === null) return undefined; |
| 143 | const { lands, reopen, comment, learn, reason } = v as Record<string, unknown>; | |
| 143 | const { lands, reopen, comment, learn, reason, log } = v as Record<string, unknown>; | |
| 144 | 144 | if (lands === true) return { lands: true }; |
| 145 | 145 | if (lands !== false || reopen !== true || typeof comment !== "string") return undefined; |
| 146 | 146 | if (!Array.isArray(learn) || !learn.every((f) => typeof f === "string")) return undefined; |
| @@ -154,6 +154,7 @@ function verdictOf(text: string): Judged | undefined { | ||
| 154 | 154 | learn: learn as string[], |
| 155 | 155 | ...(why === undefined ? {} : { reason: why }), |
| 156 | 156 | ...(named === undefined ? {} : { tests: named }), |
| 157 | ...(typeof log === "string" ? { log } : {}), | |
| 157 | 158 | }; |
| 158 | 159 | } |
| 159 | 160 |
src/checks/report.ts +10 −26
| @@ -15,6 +15,7 @@ import { addComment, createLabel, getLabel, labelsFor, listIssues, setIssueLabel | ||
| 15 | 15 | import { getRepo, type Repo } from "../core/repos.ts"; |
| 16 | 16 | import { ownRepoPath } from "../kernel/own_repo.ts"; |
| 17 | 17 | import type { CheckDetail, Run } from "../core/runs.ts"; |
| 18 | import { runDetails } from "./failure_names.ts"; | |
| 18 | 19 | import { failedTests, fileIssueOnce } from "./flake.ts"; |
| 19 | 20 | import { isSummaryLine } from "./bun-test.ts"; |
| 20 | 21 | import { safeFile } from "./verify.ts"; |
| @@ -195,26 +196,9 @@ export function failuresDetail( | ||
| 195 | 196 | } |
| 196 | 197 | |
| 197 | 198 | /** |
| 198 | * `text` as a code span or block that nothing in it can close: the fence is longer than any run of | |
| 199 | * backticks inside. | |
| 200 | */ | |
| 201 | function fence(text: string): string { | |
| 202 | const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length)); | |
| 203 | return "`".repeat(Math.max(3, longest + 1)); | |
| 204 | } | |
| 205 | ||
| 206 | /** | |
| 207 | * What a report says of one failing file: each quoted failure, then how to reproduce it (#12295). | |
| 199 | * How to reproduce one failing file (#12295). | |
| 208 | 200 | */ |
| 209 | 201 | export function redBody(detail: CheckDetail | null | undefined, file: string): string { |
| 210 | const quotes = (detail?.failures ?? []).filter((f) => f.file === file && f.excerpt !== undefined); | |
| 211 | const parts: string[] = []; | |
| 212 | for (const q of quotes) { | |
| 213 | const output = q.excerpt!.join("\n"); | |
| 214 | const f = fence(output); | |
| 215 | const head = q.assertion === undefined ? "" : `: ${inline(q.assertion)}`; | |
| 216 | parts.push(`${inline(q.name)} failed${head}\n\n${f}text\n${output}\n${f}`); | |
| 217 | } | |
| 218 | 202 | const shard = detail?.shards?.find((s) => s.file === file); |
| 219 | 203 | const repro = [`bun test ./${file}`, `bun test ./${file} ${RERUN}`]; |
| 220 | 204 | if (shard !== undefined && shard.slice.length > 1 && shard.slice.length <= SLICE_MAX) |
| @@ -224,13 +208,12 @@ export function redBody(detail: CheckDetail | null | undefined, file: string): s | ||
| 224 | 208 | shard !== undefined && shard.slice.length > 1 ? `beside ${shard.slice.length - 1} other file${shard.slice.length === 2 ? "" : "s"}` : undefined, |
| 225 | 209 | detail?.concurrency, |
| 226 | 210 | ].filter((s) => s !== undefined); |
| 227 | parts.push( | |
| 211 | return ( | |
| 228 | 212 | `To reproduce:\n\n\`\`\`sh\n${repro.join("\n")}\n\`\`\`\n\n` + |
| 229 | 213 | (ran.length === 0 |
| 230 | 214 | ? "The run's log did not say which shard it ran in." |
| 231 | : `The full suite ran it ${ran.join(", ")}${repro.length > 2 ? " (the last command runs that shard as one `bun test`)" : ""}.`), | |
| 215 | : `The full suite ran it ${ran.join(", ")}${repro.length > 2 ? " (the last command runs that shard as one `bun test`)" : ""}.`) | |
| 232 | 216 | ); |
| 233 | return parts.join("\n\n"); | |
| 234 | 217 | } |
| 235 | 218 | |
| 236 | 219 | /** `text` as one inline code span, whatever backticks it holds. */ |
| @@ -284,8 +267,8 @@ function openReports(app: App, repo: Repo): { id: string; number: number; title: | ||
| 284 | 267 | } |
| 285 | 268 | |
| 286 | 269 | /** |
| 287 | * What a report says of one red file: its failing tests by name, then the quoted failures and how | |
| 288 | * to reproduce it. | |
| 270 | * What a report says of one red file: its failing tests by name and how to reproduce it. What each | |
| 271 | * said stays with the run (`failure_names.ts`). | |
| 289 | 272 | */ |
| 290 | 273 | function fileSection(run: Run, file: string): string { |
| 291 | 274 | const names = (run.checkDetail?.failures ?? []).filter((f) => f.file === file).map((f) => f.name); |
| @@ -329,9 +312,10 @@ export function reportRed(app: App, repo: Repo, run: Run, alone: ReadonlyMap<str | ||
| 329 | 312 | ? `Still red in the full suite (${where}).${fileSection(run, issue.files[0]!)}` |
| 330 | 313 | : `Still red in the full suite (${where}): ${issue.files.map((f) => `\`${f}\``).join(", ")}.\n\n` + |
| 331 | 314 | issue.files.map((f) => `# \`${f}\`${fileSection(run, f)}`).join("\n\n"); |
| 315 | const told = `${said}\n\n${runDetails(`${repo.ownerName}/${repo.name}`, run.id)}`; | |
| 332 | 316 | const body = lifted |
| 333 | ? `A second full-suite run is red for it, so it is no longer held as \`${ALONE_GREEN_LABEL}\`: a builder may start it.\n\n${said}` | |
| 334 | : said; | |
| 317 | ? `A second full-suite run is red for it, so it is no longer held as \`${ALONE_GREEN_LABEL}\`: a builder may start it.\n\n${told}` | |
| 318 | : told; | |
| 335 | 319 | const noted = addComment(app.db, { issueId: issue.id, authorId: repo.ownerId, body }); |
| 336 | 320 | if (noted.ok) |
| 337 | 321 | app.bus.append({ |
| @@ -421,7 +405,7 @@ function fileFresh( | ||
| 421 | 405 | const labelIds = [label?.id, hold?.id].filter((id): id is string => id !== undefined); |
| 422 | 406 | const filed = fileIssueOnce(app.db, app.bus, repo, { |
| 423 | 407 | title: fresh.length === 1 ? reportTitle(fresh[0]!) : runReportTitle(run.id, fresh.length), |
| 424 | body: `${body}\n\nFiles: ${fresh.join(", ")}`, | |
| 408 | body: `${body}\n\n${runDetails(`${repo.ownerName}/${repo.name}`, run.id)}\n\nFiles: ${fresh.join(", ")}`, | |
| 425 | 409 | labelIds, |
| 426 | 410 | }); |
| 427 | 411 | const named = fresh.join(", "); |
src/checks/run_tier.ts +7 −5
| @@ -47,6 +47,7 @@ import { tryRunner } from "./tier_runner.ts"; | ||
| 47 | 47 | import { judgeLentGreen, type LentGreen } from "../actions/runners.ts"; |
| 48 | 48 | import { runInstall } from "./tier_install.ts"; |
| 49 | 49 | import { settleFlakes } from "./tier_flake.ts"; |
| 50 | import { StepLines } from "./step_lines.ts"; | |
| 50 | 51 | import { deepsecStep } from "./deepsec_step.ts"; |
| 51 | 52 | import { pickSubscription } from "../core/subscriptions.ts"; |
| 52 | 53 | import { checksRoot, reclaimIfFull, removeRunDir } from "./sweep.ts"; |
| @@ -292,7 +293,8 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 292 | 293 | ...stepFloorEnv({ alone: floor !== undefined, inCell: cell !== undefined, cellsFloored: cell?.floor !== undefined || cellsFloored() }), |
| 293 | 294 | }); |
| 294 | 295 | let ran: Result<void, string>; |
| 295 | const checkLines: string[] = []; | |
| 296 | const said = new StepLines(); | |
| 297 | const checkLines = said.masked; | |
| 296 | 298 | // A bisection step runs only some files: what it shows green says nothing of the rest. |
| 297 | 299 | const wholeVerify = x.tier === "verify" && x.only === undefined; |
| 298 | 300 | // The gate is held to what a cell holds: the forge, the registry and |
| @@ -321,7 +323,7 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 321 | 323 | commands: manifest.install === null ? [step] : [manifest.install, step], |
| 322 | 324 | env, |
| 323 | 325 | log: write, |
| 324 | output: checkLines, | |
| 326 | output: said, | |
| 325 | 327 | signal, |
| 326 | 328 | timeoutMs: manifest.timeout * 1000, |
| 327 | 329 | limits: resolveLimits("step", manifest.limits), |
| @@ -341,7 +343,7 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 341 | 343 | if (installed !== undefined) return lostCheckout(dir, installed); |
| 342 | 344 | if (runnerRed !== undefined) { |
| 343 | 345 | // The runner's check is this check's: its lines and its red, for the failed tests alone. |
| 344 | checkLines.push(...runnerRed.lines); | |
| 346 | for (const line of runnerRed.lines) said.push(line); | |
| 345 | 347 | ran = err(runnerRed.error); |
| 346 | 348 | } else { |
| 347 | 349 | // The check step's own lines are kept beside what `write` already |
| @@ -354,7 +356,7 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 354 | 356 | cwd: dir, |
| 355 | 357 | env, |
| 356 | 358 | log: (line) => { |
| 357 | if (sawEcho) checkLines.push(line); | |
| 359 | if (sawEcho) said.push(line); | |
| 358 | 360 | sawEcho = true; |
| 359 | 361 | write(line); |
| 360 | 362 | }, |
| @@ -369,7 +371,7 @@ async function runTierOnce(lane: LaneState, x: Execution, sample: (green: LentGr | ||
| 369 | 371 | ran = await settleFlakes( |
| 370 | 372 | lane, |
| 371 | 373 | x, |
| 372 | { run, repo, bare, dir, env, cell, manifest, tip, inJob: job !== undefined, checkLines, write, signal }, | |
| 374 | { run, repo, bare, dir, env, cell, manifest, tip, inJob: job !== undefined, checkLines, rawLines: said.raw, write, signal }, | |
| 373 | 375 | ran, |
| 374 | 376 | ); |
| 375 | 377 | if (!ran.ok && !existsSync(dir)) return { ok: false, error: LOST_CHECKOUT, infrastructure: true }; |
src/checks/runner_step.ts +4 −3
| @@ -36,6 +36,7 @@ import { | ||
| 36 | 36 | type RunnerStepResult, |
| 37 | 37 | type RunnerStepSpec, |
| 38 | 38 | } from "./runner_jobs.ts"; |
| 39 | import type { StepLines } from "./step_lines.ts"; | |
| 39 | 40 | import { summariseCheckFailure } from "./summary.ts"; |
| 40 | 41 | |
| 41 | 42 | /** How long a job waits for a runner to take it before the forge runs the check itself. */ |
| @@ -87,7 +88,7 @@ export interface RunnerStepInput { | ||
| 87 | 88 | readonly job: Omit<RunnerJob, "id">; |
| 88 | 89 | readonly log: (line: string) => void; |
| 89 | 90 | /** The check step's own output, apart from the echoed command. */ |
| 90 | readonly output: string[]; | |
| 91 | readonly output: Pick<StepLines, "push" | "clear">; | |
| 91 | 92 | readonly signal: AbortSignal; |
| 92 | 93 | /** The pull's author, as a lent runner's authors scope reads it. */ |
| 93 | 94 | readonly author?: string | undefined; |
| @@ -222,8 +223,7 @@ export async function runRunnerStep( | ||
| 222 | 223 | ? `runner ${holder} stopped the job (${view.result.slice(13)}): queued again, and that is not a try, nor a result` |
| 223 | 224 | : `runner ${holder} went silent: the job is queued again, and that is not a try`, |
| 224 | 225 | ); |
| 225 | // What a half-run printed is not the check's output. | |
| 226 | input.output.length = 0; | |
| 226 | input.output.clear(); | |
| 227 | 227 | sawEcho = false; |
| 228 | 228 | holder = ""; |
| 229 | 229 | offeredAt = now(); |
| @@ -297,6 +297,7 @@ export interface RunnerRed { | ||
| 297 | 297 | readonly alone: true; |
| 298 | 298 | /** The runner that ran it, as its log names it. */ |
| 299 | 299 | readonly runner: string; |
| 300 | /** As printed, in memory alone: `run_tier.ts` masks each as it takes it. */ | |
| 300 | 301 | readonly lines: readonly string[]; |
| 301 | 302 | readonly error: string; |
| 302 | 303 | } |
src/checks/step_lines.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | /** | |
| 2 | * A check step's own output, kept while the check runs. Every line is masked as it enters, as the | |
| 3 | * run's log masks it, before anything cuts or stores it: what a check keeps is made from `masked`. | |
| 4 | */ | |
| 5 | ||
| 6 | import { redactHeld } from "../kernel/log.ts"; | |
| 7 | ||
| 8 | export class StepLines { | |
| 9 | readonly masked: string[] = []; | |
| 10 | /** As printed, in memory alone: a failed test is re-run by the name it has (`tier_flake.ts`). */ | |
| 11 | readonly raw: string[] = []; | |
| 12 | ||
| 13 | push(...lines: readonly string[]): void { | |
| 14 | for (const line of lines) { | |
| 15 | this.masked.push(redactHeld(line)); | |
| 16 | this.raw.push(line); | |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | /** What a half-run printed is not the check's output. */ | |
| 21 | clear(): void { | |
| 22 | this.masked.length = 0; | |
| 23 | this.raw.length = 0; | |
| 24 | } | |
| 25 | } |
src/checks/summary.ts +5 −3
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | import { STEP_TOOK_LINE, TOOK_LINE } from "./took_line.ts"; |
| 11 | 11 | import type { CheckDetail, Run } from "../core/runs.ts"; |
| 12 | import { redactHeld } from "../kernel/log.ts"; | |
| 12 | 13 | import { parseBunTestFailure } from "./bun-test.ts"; |
| 13 | 14 | import { fullShard, OUT_OF_ROOM, TEMP_FULL } from "./disk_full.ts"; |
| 14 | 15 | import { oneLine } from "./words.ts"; |
| @@ -83,8 +84,8 @@ export interface CheckFailure { | ||
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | /** |
| 86 | * `lines` is the check step's own output, nothing from `install` mixed in | |
| 87 | * (`checks/service.ts` keeps them apart already). `fallback` is what | |
| 87 | * `lines` is the check step's own output, masked (`step_lines.ts`), nothing from `install` mixed in | |
| 88 | * (`checks/service.ts` keeps them apart already). `error` is what | |
| 88 | 89 | * `runStep` says when a step exits non-zero — "check exited with code 1", |
| 89 | 90 | * sometimes with a reason it found on its own — used only when this |
| 90 | 91 | * output named nothing better, so a truthful "no output at all" is never |
| @@ -97,8 +98,9 @@ export interface CheckFailure { | ||
| 97 | 98 | */ |
| 98 | 99 | export function summariseCheckFailure( |
| 99 | 100 | lines: readonly string[], |
| 100 | fallback: string, | |
| 101 | error: string, | |
| 101 | 102 | ): CheckFailure { |
| 103 | const fallback = redactHeld(error); | |
| 102 | 104 | const parsed = parseBunTestFailure(lines); |
| 103 | 105 | // A shard that ran out of temp space is marked on the detail, not worded |
| 104 | 106 | // into the summary: the crew reads the mark, the summary keeps the failures. |
src/checks/tier_flake.ts +6 −3
| @@ -8,6 +8,7 @@ import { parseBunTestFailure } from "./bun-test.ts"; | ||
| 8 | 8 | import { recordCrashFlakes, passedAlone, recordFlakes, rerunCommand, rerunnable, pullOwnsRed } from "./flake.ts"; |
| 9 | 9 | import { childEnv, runStep } from "../apps/process.ts"; |
| 10 | 10 | import type { CellSpec } from "../apps/contain.ts"; |
| 11 | import { redactHeld } from "../kernel/log.ts"; | |
| 11 | 12 | import type { Result } from "../kernel/result.ts"; |
| 12 | 13 | import type { LaneState } from "./lane_state.ts"; |
| 13 | 14 | import type { Execution } from "./local_runner.ts"; |
| @@ -29,7 +30,9 @@ export interface FlakeCheck { | ||
| 29 | 30 | readonly tip: string | undefined; |
| 30 | 31 | /** Whether the check ran in a cluster Job, where it is not re-run here. */ |
| 31 | 32 | readonly inJob: boolean; |
| 33 | /** The step's output, masked, and as printed: the second only finds the test to re-run. */ | |
| 32 | 34 | readonly checkLines: readonly string[]; |
| 35 | readonly rawLines: readonly string[]; | |
| 33 | 36 | readonly write: (line: string) => void; |
| 34 | 37 | readonly signal: AbortSignal; |
| 35 | 38 | } |
| @@ -46,7 +49,7 @@ export async function settleFlakes( | ||
| 46 | 49 | result: Result<void, string>, |
| 47 | 50 | ): Promise<Result<void, string>> { |
| 48 | 51 | const { app } = lane; |
| 49 | const { run, repo, bare, dir, env, cell, manifest, tip, inJob, checkLines, write, signal } = c; | |
| 52 | const { run, repo, bare, dir, env, cell, manifest, tip, inJob, checkLines, rawLines, write, signal } = c; | |
| 50 | 53 | let ran = result; |
| 51 | 54 | // A file the gate cleared because it passed alone is still a failure |
| 52 | 55 | // to track: the cell cannot reach the forge, so it is filed from here. |
| @@ -76,7 +79,7 @@ export async function settleFlakes( | ||
| 76 | 79 | // A pull's red is the same unless the pull touched the test (#7426). |
| 77 | 80 | if (!ran.ok && !inJob && (x.isMain === true || tip !== undefined)) { |
| 78 | 81 | try { |
| 79 | let tests = rerunnable(checkLines, parseBunTestFailure(checkLines)); | |
| 82 | let tests = rerunnable(rawLines, parseBunTestFailure(rawLines)); | |
| 80 | 83 | if (tests !== undefined && x.isMain !== true) { |
| 81 | 84 | const diff = await runGit( |
| 82 | 85 | ["diff", "--name-only", "-z", `${tip}...${x.commitOid}`], |
| @@ -118,7 +121,7 @@ export async function settleFlakes( | ||
| 118 | 121 | } |
| 119 | 122 | } |
| 120 | 123 | if (alone) { |
| 121 | recordFlakes(app.db, app.bus, repo, tests, { runId: run.id, commit: run.commitOid, pull: x.isMain !== true }); | |
| 124 | recordFlakes(app.db, app.bus, repo, tests.map((t) => ({ ...t, name: redactHeld(t.name) })), { runId: run.id, commit: run.commitOid, pull: x.isMain !== true }); | |
| 122 | 125 | for (const t of tests) write(`flake: ${t.file} > ${t.name} passed alone`); |
| 123 | 126 | write(`flaky: ${tests.map((t) => `"${t.name}"`).join(", ")} failed in the full run and passed alone; recorded, ${x.isMain === true ? "main" : "the check"} stays green`); |
| 124 | 127 | ran = { ok: true, value: undefined }; |
src/checks/tier_runner.ts +5 −3
| @@ -10,6 +10,7 @@ import { recordCrashFlakes, recordFlakes, rerunnable } from "./flake.ts"; | ||
| 10 | 10 | import { handoverEnv, handsTimesBack } from "./handover.ts"; |
| 11 | 11 | import { capacityEnv, checkShardCpus, egressSetting, shardsInForce, shardsLine } from "../core/capacity.ts"; |
| 12 | 12 | import { resolveLimits, STEP_HOSTS } from "../apps/contain.ts"; |
| 13 | import { StepLines } from "./step_lines.ts"; | |
| 13 | 14 | import { HANDED_OVER, runRunnerStep, runnerTakes, runnerVerdict, type RunnerRed } from "./runner_step.ts"; |
| 14 | 15 | import type { CheckOutcome } from "./runner.ts"; |
| 15 | 16 | import type { LaneState } from "./lane_state.ts"; |
| @@ -99,7 +100,8 @@ export async function tryRunner( | ||
| 99 | 100 | write("placement: runner; the install command cannot be run without its scripts; running here"); |
| 100 | 101 | return undefined; |
| 101 | 102 | } |
| 102 | const lines: string[] = []; | |
| 103 | const said = new StepLines(); | |
| 104 | const lines = said.masked; | |
| 103 | 105 | // The shard count an admin set reaches a runner's check as it does one run here (#14844); the |
| 104 | 106 | // default is sized as one run here is (`checkShardCpus`), never from the runner machine's CPUs. |
| 105 | 107 | const effective = resolveLimits("step", manifest.limits); |
| @@ -161,7 +163,7 @@ export async function tryRunner( | ||
| 161 | 163 | ...(handsTimesBack(x) ? { hands: HAND_FILES } : {}), |
| 162 | 164 | }, |
| 163 | 165 | log: write, |
| 164 | output: lines, | |
| 166 | output: said, | |
| 165 | 167 | signal, |
| 166 | 168 | waitMs: lane.placement.waitMs, |
| 167 | 169 | // A release stopping this forge leaves the job with its runner (`adoptRunnerJobs`). |
| @@ -189,7 +191,7 @@ export async function tryRunner( | ||
| 189 | 191 | if (typeof verdict === "string") write(`placement: runner; ${verdict}; running here`); |
| 190 | 192 | else if ("alone" in verdict) { |
| 191 | 193 | write(`placement: runner; one or two tests failed on runner ${verdict.runner}: only they are re-run here, alone, never the whole check`); |
| 192 | return verdict; | |
| 194 | return { ...verdict, lines: said.raw }; | |
| 193 | 195 | } else if (verdict.ok && sent.taken && sampleLentGreen(app, sent.runnerId, sent.jobId)) { |
| 194 | 196 | // A share of a lent runner's greens is run here as well (`lent_scope.ts`): this forge's |
| 195 | 197 | // own verdict is the one that stands, and a red pauses the runner (`judgeLentGreen`). |
src/checks/tiers.ts +3
| @@ -565,6 +565,8 @@ export type Judged = | ||
| 565 | 565 | readonly reason?: GateReason; |
| 566 | 566 | /** What its tests said: the counts and the failing tests by name (#6739). */ |
| 567 | 567 | readonly tests?: GateTests; |
| 568 | /** Where the gate's log is read, by who may read it. */ | |
| 569 | readonly log?: string; | |
| 568 | 570 | }; |
| 569 | 571 | |
| 570 | 572 | /** |
| @@ -602,5 +604,6 @@ export function landVerdict( | ||
| 602 | 604 | learn: [...new Set(failedFiles)], |
| 603 | 605 | ...(reason === undefined ? {} : { reason }), |
| 604 | 606 | ...(tests === undefined ? {} : { tests }), |
| 607 | ...(logLink === undefined ? {} : { log: logLink }), | |
| 605 | 608 | }; |
| 606 | 609 | } |
src/core/runs.ts +3 −1
| @@ -12,6 +12,7 @@ import type { Database } from "bun:sqlite"; | ||
| 12 | 12 | import { hostname } from "node:os"; |
| 13 | 13 | import { BUDGET_PREFIX } from "../kernel/budgets.ts"; |
| 14 | 14 | import { id } from "../kernel/id.ts"; |
| 15 | import { redactHeld } from "../kernel/log.ts"; | |
| 15 | 16 | import { appendRun } from "./ledger.ts"; |
| 16 | 17 | import { meterOf } from "./run_compute.ts"; |
| 17 | 18 | |
| @@ -416,7 +417,8 @@ export function finishRun( | ||
| 416 | 417 | .run( |
| 417 | 418 | runId, |
| 418 | 419 | outcome.state, |
| 419 | outcome.summary.slice(0, 500), | |
| 420 | // Read with the run by anyone who may read the repository: masked as its log is, before the cut. | |
| 421 | redactHeld(outcome.summary).slice(0, 500), | |
| 420 | 422 | outcome.sessionId ?? null, |
| 421 | 423 | outcome.costUsd ?? null, |
| 422 | 424 | outcome.turns ?? null, |
src/crew/failure_quote.ts +2 −1
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | * What a failed check says, quoted for a person or a builder (#12968): the failing test, its | |
| 2 | * What a failed check says, quoted in a builder's brief (#12968); an issue or a comment names the | |
| 3 | * tests instead (`checks/failure_names.ts`): the failing test, its | |
| 3 | 4 | * assertion and the end of its own output. Plain data in, one string out; a run that named no |
| 4 | 5 | * test is quoted by its summary. |
| 5 | 6 | */ |
src/crew/no_change.ts +4 −5
| @@ -4,8 +4,8 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * - First "no change": a re-check of that head is queued (reason `no_change`). Green, the pull |
| 6 | 6 | * moves on; red on a named test, the red goes back to the builder with that test's assertion. |
| 7 | * - Second "no change" on a head whose re-check was red: the failure is quoted once, in a | |
| 8 | * comment that names the head, and the pull waits for a person (the asks carry it). A later | |
| 7 | * - Second "no change" on a head whose re-check was red: the failing tests are named once, in | |
| 8 | * a comment that names the head and links the run, and the pull waits for a person (the asks carry it). A later | |
| 9 | 9 | * "no change" on that head finds the comment and says nothing again. It is never closed. |
| 10 | 10 | * - A re-check the forge cut short proved nothing: it is queued again and is no try. |
| 11 | 11 | */ |
| @@ -20,8 +20,7 @@ import type { Repo } from "../core/repos.ts"; | ||
| 20 | 20 | import { checkSummary, getRun, isCut, type Run } from "../core/runs.ts"; |
| 21 | 21 | import { getUserById } from "../core/users.ts"; |
| 22 | 22 | import { createLog } from "../kernel/log.ts"; |
| 23 | import { failingLines, failureQuote } from "./failure_quote.ts"; | |
| 24 | import { readRunLog } from "../runs/log.ts"; | |
| 23 | import { failureNames, runDetails } from "../checks/failure_names.ts"; | |
| 25 | 24 | |
| 26 | 25 | const log = createLog("no-change"); |
| 27 | 26 | |
| @@ -81,7 +80,7 @@ export function afterNoChange(app: App, repo: Repo, issueId: string): NoChangeMo | ||
| 81 | 80 | by, |
| 82 | 81 | repo, |
| 83 | 82 | issue, |
| 84 | `${quotedMark(pull.headOid)} is red again after a re-check:\n\n${failureQuote(prior, failingLines(readRunLog(app.config.dataDir, prior.id, 32 * 1024).lines))}\n\nIt stays open for a person or a new head.`, | |
| 83 | `${quotedMark(pull.headOid)} is red again after a re-check:\n\n${failureNames(prior).join("\n")}\n\n${runDetails(`${repo.ownerName}/${repo.name}`, prior.id)}\n\nIt stays open for a person or a new head.`, | |
| 85 | 84 | ); |
| 86 | 85 | log.info("no change twice on a red", { pull: pull.number }); |
| 87 | 86 | return "quoted"; |
src/crew/red_thrice.ts +12 −14
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * A crew pull red on three checks in a row is not built a fourth time (#15819). Its issue is held |
| 3 | * as `red_thrice`, gets one note quoting the last failure, and is owed to the planner to split or | |
| 3 | * as `red_thrice`, gets one note naming the last failure, and is owed to the planner to split or | |
| 4 | 4 | * rewrite. Counts red checks only: the reviewer's changes-requested path is `guard.ts`'s. |
| 5 | 5 | * |
| 6 | 6 | * The streak is the pull's failed checks since its last green one. A check the forge cut short, |
| @@ -13,7 +13,7 @@ import { getIssue } from "../core/issues.ts"; | ||
| 13 | 13 | import type { Pull } from "../core/pulls.ts"; |
| 14 | 14 | import type { Repo } from "../core/repos.ts"; |
| 15 | 15 | import { getRun, isCut } from "../core/runs.ts"; |
| 16 | import { failureQuote } from "./failure_quote.ts"; | |
| 16 | import { failureNames, runDetails } from "../checks/failure_names.ts"; | |
| 17 | 17 | import { proposedWork } from "./direct.ts"; |
| 18 | 18 | |
| 19 | 19 | /** Failed checks in a row at which a pull goes back to the planner. */ |
| @@ -22,17 +22,15 @@ export const RED_STRIKES = 3; | ||
| 22 | 22 | /** What the note starts with, before the pull it names. */ |
| 23 | 23 | export const RED_THRICE_NOTE = "Red on three checks:"; |
| 24 | 24 | |
| 25 | /** How many lines of the last failure the note quotes. */ | |
| 26 | const QUOTE_LINES = 6; | |
| 27 | ||
| 28 | 25 | export interface RedThrice { |
| 29 | 26 | readonly pull: Pull; |
| 30 | 27 | /** The failed checks in the streak. */ |
| 31 | 28 | readonly failures: number; |
| 32 | 29 | /** When the oldest of them was queued. */ |
| 33 | 30 | readonly since: string; |
| 34 | /** The first lines of the newest failure. */ | |
| 35 | readonly quote: string; | |
| 31 | /** The newest failure: its run, and its failing tests by name. */ | |
| 32 | readonly runId: string; | |
| 33 | readonly failing: readonly string[]; | |
| 36 | 34 | } |
| 37 | 35 | |
| 38 | 36 | /** The streak on one pull, or undefined when it is under the strikes. */ |
| @@ -55,8 +53,7 @@ export function redStreak(db: Database, pull: Pull): Omit<RedThrice, "pull"> | u | ||
| 55 | 53 | } |
| 56 | 54 | if (failures < RED_STRIKES || newest === undefined) return undefined; |
| 57 | 55 | const run = getRun(db, newest); |
| 58 | const lines = (run === undefined ? "the check failed" : failureQuote(run)).split("\n"); | |
| 59 | return { failures, since, quote: lines.slice(0, QUOTE_LINES).join("\n") }; | |
| 56 | return { failures, since, runId: newest, failing: run === undefined ? ["the check failed"] : failureNames(run) }; | |
| 60 | 57 | } |
| 61 | 58 | |
| 62 | 59 | /** The issues whose open crew pull is red on three checks, by issue number. */ |
| @@ -70,13 +67,14 @@ export function redThrice(db: Database, repo: Repo): Map<number, RedThrice> { | ||
| 70 | 67 | return out; |
| 71 | 68 | } |
| 72 | 69 | |
| 73 | /** The note on the issue: which pull, how often, and what the last failure said. */ | |
| 74 | export function redThriceNote(r: RedThrice): string { | |
| 75 | const quoted = r.quote.split("\n").map((l) => (l.trim() === "" ? ">" : `> ${l.replace(/\s+$/, "")}`)); | |
| 70 | /** The note on the issue: which pull, how often, and what the last failure was. */ | |
| 71 | export function redThriceNote(slug: string, r: RedThrice): string { | |
| 76 | 72 | return [ |
| 77 | 73 | `${RED_THRICE_NOTE} pull #${r.pull.number} failed its check ${r.failures} times in a row, so no builder starts on it again. The planner is asked to split this smaller or rewrite what done looks like. The last failure:`, |
| 78 | 74 | "", |
| 79 | ...quoted, | |
| 75 | ...r.failing.map((l) => `> ${l.trim()}`), | |
| 76 | "", | |
| 77 | runDetails(slug, r.runId), | |
| 80 | 78 | ].join("\n"); |
| 81 | 79 | } |
| 82 | 80 | |
| @@ -106,7 +104,7 @@ export function redThricePulls(db: Database, repo: Repo) { | ||
| 106 | 104 | repoId: repo.id, |
| 107 | 105 | number, |
| 108 | 106 | title: issue.title, |
| 109 | reasons: [r.quote.split("\n")[0] ?? ""], | |
| 107 | reasons: [r.failing[0] ?? ""], | |
| 110 | 108 | byAgent: true, |
| 111 | 109 | at, |
| 112 | 110 | }); |
src/crew/sentinel.ts +17 −18
| @@ -37,7 +37,6 @@ import { QUEUE_AGENT_FULL, QUEUE_CHECK_FULL, QUEUE_WAIT_MAX_MS } from "../kernel | ||
| 37 | 37 | import { STALE_AFTER_MS } from "../runs/lease.ts"; |
| 38 | 38 | import { isOutageSummary } from "./network.ts"; |
| 39 | 39 | import { |
| 40 | assertionLines, | |
| 41 | 40 | mainVerdict, |
| 42 | 41 | pullsFailedSince, |
| 43 | 42 | pullsOwn, |
| @@ -45,7 +44,6 @@ import { | ||
| 45 | 44 | SHARED_WINDOW_MS, |
| 46 | 45 | sharedRuns, |
| 47 | 46 | } from "../checks/shared_red.ts"; |
| 48 | import { readRunLogTail } from "../runs/log.ts"; | |
| 49 | 47 | import { clip } from "../text/clip.ts"; |
| 50 | 48 | import { forgeCeiling } from "../flow/ceiling.ts"; |
| 51 | 49 | import { personSpoke } from "./person_spoke.ts"; |
| @@ -586,7 +584,7 @@ export function degradedCauses( | ||
| 586 | 584 | `first open: ${new Date(d.first).toISOString()}`, |
| 587 | 585 | `total: ${minutes} minutes in the day`, |
| 588 | 586 | `href: ${d.href}`, |
| 589 | ...sharedLines(db, cause, now, forgeRepoId, dataDir), | |
| 587 | ...sharedLines(db, cause, now, forgeRepoId), | |
| 590 | 588 | // /system is admin people only: the finding carries what grew, so a builder can name it |
| 591 | 589 | // (#14362). |
| 592 | 590 | ...(cause === "memory-growth" ? memoryEvidence(watch, dataDir, from) : []), |
| @@ -666,7 +664,7 @@ export function budgetBreaches(db: Database, now: number, forgeRepoId?: string, | ||
| 666 | 664 | `since: ${new Date(s.openedAt).toISOString()}`, |
| 667 | 665 | `href: ${s.href}`, |
| 668 | 666 | ...runLogLines(db, s.cause, veiled), |
| 669 | ...sharedLines(db, s.cause, now, forgeRepoId, dataDir), | |
| 667 | ...sharedLines(db, s.cause, now, forgeRepoId), | |
| 670 | 668 | ], |
| 671 | 669 | pillar: "P0 Trust: the forge says when it is not well, and is well again", |
| 672 | 670 | kind: "defect", |
| @@ -702,22 +700,18 @@ function runLogLines(db: Database, cause: string, veiled: boolean): string[] { | ||
| 702 | 700 | return [`run ${id}: ${run.state}${run.summary && !veiled ? `, ${oneLine(run.summary)}` : ""}`]; |
| 703 | 701 | } |
| 704 | 702 | |
| 705 | /** How many log lines a shared finding reads from the end of its newest run's log: never the whole file. */ | |
| 706 | const SHARED_LOG_TAIL = 400; | |
| 707 | ||
| 708 | 703 | /** |
| 709 | 704 | * What a builder needs to reproduce a `shared:` cause (#8286): the pulls |
| 710 | 705 | * and runs that failed its test, newest first, the base the newest merged, |
| 711 | * the newest one's assertion lines from the tail of its log, and whether | |
| 712 | * main's newest check passes the test. A private repository's pulls and log | |
| 713 | * lines stay out of a finding filed anywhere but in that repository. | |
| 706 | * and whether main's newest check passes the test. A private repository's | |
| 707 | * pulls stay out of a finding filed anywhere but in that repository. What the | |
| 708 | * test said stays with the run: `runPathOf` leads there. | |
| 714 | 709 | */ |
| 715 | 710 | function sharedLines( |
| 716 | 711 | db: Database, |
| 717 | 712 | cause: string, |
| 718 | 713 | now: number, |
| 719 | 714 | forgeRepoId: string | undefined, |
| 720 | dataDir: string | undefined, | |
| 721 | 715 | ): string[] { |
| 722 | 716 | if (!cause.startsWith("shared:")) return []; |
| 723 | 717 | const repoId = cause.split(":")[1] ?? ""; |
| @@ -732,12 +726,7 @@ function sharedLines( | ||
| 732 | 726 | `test: ${oneLine(found.test)}`, |
| 733 | 727 | ...found.runs.map((r) => `failed: pull #${r.pull}, check run ${r.runId}`), |
| 734 | 728 | ]; |
| 735 | if (newest !== undefined) { | |
| 736 | out.push(`base: ${newest.baseOid || "none recorded"} (run ${newest.runId})`); | |
| 737 | const quoted = | |
| 738 | dataDir === undefined ? [] : assertionLines(readRunLogTail(dataDir, newest.runId, SHARED_LOG_TAIL).lines, found.test); | |
| 739 | out.push(...quoted.map((l) => `log: ${clip(oneLine(l), QUOTE_MAX)}`)); | |
| 740 | } | |
| 729 | if (newest !== undefined) out.push(`base: ${newest.baseOid || "none recorded"} (run ${newest.runId})`); | |
| 741 | 730 | const main = mainVerdict(db, repoId, found.test); |
| 742 | 731 | out.push( |
| 743 | 732 | main === undefined |
| @@ -749,6 +738,16 @@ function sharedLines( | ||
| 749 | 738 | return out; |
| 750 | 739 | } |
| 751 | 740 | |
| 741 | /** | |
| 742 | * The way to the newest run a shared finding names. Built of the forge's own names and added after | |
| 743 | * `scrub`, which takes a path this long for a token. | |
| 744 | */ | |
| 745 | function runPathOf(db: Database, f: Finding): string[] { | |
| 746 | const run = f.evidence.map((e) => /^failed: pull #\d+, check run (\w+)$/.exec(e)?.[1]).find((id) => id !== undefined); | |
| 747 | const repoId = /^shared:([^:]+):/.exec(f.cause ?? "")?.[1]; | |
| 748 | return run === undefined || repoId === undefined ? [] : [`log: /${repoSlug(db, repoId)}/runs/${run}`]; | |
| 749 | } | |
| 750 | ||
| 752 | 751 | /** Everything the sentinel reads, in one pass. */ |
| 753 | 752 | export function findFaults( |
| 754 | 753 | db: Database, |
| @@ -777,7 +776,7 @@ export function findFaults( | ||
| 777 | 776 | .map((f) => ({ |
| 778 | 777 | ...f, |
| 779 | 778 | title: scrub(f.title), |
| 780 | evidence: f.evidence.map(scrub), | |
| 779 | evidence: [...f.evidence.map(scrub), ...runPathOf(db, f)], | |
| 781 | 780 | })); |
| 782 | 781 | } |
| 783 | 782 |
src/crew/unstick.ts +2 −2
| @@ -21,7 +21,7 @@ import { landedUnder, stallReason } from "./stalls.ts"; | ||
| 21 | 21 | const log = createLog("autonomy"); |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | * One note on each issue whose pull is red on three checks (`red_thrice.ts`), quoting the last | |
| 24 | * One note on each issue whose pull is red on three checks (`red_thrice.ts`), naming the last | |
| 25 | 25 | * failure; a streak already noted is not noted again. Returns how many notes it wrote. |
| 26 | 26 | */ |
| 27 | 27 | export function noteRedThrice(app: App, repo: Repo, by: User): number { |
| @@ -29,7 +29,7 @@ export function noteRedThrice(app: App, repo: Repo, by: User): number { | ||
| 29 | 29 | for (const [number, r] of redThrice(app.db, repo)) { |
| 30 | 30 | const issue = getIssue(app.db, repo.id, number); |
| 31 | 31 | if (issue === undefined || issue.state !== "open" || notedAt(app.db, issue.id, r) !== undefined) continue; |
| 32 | if (!addComment(app, by, repo, issue, redThriceNote(r)).ok) continue; | |
| 32 | if (!addComment(app, by, repo, issue, redThriceNote(`${repo.ownerName}/${repo.name}`, r)).ok) continue; | |
| 33 | 33 | log.info("red on three checks; handed to the planner", { repo: `${repo.ownerName}/${repo.name}`, issue: number, pull: r.pull.number }); |
| 34 | 34 | wrote++; |
| 35 | 35 | } |
src/http/api.ts +4 −2
| @@ -3675,6 +3675,8 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 3675 | 3675 | // hidden by a deploy that ended after it (#17705). `runs` keeps every run. |
| 3676 | 3676 | const summary = checkSummaryOf(runs); |
| 3677 | 3677 | const latest = summary.run ?? undefined; |
| 3678 | // Each run as this reader may see it, as the runs doors give it. | |
| 3679 | const forReader = runForReader(ctx.app, ctx.auth.user, found.repo); | |
| 3678 | 3680 | // With no run, the reason: a bare "none" does not say whether to wait, approve or add a |
| 3679 | 3681 | // check. |
| 3680 | 3682 | const why = latest === undefined ? await whyNoCheck(ctx.app, found.repo, found.pull, head) : undefined; |
| @@ -3689,11 +3691,11 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 3689 | 3691 | state: summary.state, |
| 3690 | 3692 | required: found.repo.requireChecks, |
| 3691 | 3693 | ...(why === undefined ? {} : { why }), |
| 3692 | run: latest ?? null, | |
| 3694 | run: latest === undefined ? null : forReader(latest), | |
| 3693 | 3695 | looks: latest |
| 3694 | 3696 | ? looksOfCheck(ctx.app, ctx.auth.user, found.repo, { id: latest.id, commitOid: latest.commitOid }) |
| 3695 | 3697 | : [], |
| 3696 | runs, | |
| 3698 | runs: runs.map(forReader), | |
| 3697 | 3699 | }), |
| 3698 | 3700 | ); |
| 3699 | 3701 | }, |
src/main.ts +4
| @@ -55,6 +55,7 @@ import { startAdvisoryFeed } from "./core/advisory_feed.ts"; | ||
| 55 | 55 | import { followTick, watchLandings } from "./spawn/app_follow.ts"; |
| 56 | 56 | import { startReachWatch } from "./spawn/reach.ts"; |
| 57 | 57 | import { isHookName, runHookClient } from "./git/hooks.ts"; |
| 58 | import { startDetailPass } from "./checks/detail_pass.ts"; | |
| 58 | 59 | import { drainBudgets } from "./drain.ts"; |
| 59 | 60 | import { drainStreams } from "./http/sse.ts"; |
| 60 | 61 | import { serve } from "./http/server.ts"; |
| @@ -802,6 +803,8 @@ const [mirrorOut, mirrorPulls, looks, talkLive, errorFixes, maintain, probes, ni | ||
| 802 | 803 | // /metrics kept as a series every 30 s for /explore/series (series/sampler.ts). |
| 803 | 804 | startService(app.log, "seriesSampler", async () => (await import("./series/sampler.ts")).startSeriesSampler(app)), |
| 804 | 805 | ]); |
| 806 | // Runs' kept check details get one pass of the log's mask, from five minutes after boot (`checks/detail_pass.ts`). | |
| 807 | const stopDetailPass = startDetailPass(app); | |
| 805 | 808 | // Off unless FORGE_HEAP_CAPTURE_DIR is set, for a copy of production (perf/heap_capture.ts). |
| 806 | 809 | const stopHeapCapture = startHeapCapture(process.env, (m) => app.log.info(m)); |
| 807 | 810 | // The starting boards, once each (actions/boards.ts). |
| @@ -1385,6 +1388,7 @@ function drain(signal: NodeJS.Signals): Promise<unknown> { | ||
| 1385 | 1388 | memorySampler?.stop(), |
| 1386 | 1389 | seriesSampler?.stop(), |
| 1387 | 1390 | stopHeapCapture(), |
| 1391 | stopDetailPass(), | |
| 1388 | 1392 | engineStopped, |
| 1389 | 1393 | ]) |
| 1390 | 1394 | .catch(() => {}) |
test/check-details-pass.test.ts added +106
| @@ -0,0 +1,106 @@ | ||
| 1 | /** | |
| 2 | * The pass over kept check details yields to everything (`src/checks/detail_pass.ts`): it starts | |
| 3 | * minutes after boot, a slice is bounded by runs, by text and by the clock, and the wait between | |
| 4 | * two grows while the event loop is late. At 50,000 runs no slice holds the thread for 50 ms. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { BYTES, FIRST_MS, maskSlice, passFrom, PAUSE_MS, pauseFor, ROWS } from "../src/checks/detail_pass.ts"; | |
| 13 | import { createRun } from "../src/core/runs.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | ||
| 17 | quietLogs(); | |
| 18 | ||
| 19 | const SHAPE = `forge_${"a1B2".repeat(10)}`; | |
| 20 | let dir = ""; | |
| 21 | let app: App; | |
| 22 | beforeAll(async () => { | |
| 23 | dir = await mkdtemp(join(tmpdir(), "check-details-pass-")); | |
| 24 | app = createApp({ dataDir: dir, port: 0, host: "forge.test" }); | |
| 25 | const alice = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 26 | if (!alice.ok) throw new Error(alice.error); | |
| 27 | const made = await createRepo(app, alice.value, { name: "many", visibility: "public" }); | |
| 28 | if (!made.ok) throw new Error("repo"); | |
| 29 | createRun(app.db, { repoId: made.value.id, kind: "check", env: "main", commitOid: "a".repeat(40), summary: "" }); | |
| 30 | }); | |
| 31 | afterAll(async () => { | |
| 32 | app.close(); | |
| 33 | await rm(dir, { recursive: true, force: true }); | |
| 34 | }); | |
| 35 | ||
| 36 | /** Exactly `n` runs, ids in order; `detail(i)` is SQL over `i`. */ | |
| 37 | function fill(n: number, detail: string): void { | |
| 38 | const cols = app.db.query<{ name: string }, []>("SELECT name FROM pragma_table_info('run')").all().map((c) => c.name); | |
| 39 | const put = cols.map((c) => (c === "id" ? "'r' || printf('%08d', i)" : c === "check_detail" ? detail : c === "summary" ? "'check failed: 1 of 2 tests'" : `t.${c}`)); | |
| 40 | app.db.run("CREATE TEMP TABLE IF NOT EXISTS seed AS SELECT * FROM run LIMIT 1"); | |
| 41 | app.db.run("DELETE FROM run"); | |
| 42 | app.db.run(`WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < ${n}) INSERT INTO run (${cols.join(", ")}) SELECT ${put.join(", ")} FROM n, temp.seed t`); | |
| 43 | } | |
| 44 | ||
| 45 | const still = (): number => 0; | |
| 46 | const detailOf = (failures: number, lines: number, width: number, secret: string): string => | |
| 47 | JSON.stringify({ | |
| 48 | passed: 1, | |
| 49 | failed: failures, | |
| 50 | names: ["adds"], | |
| 51 | failures: Array.from({ length: failures }, (_, i) => ({ file: "t/a.test.ts", name: `adds ${i}`, assertion: "error: no", excerpt: [`got ${secret}`, ...Array.from({ length: lines }, () => "word ".repeat(width / 5))] })), | |
| 52 | }); | |
| 53 | ||
| 54 | test("it starts five minutes after boot at the soonest, and waits longer while the loop is late", () => { | |
| 55 | expect(FIRST_MS).toBeGreaterThanOrEqual(5 * 60_000); | |
| 56 | expect(PAUSE_MS).toBeGreaterThanOrEqual(250); | |
| 57 | expect(pauseFor(0)).toBe(PAUSE_MS); | |
| 58 | expect(pauseFor(100)).toBeGreaterThan(pauseFor(20)); | |
| 59 | expect(pauseFor(1_000)).toBeGreaterThanOrEqual(10_000); | |
| 60 | }); | |
| 61 | ||
| 62 | test("a slice ends at 25 runs, at 256 KiB of text or with its time, whichever is first", () => { | |
| 63 | expect([ROWS, BYTES]).toEqual([25, 256 * 1024]); | |
| 64 | fill(60, "''"); | |
| 65 | const first = maskSlice(app.db, passFrom(app.db), still); | |
| 66 | expect(first).toMatchObject({ read: 25, at: "r00000025", done: false }); | |
| 67 | const last = maskSlice(app.db, maskSlice(app.db, first, still), still); | |
| 68 | expect(last).toMatchObject({ read: 60, masked: 0, done: true }); | |
| 69 | // 100 KiB a run: the third passes the bound and is the last. | |
| 70 | fill(10, `'"' || printf('%.102400c', 'x') || '"'`); | |
| 71 | expect(maskSlice(app.db, passFrom(app.db), still).read).toBe(3); | |
| 72 | // A clock that says each run took 30 ms: one run a slice, never none. | |
| 73 | fill(10, "''"); | |
| 74 | let t = 0; | |
| 75 | expect(maskSlice(app.db, passFrom(app.db), () => (t += 30)).read).toBe(1); | |
| 76 | }); | |
| 77 | ||
| 78 | test("50,000 runs: every one is masked and no slice holds the thread for 50 ms", () => { | |
| 79 | const red = detailOf(1, 30, 80, SHAPE); | |
| 80 | const worst = detailOf(40, 30, 160, SHAPE); | |
| 81 | // One run in ten is red; a stretch of fifty carries the most a check keeps. | |
| 82 | fill(50_000, `CASE WHEN i BETWEEN 20000 AND 20049 THEN '${worst}' WHEN i % 10 = 0 THEN '${red}' ELSE '' END`); | |
| 83 | app.db.run("CREATE TEMP TABLE was AS SELECT id, check_detail FROM run WHERE check_detail <> ''"); | |
| 84 | app.db.run("CREATE INDEX temp.was_id ON was (id)"); | |
| 85 | const took: number[] = []; | |
| 86 | let p = passFrom(app.db); | |
| 87 | while (!p.done) { | |
| 88 | const at = p.at; | |
| 89 | let best = Infinity; | |
| 90 | let next = p; | |
| 91 | // A slice over the bound is put back and timed again: the machine's own pause is not its work. | |
| 92 | for (let tries = 0; tries < 4 && best >= 50; tries++) { | |
| 93 | if (tries > 0) app.db.query("UPDATE run SET check_detail = (SELECT check_detail FROM temp.was WHERE was.id = run.id) WHERE id > ?1 AND id <= ?2 AND check_detail <> ''").run(at, next.at); | |
| 94 | const from = performance.now(); | |
| 95 | next = maskSlice(app.db, p); | |
| 96 | best = Math.min(best, performance.now() - from); | |
| 97 | } | |
| 98 | took.push(best); | |
| 99 | p = next; | |
| 100 | } | |
| 101 | const sorted = [...took].sort((a, b) => a - b); | |
| 102 | console.log(`kept details: ${p.read} runs, ${p.masked} masked, ${took.length} slices, ${(took.reduce((a, b) => a + b, 0) / 1000).toFixed(2)} s of work, median ${sorted[took.length >> 1]!.toFixed(2)} ms, worst ${sorted.at(-1)!.toFixed(1)} ms`); | |
| 103 | expect(p).toMatchObject({ read: 50_000, masked: 5_045, unread: 0 }); | |
| 104 | expect(app.db.query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM run WHERE instr(check_detail, ?1) > 0").get(SHAPE)!.n).toBe(0); | |
| 105 | expect(sorted.at(-1)!).toBeLessThan(50); | |
| 106 | }, 120_000); |
test/check-details.test.ts added +245
| @@ -0,0 +1,245 @@ | ||
| 1 | /** | |
| 2 | * A check's kept details are read and masked as its log is (`checks/step_lines.ts`): each line is | |
| 3 | * masked as it enters, before any cut; the API gives the details to who may read the log; what is | |
| 4 | * kept already gets one pass (`checks/detail_pass.ts`). A failed test is still re-run by its own name. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { startDetailPass } from "../src/checks/detail_pass.ts"; | |
| 14 | import { failuresDetail } from "../src/checks/report.ts"; | |
| 15 | import type { runRunnerStep } from "../src/checks/runner_step.ts"; | |
| 16 | import { startChecks } from "../src/checks/service.ts"; | |
| 17 | import { StepLines } from "../src/checks/step_lines.ts"; | |
| 18 | import { createRun, finishRun, claimRun, getRun, getRunErrorLine, listRuns, setRunErrorLine, type Run } from "../src/core/runs.ts"; | |
| 19 | import { createSession } from "../src/core/sessions.ts"; | |
| 20 | import { createUser, type User } from "../src/core/users.ts"; | |
| 21 | import { forgeHttp } from "../src/http/server.ts"; | |
| 22 | import { err, ok } from "../src/kernel/result.ts"; | |
| 23 | import { holdValues, releaseValues } from "../src/kernel/log.ts"; | |
| 24 | import { jobWatchOf, runningOf } from "../src/perf/jobs.ts"; | |
| 25 | import { readRunLog } from "../src/runs/log.ts"; | |
| 26 | import { quietLogs } from "./helpers/globals.ts"; | |
| 27 | import { waitFor } from "./helpers/poll.ts"; | |
| 28 | ||
| 29 | quietLogs(); | |
| 30 | ||
| 31 | const VALUE = "s3cr3t-Value-91x"; | |
| 32 | const SHAPE = `forge_${"a1B2".repeat(10)}`; | |
| 33 | const priorCells = process.env["FORGE_CELLS"]; // env-restored: afterAll | |
| 34 | let dir = ""; | |
| 35 | let app: App; | |
| 36 | let alice: User; | |
| 37 | let bob: User; | |
| 38 | beforeAll(async () => { | |
| 39 | process.env["FORGE_CELLS"] = "off"; // env-restored: afterAll | |
| 40 | dir = await mkdtemp(join(tmpdir(), "check-details-")); | |
| 41 | app = createApp({ dataDir: dir, port: 0, host: "forge.test" }); | |
| 42 | const make = async (username: string, adminIfFirst: boolean): Promise<User> => { | |
| 43 | const u = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst }); | |
| 44 | if (!u.ok) throw new Error(u.error); | |
| 45 | return u.value; | |
| 46 | }; | |
| 47 | alice = await make("alice", true); | |
| 48 | bob = await make("bob", false); | |
| 49 | holdValues("check-details", [VALUE]); | |
| 50 | }); | |
| 51 | afterAll(async () => { | |
| 52 | releaseValues("check-details"); | |
| 53 | if (priorCells === undefined) delete process.env["FORGE_CELLS"]; | |
| 54 | else process.env["FORGE_CELLS"] = priorCells; | |
| 55 | app.close(); | |
| 56 | await rm(dir, { recursive: true, force: true }); | |
| 57 | }); | |
| 58 | ||
| 59 | /** A test named with a secret, whose assertion puts one across the cut at 200. */ | |
| 60 | const said = (name: string, secret: string): string[] => [ | |
| 61 | "t/a.test.ts:", | |
| 62 | `error: ${"x".repeat(185)} ${secret} end`, | |
| 63 | `got ${secret}`, | |
| 64 | `(fail) ${name}`, | |
| 65 | " 41 pass", | |
| 66 | " 1 fail", | |
| 67 | "Ran 42 tests across 9 files.", | |
| 68 | ]; | |
| 69 | ||
| 70 | test("a line is masked as it enters, before the cut at 200", () => { | |
| 71 | for (const secret of [VALUE, SHAPE]) { | |
| 72 | const lines = new StepLines(); | |
| 73 | for (const l of said(`signs in with ${secret}`, secret)) lines.push(l); | |
| 74 | const detail = JSON.stringify(failuresDetail(undefined, ["t/a.test.ts"], lines.masked)); | |
| 75 | expect(detail).toContain("got [redacted]"); | |
| 76 | expect(detail).toContain("signs in with [redacted]"); | |
| 77 | expect(detail).not.toContain(secret.slice(0, 8)); | |
| 78 | expect(lines.raw[3]).toBe(`(fail) signs in with ${secret}`); | |
| 79 | // A runner that went silent: what its half-run printed goes, in both. | |
| 80 | lines.clear(); | |
| 81 | expect([lines.masked, lines.raw]).toEqual([[], []]); | |
| 82 | } | |
| 83 | }); | |
| 84 | ||
| 85 | /** The checks on a pull give the same details to the same people. */ | |
| 86 | async function pullDoor(slug: string, number: number): Promise<void> { | |
| 87 | const http = forgeHttp(app); | |
| 88 | const get = async (who?: User): Promise<string> => | |
| 89 | ( | |
| 90 | await http.handle( | |
| 91 | new Request(`http://forge.test/api/v1/repos/alice/${slug}/pulls/${String(number)}/checks`, who === undefined ? {} : { headers: { cookie: `forge_session=${createSession(app.db, who.id).token}` } }), | |
| 92 | ) | |
| 93 | ).text(); | |
| 94 | expect(await get(alice)).toContain('"excerpt"'); | |
| 95 | for (const who of [undefined, bob]) { | |
| 96 | const body = await get(who); | |
| 97 | expect(body).toContain('"state":"failed"'); | |
| 98 | expect(body).toContain('"checkDetail":null'); | |
| 99 | expect(body).not.toContain('"excerpt"'); | |
| 100 | } | |
| 101 | } | |
| 102 | ||
| 103 | /** A pull's check whose step says `lines` here or on a runner; the test's file passes alone or not. */ | |
| 104 | async function checked(slug: string, where: "here" | "runner", name: string, secret: string, passes: boolean): Promise<{ run: Run; log: string; gate: string }> { | |
| 105 | const made = await createRepo(app, alice, { name: slug, visibility: "public" }); | |
| 106 | if (!made.ok) throw new Error("repo"); | |
| 107 | const repo = made.value; | |
| 108 | const spec = `import { test, expect } from "bun:test";\ntest(${JSON.stringify(name)}, () => { expect(1).toBe(${passes ? "1" : "2"}); });\n`; | |
| 109 | const base = await commitToBranch(app, alice, repo, { | |
| 110 | message: "base", | |
| 111 | files: [ | |
| 112 | { path: "forge.json", content: JSON.stringify({ check: { run: "true", install: "" } }) }, | |
| 113 | { path: "t/a.test.ts", content: spec }, | |
| 114 | ], | |
| 115 | }); | |
| 116 | if (!base.ok) throw new Error(JSON.stringify(base.error)); | |
| 117 | const topic = await commitToBranch(app, alice, repo, { branch: "topic", message: "topic", files: [{ path: "notes.txt", content: "x" }] }); | |
| 118 | if (!topic.ok) throw new Error(JSON.stringify(topic.error)); | |
| 119 | const runnerStep: typeof runRunnerStep = async (_app, input) => { | |
| 120 | for (const line of said(name, secret)) { | |
| 121 | input.output.push(line); | |
| 122 | input.log(line); | |
| 123 | } | |
| 124 | return { taken: true, ran: err("check exited with code 1"), failed: "check", runner: "local-1", contained: true, note: "" }; | |
| 125 | }; | |
| 126 | const checks = startChecks(app, { | |
| 127 | forgeUrl: "http://forge.test", | |
| 128 | concurrency: 1, | |
| 129 | ...(where === "runner" ? { placement: { mode: "runner" as const, waitMs: 300 }, runnerStep } : {}), | |
| 130 | checkStep: async (_step, command, options) => { | |
| 131 | if (where === "runner") return ok(); | |
| 132 | for (const line of [`$ ${command}`, ...said(name, secret)]) options.log(line); | |
| 133 | return err("check exited with code 1"); | |
| 134 | }, | |
| 135 | }); | |
| 136 | try { | |
| 137 | const pull = await openPull(app, alice, repo, { title: "t", body: "", baseBranch: "main", headBranch: "topic" }); | |
| 138 | if (!pull.ok) throw new Error(JSON.stringify(pull.error)); | |
| 139 | const finished = () => listRuns(app.db, repo.id, { kind: "check", limit: 50 }).find((r) => r.issueId !== null && (r.state === "ok" || r.state === "failed")); | |
| 140 | expect(await waitFor(() => finished() !== undefined, { within: 40_000 })).toBe(true); | |
| 141 | const run = finished()!; | |
| 142 | // The merge queue's gate of the same commit, whose lines are kept and read too. | |
| 143 | const gate = run.state === "failed" && where === "here" ? (await checks.gate(repo, pull.value, topic.value.commitOid)).lines.join("\n") : ""; | |
| 144 | return { run, log: readRunLog(app.config.dataDir, run.id).lines.join("\n"), gate }; | |
| 145 | } finally { | |
| 146 | await checks.stop(); | |
| 147 | } | |
| 148 | } | |
| 149 | ||
| 150 | for (const where of ["here", "runner"] as const) { | |
| 151 | test(`a check that ran ${where}: its details and summary are masked, and its failed test is re-run by its own name`, async () => { | |
| 152 | for (const [i, secret] of [VALUE, SHAPE].entries()) { | |
| 153 | const { run, log, gate } = await checked(`red-${where}-${String(i)}`, where, `signs in with ${secret}`, secret, false); | |
| 154 | expect(run.state).toBe("failed"); | |
| 155 | expect(log).toContain(`"signs in with [redacted]" fails alone too`); | |
| 156 | expect(run.summary).toContain("signs in with [redacted]"); | |
| 157 | expect(run.checkDetail?.names).toEqual(["signs in with [redacted]"]); | |
| 158 | expect(JSON.stringify(run.checkDetail)).toContain("got [redacted]"); | |
| 159 | if (where === "here") expect(gate).toContain("signs in with [redacted]"); | |
| 160 | for (const kept of [run.summary, JSON.stringify(run.checkDetail), log, gate]) expect(kept).not.toContain(secret.slice(0, 8)); | |
| 161 | } | |
| 162 | }, 120_000); | |
| 163 | ||
| 164 | test(`a check that ran ${where}: a test whose name is masked passes alone, so the check is green and the flake is kept masked`, async () => { | |
| 165 | const { run } = await checked(`flake-${where}`, where, `signs in with ${SHAPE}`, SHAPE, true); | |
| 166 | expect(run.state).toBe("ok"); | |
| 167 | const kept = app.db.query<{ test: string }, [string]>("SELECT test FROM check_flake WHERE run_id = ?1").all(run.id); | |
| 168 | expect(kept).toEqual([{ test: "signs in with [redacted]" }]); | |
| 169 | }, 60_000); | |
| 170 | } | |
| 171 | ||
| 172 | test("the API gives a run's details to who may read its log, and to nobody else", async () => { | |
| 173 | const made = await createRepo(app, alice, { name: "doors", visibility: "public" }); | |
| 174 | if (!made.ok) throw new Error("repo"); | |
| 175 | const detail = { passed: 1, failed: 1, names: ["adds"], failures: [{ file: "t/a.test.ts", name: "adds", excerpt: ["got 3"] }] }; | |
| 176 | const run = createRun(app.db, { repoId: made.value.id, kind: "check", env: "main", commitOid: "a".repeat(40), summary: "" }); | |
| 177 | claimRun(app.db, run.id); | |
| 178 | finishRun(app.db, run.id, { state: "failed", summary: "check failed: 1 of 2 tests", checkDetail: detail }); | |
| 179 | const http = forgeHttp(app); | |
| 180 | const get = async (path: string, who?: User) => | |
| 181 | http.handle(new Request(`http://forge.test/api/v1/repos/alice/doors${path}`, who === undefined ? {} : { headers: { cookie: `forge_session=${createSession(app.db, who.id).token}` } })); | |
| 182 | for (const path of ["/runs", `/runs/${run.id}`]) { | |
| 183 | expect(await (await get(path, alice)).text()).toContain("got 3"); | |
| 184 | for (const who of [undefined, bob]) { | |
| 185 | const res = await get(path, who); | |
| 186 | const body = await res.text(); | |
| 187 | expect(res.status).toBe(200); | |
| 188 | expect(body).toContain("1 of 2 tests"); | |
| 189 | expect(body).toContain('"checkDetail":null'); | |
| 190 | expect(body).not.toContain("got 3"); | |
| 191 | } | |
| 192 | } | |
| 193 | expect((await get(`/runs/${run.id}/log`, bob)).status).toBe(404); | |
| 194 | // The checks on a pull give the same details to the same people. | |
| 195 | for (const branch of [undefined, "topic"]) { | |
| 196 | const put = await commitToBranch(app, alice, made.value, { ...(branch === undefined ? {} : { branch }), message: "m", files: [{ path: `${branch ?? "base"}.txt`, content: "x" }] }); | |
| 197 | if (!put.ok) throw new Error(JSON.stringify(put.error)); | |
| 198 | } | |
| 199 | const pull = await openPull(app, alice, made.value, { title: "t", body: "", baseBranch: "main", headBranch: "topic" }); | |
| 200 | if (!pull.ok) throw new Error(JSON.stringify(pull.error)); | |
| 201 | const its = createRun(app.db, { repoId: made.value.id, kind: "check", env: "pull-1", issueId: pull.value.id, commitOid: pull.value.headOid, summary: "" }); | |
| 202 | claimRun(app.db, its.id); | |
| 203 | finishRun(app.db, its.id, { state: "failed", summary: "check failed: 1 of 2 tests", checkDetail: detail }); | |
| 204 | await pullDoor("doors", pull.value.number); | |
| 205 | }); | |
| 206 | ||
| 207 | test("what is kept already is masked once, and counted", async () => { | |
| 208 | const made = await createRepo(app, alice, { name: "kept", visibility: "public" }); | |
| 209 | if (!made.ok) throw new Error("repo"); | |
| 210 | const keep = (secret: string): string => { | |
| 211 | const run = createRun(app.db, { repoId: made.value.id, kind: "check", env: "main", commitOid: "b".repeat(40), summary: "" }); | |
| 212 | claimRun(app.db, run.id); | |
| 213 | finishRun(app.db, run.id, { state: "failed", summary: "x" }); | |
| 214 | const detail = { passed: 1, failed: 1, names: [`a "${secret}" name`], failures: [{ file: "t/a.test.ts", name: "adds", assertion: `error: ${secret}`, excerpt: [`got ${secret}`] }], diskFree: 0.5 }; | |
| 215 | app.db.query("UPDATE run SET check_detail = ?2, summary = ?3 WHERE id = ?1").run(run.id, JSON.stringify(detail), `check failed: ${secret}`); | |
| 216 | setRunErrorLine(app.db, run.id, `error: ${secret}`, 4); | |
| 217 | return run.id; | |
| 218 | }; | |
| 219 | const ids = [keep(VALUE), keep(SHAPE), keep("plain")]; | |
| 220 | app.db.query("UPDATE run SET check_detail = ?2 WHERE id = ?1").run(ids[2]!, "{not json"); | |
| 221 | const before = app.db.query("SELECT COUNT(*) AS n FROM run").get() as { n: number }; | |
| 222 | // A new handle each time: a BunFile keeps the size it first saw. | |
| 223 | const record = () => Bun.file(join(dir, "check-details-pass.json")).text().catch(() => "{}"); | |
| 224 | const kept = async () => JSON.parse(await record()) as { done?: boolean }; | |
| 225 | const stop = startDetailPass(app, 0, () => 0); | |
| 226 | expect(await waitFor(async () => (await kept()).done === true, { within: 20_000 })).toBe(true); | |
| 227 | stop(); | |
| 228 | expect(await kept()).toMatchObject({ read: before.n, masked: 2, unread: 1 }); | |
| 229 | for (const id of ids.slice(0, 2)) { | |
| 230 | const run = getRun(app.db, id)!; | |
| 231 | expect(run.checkDetail).toEqual({ passed: 1, failed: 1, names: ['a "[redacted]" name'], failures: [{ file: "t/a.test.ts", name: "adds", assertion: "error: [redacted]", excerpt: ["got [redacted]"] }], diskFree: 0.5 }); | |
| 232 | expect(run.summary).toBe("check failed: [redacted]"); | |
| 233 | expect(getRunErrorLine(app.db, id)).toEqual({ text: "error: [redacted]", at: 4 }); | |
| 234 | } | |
| 235 | // Once: a run kept after it is another path's to mask, and a later boot leaves it and the record. | |
| 236 | const was = await record(); | |
| 237 | const later = keep(SHAPE); | |
| 238 | const from = performance.now(); | |
| 239 | const again = startDetailPass(app, 0, () => 0); | |
| 240 | const looked = () => jobWatchOf(app).across(from, performance.now()).includes("kept-details") && !runningOf(app).some((j) => j.name === "kept-details"); | |
| 241 | expect(await waitFor(looked, { within: 20_000 })).toBe(true); | |
| 242 | again(); | |
| 243 | expect(await record()).toBe(was); | |
| 244 | expect(getRun(app.db, later)!.summary).toContain(SHAPE); | |
| 245 | }, 30_000); |
test/crew-red-thrice.test.ts +3 −1
| @@ -61,7 +61,7 @@ describe("a pull red on three checks goes back to the planner", () => { | ||
| 61 | 61 | finishRun(app.db, run.id, { |
| 62 | 62 | state, |
| 63 | 63 | summary: state === "ok" ? "ok" : "check failed: 1 test failed", |
| 64 | ...(state === "failed" ? { checkDetail: { passed: 1, failed: 1, names: [`widget renders ${n}`] } } : {}), | |
| 64 | ...(state === "failed" ? { checkDetail: { passed: 1, failed: 1, names: [`widget renders ${n}`], failures: [{ file: "t/w.test.ts", name: `widget renders ${n}`, assertion: "error: no widget", excerpt: ["got none"] }] } } : {}), | |
| 65 | 65 | }); |
| 66 | 66 | } |
| 67 | 67 | |
| @@ -112,6 +112,8 @@ describe("a pull red on three checks goes back to the planner", () => { | ||
| 112 | 112 | expect(noteRedThrice(app, repo, me)).toBe(0); // once, not on every tick |
| 113 | 113 | expect(notes(three)).toHaveLength(1); |
| 114 | 114 | expect(notes(three)[0]!.body).toContain("> widget renders 3"); |
| 115 | expect(notes(three)[0]!.body).toContain("(/alice/engine/runs/"); | |
| 116 | for (const said of ["no widget", "got none"]) expect(notes(three)[0]!.body).not.toContain(said); | |
| 115 | 117 | expect(notes(two)).toHaveLength(0); |
| 116 | 118 | |
| 117 | 119 | // The planner is owed it, once the note is said. |
test/doctor-culprit.test.ts +5 −3
| @@ -12,9 +12,10 @@ describe("the batch doctor and a red culprit", () => { | ||
| 12 | 12 | }); |
| 13 | 13 | afterAll(() => w.close()); |
| 14 | 14 | |
| 15 | test("a functional red alone is held with a comment naming test, file, error and command; the batch is recorded", async () => { | |
| 15 | test("a functional red alone is held with a comment naming test, file, the gate's log and command; the batch is recorded", async () => { | |
| 16 | 16 | const pull = await w.pull("bad.ts"); |
| 17 | const red = redFor("adds two numbers", "test/add.test.ts", "error: expect(received).toBe(expected)"); | |
| 17 | const log = "/api/v1/repos/alice/app/gates/g1/log"; | |
| 18 | const red = { ...redFor("adds two numbers", "test/add.test.ts", "error: expect(received).toBe(expected)"), log }; | |
| 18 | 19 | expect(treatRed(w.app, w.repo, w.alice, pull, red, "b".repeat(40))).toBe("held"); |
| 19 | 20 | const hold = getHold(w.app.db, pull.id)!; |
| 20 | 21 | expect(hold.until).toBe("green"); |
| @@ -25,7 +26,8 @@ describe("the batch doctor and a red culprit", () => { | ||
| 25 | 26 | const said = listComments(w.app.db, pull.id).map((c) => c.body).join("\n"); |
| 26 | 27 | expect(said).toContain("adds two numbers"); |
| 27 | 28 | expect(said).toContain("test/add.test.ts"); |
| 28 | expect(said).toContain("expect(received).toBe(expected)"); | |
| 29 | expect(said).toContain(`(${log})`); | |
| 30 | expect(said).not.toContain("expect(received)"); | |
| 29 | 31 | expect(said).toContain("bun test ./test/add.test.ts"); |
| 30 | 32 | const [run] = doctorRuns(w.app.db, w.repo.id); |
| 31 | 33 | expect(run).toMatchObject({ culprit: pull.number, class: "functional", action: "held" }); |
test/full-suite-report.test.ts +15 −13
| @@ -476,15 +476,15 @@ describe("the report", () => { | ||
| 476 | 476 | return getRun(app.db, run.id)!; |
| 477 | 477 | }; |
| 478 | 478 | |
| 479 | test("the issue quotes the failing assertion and its output, fenced so nothing in it closes the block (#12295)", () => { | |
| 480 | reportRed(app, repo, redFrom(SHARD_LOG, "a".repeat(40))); | |
| 479 | test("the issue names the failing test and links the run; what it said stays with the run", () => { | |
| 480 | const run = redFrom(SHARD_LOG, "a".repeat(40)); | |
| 481 | reportRed(app, repo, run); | |
| 481 | 482 | const body = reports()[0]!.body; |
| 482 | expect(body).toContain("error: expect(received).toBe(expected)"); | |
| 483 | expect(body).toContain("noise before the error\n4 | test("); | |
| 484 | expect(body).toContain("Received: \"<b>`x`</b>```\""); | |
| 485 | expect(body).toContain("````text\n"); | |
| 486 | expect(body).not.toContain("(pass) a > ok"); | |
| 487 | expect(body.indexOf("error:")).toBeLessThan(body.indexOf("Files: test/a.test.ts")); | |
| 483 | expect(body).toContain("a > one"); | |
| 484 | expect(body).toContain(`(/${repo.ownerName}/${repo.name}/runs/${run.id})`); | |
| 485 | for (const said of ["error: expect", "noise before the error", "Received:", "```text"]) expect(body).not.toContain(said); | |
| 486 | expect(body.trimEnd()).toEndWith("Files: test/a.test.ts"); | |
| 487 | expect(run.checkDetail!.failures![0]!.excerpt!.join("\n")).toContain("noise before the error"); | |
| 488 | 488 | }); |
| 489 | 489 | |
| 490 | 490 | test("the issue says how to reproduce it: the file, ten reruns, and the shard and concurrency it ran under (#12295)", () => { |
| @@ -496,12 +496,15 @@ describe("the report", () => { | ||
| 496 | 496 | expect(body).toContain("in shard 7/120, beside 1 other file, 4 files at a time"); |
| 497 | 497 | }); |
| 498 | 498 | |
| 499 | test("each Still red comment carries the excerpt and the commands too (#12295)", () => { | |
| 499 | test("each Still red comment carries the name, the run and the commands too (#12295)", () => { | |
| 500 | 500 | reportRed(app, repo, redFrom(SHARD_LOG, "a".repeat(40))); |
| 501 | reportRed(app, repo, redFrom(SHARD_LOG, "b".repeat(40))); | |
| 501 | const second = redFrom(SHARD_LOG, "b".repeat(40)); | |
| 502 | reportRed(app, repo, second); | |
| 502 | 503 | const [comment] = listComments(app.db, reports()[0]!.id); |
| 503 | 504 | expect(comment!.body).toStartWith("Still red in the full suite"); |
| 504 | expect(comment!.body).toContain("error: expect(received).toBe(expected)"); | |
| 505 | expect(comment!.body).toContain("a > one"); | |
| 506 | expect(comment!.body).toContain(`/runs/${second.id})`); | |
| 507 | expect(comment!.body).not.toContain("error: expect"); | |
| 505 | 508 | expect(comment!.body).toContain(`bun test ./test/a.test.ts ${RERUN}`); |
| 506 | 509 | }); |
| 507 | 510 | |
| @@ -518,10 +521,9 @@ describe("the report", () => { | ||
| 518 | 521 | expect(body).toContain(`bun test ./test/a.test.ts ${RERUN}`); |
| 519 | 522 | }); |
| 520 | 523 | |
| 521 | test("a failure that printed nothing is named, not quoted with its bare (fail) line", () => { | |
| 524 | test("a failure that printed nothing keeps its name alone", () => { | |
| 522 | 525 | const detail = redDetail(undefined, ["test/a.test.ts"], ["test/a.test.ts:", "(fail) a > one", "1 tests failed:"])!; |
| 523 | 526 | expect(detail.failures).toEqual([{ file: "test/a.test.ts", name: "a > one" }]); |
| 524 | expect(redBody(detail, "test/a.test.ts")).not.toContain("```text"); | |
| 525 | 527 | }); |
| 526 | 528 | |
| 527 | 529 | test("a log with no shard banner still says how to reproduce, and that the shard is unknown", () => { |
test/job-slices.test.ts +3
| @@ -67,6 +67,7 @@ import { nightlyDue } from "../src/checks/scan_store.ts"; | ||
| 67 | 67 | import { startNotifier } from "../src/crew/notify.ts"; |
| 68 | 68 | import { pullDue } from "../src/apps/pull_schedule.ts"; |
| 69 | 69 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 70 | import { maskSlice, passFrom } from "../src/checks/detail_pass.ts"; | |
| 70 | 71 | import { retentionJobs } from "../src/system/retention.ts"; |
| 71 | 72 | import { returnSnoozed } from "../src/actions/gate_snooze.ts"; |
| 72 | 73 | import { synced } from "../src/games/notify.ts"; |
| @@ -290,6 +291,8 @@ function jobs(): Record<string, () => unknown> { | ||
| 290 | 291 | "retention-deploys": () => retention.deploys.slice(Date.now()), |
| 291 | 292 | "retention-telemetry": () => retention.telemetry.slice(Date.now() + 40 * 86_400_000), |
| 292 | 293 | "retention-vacuum": () => retention.vacuum.slice(Date.now()), |
| 294 | // One slice; check-details-pass.test.ts times 50,000 runs. | |
| 295 | "kept-details": () => maskSlice(app.db, passFrom(app.db)), | |
| 293 | 296 | }; |
| 294 | 297 | } |
| 295 | 298 |
test/no_change_recheck.test.ts +4 −3
| @@ -87,7 +87,7 @@ test("a deploy that came up is never offered as the failure", () => { | ||
| 87 | 87 | expect(taskPrompt({ ...base, noFailure: true } as unknown as TaskInput)).toContain("no check of its head is recorded as failed"); |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | test("a cut check is no failure; a builder's no change re-checks the head, and a second quotes the failure", () => { | |
| 90 | test("a cut check is no failure; a builder's no change re-checks the head, and a second names the failure and links the run", () => { | |
| 91 | 91 | app.db.query("DELETE FROM run WHERE issue_id = ?1").run(pull.id); |
| 92 | 92 | const cut = run("check"); |
| 93 | 93 | mark(cut.id, "failed", "interrupted by a restart; queued again"); |
| @@ -100,14 +100,15 @@ test("a cut check is no failure; a builder's no change re-checks the head, and a | ||
| 100 | 100 | expect(noChange()).toBe(false); |
| 101 | 101 | expect(rechecks()).toHaveLength(1); |
| 102 | 102 | |
| 103 | // It ends red on a named test: the stall is counted, and a second no change quotes it. | |
| 103 | // It ends red on a named test: the stall is counted, and a second no change names it. | |
| 104 | 104 | mark(rechecks()[0]!.id, "failed", "failed: engine > adds up", JSON.stringify({ names: ["engine > adds up"], failures: [{ file: "a.test.ts", name: "engine > adds up", assertion: "expected 2, got 3" }] })); |
| 105 | 105 | expect(redUnattended(app, repo, [])).toBe(1); |
| 106 | 106 | expect(noChange()).toBe(true); |
| 107 | 107 | expect(rechecks()).toHaveLength(1); |
| 108 | 108 | const said = listComments(app.db, pull.id).map((c) => c.body).join("\n"); |
| 109 | 109 | expect(said).toContain("engine > adds up"); |
| 110 | expect(said).toContain("expected 2, got 3"); | |
| 110 | expect(said).toContain(`/runs/${rechecks()[0]!.id})`); | |
| 111 | expect(said).not.toContain("expected 2, got 3"); | |
| 111 | 112 | |
| 112 | 113 | // A third no change on the same head finds the quote and says nothing again. |
| 113 | 114 | const before = listComments(app.db, pull.id).length; |
new above
offline