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

A check's run page shows install, typecheck and tests as step rows from the first paint #2415

Parked opened this
Closed without merging

scout/forge:scout/2382-a-check-s-run-page-shows-install-typeche → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
10 files changed +482 −10
README.md +9
@@ -550,6 +550,15 @@ file), and if you named an agent, the sentence became issue #1, assigned.
550550 "Carries #3, #5" and `GET /api/v1/repos/:owner/:name/runs/:id` has `carries`.
551551 In the terminal, open a repository and press `d` for its production deploys
552552 (each with what it carries), `enter` for the log, `r` to refresh.
553 - A check's run page, and the pull screen in the terminal, show three steps —
554 install, typecheck, tests — each with its state (pending until known) and, once
555 finished, its time. The check writes marked `step <name> <state> [seconds]` lines into
556 its log (`checks/summary.ts` reads them). The marker is a control character
557 the command under test cannot print (its output is stripped of it), so a
558 check cannot forge a row. The page leaves the lines out of the displayed
559 log; the raw log and API keep them. Rows refresh on load, not live.
560 Typecheck ends when the shard runner's `test-shards:` banner appears; a check
561 without it reports a green run's two steps without times.
553562 - A **private** app answers only to someone the forge has vouched for
554563 (`canRead` on the repository, then a signed grant); a public one to anyone.
555564 - **Every app has a terminal.** `ssh -p 2222 <name>@<forge>` runs the app's
src/checks/progress.ts +15
@@ -9,6 +9,7 @@
99
1010 import type { CheckSummary } from "../core/runs.ts";
1111 import { readRunLog } from "../runs/log.ts";
12 import { checkSteps, stepWords } from "./summary.ts";
1213
1314 export type CheckProgress = {
1415 /** Files in the run, from the banner; undefined until it is written. */
@@ -90,3 +91,17 @@ export function runningProgress(dataDir: string, check: CheckSummary): string {
9091 return "";
9192 return progressWords(parseShardProgress(readRunLog(dataDir, run.id).lines));
9293 }
94
95 /**
96 * The terminal's rows for a check's steps, in one line: empty for anything
97 * that is not a check that has started, so the merge box grows only when
98 * there is something to say. The same `checkSteps` the run page draws.
99 */
100 export function checkStepWords(dataDir: string, check: CheckSummary): string {
101 const run = check.run;
102 if (run === null || run.kind !== "check") return "";
103 if (check.state === "queued" || check.state === "none") return "";
104 return stepWords(
105 checkSteps({ state: check.state }, readRunLog(dataDir, run.id).lines),
106 );
107 }
src/checks/service.ts +32 −5
@@ -75,7 +75,7 @@ import {
7575 STEP_HOSTS,
7676 type CellSpec,
7777 } from "../apps/contain.ts";
78 import { summariseCheckFailure } from "./summary.ts";
78 import { stepLine, summariseCheckFailure, unmark } from "./summary.ts";
7979 import type { Result } from "../kernel/result.ts";
8080 import { placementFromEnv, type Placement } from "./placement.ts";
8181 import { JOB_VANISHED, runJobStep } from "./job_step.ts";
@@ -613,6 +613,9 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle {
613613 | { ok: false; error: string; detail?: CheckDetail | undefined }
614614 > {
615615 const { bare, repo, write, signal } = x;
616 // What the command under test prints goes through `out`: the step
617 // marker (`STEP_MARK`) is the runner's alone, so output cannot forge a row.
618 const out = (line: string): void => write(unmark(line));
616619 // A pull's fast check is of the pull as it would land: its head merged
617620 // into the base's tip. The gate comes from that tree, so a pull forked
618621 // before the base learned something is judged with it.
@@ -815,7 +818,7 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle {
815818 dir,
816819 commands: manifest.install === null ? [command] : [manifest.install, command],
817820 env,
818 log: write,
821 log: out,
819822 output: checkLines,
820823 signal,
821824 timeoutMs: manifest.timeout * 1000,
@@ -827,34 +830,58 @@ export function startChecks(app: App, options: ChecksOptions): ChecksHandle {
827830 });
828831 } else {
829832 if (manifest.install !== null) {
833 write(stepLine("install", "running"));
834 const began = Date.now();
830835 const installed = await runStep("install", manifest.install, {
831836 cwd: dir,
832837 env,
833 log: write,
838 log: out,
834839 signal,
835840 timeoutMs: manifest.timeout * 1000,
836841 cell,
837842 });
843 write(
844 stepLine("install", installed.ok ? "ok" : "failed", Date.now() - began),
845 );
838846 if (!installed.ok) return { ok: false, error: installed.error };
839 }
847 } else write(stepLine("install", "skipped"));
840848 // The check step's own lines are kept beside what `write` already
841849 // logs, so a failure can be summarised once here — never by reading
842850 // the log back, on this run or any later render of it. `runStep`
843851 // echoes the command as its first line before any output of the
844852 // command's own; that echo is not output to summarise from.
845853 let sawEcho = false;
854 // The command runs the type check, then the tests; the shard
855 // runner's banner is the first sign the tests have begun.
856 const checkBegan = Date.now();
857 let testsBegan: number | undefined;
858 write(stepLine("typecheck", "running"));
846859 ran = await runStep("check", command, {
847860 cwd: dir,
848861 env,
849862 log: (line) => {
850863 if (sawEcho) checkLines.push(line);
851864 sawEcho = true;
852 write(line);
865 out(line);
866 if (testsBegan === undefined && line.startsWith("test-shards: ")) {
867 testsBegan = Date.now();
868 write(stepLine("typecheck", "ok", testsBegan - checkBegan));
869 write(stepLine("tests", "running"));
870 }
853871 },
854872 signal,
855873 timeoutMs: manifest.timeout * 1000,
856874 cell,
857875 });
876 const state = ran.ok ? "ok" : "failed";
877 if (testsBegan === undefined) {
878 // No banner: the command's own runner is unknown, so a green run
879 // cannot split its time between the two steps and gives neither.
880 write(
881 stepLine("typecheck", state, ran.ok ? undefined : Date.now() - checkBegan),
882 );
883 if (ran.ok) write(stepLine("tests", "ok"));
884 } else write(stepLine("tests", state, Date.now() - testsBegan));
858885 }
859886 if (!ran.ok && ran.error === JOB_VANISHED) return { ok: false, error: JOB_VANISHED };
860887 if (!ran.ok) {
src/checks/summary.ts +84
@@ -111,3 +111,87 @@ export function checkWords(
111111 }
112112 return undefined;
113113 }
114
115 export type StepName = "install" | "typecheck" | "tests";
116 export type StepState = "pending" | "running" | "ok" | "failed" | "skipped";
117
118 export interface CheckStep {
119 readonly name: StepName;
120 readonly state: StepState;
121 /** `spanWords` of how long it took, once it finished and said so. */
122 readonly duration: string | undefined;
123 }
124
125 export const STEP_NAMES: readonly StepName[] = ["install", "typecheck", "tests"];
126
127 /**
128 * The line a check writes as a step changes state: `step tests failed 41.2`
129 * (seconds after the state, when the step has finished). The run page reads
130 * these back, so the format lives beside its reader.
131 */
132 export function stepLine(
133 name: StepName,
134 state: Exclude<StepState, "pending">,
135 ms?: number,
136 ): string {
137 return `${STEP_MARK}step ${name} ${state}${ms === undefined ? "" : ` ${(ms / 1000).toFixed(1)}`}`;
138 }
139
140 /**
141 * What starts a step line. A control character the runner alone writes: the
142 * lines of the command under test pass through `unmark`, so a check's own
143 * output can neither forge a row nor have its look-alike hidden from the log.
144 */
145 export const STEP_MARK = "\u0001";
146
147 /** A line of the command's own output, with any leading step marker removed. */
148 export const unmark = (line: string): string => line.replace(/^\u0001+/, "");
149
150 const STEP_LINE = /^\u0001step (install|typecheck|tests) (running|ok|failed|skipped)(?: ([0-9]+(?:\.[0-9])?))?$/;
151
152 /**
153 * The three rows of a check's run page, from the run's own state and the
154 * `step` lines its log carries. Every row is always present: a step the log
155 * has not reached is pending. A log with no step lines (an older run, a
156 * job-lane run) says only what the run's state does — a green run passed
157 * every step, anything else leaves them pending rather than guessed.
158 */
159 export function checkSteps(
160 run: Pick<Run, "state">,
161 lines: readonly string[],
162 ): CheckStep[] {
163 const seen = new Map<StepName, { state: StepState; duration: string | undefined }>();
164 for (const line of lines) {
165 const m = STEP_LINE.exec(line);
166 if (m === null) continue;
167 seen.set(m[1] as StepName, {
168 state: m[2] as StepState,
169 duration: m[3] === undefined ? undefined : spanWords(Number(m[3]) * 1000),
170 });
171 }
172 return STEP_NAMES.map((name) => {
173 const got = seen.get(name);
174 if (got === undefined)
175 return { name, state: run.state === "ok" ? "ok" : "pending", duration: undefined };
176 // A step still "running" in the log of a run that is over did not finish.
177 const over = run.state === "failed" || run.state === "cancelled";
178 return {
179 name,
180 state: got.state === "running" && over ? "failed" : got.state,
181 duration: got.duration,
182 };
183 });
184 }
185
186 /** The `step` lines are the page's rows, not output: a log shown to a person leaves them out. */
187 export const isStepLine = (line: string): boolean => STEP_LINE.test(line);
188
189 /** `install done 3s · typecheck done 41s · tests running`: the rows in one line, for the terminal. */
190 export function stepWords(steps: readonly CheckStep[]): string {
191 return steps
192 .map((s) => {
193 const word = s.state === "ok" ? "done" : s.state;
194 return `${s.name} ${word}${s.duration === undefined ? "" : ` ${s.duration}`}`;
195 })
196 .join(" · ");
197 }
src/tui/screens/pull.ts +17 −2
@@ -49,7 +49,7 @@ import { proposedByText } from "../../core/proposal_token.ts";
4949 import { getAppByRepo } from "../../core/apps.ts";
5050 import { getIssue, type Issue } from "../../core/issues.ts";
5151 import { isProposed, pullMayRun } from "../../core/pull_trust.ts";
52 import { runningProgress } from "../../checks/progress.ts";
52 import { checkStepWords, runningProgress } from "../../checks/progress.ts";
5353 import { askCheck } from "../../checks/again.ts";
5454 import { checkStale, checksHold } from "../../checks/stale.ts";
5555 import { checkWords } from "../../checks/summary.ts";
@@ -237,6 +237,7 @@ export function pullScreen(
237237 /** The pull's base branch, to name what the check was merged with. */
238238 let checkBase = "";
239239 let checkProgress = "";
240 let checkStepsLine = "";
240241 /** The check's green was against a base that has since moved. */
241242 let checkOld = false;
242243 /** Agent runs about this pull, newest first. */
@@ -288,6 +289,7 @@ export function pullScreen(
288289 : checkSummary(f.db, row.id, row.headOid || (facts?.headOid ?? ""));
289290 checkBase = row?.baseBranch ?? facts?.baseBranch ?? "";
290291 checkProgress = runningProgress(f.app.config.dataDir, check);
292 checkStepsLine = checkStepWords(f.app.config.dataDir, check);
291293 checkOld =
292294 repo !== undefined &&
293295 row !== undefined &&
@@ -794,7 +796,8 @@ export function pullScreen(
794796 const boxH =
795797 3 +
796798 (standingText(standing(), requireReview) === "" ? 0 : 1) +
797 (checksLine === "" ? 0 : 1);
799 (checksLine === "" ? 0 : 1) +
800 (checkStepsLine === "" || checksLine === "" ? 0 : 1);
798801 const [strip, head, previewRow, boxRow, tabRow, body, comp] = split(
799802 area,
800803 "v",
@@ -849,6 +852,7 @@ export function pullScreen(
849852 checkOld,
850853 check,
851854 checksLine,
855 stepsLine: checkStepsLine,
852856 standing: standing(),
853857 required: requireReview,
854858 });
@@ -1352,6 +1356,8 @@ function drawMergeBox(
13521356 check: CheckSummary;
13531357 /** The checks row, already worded; "" draws none. */
13541358 checksLine: string;
1359 /** The check's three steps in one row; "" draws none. */
1360 stepsLine: string;
13551361 standing: Standing;
13561362 required: boolean;
13571363 },
@@ -1453,5 +1459,14 @@ function drawMergeBox(
14531459 ),
14541460 inner.x + inner.w,
14551461 );
1462 y++;
1463 if (o.stepsLine !== "" && y < inner.y + inner.h)
1464 s.text(
1465 inner.x,
1466 y,
1467 truncate(o.stepsLine, inner.w),
1468 style(c.mutedFg, c.card),
1469 inner.x + inner.w,
1470 );
14561471 }
14571472 }
src/web/client.ts +2
@@ -340,6 +340,7 @@ export const studioRunJs = /* js */ `
340340 }
341341 var text = event.data;
342342 try { var parsed = JSON.parse(text); if (typeof parsed === 'string') text = parsed; } catch (err) {}
343 if (text.charCodeAt(0) === 1) return; // a step line: the rows above, not output
343344 add(draw(text));
344345 });
345346 source.addEventListener('done', function (event) {
@@ -407,6 +408,7 @@ export const appTailJs = /* js */ `
407408 }
408409 var text = event.data;
409410 try { var parsed = JSON.parse(text); if (typeof parsed === 'string') text = parsed; } catch (err) {}
411 if (text.charCodeAt(0) === 1) return; // a step line: the rows above, not output
410412 add(draw(text));
411413 });
412414 // The run is over: stop appending. The row above settles on its final
src/web/studio/run.ts +32 −3
@@ -8,6 +8,7 @@
88 * at `?all=1`.
99 */
1010
11 import { checkSteps, isStepLine, type CheckStep } from "../../checks/summary.ts";
1112 import { directionNote } from "../../crew/direct.ts";
1213 import { appsRuntime } from "../../apps/runtime.ts";
1314 import { getAppByRepo } from "../../core/apps.ts";
@@ -54,6 +55,31 @@ export function stopForm(ctx: Ctx, repo: Repo, run: Run): Html | null {
5455 </form>`;
5556 }
5657
58 const STEP_WORD: Record<CheckStep["state"], string> = {
59 pending: "pending",
60 running: "running",
61 ok: "done",
62 failed: "failed",
63 skipped: "skipped",
64 };
65
66 /**
67 * A check's three steps, always all three so the page never shifts: each
68 * with its state and, once it has finished and said so, its duration.
69 */
70 export function stepRows(run: Run, lines: readonly string[]): Html {
71 return html`<ol class="check-steps" id="check-steps">
72 ${checkSteps(run, lines).map(
73 (s) =>
74 html`<li data-step="${s.name}" data-state="${s.state}">
75 <span class="step-name">${s.name}</span>
76 <span class="step-state">${STEP_WORD[s.state]}</span>
77 <span class="num step-time">${s.duration ?? ""}</span>
78 </li>`,
79 )}
80 </ol>`;
81 }
82
5783 /**
5884 * GET /:owner/:name/runs/:id: who is on it, the tell it came from, the
5985 * commit a deploy or a check is about, how long it has gone and what it has
@@ -71,6 +97,8 @@ export async function runView(
7197 logHidden = false,
7298 ): Promise<Response> {
7399 const db = ctx.app.db;
100 // The `step` lines are the rows above the log, not output.
101 const shown = lines.filter((line) => !isStepLine(line));
74102 const base = repoBase(repo);
75103 const writer = canSeeOwnerFacts(db, repo, ctx.auth.user);
76104 const actor = run.actorId === null ? undefined : getUserById(db, run.actorId);
@@ -220,6 +248,7 @@ export async function runView(
220248 </form>
221249 </div>`,
222250 )}
251 ${when(run.kind === "check" && !logHidden, () => stepRows(run, lines))}
223252 ${when(pull, (p) => previewCard(ctx, repo, p))}
224253 ${when(
225254 logHidden,
@@ -236,7 +265,7 @@ export async function runView(
236265 </p>`,
237266 )}
238267 ${when(
239 lines.length === 0 && !logHidden,
268 shown.length === 0 && !logHidden,
240269 () =>
241270 html`<p class="muted small" id="run-empty">
242271 Nothing has been logged yet.
@@ -247,9 +276,9 @@ export async function runView(
247276 id: "run-log",
248277 who,
249278 cap: all
250 ? Math.max(lines.length, RUN_TRANSCRIPT_CAP)
279 ? Math.max(shown.length, RUN_TRANSCRIPT_CAP)
251280 : RUN_TRANSCRIPT_CAP,
252 lines,
281 lines: shown,
253282 allHref: `${base}/runs/${run.id}?all=1`,
254283 truncated,
255284 ...(unfinished ? { stream } : {}),
src/web/style/content.ts +4
@@ -904,6 +904,10 @@ form.inline { display: inline; margin-left: auto; }
904904 .run-steer .bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
905905 .run-steer .bar .muted { flex: 1 1 200px; }
906906 .run-summary { margin: 10px 0 0; text-wrap: pretty; }
907 .check-steps { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 4px; }
908 .check-steps li { display: grid; grid-template-columns: 8em 6em 1fr; gap: 8px; min-height: 1.6em; }
909 .check-steps li[data-state="failed"] .step-state { color: var(--danger); }
910 .check-steps li[data-state="pending"] { opacity: .6; }
907911 .run-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
908912 .run-actions form { display: inline-flex; }
909913 /* A tail beside a running row (studio/app.ts): the same log, a peek at it
test/check-steps.test.ts added +236
@@ -0,0 +1,236 @@
1 /**
2 * A check's three steps (#2382): the writer in `startChecks` (what lands in
3 * the log, for a command with the shard banner, without it, failing, and
4 * with an install), the reader `checkSteps`, and the terminal's one line.
5 */
6
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
13 import { checkStepWords } from "../src/checks/progress.ts";
14 import { startChecks, type ChecksHandle } from "../src/checks/service.ts";
15 import {
16 checkSteps,
17 isStepLine,
18 stepLine,
19 stepWords,
20 } from "../src/checks/summary.ts";
21 import { listRuns, type Run } from "../src/core/runs.ts";
22 import type { Repo } from "../src/core/repos.ts";
23 import { createUser, type User } from "../src/core/users.ts";
24 import { serve, type Servers } from "../src/http/server.ts";
25 import { readRunLog } from "../src/runs/log.ts";
26 import { quietLogs } from "./helpers/globals.ts";
27
28 quietLogs();
29
30 const states = (run: Pick<Run, "state">, lines: string[]): string =>
31 checkSteps(run, lines)
32 .map((s) => `${s.name}:${s.state}${s.duration === undefined ? "" : `:${s.duration}`}`)
33 .join(" ");
34
35 describe("checkSteps", () => {
36 test("stepLine and the reader agree, and a step line is recognised", () => {
37 expect(stepLine("tests", "failed", 41_234)).toBe("\u0001step tests failed 41.2");
38 expect(stepLine("install", "skipped")).toBe("\u0001step install skipped");
39 expect(isStepLine("\u0001step tests failed 41.2")).toBe(true);
40 expect(isStepLine("\u0001step tests exploded")).toBe(false);
41 expect(isStepLine("step tests ok 0.1")).toBe(false);
42 expect(isStepLine("$ step tests ok")).toBe(false);
43 });
44
45 test("all three rows are always present, pending until known", () => {
46 expect(states({ state: "queued" }, [])).toBe(
47 "install:pending typecheck:pending tests:pending",
48 );
49 expect(states({ state: "running" }, ["\u0001step install running"])).toBe(
50 "install:running typecheck:pending tests:pending",
51 );
52 });
53
54 test("a running check shows install done and tests running", () => {
55 expect(
56 states({ state: "running" }, [
57 "\u0001step install ok 3.2",
58 "\u0001step typecheck ok 41.0",
59 "\u0001step tests running",
60 ]),
61 ).toBe("install:ok:3s typecheck:ok:41s tests:running");
62 });
63
64 test("a finished red one shows tests failed", () => {
65 expect(
66 states({ state: "failed" }, [
67 "\u0001step install ok 1.0",
68 "\u0001step typecheck ok 2.0",
69 "\u0001step tests running",
70 "\u0001step tests failed 9.0",
71 ]),
72 ).toBe("install:ok:1s typecheck:ok:2s tests:failed:9s");
73 });
74
75 test("no step lines: a green run passed every step", () => {
76 expect(states({ state: "ok" }, ["$ true"])).toBe("install:ok typecheck:ok tests:ok");
77 });
78
79 test("no step lines: a failed run leaves them pending, not guessed", () => {
80 expect(states({ state: "failed" }, ["$ false"])).toBe(
81 "install:pending typecheck:pending tests:pending",
82 );
83 });
84
85 test("a step still running in a failed or cancelled run did not finish", () => {
86 for (const state of ["failed", "cancelled"] as const)
87 expect(states({ state }, ["\u0001step install ok 1.0", "\u0001step typecheck running"])).toBe(
88 "install:ok:1s typecheck:failed tests:pending",
89 );
90 });
91
92 test("a malformed line is ignored", () => {
93 expect(
94 states({ state: "running" }, [
95 "\u0001step tests ok soon",
96 "\u0001step lint ok",
97 "\u0001step install ok 1.0 extra",
98 "\u0001step install ok 2.0",
99 ]),
100 ).toBe("install:ok:2s typecheck:pending tests:pending");
101 });
102
103 test("the terminal's line words the same rows", () => {
104 expect(
105 stepWords(
106 checkSteps({ state: "running" }, ["\u0001step install ok 3.2", "\u0001step typecheck running"]),
107 ),
108 ).toBe("install done 3s · typecheck running · tests pending");
109 });
110 });
111
112 describe("startChecks writes the step lines", () => {
113 let dataDir: string;
114 let app: App;
115 let servers: Servers;
116 let checks: ChecksHandle;
117 let alice: User;
118 let repo: Repo;
119
120 const json = (run: string, install: string): string =>
121 `{"check": {"run": ${JSON.stringify(run)}, "install": ${JSON.stringify(install)}}}\n`;
122
123 async function runOf(run: string, install: string): Promise<{ run: Run; lines: string[] }> {
124 const pushed = await commitToBranch(app, alice, repo, {
125 message: "a check",
126 files: [{ path: "forge.json", content: json(run, install) }],
127 });
128 if (!pushed.ok) throw new Error(JSON.stringify(pushed.error));
129 const deadline = Date.now() + 30_000;
130 while (Date.now() < deadline) {
131 const found = listRuns(app.db, repo.id, { kind: "check", limit: 50 }).find(
132 (r) => r.commitOid === pushed.value.commitOid,
133 );
134 if (found && (found.state === "ok" || found.state === "failed"))
135 return { run: found, lines: readRunLog(dataDir, found.id).lines };
136 await Bun.sleep(50);
137 }
138 throw new Error("check did not settle");
139 }
140
141 const stepLines = (lines: string[]): string[] =>
142 lines.filter(isStepLine).map((l) => l.replace(/ [0-9]+\.[0-9]$/, " T"));
143
144 beforeAll(async () => {
145 dataDir = await mkdtemp(join(tmpdir(), "forge-check-steps-"));
146 app = createApp({ dataDir, port: 0 });
147 servers = await serve(app);
148 checks = startChecks(app, { forgeUrl: servers.url, concurrency: 1 });
149 const a = await createUser(app.db, {
150 trusted: true,
151 username: "alice",
152 email: "[email protected]",
153 password: "a-good-passphrase",
154 adminIfFirst: true,
155 });
156 if (!a.ok) throw new Error(a.error);
157 alice = a.value;
158 const made = await createRepo(app, alice, { name: "lib", visibility: "public" });
159 if (!made.ok) throw new Error(String(made.error));
160 repo = made.value;
161 });
162
163 afterAll(async () => {
164 await checks.stop();
165 servers.stop();
166 app.close();
167 await rm(dataDir, { recursive: true, force: true });
168 });
169
170 test("with the shard banner: typecheck ends where the tests begin; install is skipped when none", async () => {
171 const { run, lines } = await runOf('echo "test-shards: 3 files"', "");
172 expect(run.state).toBe("ok");
173 expect(stepLines(lines)).toEqual([
174 "\u0001step install skipped",
175 "\u0001step typecheck running",
176 "\u0001step typecheck ok T",
177 "\u0001step tests running",
178 "\u0001step tests ok T",
179 ]);
180 expect(checkSteps(run, lines).map((s) => s.state)).toEqual(["skipped", "ok", "ok"]);
181 expect(checkStepWords(dataDir, { state: "ok", run })).toContain("tests done");
182 });
183
184 test("without the banner: a green run gives typecheck and tests no times", async () => {
185 const { run, lines } = await runOf("true", "");
186 expect(run.state).toBe("ok");
187 expect(stepLines(lines)).toEqual([
188 "\u0001step install skipped",
189 "\u0001step typecheck running",
190 "\u0001step typecheck ok",
191 "\u0001step tests ok",
192 ]);
193 });
194
195 test("a failing command after the banner fails the tests, not the typecheck", async () => {
196 const { run, lines } = await runOf('echo "test-shards: 1 files"; exit 1', "");
197 expect(run.state).toBe("failed");
198 expect(stepLines(lines).slice(-3)).toEqual([
199 "\u0001step typecheck ok T",
200 "\u0001step tests running",
201 "\u0001step tests failed T",
202 ]);
203 expect(checkSteps(run, lines).map((s) => s.state)).toEqual(["skipped", "ok", "failed"]);
204 });
205
206 test("a command that prints step lines cannot forge the rows", async () => {
207 const { run, lines } = await runOf(
208 `printf 'step tests ok 0.1\\n\\001step tests ok 0.1\\n\\001\\001step typecheck ok 0.1\\n'; exit 1`,
209 "",
210 );
211 expect(run.state).toBe("failed");
212 // The look-alikes are in the log as output, shorn of the marker...
213 expect(lines.filter((l) => l === "step tests ok 0.1")).toHaveLength(2);
214 expect(lines).toContain("step typecheck ok 0.1");
215 // ...and only the runner's own lines make rows.
216 expect(stepLines(lines)).toEqual(["\u0001step install skipped", "\u0001step typecheck running", "\u0001step typecheck failed T"].map((l) => l));
217 expect(checkSteps(run, lines).map((s) => s.state)).toEqual(["skipped", "failed", "pending"]);
218 });
219
220 test("a failing command with no banner fails the typecheck, timed", async () => {
221 const { lines } = await runOf("exit 1", "");
222 expect(stepLines(lines).slice(-1)).toEqual(["\u0001step typecheck failed T"]);
223 });
224
225 test("an install runs before the check and is timed", async () => {
226 const { run, lines } = await runOf("true", "echo installing");
227 expect(run.state).toBe("ok");
228 expect(stepLines(lines).slice(0, 2)).toEqual(["\u0001step install running", "\u0001step install ok T"]);
229 });
230
231 test("a failed install stops the check there", async () => {
232 const { run, lines } = await runOf("true", "exit 1");
233 expect(run.state).toBe("failed");
234 expect(stepLines(lines)).toEqual(["\u0001step install running", "\u0001step install failed T"]);
235 });
236 });
test/studio-runs.test.ts +51
@@ -486,6 +486,57 @@ describe("working: a run's own page in the studio", () => {
486486 await rm(dataDir, { recursive: true, force: true });
487487 });
488488
489 test("a check's page shows install, typecheck and tests as rows from the first paint", async () => {
490 const stepOf = (page: string, name: string): string =>
491 new RegExp(`<li data-step="${name}" data-state="([a-z]+)"`).exec(page)?.[1] ?? "";
492 const check = (): ReturnType<typeof createRun> =>
493 createRun(app.db, {
494 repoId: repo.id,
495 kind: "check",
496 reason: "push",
497 commitOid: "a".repeat(40),
498 });
499 const pageOf = async (id: string): Promise<string> =>
500 await (await get(`/alice/engine/runs/${id}`, writerCookie)).text();
501
502 const queued = check();
503 const first = await pageOf(queued.id);
504 for (const name of ["install", "typecheck", "tests"])
505 expect(stepOf(first, name)).toBe("pending");
506
507 const running = check();
508 claimRun(app.db, running.id);
509 for (const line of [
510 "\u0001step install running",
511 "\u0001step install ok 3.2",
512 "\u0001step typecheck running",
513 "\u0001step typecheck ok 41.0",
514 "\u0001step tests running",
515 ])
516 appendRunLog(dataDir, running.id, line);
517 const live = await pageOf(running.id);
518 expect(stepOf(live, "install")).toBe("ok");
519 expect(live).toContain("3s");
520 expect(stepOf(live, "typecheck")).toBe("ok");
521 expect(stepOf(live, "tests")).toBe("running");
522 // The step lines are the rows, not output: the log leaves them out.
523 expect(live).not.toContain("step tests running");
524
525 const red = check();
526 claimRun(app.db, red.id);
527 for (const line of [
528 "\u0001step install ok 1.0",
529 "\u0001step typecheck ok 2.0",
530 "\u0001step tests running",
531 "\u0001step tests failed 9.0",
532 ])
533 appendRunLog(dataDir, red.id, line);
534 finishRun(app.db, red.id, { state: "failed", summary: "1 of 2 tests" });
535 const failed = await pageOf(red.id);
536 expect(stepOf(failed, "typecheck")).toBe("ok");
537 expect(stepOf(failed, "tests")).toBe("failed");
538 });
539
489540 test("the studio transcript names the tell, the cost, and the steer box", async () => {
490541 const tell = openIssue(app, alice, repo, {
491542 title: "Fix the flicker on load",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs