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

A finished check shard is announced on /events, and the pull page's checks line stops beating every 5 seconds #2892

Parked opened this
Closed without merging

scout/forge:scout/2889-a-finished-check-shard-is-announced-on-e → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
6 files changed +77 −8
src/checks/service.ts +4 −1
@@ -17,6 +17,7 @@ import { tmpdir } from "node:os";
1717 import { join } from "node:path";
1818 import type { App } from "../app.ts";
1919 import { announceRun } from "../actions/runs.ts";
20 import { announceShard } from "./shard_event.ts";
2021 import type { ForgeEvent } from "../core/events.ts";
2122 import { getPull, listPulls, type Pull } from "../core/pulls.ts";
2223 import { issueMayRun } from "../core/pull_trust.ts";
@@ -476,8 +477,10 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle {
476477 if (!claimed) return;
477478 const lease = holdLease(app.db, run.id);
478479 announceRun(app, claimed);
479 const write = (line: string): void =>
480 const write = (line: string): void => {
480481 appendRunLog(app.config.dataDir, run.id, line);
482 announceShard(app, run, line);
483 };
481484 if (options.label !== undefined)
482485 write(`forge ${options.label} — checked in its parent's lane`);
483486 const started = Date.now();
src/checks/shard_event.ts added +37
@@ -0,0 +1,37 @@
1 /**
2 * A check's shard finishing, said on the outbox. The shard runner
3 * (`scripts/test-shards.ts`) writes a line when a shard ends; this reads that
4 * line and announces it as `run.shard`, so a pull's checks line, which listens
5 * to `run.*`, patches itself instead of beating on a timer. One line, one
6 * event: the live form ends at `done`, the batched form at its `(exit` header,
7 * and neither line is the other's.
8 */
9 import type { App } from "../app.ts";
10 import type { Run } from "../core/runs.ts";
11
12 const LIVE_DONE = /^── shard (\d+)\/(\d+) done \(exit \d+, [0-9.]+s\)$/;
13 const BATCHED = /^── shard (\d+)\/(\d+) \(exit \d+, [0-9.]+s\): /;
14
15 /** Which shard a log line says has finished, or nothing. */
16 export function finishedShard(line: string): { shard: number; of: number } | undefined {
17 const m = LIVE_DONE.exec(line) ?? BATCHED.exec(line);
18 return m === null ? undefined : { shard: Number(m[1]), of: Number(m[2]) };
19 }
20
21 /** Announce the shard `line` finishes, if it finishes one. */
22 export function announceShard(app: App, run: Run, line: string): void {
23 const done = finishedShard(line);
24 if (done === undefined) return;
25 app.bus.append({
26 kind: "run.shard",
27 repoId: run.repoId,
28 payload: {
29 runId: run.id,
30 kind: run.kind,
31 env: run.env,
32 commitOid: run.commitOid,
33 shard: done.shard,
34 of: done.of,
35 },
36 });
37 }
src/design/activity.ts +1
@@ -88,6 +88,7 @@ export function eventActor(
8888 }
8989
9090 const WORDS: Record<string, string> = {
91 "run.shard": "finished a check shard",
9192 push: "pushed",
9293 "issue.opened": "opened an issue",
9394 "issue.closed": "closed an issue",
src/web/pages/pull.ts +3 −6
@@ -272,15 +272,12 @@ export function checksLine(
272272 : waiting
273273 ? html`<span>${icon("lock")}${WAITING_WORDS}</span>`
274274 : html`<span>${icon("clock")}No checks on this head yet</span>`;
275 // Its own address: an event or the beat fetches this line, not the page.
276 // While a check runs there is no event for a finished shard, so it also
277 // asks on a beat.
275 // Its own address: an event fetches this line, not the page. A finished
276 // shard is a `run.shard` event (`checks/shard_event.ts`), so no beat.
278277 const live =
279278 liveSrc === ""
280279 ? null
281 : html`id="live-checks" data-live="run.*" data-live-src="${liveSrc}"${
282 check.state === "running" || check.state === "queued" ? html` data-live-every="5"` : null
283 }`;
280 : html`id="live-checks" data-live="run.*" data-live-src="${liveSrc}"`;
284281 return html`<p class="checks-line" ${live}>
285282 ${body}${against}${when(
286283 tier !== "",
test/check-shard-event.test.ts added +32
@@ -0,0 +1,32 @@
1 import { expect, test } from "bun:test";
2 import { announceShard, finishedShard } from "../src/checks/shard_event.ts";
3 import { checksLine } from "../src/web/pages/pull.ts";
4
5 const run = { id: "r1", repoId: "repo1", kind: "check", env: "pull-7", commitOid: "abc" } as never;
6
7 function fakeApp() {
8 const events: { kind: string; repoId: string; payload: Record<string, unknown> }[] = [];
9 return { events, app: { bus: { append: (e: never) => events.push(e) } } as never };
10 }
11
12 test("a finished shard, live or batched, is one line and one event", () => {
13 expect(finishedShard("── shard 2/4 done (exit 0, 3.0s)")).toEqual({ shard: 2, of: 4 });
14 expect(finishedShard("── shard 3/4 (exit 1, 2.0s): a.ts b.ts")).toEqual({ shard: 3, of: 4 });
15 expect(finishedShard("── shard 2/4: a.ts b.ts")).toBeUndefined();
16 expect(finishedShard(" 5 pass")).toBeUndefined();
17
18 const { app, events } = fakeApp();
19 for (const line of ["── shard 1/2: a.ts", " 5 pass", "── shard 1/2 done (exit 0, 1.0s)"])
20 announceShard(app, run, line);
21 expect(events).toHaveLength(1);
22 expect(events[0]!.kind).toBe("run.shard");
23 expect(events[0]!.repoId).toBe("repo1");
24 expect(events[0]!.payload).toEqual({ runId: "r1", kind: "check", env: "pull-7", commitOid: "abc", shard: 1, of: 2 });
25 });
26
27 test("the checks line of a running check listens for run.* and never beats", () => {
28 const run = { id: "r1", kind: "check", env: "pull-7", commitOid: "abcdef1234567", state: "running", summary: "", createdAt: "2026-10-16T10:00:00Z" } as never;
29 const html = checksLine("/a/b", { state: "running", run }, false, true, false, "", "", 0, "", false, "", "/a/b/pulls/7/checks-line").text;
30 expect(html).toContain('data-live="run.*"');
31 expect(html).not.toContain("data-live-every");
32 });
test/no-polling.test.ts −1
@@ -14,7 +14,6 @@ const ALLOWED: Record<string, { allow: string[]; why: string }> = {
1414 "src/web/pages/migrate.ts": { allow: ["refresh: {", 'http-equiv="refresh"'], why: "migrate progress runs in a process that emits no events" },
1515 "src/web/pages/browse.ts": { allow: ["refresh: {"], why: "mirror progress runs in a process that emits no events" },
1616 "src/web/pages/backups.ts": { allow: ["refresh: {"], why: "a backup moving emits no event" },
17 "src/web/pages/pull.ts": { allow: ["data-live-every"], why: "a shard finishing emits no event, so a running check row beats" },
1817 "src/web/client.ts": { allow: ["data-live-every", "setInterval"], why: "the data-live-every mechanism itself, and clocks that only redraw text" },
1918 "src/web/fleet-graph.ts": { allow: ["setInterval"], why: "no fleet event yet; remove once it has one" },
2019 };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs