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

/flow shows the merge queue against its targets: pull check p50 under 8 min, main's full check under 30 min, 60 landed an hour, 90% of queue gates green #17018

Merged opened this

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

Merged

scout/forge:scout/17006-flow-shows-the-merge-queue-against-its-t → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/17006-flow-shows-the-merge-queue-against-its-t was merged into main as f6b58d2.

Review

Sign in to review this change.
8 files changed +413 −2
docs/design/areas/boards.md +1 −1
@@ -27,7 +27,7 @@ The card under the Pipeline table (`id="verified"`) adds no class: it is a `card
2727 - `.bd-live` — the region that redraws as work moves (`data-live`, no address of its own, so the page is refetched for it at most once in 30 s): the sentence, the figures, the pipeline.
2828 - `.bd-now`, `.bd-lead` — the bottleneck sentence at 16px and, under it in the muted colour, only the lines that hold right now (conflicted pulls, a held rebase lane, idle pulls).
2929 - `.bd-block`, `.bd-head`, `.bd-sub` — a block of the page: its `<h2>`, one sentence of what it shows, and its quiet links.
30 - `.fl-stages`, `.fl-stage` — /flow's answer under its one sentence: each stage that has anything waiting or worked, one line (`stageSays`: what waits, what is active, what limits it, the oldest wait), the bottleneck in the danger colour. Everything else on /flow folds under one line, and no list shows more than ten rows: the last line, "and N more", links to /flow?all=<list id>, that list whole with its fold open.
30 - `.fl-stages`, `.fl-stage` — /flow's answer under its one sentence: each stage that has anything waiting or worked, one line (`stageSays`: what waits, what is active, what limits it, the oldest wait), the bottleneck in the danger colour. Everything else on /flow folds under one line, and no list shows more than ten rows: the last line, "and N more", links to /flow?all=<list id>, that list whole with its fold open. The same rows carry the merge queue against its targets (#17006), the first fold: one `.fl-stage` per target (`data-target`, `data-met`), and a missed one is marked as the bottleneck is.
3131 - `.sl-block`, `.sl`, `.sl-head` (the name, the busy count and, in `.sl-say`, what waits), `.sl-used`, `.sl-chart`, `.sl-busy`, `.sl-full`, `.sl-wait`, `.sl-line`, `.sl-foot` — the slots above the pipeline (`src/web/flow_slots.ts`): for checks and the crew, "4 of 4 slots busy" in the danger colour with a full badge when every slot is busy and something waits, what waits and its oldest and median wait, the crew's pace when it allows fewer, and the 24 hours as bars with the setting dashed across them (solid red where a bar reaches it, muted below, waiting lighter on top). Change capacity is a button under them.
3232 - `.pl`, `.pl-cap`, `.pl-trend`, `.pl-spark` — the pipeline: §5's `.table` with every number right-aligned and tabular, a zero in the faint colour, the day's 24 hours as bars. On a phone each stage is a card: its name, then its five numbers in one row with their names over them.
3333 - `.bd-boards` — the boards as tiles: two across on a phone, four from 720px. Each tile is a `data-nav` row for `j`/`k`.
docs/features/flow-targets.md added +24
@@ -0,0 +1,24 @@
1 ---
2 topic: Tell the crew
3 row: /flow: the merge queue against its targets
4 ---
5 # /flow: the merge queue against its targets (#17006)
6
7 The owner's targets for the forge's own merge queue (2026-11-30, the goal of #7615), measured in one place so every speed change is judged against them. The window is the last 24 hours of the forge's own repository: its source setting, or `FORGE_REPO` when that is not set.
8
9 ## What it shows
10
11 | Figure | Read from | Target |
12 | --- | --- | --- |
13 | Pull check: median, with p90 beside it | finished pull checks (`run`, verify lanes left out) | median under 8 min |
14 | Main's full check: median | finished checks on the default branch that belong to no pull | under 30 min |
15 | Landed an hour | pulls merged in each clock hour; the median of the 24 hours | 60 or more |
16 | Queue gates green | merge-queue batches judged (`queue_batch`) that were not red | 90% or more |
17
18 Each row ends with **met** or **missed**. A figure with nothing in the window says so ("no runs in the last 24 h") and does not show 0. A sealed pull's checks and landings are not counted, and neither is any other repository's. `src/flow/queue_targets.ts` reads each figure with one indexed query and adds no table.
19
20 ## Where to read it
21
22 - **Page:** `/flow`, the first fold, "The merge queue against its targets", whose summary reads "N of 4 met in the last 24 h". It opens by itself when a target is missed. Each figure is one `.fl-stage` row; a missed one gets the bottleneck's colour. Forge admins only, like the rest of `/flow`.
23 - **JSON:** `GET /api/v1/telemetry/flow` includes `queueTargets: { repo, targets: [{ key, label, value, p90?, count, target, met, says }] }` for the owner reader only.
24 - **Terminal:** the Flow command (palette, admins) prints the same four lines under "Merge queue against its targets" (`src/tui/screens/flow_targets.ts`).
src/flow/queue_targets.ts added +173
@@ -0,0 +1,173 @@
1 /**
2 * The merge queue against its targets (#17006, the owner's 2026-11-30
3 * numbers for #7615): four figures of the forge's own repository over the
4 * last 24 hours, each beside its target with "met" or "missed".
5 *
6 * pull check median of finished − started over the pull checks that
7 * started in the window (verify lanes aside), p90 beside it;
8 * met when the median is under 8 min
9 * main check median of the same over main's full checks (no pull, env =
10 * the default branch); met when under 30 min
11 * landed pulls merged per clock hour, the median of the 24 hours;
12 * met at 60 or more
13 * gates green of the merge-queue batches judged (`queue_batch`), the share
14 * not red; met at 90% or more
15 *
16 * A figure with nothing in the window is `null` and says so, never 0. A
17 * sealed pull's checks and landing are not counted, nor any other
18 * repository's. One indexed read per figure, kept a minute, from what the forge already
19 * keeps (`run`, `pull`, `queue_batch`): no table of its own.
20 */
21
22 import type { Database } from "bun:sqlite";
23 import type { App } from "../app.ts";
24 import { getRepo } from "../core/repos.ts";
25 import { forgeSource } from "../settings/forge_source.ts";
26 import { span } from "./pipeline.ts";
27 import { medianOf, percentileOf } from "./ship_time.ts";
28
29 const HOUR_MS = 3_600_000;
30 const DAY_MS = 24 * HOUR_MS;
31
32 /** The owner's targets (2026-11-30). */
33 export const QUEUE_TARGETS = {
34 pullCheckSec: 8 * 60,
35 mainCheckSec: 30 * 60,
36 landedPerHour: 60,
37 gatesGreen: 0.9,
38 } as const;
39
40 export interface QueueTarget {
41 readonly key: "pull-check" | "main-check" | "landed" | "gates-green";
42 readonly label: string;
43 /** The figure: seconds, pulls an hour, or a share 0–1; null when nothing was in the window. */
44 readonly value: number | null;
45 /** The pull check's p90 in seconds; absent for the other figures. */
46 readonly p90?: number | null;
47 /** How many runs, landings or batches the figure is over. */
48 readonly count: number;
49 readonly target: number;
50 /** null when there is nothing to judge. */
51 readonly met: boolean | null;
52 /** The figure in words, then the target: "median 6m (p90 11m) · target under 8m". */
53 readonly says: string;
54 }
55
56 export interface QueueTargets {
57 /** `owner/name` of the repository read; undefined when the forge names none. */
58 readonly repo: string | undefined;
59 readonly targets: readonly QueueTarget[];
60 }
61
62 const MS = "(julianday(x.finished_at) - julianday(x.started_at)) * 86400000.0";
63
64 /** Durations in whole seconds, sorted, of the finished checks `where` picks in the window. */
65 function checkSeconds(db: Database, repoId: string, since: string, where: string): number[] {
66 return db
67 .query<{ ms: number }, [string, string]>(
68 `SELECT ${MS} AS ms FROM run x JOIN repo r ON r.id = x.repo_id
69 LEFT JOIN issue i ON i.id = x.issue_id
70 WHERE x.kind = 'check' AND x.started_at >= ?2 AND x.repo_id = ?1
71 AND x.finished_at IS NOT NULL AND x.state IN ('ok','failed')
72 AND COALESCE(i.sealed, 0) = 0 AND ${where}`,
73 )
74 .all(repoId, since)
75 .map((row) => Math.round(row.ms / 1000))
76 .sort((a, b) => a - b);
77 }
78
79 const word = (met: boolean | null): string => (met === null ? "" : met ? " · met" : " · missed");
80
81 function timed(key: "pull-check" | "main-check", label: string, secs: number[], target: number, withP90: boolean): QueueTarget {
82 const value = medianOf(secs);
83 const p90 = percentileOf(secs, 0.9);
84 const met = value === null ? null : value < target;
85 const goal = `target under ${span(target * 1000)}`;
86 const says =

'over 3' with no noun reads oddly. Say 'over 3 runs' for the check rows.

87 value === null
88 ? `no runs in the last 24 h · ${goal}`
89 : `median ${span(value * 1000)}${withP90 && p90 !== null ? ` (p90 ${span(p90 * 1000)})` : ""} over ${String(secs.length)} · ${goal}${word(met)}`;
90 return { key, label, value, ...(withP90 ? { p90 } : {}), count: secs.length, target, met, says };
91 }
92
93 /** The four figures for one repository, over the 24 hours to `now`. */
94 export function readQueueTargets(db: Database, repoId: string, now = new Date()): QueueTarget[] {
95 const since = new Date(now.getTime() - DAY_MS).toISOString();
96 const pull = checkSeconds(db, repoId, since, "x.issue_id IS NOT NULL AND COALESCE(x.env, '') NOT IN ('verify','verify-bisect')");
97 const main = checkSeconds(db, repoId, since, "x.issue_id IS NULL AND x.env = r.default_branch");
98 const merged = db
99 .query<{ at: string }, [string, string, string]>(
100 `SELECT p.merged_at AS at FROM pull p JOIN issue i ON i.id = p.issue_id
101 WHERE p.merged_at >= ?2 AND p.merged_at <= ?3 AND i.repo_id = ?1 AND i.sealed = 0`,
102 )
103 .all(repoId, since, now.toISOString());
104 const hours = Array.from({ length: 24 }, () => 0);
105 for (const m of merged) {
106 const back = Math.floor((now.getTime() - Date.parse(m.at)) / HOUR_MS);
107 if (back >= 0 && back < 24) hours[back]! += 1;
108 }
109 const perHour = merged.length === 0 ? null : medianOf([...hours].sort((a, b) => a - b));
110 const landedMet = perHour === null ? null : perHour >= QUEUE_TARGETS.landedPerHour;
111 const batches = db
112 .query<{ n: number; red: number | null }, [string, string]>(
113 `SELECT COUNT(*) AS n, SUM(b.red) AS red FROM queue_batch b WHERE b.finished_at >= ?2 AND b.repo_id = ?1`,
114 )
115 .get(repoId, since) ?? { n: 0, red: 0 };
116 const green = batches.n === 0 ? null : (batches.n - (batches.red ?? 0)) / batches.n;
117 const greenMet = green === null ? null : green >= QUEUE_TARGETS.gatesGreen;
118 const pct = (x: number) => `${String(Math.round(x * 100))}%`;
119 return [
120 timed("pull-check", "Pull check", pull, QUEUE_TARGETS.pullCheckSec, true),
121 timed("main-check", "Main's full check", main, QUEUE_TARGETS.mainCheckSec, false),
122 {
123 key: "landed",
124 label: "Landed an hour",
125 value: perHour,
126 count: merged.length,
127 target: QUEUE_TARGETS.landedPerHour,
128 met: landedMet,
129 says:
130 perHour === null
131 ? `nothing landed in the last 24 h · target ${String(QUEUE_TARGETS.landedPerHour)} an hour`
132 : `median ${String(perHour)} an hour, ${String(merged.length)} in 24 h · target ${String(QUEUE_TARGETS.landedPerHour)} an hour${word(landedMet)}`,
133 },
134 {
135 key: "gates-green",
136 label: "Queue gates green",
137 value: green,
138 count: batches.n,
139 target: QUEUE_TARGETS.gatesGreen,
140 met: greenMet,
141 says:
142 green === null
143 ? `no gates judged in the last 24 h · target ${pct(QUEUE_TARGETS.gatesGreen)}`
144 : `${pct(green)} of ${String(batches.n)} · target ${pct(QUEUE_TARGETS.gatesGreen)}${word(greenMet)}`,
145 },
146 ];
147 }
148
149 /**
150 * How long the figures are kept once read: they are over 24 hours, six statements to read, and
151 * /flow, its API and the terminal all draw them, so a minute's staleness costs nothing.
152 */
153 const TARGETS_KEPT_MS = 60_000;
154 const targetsRead = new WeakMap<App, { at: number; read: QueueTargets }>();
155
156 /**
157 * The forge's own repository (its source setting, else `FORGE_REPO`), read against the targets,
158 * at most once a minute.
159 */
160 export function queueTargetsFor(app: App, now = new Date()): QueueTargets {
161 const kept = targetsRead.get(app);
162 if (kept !== undefined && Math.abs(now.getTime() - kept.at) < TARGETS_KEPT_MS) return kept.read;
163 const read = readTargetsOf(app, now);
164 targetsRead.set(app, { at: now.getTime(), read });
165 return read;
166 }
167
168 function readTargetsOf(app: App, now: Date): QueueTargets {
169 const name = forgeSource(app.db, app.config.forgeRepo);
170 const [owner = "", repo = ""] = (name ?? "").split("/");
171 const found = owner === "" || repo === "" ? undefined : getRepo(app.db, owner, repo);
172 return { repo: found === undefined ? undefined : `${found.ownerName}/${found.name}`, targets: found === undefined ? [] : readQueueTargets(app.db, found.id, now) };
173 }
src/system/telemetry.ts +4
@@ -5,6 +5,7 @@
55 * node's history. Everything here is counts, rates and names of public
66 * things — no sealed value, no private repository's content, no person.
77 */
8 import { queueTargetsFor } from "../flow/queue_targets.ts";
89 import { CONTRIBUTE_ONE_LINE, CONTRIBUTE_PATH } from "../spawn/contribute_words.ts";
910 import { readRepeats } from "../flow/repeats.ts";
1011 import { readVerdicts } from "../flow/culprits.ts";
@@ -106,6 +107,9 @@ function flowBody(x: {
106107 says: verdict(stages, now.getTime()),
107108 // Each step of the path: median time and red rate over 30 days (#7784); private repositories for the owner only.
108109 steps: x.steps.map((m) => ({ ...m, says: statWords(m) })),
110 // The forge's own merge queue against the owner's targets (#17006), as /flow draws it: the
111 // owner's only.
112 ...(reader.kind === "owner" ? { queueTargets: queueTargetsFor(app, now) } : {}),
109113 // The cause binding landings now and the keeper's last act (#7645).
110114 keeper: readKeeper(app.db, reader.kind === "owner"),
111115 // The release tick's last report, reason and all, for the owner only (#11507): the reason may name private work.
src/tui/forge.ts +3 −1
@@ -8,6 +8,8 @@
88 * to see something the web would have hidden.
99 */
1010
11 import { queueTargetsFor } from "../flow/queue_targets.ts";
12 import { queueTargetLines } from "./screens/flow_targets.ts";
1113 import { publicOrigin } from "../core/public_origin.ts";
1214 import { nearPages } from "../web/near_pages.ts";
1315 import type { App as Forge } from "../app.ts";
@@ -623,7 +625,7 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
623625 session.app.config.dataDir,
624626 flowReader.kind === "owner" ? beatLine(lastBeat(session.db), new Date()) : undefined,
625627 publicOrigin(session.app.config.url, `http://${session.app.config.host ?? "localhost"}:${session.app.config.port ?? 3000}`),
626 ).concat(laneTimeLines(session.db, user), reportLines), keeper.ask && user ? { ask: keeper.ask, answer: () => answerKeeper(session.app, keeper.ask!.id, user.id) } : undefined,
628 ).concat(laneTimeLines(session.db, user), flowReader.kind === "owner" ? ["", ...queueTargetLines(queueTargetsFor(session.app)).flatMap((l) => wrap(l, 58))] : [], reportLines), keeper.ask && user ? { ask: keeper.ask, answer: () => answerKeeper(session.app, keeper.ask!.id, user.id) } : undefined,
627629 mayDrift(session)
628630 ? { read: async () => readHandoverLists(session.db, await readDrifts(session.app), Date.now()), update: (n) => askUpdate(session, n) }
629631 : undefined));
src/tui/screens/flow_targets.ts added +16
@@ -0,0 +1,16 @@
1 /**
2 * The merge queue against its targets (#17006) in the terminal's Flow command: the same four
3 * figures /flow draws (`flow/queue_targets.ts`), one line each, under a heading naming the
4 * repository read.
5 */
6
7 import type { QueueTargets } from "../../flow/queue_targets.ts";
8
9 /**
10 * The figures as terminal lines: a heading, then "Label: says" each; one line when no repository is
11 * named.
12 */
13 export function queueTargetLines(q: QueueTargets): string[] {
14 if (q.repo === undefined) return ["Merge queue against its targets: the forge names no repository of its own."];
15 return [`Merge queue against its targets (${q.repo}, last 24 h):`, ...q.targets.map((t) => `${t.label}: ${t.says}`)];
16 }
src/web/pages/flow.ts +16
@@ -42,6 +42,7 @@ import { cpuStops } from "../../flow/cpu_stops.ts";
4242 import { bottleneck, readPipeline, stageSays, STAGE_LABEL, verdict } from "../../flow/pipeline.ts";
4343 import { readSlots } from "../../flow/slots.ts";
4444 import { slotsBlock } from "../flow_slots.ts";
45 import { queueTargetsFor, type QueueTargets } from "../../flow/queue_targets.ts";
4546
4647 const plural = (n: number, one: string, many = `${one}s`): string => `${String(n)} ${n === 1 ? one : many}`;
4748
@@ -138,6 +139,20 @@ function mayWriteRepo(ctx: Ctx, name: string): boolean {
138139 return found !== undefined && canWrite(ctx.app.db, found, ctx.auth.user);
139140 }
140141
142 /**
143 * The merge queue against its targets (#17006): one line for how many are met, the four figures
144 * under it, open when one is missed.
145 */
146 export function targetsFold(q: QueueTargets) {

Principle 7 and 8: the rows are right (a dl of rows, not cards). The says text in each dd packs figure, count and target into one dot-separated line. On a 360px phone it wraps mid-phrase. Put 'met'/'missed' first or on its own line so the verdict is read first. Not blocking.

147 if (q.repo === undefined) return html`<p class="muted" id="flow-targets">The forge names no repository of its own, so there is no merge queue to measure against its targets.</p>`;
148 const judged = q.targets.filter((t) => t.met !== null);
149 const met = judged.filter((t) => t.met === true).length;
150 const says = judged.length === 0 ? "nothing ran in the last 24 h" : `${String(met)} of ${String(judged.length)} met in the last 24 h`;
151 return fold("The merge queue against its targets", says, html`<dl class="fl-stages">${q.targets.map(
152 (t) => html`<div class="fl-stage" data-target="${t.key}" data-met="${t.met === null ? "none" : t.met ? "met" : "missed"}" ${t.met === false ? html`data-bottleneck` : null}><dt>${t.label}</dt><dd>${t.says}</dd></div>`,
153 )}</dl>`, { id: "flow-targets", open: met < judged.length });
154 }
155
141156 // GET /flow
142157 export async function flowPage(ctx: Ctx): Promise<Response> {
143158 const waiting = ctx.url.search === "?wait=1";
@@ -192,6 +207,7 @@ export async function flowPage(ctx: Ctx): Promise<Response> {
192207 ${slotsBlock(readSlots(ctx.app, new Date(now)), now, true)}
193208 </section>
194209 <div class="folds" id="flow-folds">
210 ${targetsFold(queueTargetsFor(ctx.app, new Date(now)))}
195211 ${p.valves.length === 0
196212 ? html`<p class="muted" id="flow-week">${weekSays(p)}</p>`
197213 : fold("The week's money", weekSays(p), html`${strip}
test/queue-targets.test.ts added +176
@@ -0,0 +1,176 @@
1 /**
2 * The merge queue against its targets (#17006): met, missed and empty windows; sealed and other
3 * repositories' rows not counted.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { openIssue } from "../src/actions/issues.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { createRun } from "../src/core/runs.ts";
13 import { createUser, type User } from "../src/core/users.ts";
14 import { queueTargetLines } from "../src/tui/screens/flow_targets.ts";
15 import { queueTargetsFor, readQueueTargets, type QueueTarget } from "../src/flow/queue_targets.ts";
16 import { flowFor } from "../src/system/telemetry.ts";
17 import { targetsFold } from "../src/web/pages/flow.ts";
18
19 const MIN = 60_000;
20 const HOUR = 3_600_000;
21 const NOW = new Date();
22
23 let dataDir: string;
24 let app: App;
25 let alice: User;
26 let forgeId: string;
27 let slowId: string;
28 let otherId: string;
29 const repos = new Map<string, Parameters<typeof openIssue>[2]>();
30
31 function issueIn(repoId: string, sealed = false): string {
32 const opened = openIssue(app, alice, repos.get(repoId)!, { title: "A change" });
33 if (!opened.ok) throw new Error(String(opened.error));
34 if (sealed) app.db.query("UPDATE issue SET sealed = 1 WHERE id = ?1").run(opened.value.id);
35 return opened.value.id;
36 }
37
38
39 /** A finished check of `mins` minutes that ended `hoursAgo` before NOW. */
40 function check(repoId: string, mins: number, hoursAgo: number, issue: string | null, env = "", state = "ok") {
41 const run = createRun(app.db, { repoId, kind: "check", reason: "push" });
42 const end = NOW.getTime() - hoursAgo * HOUR;
43 app.db
44 .query("UPDATE run SET state = ?1, started_at = ?2, finished_at = ?3, issue_id = ?4, env = ?5 WHERE id = ?6")
45 .run(state, new Date(end - mins * MIN).toISOString(), new Date(end).toISOString(), issue, env, run.id);
46 }
47
48 /** Numbers for the landed pulls written here, far past any `openIssue` gives. */
49 let raw = 100_000;
50
51 /** `perHour` pulls merged in each of the `hours` hours before NOW. */
52 function landed(repoId: string, hours: number, perHour: number, sealed = false) {
53 let k = 0;
54 for (let h = 0; h < hours; h++)
55 for (let j = 0; j < perHour; j++, k++) {
56 const id = `${repoId}-${sealed ? "s" : "p"}-${String(k)}`;
57 app.db
58 .query("INSERT INTO issue (id, repo_id, number, kind, title, author_id, sealed) VALUES (?1, ?2, ?5, 'pull', 'x', ?3, ?4)")
59 .run(id, repoId, alice.id, sealed ? 1 : 0, (raw += 1));
60 app.db
61 .query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, merged_at) VALUES (?1, 'main', 'b', '', '', ?2)")
62 .run(id, new Date(NOW.getTime() - h * HOUR - (j + 1) * 1000).toISOString());
63 }
64 }
65
66 function batches(repoId: string, green: number, red: number) {
67 for (let i = 0; i < green + red; i++)
68 app.db.query("INSERT INTO queue_batch (repo_id, red, finished_at) VALUES (?1, ?2, ?3)").run(repoId, i < red ? 1 : 0, new Date(NOW.getTime() - (i + 1) * MIN).toISOString());
69 }
70
71 const by = (ts: readonly QueueTarget[], key: QueueTarget["key"]) => ts.find((t) => t.key === key)!;
72
73 beforeAll(async () => {
74 dataDir = await mkdtemp(join(tmpdir(), "forge-queue-targets-"));
75 app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" });
76 const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
77 if (!u.ok) throw new Error(u.error);
78 alice = u.value;
79 for (const name of ["forge", "slow", "other"]) {
80 const r = await createRepo(app, alice, { name });
81 if (!r.ok) throw new Error("repo");
82 repos.set(r.value.id, r.value);
83 }
84 [forgeId, slowId, otherId] = [...repos.keys()] as [string, string, string];
85
86 // The forge: every figure met.
87 const pull = issueIn(forgeId);
88 for (const m of [5, 6, 7]) check(forgeId, m, 1, pull);
89 check(forgeId, 20, 2, null, "main");
90 check(forgeId, 90, 30, pull); // outside the 24 h
91 landed(forgeId, 13, 60);
92 batches(forgeId, 10, 0);
93 // A sealed pull's checks and landings, and another repository's: none of them counted.
94 const sealed = issueIn(forgeId, true);
95 for (let i = 0; i < 5; i++) check(forgeId, 60, 1, sealed);
96 landed(forgeId, 1, 3, true);
97 const theirs = issueIn(otherId);
98 for (let i = 0; i < 5; i++) check(otherId, 60, 1, theirs);
99 check(otherId, 120, 1, null, "main");
100 batches(otherId, 0, 20);
101
102 // The slow repository: every figure missed.
103 const slow = issueIn(slowId);
104 check(slowId, 10, 1, slow);
105 check(slowId, 12, 1, slow, "", "failed");
106 check(slowId, 40, 1, null, "main");
107 landed(slowId, 1, 5);
108 batches(slowId, 1, 1);
109 });
110
111 afterAll(async () => {
112 app.close();
113 await rm(dataDir, { recursive: true, force: true });
114 });
115
116 test("a window where every target is met, with sealed and other repositories' rows left out", () => {
117 const t = readQueueTargets(app.db, forgeId, NOW);
118 expect(by(t, "pull-check")).toMatchObject({ count: 3, met: true, p90: 7 * 60 });
119 expect(by(t, "pull-check").value).toBe(6 * 60);
120 expect(by(t, "pull-check").says).toBe("median 6m (p90 7m) over 3 · target under 8m · met");
121 expect(by(t, "main-check")).toMatchObject({ count: 1, met: true });
122 expect(by(t, "landed")).toMatchObject({ value: 60, count: 780, met: true });
123 expect(by(t, "gates-green")).toMatchObject({ value: 1, count: 10, met: true });
124 });
125
126 test("a window where every target is missed", () => {
127 const t = readQueueTargets(app.db, slowId, NOW);
128 expect(by(t, "pull-check")).toMatchObject({ count: 2, met: false });
129 expect(by(t, "pull-check").says).toEndWith("· missed");
130 expect(by(t, "main-check")).toMatchObject({ met: false });
131 expect(by(t, "landed")).toMatchObject({ value: 0, count: 5, met: false });
132 expect(by(t, "gates-green")).toMatchObject({ value: 0.5, met: false });
133 expect(by(t, "gates-green").says).toBe("50% of 2 · target 90% · missed");
134 });
135
136 test("an empty window says nothing ran, never 0", () => {
137 const t = readQueueTargets(app.db, forgeId, new Date(NOW.getTime() + 10 * 24 * HOUR));
138 for (const f of t) expect(f).toMatchObject({ value: null, met: null, count: 0 });
139 expect(by(t, "pull-check").says).toBe("no runs in the last 24 h · target under 8m");
140 expect(by(t, "landed").says).toBe("nothing landed in the last 24 h · target 60 an hour");
141 expect(by(t, "gates-green").says).toBe("no gates judged in the last 24 h · target 90%");
142 });
143
144 test("the forge's own repository is read; the page, the JSON and the terminal say the same four rows", () => {
145 const q = queueTargetsFor(app, NOW);
146 expect(q.repo).toBe("alice/forge");
147 expect(q.targets.map((t) => t.met)).toEqual([true, true, true, true]);
148 const page = String(targetsFold(q));
149 expect(page).toContain("4 of 4 met in the last 24 h");
150 expect(page.match(/data-target="/g)?.length).toBe(4);
151 expect(page).toContain("median 6m (p90 7m) over 3 · target under 8m · met");
152 const owner = flowFor(app, { kind: "owner" }, NOW) as { queueTargets?: unknown };
153 expect(owner.queueTargets).toEqual(queueTargetsFor(app, NOW));
154 const agent = flowFor(app, { kind: "agent", spend: true }, NOW) as { queueTargets?: unknown };
155 expect(agent.queueTargets).toBeUndefined();
156 const lines = queueTargetLines(q);
157 expect(lines[0]).toBe("Merge queue against its targets (alice/forge, last 24 h):");
158 expect(lines).toContain("Queue gates green: 100% of 10 · target 90% · met");
159 });
160
161 test("a forge that names no repository of its own says so", () => {
162 expect(queueTargetLines({ repo: undefined, targets: [] })).toEqual(["Merge queue against its targets: the forge names no repository of its own."]);
163 expect(String(targetsFold({ repo: undefined, targets: [] }))).toContain("names no repository of its own");
164 });
165
166 test("the figures are kept a minute, so a warm /flow reads them no more; after it they are read again", () => {
167 const first = queueTargetsFor(app, NOW);
168 check(forgeId, 20, 1, issueIn(forgeId));
169 check(forgeId, 20, 1, issueIn(forgeId));
170 check(forgeId, 20, 1, issueIn(forgeId));
171 check(forgeId, 20, 1, issueIn(forgeId));
172 expect(queueTargetsFor(app, new Date(NOW.getTime() + 30_000))).toBe(first);
173 const later = queueTargetsFor(app, new Date(NOW.getTime() + 2 * MIN));
174 expect(later).not.toBe(first);
175 expect(by(later.targets, "pull-check").count).toBe(by(first.targets, "pull-check").count + 4);
176 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs