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

Batch doctor: on a red merge batch, find the culprit, tell load reds from real ones, hold with the exact failing test #7619

Parked opened this in answer to
Closed without merging

scout/forge:scout/7555-batch-doctor-on-a-red-merge-batch-find-t → main 5 commits fork 3 threads · 3 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
19 files changed +670 −4
README.md +1
@@ -515,6 +515,7 @@ This page is the front door. Everything else is a file of its own under
515515 - The flow panel's Hot files card and the terminal Flow dialog also name files that gained open pulls over the last hour ("warming: src/a.ts 2 → 4 pulls", at most 5; `src/flow/hot_trend.ts`). The hour-old counts are samples kept in memory by `src/crew/hot_history.ts`, so after a restart nothing is named until a half-hour-old sample exists; an agent sees public repositories only. The MCP `flow` tool does not carry it yet.
516516 - Under each queued repository's merge-queue line, the terminal Flow dialog lists its last five gates, newest first: the pulls carried, `green`, `red` or `cut off`, how long ago, and for a red gate the first failing test with its file, `flaky` when two gates sharing no pull failed it (`src/checks/gate_result.ts`, as MCP `queue_gates` reads them); a repository with none kept says `no gates yet`, and an agent reader sees public repositories only.
517517 - The flow panel on `/boards` has a Last gates card: the newest ten merge-queue gates, each with its pulls linked, green, red or cut off, and the first failing test with its first error line (or the reason a gate was cut off). A gate carrying a sealed pull shows `a sealed pull` and the verdict alone; a non-admin reader sees public repositories only (`src/web/pages/boards-gates.ts`, the same `recentGates` read as MCP `queue_gates`).
518 - The batch doctor (#7555) treats a red the merge queue hands back: a functional red that reproduces on the re-gate, with no pull ahead of it, is held until green with a comment naming the failing test, its file, the error line and `bun test ./file`; a budget or infra red is only recorded. Every act is a `maintenance_run` row, shown as a Batch doctor card on the flow panel (`src/web/pages/boards-doctor.ts`; a sealed pull is named `a sealed pull` with no error line; a non-admin sees public repositories only), as `doctor` lines under each repository in the terminal Flow dialog, and as `doctor` in MCP `queue_gates`. Its holds begin `batch doctor:` (`isDoctorHold`). See `docs/features/batch-doctor.md`.
518519 - The flow panel on `/boards` and the terminal Flow dialog say how the open crew pulls sort into piles (red, conflicted, changes asked, approved and waiting, awaiting review), each pull counted once in the first pile it fits (`src/flow/pile.ts`).
519520 - On the terminal's Asked screen, Enter on a thought opens a card of what became of it, as MCP `thought` answers: the issue it placed (Enter opens it), "kept as a note" or "not placed yet", and the thoughts it repeats or takes back and the later ones that did the same to it. A repository you cannot read is named as nothing, and a thought that is not yours or is gone says "No such thought". The card is a snapshot; `r` re-reads it (`src/tui/screens/asked.ts`).
520521 - The off-box snapshot mirror is set from three doors with one set of rules (`src/actions/mirror.ts`): Settings → Backups, MCP `mirror_set` (`set` or `forget`), and the terminal's Resilience screen (a forge admin who is a person; an admin agent only reads). The screen shows `Mirror: <place>` or `Mirror: none.`, `m` seals it with five prompts (endpoint, bucket, region, access key, secret key; the keys are masked as typed) where a blank keeps what was sealed, and `f` forgets it after a confirm. `t` tests where snapshots go, as MCP `backups_test` and the Backups page's Test button do: the sealed destination, otherwise the environment's, said as `Reached …: N objects listed.` or `Could not list …: <reason>` in the page's words; with none set it says so and calls nobody. A key is never read back or drawn.
docs/MCP.md +1 −1
@@ -135,7 +135,7 @@ for a tunnel and a forge that sleeps.
135135 | `propose_to_parent_forge` | `{ repo }`: offer this forge's landed change to its parent as a pull on `child/<name>/…`; the same tip answers with that pull | yes |
136136 | `pull` | `{ repo, number }`: a pull's title, state, head and base, and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), and `next: { who, why }` (open only; who acts next: builder, reviewer, queue or person), and `comments` (the newest 50: author, body, at, `untrusted` on an outsider's), `commentsTotal` and `commentsNext` (older: `GET …/issues/:number/comments?cursor=`), and `check: { state, baseOid }`: the latest check's state and the base tip it was merged with (empty when it merged nothing); `mergeable` and `conflicts` are the same fields as `GET …/pulls/:number`, `check` is `state` and `run.baseOid` from `GET …/pulls/:number/checks`; draws the `ui://forge/pull` card: `#N title`, state with check and conflicts while open, `head → base` linked to the pull, and the preview link when the pull has an environment | |
137137 | `pulls` | `{ repo?, state?, limit?, cursor? }`: without `repo`, every open pull you may read, oldest first, as `{ pulls, next_cursor }` (limit 1-200, default 50): `repo`, `number`, `title`, `check`, `verdict` (approved, changes_requested or none) and `gate` (what holds it, or null; the `why` module's cause); with `repo`, a repository's pulls, newest first, one brief line each: `number`, `title`, `author`, `head`, `check` (state), `approvals`, `changesRequested`, `mergeable` (null once closed); `state` open (default) or closed, `limit` 1-50 (default 20); no bodies, no diffs | |
138 | `queue_gates` | `{ repo, limit? }`: the merge queue's recent gates, newest first (`limit` 1–100, default 20), as `GET …/queue/gates` answers: each gate's pulls, state, reason, counts and failing tests by name with their first error lines, a test red in two gates that share no pull flagged `flaky` | |
138 | `queue_gates` | `{ repo, limit? }`: the merge queue's recent gates, newest first (`limit` 1–100, default 20), as `GET …/queue/gates` answers: each gate's pulls, state, reason, counts and failing tests by name with their first error lines, a test red in two gates that share no pull flagged `flaky`; `doctor`: the batch doctor's last acts on the repository (`culprit`, `class`, `action` held/recheck/kept, `probe`; a sealed pull's `culprit` is null and its `batch` and `probe` blank) | |
139139 | `quotas` | `{ key?, value?, dryRun? }` (forge admin): the per-account quotas `repositories`, `apps`, `storage` (MB), `previews`, `runs`, `checks`, each a number or null for none. `repositories` bounds repos on create, fork and copy; `apps` the apps made; `storage` the MB of repos plus app data, asked on push, create and fork; `previews` live previews; `runs` concurrent agent runs; `checks` concurrent checks. Each is asked before the thing is made or started and a forge admin is never limited; with `key` and `value` (`""` clears), planned first (`dryRun` is true unless `false`); applying needs an admin-scope token | yes |
140140 | `read_file` | a file (utf-8, or base64 for binary) or a directory listing at a ref, as GET …/contents; MP4/MOV/M4A files also carry about: {kind, seconds, width?, height?, says} | |
141141 | `releases` | `{shipped: true}`: what went live, for anyone: `version`, `commit`, `live` (newest first: `repo`, `number`, `title`, `at`) and `onItsWay` (landed, not yet in the running commit), the list /changelog shows. `{}`: the forge's kept releases newest first: short sha, version, the pull that landed it, when, and for the live one `live: true` and `since`; for whoever may read /releases, others get its refusal; no rollback, a person does that on the page | |
docs/features/batch-doctor.md added +8
@@ -0,0 +1,8 @@
1 # Batch doctor (#7555)
2
3 When the merge queue's re-gate hands a pull back red (the re-gate carries it alone, so a red on top of other pulls is the queue's own search, #4999), `src/checks/doctor.ts` classes the red (`doctor_classify.ts`) and acts, in `crew/autonomy.ts`'s `handBack`:
4
5 - **functional, alone on its merge**: the pull is held "until green" (out of the line), commented with the test, file, error line and `bun test ./file` to reproduce, and assigned back to its builder. A new head that passes its own check lifts the hold (`releaseOnGreen`). A red is held only when it reproduces on the queue's re-gate (the same head and base red again), so a flaky red still lands (#3155). A hold already on the pull (a person's) is kept, never overwritten.
6 - **budget / infra**: recorded as `recheck`, not held. `budget_retry.ts` already re-ran budget reds once; the queue re-gates a red pull alone later (#3155).
7
8 Every act is a `maintenance_run` row (`duty = batch-doctor`): batch (`base:head`), culprit pull, class, action, probe (the first error line); the newest 200 per repository are kept (`RUNS_KEPT`). A sealed pull's number, batch and probe are told by no door. Read them on the flow panel (Batch doctor card), in the terminal Flow dialog, or as `doctor` in MCP `queue_gates` (all `doctorRuns`). A doctor's hold reason begins `batch doctor:` (`HOLD_PREFIX`, `isDoctorHold`). The infra class matches errno codes, `no space left`, `disk quota` and `tar:` lines only.
src/checks/doctor.ts added +156
@@ -0,0 +1,156 @@
1 /**
2 * The batch doctor (#7555): a merge-queue gate found one pull red. It classes
3 * the red (`doctor_classify.ts`), and only a functional red of a pull alone
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
6 * handed back to its builder. The hold is "until green": the first check
7 * that passes on a new head lets it go (`actions/holds.ts` `releaseOnGreen`).
8 * A hold already on the pull — a person's above all — is never overwritten.
9 * Budget and infra reds are recorded and left to the queue's own re-gate.
10 * It is called only on the queue's re-gate, which carries the pull alone.
11 * Every act is one `maintenance_run` row; the newest `RUNS_KEPT` per
12 * repository are kept.
13 */
14
15 import type { Database } from "bun:sqlite";
16 import type { App } from "../app.ts";
17 import { builderOf } from "../actions/give_back.ts";
18 import { addComment } from "../actions/issues.ts";
19 import { getHold, setHold } from "../core/holds.ts";
20 import { getIssueById, setAssignee } from "../core/issues.ts";
21 import type { Pull } from "../core/pulls.ts";
22 import type { Repo } from "../core/repos.ts";
23 import type { User } from "../core/users.ts";
24 import { id } from "../kernel/id.ts";
25 import { classify, reproduce, type Diagnosis } from "./doctor_classify.ts";
26 import type { Red } from "./queue.ts";
27
28 export const DUTY = "batch-doctor";
29
30 /** What every doctor hold's reason begins with: how a person and `releaseOnGreen` tell it from the autonomy user's own. */
31 export const HOLD_PREFIX = "batch doctor:";
32
33 export const isDoctorHold = (why: string): boolean => why.startsWith(HOLD_PREFIX);
34
35 export type DoctorAction = "held" | "recheck" | "kept";
36
37 /** The most `maintenance_run` rows the doctor keeps per repository; older ones are pruned on each write. */
38 export const RUNS_KEPT = 200;
39
40 export interface DoctorRun {
41 /** `base:head`, blank for a sealed pull. */
42 readonly batch: string;
43 /** The pull's number, null for a sealed pull. */
44 readonly culprit: number | null;
45 readonly class: string;
46 readonly action: string;
47 readonly probe: string;
48 readonly at: string;
49 /** The culprit is a sealed pull: its number, batch and probe are not told. */
50 readonly sealed: boolean;
51 }
52
53 /** Why a held pull says it is held: one line, the test first. */
54 function whyLine(d: Diagnosis): string {
55 const name = d.test?.name ?? "the check";
56 return `${HOLD_PREFIX} ${name} fails alone`;
57 }
58
59 /** The comment a held pull gets: test, file, error line, command, what lifts it. */
60 export function holdComment(d: Diagnosis, builder: User | undefined): string {
61 const lines = ["The batch doctor held this pull: it is red on its own merge with main, in a functional test."];
62 if (d.test !== undefined) {
63 lines.push("", `- test: \`${d.test.name}\``);
64 if (d.test.file !== undefined) lines.push(`- file: \`${d.test.file}\``);
65 }
66 lines.push(`- error: \`${d.probe}\``);
67 const cmd = reproduce(d.test);
68 if (cmd !== undefined) lines.push(`- reproduce: \`${cmd}\``);
69 lines.push(
70 "",
71 `Rebase on main and fix it, then push: the hold lifts when the new head passes its own check.${builder ? ` Back to @${builder.username}.` : ""}`,
72 );
73 return lines.join("\n");
74 }
75
76 function record(app: App, repo: Repo, pull: Pull, batch: string, d: Diagnosis, action: DoctorAction): void {
77 app.db
78 .query(
79 "INSERT INTO maintenance_run (id, duty, repo_id, issue_id, batch, culprit, class, action, probe) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
80 )
81 .run(id(), DUTY, repo.id, pull.id, batch, pull.number, d.class, action, d.probe);
82 app.db
83 .query(
84 `DELETE FROM maintenance_run WHERE duty = ?1 AND repo_id = ?2 AND id NOT IN
85 (SELECT id FROM maintenance_run WHERE duty = ?1 AND repo_id = ?2 ORDER BY at DESC, id DESC LIMIT ?3)`,
86 )
87 .run(DUTY, repo.id, RUNS_KEPT);
88 }
89
90 /** Treat one red the queue's re-gate handed back, the pull alone on its merge. `by` acts. */
91 export function treatRed(app: App, repo: Repo, by: User, pull: Pull, red: Red, baseOid: string): DoctorAction {
92 const batch = `${baseOid.slice(0, 12)}:${pull.headOid.slice(0, 12)}`;
93 const d = classify(red.reason, red.tests);
94 let action: DoctorAction;
95 if (d.class !== "functional") action = "recheck";
96 else if (getHold(app.db, pull.id) !== undefined) action = "kept";
97 else {
98 action = "held";
99 const issue = getIssueById(app.db, pull.id);
100 const hold = setHold(app.db, pull.id, by.id, whyLine(d).slice(0, 200), "green");
101 app.bus.append({
102 kind: "pull.held",
103 repoId: repo.id,
104 actorId: by.id,
105 payload: { number: pull.number, why: hold.why },

together.length > 0 cannot happen from the only caller (if (again)), so searched is dead code. Remove it, or wire a caller where it can occur.

106 });
107 if (issue !== undefined) {
108 const builder = builderOf(app.db, repo, issue);
109 addComment(app, by, repo, issue, holdComment(d, builder));
110 if (builder && setAssignee(app.db, issue.id, builder.id))
111 app.bus.append({
112 kind: "pull.assigned",
113 repoId: repo.id,
114 actorId: by.id,
115 payload: { number: pull.number, assignee: builder.username, agent: true },
116 });
117 }
118 }
119 record(app, repo, pull, batch, d, action);
120 return action;
121 }
122
123 /** What a reader is told of one run: a sealed pull's number, batch and probe are blanked. */
124 const RUN_COLUMNS = `CASE WHEN i.sealed = 1 THEN '' ELSE m.batch END AS batch,
125 CASE WHEN i.sealed = 1 THEN NULL ELSE m.culprit END AS culprit, m.class, m.action,
126 CASE WHEN i.sealed = 1 THEN '' ELSE m.probe END AS probe, m.at, COALESCE(i.sealed, 0) AS sealed`;
127
128 type RunRow = Omit<DoctorRun, "sealed"> & { sealed: number };
outdated

Sealed rows must not expose culprit or batch either: MCP returns them as they are. Blank both here (or filter the row out) when i.sealed = 1.

129 const toRun = ({ sealed, ...r }: RunRow): DoctorRun => ({ ...r, sealed: sealed === 1 });
130
131 /** The doctor's last runs on a repository, newest first; a sealed pull is not named. */
132 export function doctorRuns(db: Database, repoId: string, limit = 20): DoctorRun[] {
133 return db
134 .query<RunRow, [string, string, number]>(
135 `SELECT ${RUN_COLUMNS}
136 FROM maintenance_run m LEFT JOIN issue i ON i.id = m.issue_id
137 WHERE m.duty = ?1 AND m.repo_id = ?2 ORDER BY m.at DESC, m.id DESC LIMIT ?3`,
138 )
139 .all(DUTY, repoId, limit)
140 .map(toRun);
141 }
142
143 /** The doctor's newest runs across repositories, in one read: every repository for `all`, public ones otherwise. */
144 export function recentDoctorRuns(db: Database, all: boolean, limit: number): { repo: string; run: DoctorRun }[] {
145 return db
146 .query<RunRow & { repo: string }, [string, number]>(
147 `SELECT ${RUN_COLUMNS}, u.username || '/' || r.name AS repo
148 FROM maintenance_run m
149 JOIN repo r ON r.id = m.repo_id JOIN user u ON u.id = r.owner_id
150 LEFT JOIN issue i ON i.id = m.issue_id
151 WHERE m.duty = ?1${all ? "" : " AND r.visibility = 'public'"}
152 ORDER BY m.at DESC, m.id DESC LIMIT ?2`,
153 )
154 .all(DUTY, limit)
155 .map(({ repo, ...r }) => ({ repo, run: toRun(r) }));
156 }
src/checks/doctor_classify.ts added +57
@@ -0,0 +1,57 @@
1 /**
2 * The batch doctor's first question about a red (#7555): was it the load,
3 * the machine, or the code? Read off the verdict the gate already carries
4 * (`reason`, `tests`), never off a log.
5 *
6 * - `budget`: every failing test threw `expectBudget` — the gate's own load
7 * (`budget_retry.ts` has already re-run it once); not held.
8 * - `infra`: the gate stopped before tests, or a test died on the machine
9 * (extract, ENOENT, tarball, disk); not held.
10 * - `functional`: a test the code made fail; held when alone.
11 *
12 * Plain data in, plain data out: no I/O.
13 */
14
15 import { BUDGET_MARK } from "./budget_retry.ts";
16 import type { GateReason } from "./gate_reason.ts";
17 import type { FailedTest, GateTests } from "./gate_tests.ts";
18
19 export type RedClass = "budget" | "infra" | "functional";
20
21 export interface Diagnosis {
22 readonly class: RedClass;
23 /** The first failing test, when the gate named one. */
24 readonly test?: FailedTest;
25 /** The line the class went on: the first error line, else the reason. */
26 readonly probe: string;
27 }
28
29 // Specific shapes only: a bare word like `extract` is as likely a function under test.
30 const INFRA = /\b(ENOENT|ENOSPC|EMFILE|ETIMEDOUT|ECONNRESET)\b|no space left|disk quota|(^|\s)tar: /i;
31 const PROBE_MAX = 300;
32
33 const clip = (s: string): string => (s.length > PROBE_MAX ? `${s.slice(0, PROBE_MAX - 1)}…` : s);
34
35 /** Class a red from its reason and the tests it named. */
36 export function classify(reason: GateReason | undefined, tests: GateTests | undefined): Diagnosis {
37 if (reason !== undefined && (reason.kind === "install" || reason.kind === "setup" || reason.kind === "timeout"))
38 return { class: "infra", probe: reason.kind };
39 const failing = tests?.failing ?? [];
40 const first = failing[0];
41 const probe = clip(first?.errors[0] ?? (reason?.kind ?? "check"));
42 // No test named: nothing to hold it by, so it is the queue's to re-gate.
43 if (first === undefined) return { class: "infra", probe };
44 const errors = (t: FailedTest): string => t.errors.join("\n");
45 if (failing.every((t) => t.errors[0]?.includes(BUDGET_MARK))) return { class: "budget", test: first, probe };
46 if (failing.every((t) => INFRA.test(errors(t)))) return { class: "infra", test: first, probe };
47 return { class: "functional", test: first, probe };
48 }
49
50 const SAFE = /^[\w@./+-]{1,200}$/;
51
52 /** The command that reproduces a failing test, or undefined when its file is not a plain path. */
53 export function reproduce(test: FailedTest | undefined): string | undefined {
54 if (test?.file === undefined || !SAFE.test(test.file)) return undefined;
55 const path = test.file.startsWith("./") || test.file.startsWith("/") ? test.file : `./${test.file}`;
56 return `bun test ${path}`;
57 }
src/core/migration-pins/20261028100000-maintenance-run.pin added +1
@@ -0,0 +1,1 @@
1 1f0c3e379986fea7c5d6d84a411abf796868e7f3d3036a11bb4160baaa77bcd4
src/core/migrations/20261028100000-maintenance-run.ts added +18
@@ -0,0 +1,18 @@
1 // One row each time a maintenance duty acts (#7555): the batch doctor writes
2 // the batch, the culprit pull, how the red was classed, what it did and the
3 // test output line it went on. Additive.
4 export default `
5 CREATE TABLE maintenance_run (
6 id TEXT PRIMARY KEY,
7 duty TEXT NOT NULL,
8 repo_id TEXT NOT NULL REFERENCES repo(id) ON DELETE CASCADE,
9 issue_id TEXT REFERENCES issue(id) ON DELETE SET NULL,
10 batch TEXT NOT NULL DEFAULT '',
11 culprit INTEGER,
12 class TEXT NOT NULL DEFAULT '',
13 action TEXT NOT NULL DEFAULT '',
14 probe TEXT NOT NULL DEFAULT '',
15 at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now'))
16 );
17 CREATE INDEX maintenance_run_duty ON maintenance_run(duty, at);
18 `;
src/crew/autonomy.ts +3
@@ -12,6 +12,7 @@
1212 * repository's origin.
1313 */
1414
15 import { treatRed } from "../checks/doctor.ts";
1516 import { closedToday, closeStale } from "./stale_pulls.ts";
1617 import { authorsInRepoPull } from "./authors_pull.ts";
1718 import type { Database } from "bun:sqlite";
@@ -2069,6 +2070,8 @@ async function admit(
20692070 });
20702071 addLearned(app.config.dataDir, pull.id, red.learn);
20712072 if (!again) addComment(app, by, repo, getIssueById(app.db, pull.id) ?? pull, clashSaid(red.comment, together));
2073 // A red that reproduces on the re-gate is the code's: only then is it the doctor's to hold.
2074 if (again) treatRed(app, repo, by, pull, red, baseOid);
20722075 },
20732076 // A proof the base has moved too far past is proved again before the batch.
20742077 ...(proves ? { proven: (baseOid: string) => proofHolds(app, pull, dir, baseOid) } : {}),
src/http/mcp/tools/queue_gates.ts +3 −2
@@ -1,9 +1,10 @@
1 import { doctorRuns } from "../../../checks/doctor.ts";
12 import { recentGates } from "../../../checks/gate_result.ts";
23 import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
34
45 export const tool: Tool = {
56 name: "queue_gates",
6 doc: "`{ repo, limit? }`: the merge queue's recent gates, newest first (`limit` 1–100, default 20), as `GET …/queue/gates` answers: each gate's pulls, state, reason, counts and failing tests by name with their first error lines, a test red in two gates that share no pull flagged `flaky`",
7 doc: "`{ repo, limit? }`: the merge queue's recent gates, newest first (`limit` 1–100, default 20), as `GET …/queue/gates` answers: each gate's pulls, state, reason, counts and failing tests by name with their first error lines, a test red in two gates that share no pull flagged `flaky`; `doctor`: the batch doctor's last acts on the repository (`culprit`, `class`, `action` held/recheck/kept, `probe`; a sealed pull's `culprit` is null and its `batch` and `probe` blank)",
78 description: "Recent merge-queue gates: pulls, verdicts, failing tests.",
89 inputSchema: {
910 type: "object",
@@ -22,6 +23,6 @@ export const tool: Tool = {
2223 return bad("invalid", "`limit` is a whole number from 1 to 100");
2324 const gates = recentGates(ctx.app.db, repo.id, limit);
2425 const red = gates.filter((g) => g.state === "red").length;
25 return good({ says: `${gates.length} gate(s), ${red} red.`, gates });
26 return good({ says: `${gates.length} gate(s), ${red} red.`, gates, doctor: doctorRuns(ctx.app.db, repo.id, limit) });
2627 },
2728 };
src/tui/screens/flow.ts +13
@@ -17,6 +17,7 @@
1717 */
1818
1919 import type { Database } from "bun:sqlite";
20 import { doctorRuns, type DoctorRun } from "../../checks/doctor.ts";
2021 import { recentGates, type KeptResult } from "../../checks/gate_result.ts";
2122 import { HOLDS } from "../../crew/held.ts";
2223 import { pullCounts } from "../../crew/hot_files.ts";
@@ -110,6 +111,7 @@ export function flowLines(
110111 return [
111112 `${pad(truncate(q.repo, 15), 15)} ${pad(String(q.queued), 6, "right")} ${pad(String(q.gating), 6, "right")} ${pad(String(q.gates), 5, "right")} ${pad(String(q.landedHour), 9, "right")} ${pad(q.approvedToLanded === null ? "—" : String(q.approvedToLanded), 12, "right")}`,
112113 ...gateLines(id === undefined ? [] : recentGates(db, id, GATES_SHOWN), now.getTime(), inner),
114 ...doctorLines(id === undefined ? [] : doctorRuns(db, id, DOCTOR_SHOWN), now.getTime(), inner),
113115 ];
114116 })),
115117 ...(red.length === 0
@@ -164,6 +166,17 @@ export function gateLines(gates: readonly KeptResult[], now: number, inner: numb
164166 });
165167 }
166168
169 /** The doctor's acts shown under a repository's gates. */
170 const DOCTOR_SHOWN = 3;
171
172 /** One indented line per batch-doctor act (#7555), newest first: `doctor #14 held · functional · how long ago · the error line`; none when it has not acted. */
173 export function doctorLines(runs: readonly DoctorRun[], now: number, inner: number): string[] {
174 return runs.map((r) => {
175 const pull = r.sealed || r.culprit === null ? "a sealed pull" : `#${r.culprit}`;
176 return truncate(` doctor ${pull} ${r.action} · ${r.class} · ${ago(Date.parse(r.at), now)}${r.probe === "" ? "" : ` · ${r.probe}`}`, inner);
177 });
178 }
179
167180 /** Idle pulls shown before `+N more`. */
168181 const IDLE_SHOWN = 5;
169182
src/web/pages/boards-doctor.ts added +37
@@ -0,0 +1,37 @@
1 /**
2 * The batch doctor's last acts (#7555), for the flow panel: the newest ten
3 * across the repositories the reader may see, one row each with when, the
4 * culprit pull, what the doctor did and how it classed the red. A sealed
5 * pull is named only as `a sealed pull`, with no probe; one read
6 * (`recentDoctorRuns`).
7 */
8
9 import type { Database } from "bun:sqlite";
10 import { recentDoctorRuns, type DoctorRun } from "../../checks/doctor.ts";
11 import { span } from "../../flow/pipeline.ts";
12 import { html, type Html } from "../html.ts";
13 import { badge, card, row } from "../ui.ts";
14
15 /** The most runs the card lists. */
16 export const DOCTOR_LISTED = 10;
17
18 function runRow(repo: string, run: DoctorRun, now: number): Html {
19 const tone = run.action === "held" ? "danger" : "default";
20 return row({
21 data: { doctor: run.action },
22 title: html`${run.sealed || run.culprit === null ? html`<span class="muted">a sealed pull</span>` : html`<a href="/${repo}/pulls/${String(run.culprit)}">#${String(run.culprit)}</a>`} ${badge(run.action, { tone })}`,
23 meta: html`${span(Math.max(0, now - Date.parse(run.at)))} ago · ${repo} · ${run.class}${run.probe === "" ? null : html` · <span data-detail title="${run.probe}">${run.probe}</span>`}`,
24 });
25 }
26
27 /** The "Batch doctor" card. */
28 export function doctorCard(db: Database, owner: boolean, now: number): Html {
29 const top = recentDoctorRuns(db, owner, DOCTOR_LISTED);
30 return card(
31 html`<h2>Batch doctor</h2>
32 ${top.length === 0
33 ? html`<p class="muted">No red has been treated yet.</p>`
34 : html`<ul class="list">${top.map((l) => runRow(l.repo, l.run, now))}</ul>`}`,
35 { id: "doctor" },
36 );
37 }
src/web/pages/flow-panel.ts +2
@@ -45,6 +45,7 @@ import { openerCounts } from "../../flow/openers.ts";
4545 import { readHeld } from "../../flow/held.ts";
4646 import type { App } from "../../app.ts";
4747 import { html, type Html } from "../html.ts";
48 import { doctorCard } from "./boards-doctor.ts";
4849 import { gatesCard } from "./boards-gates.ts";
4950 import { heldCard } from "./boards-held.ts";
5051 import { badge, card, meter } from "../ui.ts";
@@ -215,6 +216,7 @@ export function flowPanel(app: App, reader: Reader, url: URL, base: string): Htm
215216 ${heldCard(readHeld(app, reader.kind === "owner", now))}
216217 ${queueCard(queuesFor(app, reader, new Date(now), { batches: true }))}
217218 ${gatesCard(app.db, reader.kind === "owner", now)}
219 ${doctorCard(app.db, reader.kind === "owner", now)}
218220 ${url.searchParams.get("idle") === "all" && idle.length > 0 ? idleList(idle) : null}
219221 ${listed === null || shown === undefined ? null : outList(shown, listed.hour, now)}`;
220222 }
test/doctor-classify.test.ts added +51
@@ -0,0 +1,51 @@
1 import { describe, expect, test } from "bun:test";
2 import { classify, reproduce } from "../src/checks/doctor_classify.ts";
3 import { redFor } from "./helpers/doctor.ts";
4
5 const of = (error: string, reason?: Parameters<typeof redFor>[3]) => {
6 const red = redFor("t", "test/a.test.ts", error, reason);
7 return classify(red.reason, red.tests);
8 };
9
10 describe("the batch doctor classes a red", () => {
11 test("every test over its budget is a budget red", () => {
12 const d = of("error: over budget (expectBudget): GET / took 90ms, budget 50ms");
13 expect(d.class).toBe("budget");
14 expect(d.probe).toContain("over budget");
15 });
16
17 test("ENOENT, tarball and disk errors are infra", () => {
18 expect(of("error: ENOENT: no such file or directory, open 'x'").class).toBe("infra");
19 expect(of("error: tar: extract failed: unexpected end of tarball").class).toBe("infra");
20 expect(of("error: ENOSPC: no space left on device").class).toBe("infra");
21 });
22
23 test("a functional error that merely says extract or tarball is not infra", () => {
24 expect(of("error: expected extract() to return 3").class).toBe("functional");
25 expect(of("error: tarball is not a function").class).toBe("functional");
26 });
27
28 test("a gate that stopped before its tests is infra", () => {
29 expect(of("", { kind: "install" }).class).toBe("infra");
30 expect(of("", { kind: "timeout" }).class).toBe("infra");
31 });
32
33 test("anything else is functional, with the test and its error line as the probe", () => {
34 const d = of("error: expect(received).toBe(expected)");
35 expect(d.class).toBe("functional");
36 expect(d.test?.name).toBe("t");
37 expect(d.probe).toBe("error: expect(received).toBe(expected)");
38 });
39
40 test("a mix of budget and functional reds is functional", () => {
41 const red = redFor("a", "test/a.test.ts", "error: over budget (expectBudget): slow");
42 const tests = { ...red.tests!, failed: 2, failing: [...red.tests!.failing, { name: "b", file: "test/b.test.ts", errors: ["error: boom"] }] };
43 expect(classify(red.reason, tests).class).toBe("functional");
44 });
45
46 test("the reproduce command refuses a file that is not a plain path", () => {
47 expect(reproduce({ name: "t", file: "test/a.test.ts", errors: [] })).toBe("bun test ./test/a.test.ts");
48 expect(reproduce({ name: "t", file: "a; rm -rf /", errors: [] })).toBeUndefined();
49 expect(reproduce(undefined)).toBeUndefined();
50 });
51 });
test/doctor-culprit.test.ts added +52
@@ -0,0 +1,52 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { doctorRuns, HOLD_PREFIX, isDoctorHold, RUNS_KEPT, treatRed } from "../src/checks/doctor.ts";
3 import { getHold } from "../src/core/holds.ts";
4 import { listComments } from "../src/core/issues.ts";
5 import { doctorWorld, redFor, type Doctor } from "./helpers/doctor.ts";
6
7 describe("the batch doctor and a red culprit", () => {
8 let w: Doctor;
9 beforeAll(async () => {
10 w = await doctorWorld("culprit");
11 });
12 afterAll(() => w.close());
13
14 test("a functional red alone is held with a comment naming test, file, error and command; the batch is recorded", async () => {
15 const pull = await w.pull("bad.ts");
16 const red = redFor("adds two numbers", "test/add.test.ts", "error: expect(received).toBe(expected)");
17 expect(treatRed(w.app, w.repo, w.alice, pull, red, "b".repeat(40))).toBe("held");
18 const hold = getHold(w.app.db, pull.id)!;
19 expect(hold.until).toBe("green");
20 expect(hold.why).toContain("adds two numbers");
21 expect(hold.why.startsWith(HOLD_PREFIX)).toBe(true);
22 expect(isDoctorHold(hold.why)).toBe(true);
23 expect(isDoctorHold("waiting on a person")).toBe(false);
24 const said = listComments(w.app.db, pull.id).map((c) => c.body).join("\n");
25 expect(said).toContain("adds two numbers");
26 expect(said).toContain("test/add.test.ts");
27 expect(said).toContain("expect(received).toBe(expected)");
28 expect(said).toContain("bun test ./test/add.test.ts");
29 const [run] = doctorRuns(w.app.db, w.repo.id);
30 expect(run).toMatchObject({ culprit: pull.number, class: "functional", action: "held" });
31 expect(run!.batch).toStartWith("bbbbbbbbbbbb:");
32 expect(run!.probe).toContain("expect(received)");
33 });
34
35 test("a budget-only red is rechecked, not held", async () => {
36 const pull = await w.pull("slow.ts");
37 const red = redFor("serves /", "test/slow.test.ts", "error: over budget (expectBudget): 90ms");
38 expect(treatRed(w.app, w.repo, w.alice, pull, red, "c".repeat(40))).toBe("recheck");
39 expect(getHold(w.app.db, pull.id)).toBeUndefined();
40 expect(doctorRuns(w.app.db, w.repo.id)[0]).toMatchObject({ class: "budget", action: "recheck" });
41 });
42
43 test("the doctor keeps only its newest RUNS_KEPT runs per repository", async () => {
44 const pull = await w.pull("many.ts");
45 const red = redFor("serves /", "test/slow.test.ts", "error: over budget (expectBudget): 90ms");
46 for (let i = 0; i < RUNS_KEPT + 5; i++) treatRed(w.app, w.repo, w.alice, pull, red, "e".repeat(40));
47 const kept = w.app.db
48 .query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM maintenance_run WHERE repo_id = ?1")
49 .get(w.repo.id)!.n;
50 expect(kept).toBe(RUNS_KEPT);
51 });
52 });
test/doctor-doors.test.ts added +88
@@ -0,0 +1,88 @@
1 /** The batch doctor's runs are reachable (#7555): the flow panel, the terminal Flow dialog and MCP `queue_gates` each show them, and none tells a guest or a sealed pull's probe. */
2 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
3 import { treatRed } from "../src/checks/doctor.ts";
4 import { createToken } from "../src/core/tokens.ts";
5 import { serve, type Servers } from "../src/http/server.ts";
6 import { doctorLines, flowLines } from "../src/tui/screens/flow.ts";
7 import { doctorWorld, redFor, type Doctor } from "./helpers/doctor.ts";
8
9 describe("the batch doctor's runs are reachable", () => {
10 let w: Doctor;
11 let servers: Servers;
12 let pullNumber = 0;
13 beforeAll(async () => {
14 w = await doctorWorld("doors");
15 servers = await serve(w.app);
16 const pull = await w.pull("bad.ts");
17 pullNumber = pull.number;
18 treatRed(w.app, w.repo, w.alice, pull, redFor("adds two", "test/add.test.ts", "error: expected 3 got 4"), "c".repeat(40));
19 });
20 afterAll(async () => {
21 servers.stop();
22 await w.close();
23 });
24
25 const login = async (): Promise<string> => {
26 const res = await fetch(`${servers.url}/signin`, {
27 method: "POST",
28 redirect: "manual",
29 headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url },
30 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
31 });
32 return (res.headers.get("set-cookie") ?? "").split(";")[0] ?? "";
33 };
34 const mcp = async () => {
35 const res = await fetch(`${servers.url}/mcp`, {
36 method: "POST",
37 headers: {
38 authorization: `Bearer ${createToken(w.app.db, w.alice.id, "t", "ro").token}`,
39 "content-type": "application/json",
40 accept: "application/json, text/event-stream",
41 },
42 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "queue_gates", arguments: { repo: "alice/doors" } } }),
43 });
44 const body = (await res.json()) as { result: { isError?: boolean; content: { text: string }[] } };
45 expect(body.result.isError).not.toBe(true);
46 return JSON.parse(body.result.content[0]!.text) as { doctor: { culprit: number | null; batch: string; action: string; class: string; probe: string; sealed: boolean }[] };
47 };
48 const seal = (on: number) => w.app.db.query("UPDATE issue SET sealed = ?2 WHERE repo_id = ?1 AND number = ?3").run(w.repo.id, on, pullNumber);
49
50 test("the flow panel lists it for the owner and not for a guest", async () => {
51 const page = await (await fetch(`${servers.url}/boards`, { headers: { cookie: await login() } })).text();
52 expect(page).toContain("Batch doctor");
53 expect(page).toContain(`/alice/doors/pulls/${pullNumber}`);
54 expect(page).toContain("expected 3 got 4");
55 const guest = await (await fetch(`${servers.url}/boards`)).text();
56 expect(guest).not.toContain("alice/doors");
57 expect(guest).not.toContain("expected 3 got 4");
58 });
59
60 test("the terminal Flow dialog lists it under the repository's queue line", () => {
61 const queues = [{ repo: "alice/doors", queued: 1, gating: 0, gates: 0, landedHour: 0, approvedToLanded: null }];
62 const lines = flowLines(w.app.db, new Date(), [], { queues }, []);
63 expect(lines.some((l) => l.startsWith(` doctor #${pullNumber} held · functional`))).toBe(true);
64 });
65
66 test("MCP queue_gates carries it, and a read-only token may read it", async () => {
67 const { doctor } = await mcp();
68 expect(doctor[0]).toMatchObject({ culprit: pullNumber, action: "held", class: "functional", sealed: false });
69 expect(doctor[0]!.probe).toContain("expected 3 got 4");
70 });
71
72 test("a sealed culprit is named by no door and its probe is blank", async () => {
73 seal(1);
74 try {
75 const { doctor } = await mcp();
76 expect(doctor[0]).toMatchObject({ sealed: true, probe: "", culprit: null, batch: "" });
77 expect(JSON.stringify(doctor)).not.toContain(`"culprit":${pullNumber}`);
78 const page = await (await fetch(`${servers.url}/boards`, { headers: { cookie: await login() } })).text();
79 expect(page).toContain("a sealed pull");
80 expect(page).not.toContain("expected 3 got 4");
81 const lines = doctorLines(doctor.map((d) => ({ ...d, at: new Date().toISOString() })), Date.now(), 70);
82 expect(lines[0]).toContain("a sealed pull");
83 expect(lines[0]).not.toContain("expected 3 got 4");
84 } finally {
85 seal(0);
86 }
87 });
88 });
test/doctor-hold-lift.test.ts added +30
@@ -0,0 +1,30 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { releaseOnGreen } from "../src/actions/holds.ts";
3 import { treatRed } from "../src/checks/doctor.ts";
4 import { getHold } from "../src/core/holds.ts";
5 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
6 import { doctorWorld, redFor, type Doctor } from "./helpers/doctor.ts";
7
8 describe("a hold the doctor set lifts on a green new head", () => {
9 let w: Doctor;
10 beforeAll(async () => {
11 w = await doctorWorld("lift");
12 });
13 afterAll(() => w.close());
14
15 const check = (pullId: string, number: number, commitOid: string, state: "ok" | "failed") => {
16 const run = createRun(w.app.db, { repoId: w.repo.id, kind: "check", issueId: pullId, env: `pull-${number}`, commitOid, reason: "pull" });
17 claimRun(w.app.db, run.id);
18 return finishRun(w.app.db, run.id, { state, summary: state })!;
19 };
20
21 test("a red check keeps it, a green check of the head lets it go", async () => {
22 const pull = await w.pull("lift.ts");
23 treatRed(w.app, w.repo, w.alice, pull, redFor("t", "test/t.test.ts", "error: boom"), "e".repeat(40));
24 expect(getHold(w.app.db, pull.id)).toBeDefined();
25 expect(releaseOnGreen(w.app, check(pull.id, pull.number, pull.headOid, "failed"))).toBe(false);
26 expect(getHold(w.app.db, pull.id)).toBeDefined();
27 expect(releaseOnGreen(w.app, check(pull.id, pull.number, pull.headOid, "ok"))).toBe(true);
28 expect(getHold(w.app.db, pull.id)).toBeUndefined();
29 });
30 });
test/doctor-person-hold.test.ts added +32
@@ -0,0 +1,32 @@
1 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2 import { releaseOnGreen } from "../src/actions/holds.ts";
3 import { doctorRuns, treatRed } from "../src/checks/doctor.ts";
4 import { getHold, setHold } from "../src/core/holds.ts";
5 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
6 import { doctorWorld, redFor, type Doctor } from "./helpers/doctor.ts";
7
8 describe("the doctor never touches a hold a person set", () => {
9 let w: Doctor;
10 beforeAll(async () => {
11 w = await doctorWorld("person");
12 });
13 afterAll(() => w.close());
14
15 test("a person's hold stands through a functional red: kept, not overwritten", async () => {
16 const pull = await w.pull("mine.ts");
17 setHold(w.app.db, pull.id, w.alice.id, "waiting on design");
18 const action = treatRed(w.app, w.repo, w.alice, pull, redFor("t", "test/t.test.ts", "error: boom"), "f".repeat(40));
19 expect(action).toBe("kept");
20 expect(getHold(w.app.db, pull.id)).toMatchObject({ why: "waiting on design", heldByName: "alice" });
21 expect(doctorRuns(w.app.db, w.repo.id)[0]).toMatchObject({ action: "kept" });
22 });
23
24 test("a green check does not lift a person's plain hold", async () => {
25 const pull = await w.pull("mine2.ts");
26 setHold(w.app.db, pull.id, w.alice.id, "waiting on design");
27 const run = createRun(w.app.db, { repoId: w.repo.id, kind: "check", issueId: pull.id, env: `pull-${pull.number}`, commitOid: pull.headOid, reason: "pull" });
28 claimRun(w.app.db, run.id);
29 expect(releaseOnGreen(w.app, finishRun(w.app.db, run.id, { state: "ok", summary: "ok" })!)).toBe(false);
30 expect(getHold(w.app.db, pull.id)).toBeDefined();
31 });
32 });
test/helpers/doctor.ts added +76
@@ -0,0 +1,76 @@
1 import { mkdtemp, rm } from "node:fs/promises";
2 import { tmpdir } from "node:os";
3 import { join } from "node:path";
4 import { createApp, type App } from "../../src/app.ts";
5 import { openPull } from "../../src/actions/pulls.ts";
6 import { commitToBranch, createRepo } from "../../src/actions/repos.ts";
7 import type { Red } from "../../src/checks/queue.ts";
8 import { getPull, type Pull } from "../../src/core/pulls.ts";
9 import { getRepoById, type Repo } from "../../src/core/repos.ts";
10 import { createUser, type User } from "../../src/core/users.ts";
11
12 export interface Doctor {
13 readonly app: App;
14 readonly alice: User;
15 readonly repo: Repo;
16 /** Open one more pull from a fresh branch. */
17 pull(path: string): Promise<Pull>;
18 close(): Promise<void>;
19 }
20
21 /** A forge with one person, one repository, and a way to open pulls: what the doctor treats. */
22 export async function doctorWorld(name: string): Promise<Doctor> {
23 const dataDir = await mkdtemp(join(tmpdir(), `forge-doctor-${name}-`));
24 const app = createApp({ dataDir, port: 0 });
25 const a = await createUser(app.db, {
26 origin: "seed",
27 trusted: true,
28 username: "alice",
29 email: "[email protected]",
30 password: "a-good-passphrase",
31 adminIfFirst: true,
32 });
33 if (!a.ok) throw new Error(a.error);
34 const alice = a.value;
35 const made = await createRepo(app, alice, { name, visibility: "private" });
36 if (!made.ok) throw new Error(String(made.error));
37 const seeded = await commitToBranch(app, alice, made.value, {
38 message: "Start",
39 files: [{ path: "README.md", content: `# ${name}\n` }],
40 });
41 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
42 const repo = getRepoById(app.db, made.value.id)!;
43 return {
44 app,
45 alice,
46 repo,
47 async pull(path) {
48 const pushed = await commitToBranch(app, alice, repo, {
49 branch: `feature/${path}`,
50 base: "main",
51 message: path,
52 files: [{ path, content: `export const n = "${path}";\n` }],
53 });
54 if (!pushed.ok) throw new Error(JSON.stringify(pushed.error));
55 const opened = await openPull(app, alice, repo, { title: path, baseBranch: "main", headBranch: `feature/${path}` });
56 if (!opened.ok) throw new Error(String(opened.error));
57 return getPull(app.db, repo.id, opened.value.number)!;
58 },
59 async close() {
60 await app.close?.();
61 await rm(dataDir, { recursive: true, force: true });
62 },
63 };
64 }
65
66 /** A red verdict naming one failing test with this error line. */
67 export function redFor(name: string, file: string, error: string, reason: Red["reason"] = { kind: "tests", failed: 1 }): Red {
68 return {
69 lands: false,
70 reopen: true,
71 comment: "red",
72 learn: [file],
73 ...(reason === undefined ? {} : { reason }),
74 tests: { passed: 10, failed: 1, failing: [{ name, file, errors: [error] }] },
75 };
76 }
test/merge-queue.test.ts +41 −1
@@ -23,6 +23,8 @@ import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
2323 import { createUser, type User } from "../src/core/users.ts";
2424 import { landIfGreen, REGATE_RED_MS, regateDue, sweepGreen } from "../src/crew/autonomy.ts";
2525 import { listComments } from "../src/core/issues.ts";
26 import { doctorRuns, isDoctorHold } from "../src/checks/doctor.ts";
27 import { getHold } from "../src/core/holds.ts";
2628 import { readQueues } from "../src/flow/queue.ts";
2729 import { repoDir } from "../src/git/repos.ts";
2830 import { logLevel, setLogLevel } from "../src/kernel/log.ts";
@@ -679,6 +681,39 @@ describe("the merge queue", () => {
679681 expect(await sweepGreen(app, repo)).toBe(1);
680682 expect(gatesOf(repo)).toHaveLength(before + 1);
681683 expect(merged(repo, pull)).toBe(true);
684 // A red that went green on the re-gate was never the doctor's.
685 expect(getHold(app.db, pull.id)).toBeUndefined();
686 expect(doctorRuns(app.db, repo.id)).toEqual([]);
687 });
688
689 test("the batch doctor holds a red only once it reproduces on the re-gate, with its own comment (#7555)", async () => {
690 const repo = await autonomousRepo("doctor-wiring");
691 const pull = await greenPull(repo, "red-a.ts");
692 expect(await sweepGreen(app, repo)).toBe(0);
693 // First red: told, not held, nothing recorded.
694 expect(getHold(app.db, pull.id)).toBeUndefined();
695 expect(doctorRuns(app.db, repo.id)).toEqual([]);
696 age(pull);
697 expect(await sweepGreen(app, repo)).toBe(0);
698 // The same head and base red again: held, marked as the doctor's, recorded.
699 const hold = getHold(app.db, pull.id);
700 expect(hold?.until).toBe("green");
701 expect(isDoctorHold(hold!.why)).toBe(true);
702 expect(hold!.why).toContain("goes red");
703 const [run] = doctorRuns(app.db, repo.id);
704 expect(run).toMatchObject({ culprit: pull.number, class: "functional", action: "held" });
705 expect(listComments(app.db, pull.id).at(-1)!.body).toContain("bun test ./test/red.test.ts");
706 });
707
708 test("a red handed back while others landed ahead of it is not held by the doctor (#7555)", async () => {
709 const repo = await autonomousRepo("doctor-on-top");
710 const pulls = [];
711 for (const name of ["a.ts", "b.ts", "red-c.ts"]) pulls.push(await greenPull(repo, name));
712 expect(await sweepGreen(app, repo)).toBe(2);
713 const red = pulls[2]!;
714 expect(latestDecision(app.db, red.id, "land")?.answer).toBe("red");
715 expect(getHold(app.db, red.id)).toBeUndefined();
716 expect(doctorRuns(app.db, repo.id)).toEqual([]);
682717 });
683718
684719 test("a red that reproduces on the re-gate stays red, told once", async () => {
@@ -693,7 +728,12 @@ describe("the merge queue", () => {
693728 expect(again?.answer).toBe("red");
694729 expect((again?.state as { again?: boolean }).again).toBe(true);
695730 expect(regateDue(again!, Date.now() + 10 * REGATE_RED_MS)).toBe(false);
696 expect(listComments(app.db, pull.id)).toHaveLength(comments);
731 // The red is not told twice. The one comment added is the doctor's hold
732 // notice: it says the red reproduced, which the first comment could not.
733 const added = listComments(app.db, pull.id).slice(comments);
734 expect(added).toHaveLength(1);
735 expect(added[0]!.body).toContain("The batch doctor held this pull");
736 expect(added[0]!.body).toContain("goes red");
697737 // However long it waits now, it is not gated again until a side moves.
698738 age(pull);
699739 const before = gatesOf(repo).length;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs