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

A run's page opens its log, steps and cost in folds and leads with the verdict #13016

Merged opened this

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

Merged

scout/forge:scout/13002-a-run-s-page-opens-its-log-steps-and-cos → main 6 commits fork 3 threads · 3 unresolved

  • Merged. scout/13002-a-run-s-page-opens-its-log-steps-and-cos was merged into main as 4ca8f3b.

Review

Sign in to review this change.
6 files changed +151 −11
docs/design/attention-budget.json +4 −4
@@ -97,13 +97,13 @@
9797 },
9898 "run": {
9999 "390": {
100 "words": 34,
101 "blocks": 11,
100 "words": 38,
outdated

Budget raised instead of trimming the labels (finding 3, principle 1).

101 "blocks": 13,
102102 "colours": 3
103103 },
104104 "1280": {
105 "words": 34,
106 "blocks": 11,
105 "words": 38,
106 "blocks": 13,
107107 "colours": 3
108108 }
109109 },
docs/features/README.md +1
@@ -208,6 +208,7 @@ Read with the guide page [Your apps](../guide-your-apps.md).
208208 - [One place for a secret (`Settings → App → Secrets this app uses`)](app-secrets.md)
209209 - [Pause and resume a maintenance duty](maintenance-duties.md)
210210 - [Pinned toolchains (rust)](toolchains.md)
211 - [A run's page folds its steps and its log](run-folds.md)
211212 - [Scheduled tools: the forge calls an absorbed app's tool on time](feature-schedule.md)
212213 - [Scrape evidence](scrapes.md)
213214 - [The box pass](box-pass.md)
docs/features/run-folds.md added +12
@@ -0,0 +1,12 @@
1 # A run's page folds its steps and its log
2
3 This page is for anyone reading a run. A finished run leads with its verdict; the detail sits in two folds below it.
4
5 - **Steps** (checks only): the summary says the outcome, for example `Steps 3/3 passed`. A passing run's fold is closed; a failed or still-running run's is open.
6 - **Log**: the summary is `Log`. Closed on a finished run that passed, open while it runs and when it failed.
7
8 A link to a log line (`/alice/app/runs/ID#L12`) or to the log (`#run-log`) opens the folds around its target and scrolls to it. Press the summary to open a fold by hand.
9
10 With JavaScript off, the page is the same, but a link to a line lands on a closed fold: press `Log` to see it. Nothing is hidden by script.
11
12 The terminal's run screen (`runlog`) has no folds: it already shows the state line, the steps and the last 200 log lines flat, so nothing changed there.
src/web/client.ts +7
@@ -190,6 +190,13 @@ const logLineJs = /* js */ `
190190 }
191191 `;
192192
193 /**
194 * A link to a log line (#L12) or the log (#run-log) lands with every fold
195 * around its target open, then scrolls to it. With scripts off the fold stays
196 * closed and its summary opens it by hand.
197 */
198 export const openFoldJs = /* js */ `(function(){function o(){var h=location.hash.slice(1);if(!h)return;var t=document.getElementById(h);var d=t&&t.closest("details");while(d){d.open=true;d=d.parentElement&&d.parentElement.closest("details")}if(t)t.scrollIntoView()}o();addEventListener("hashchange",o)})();`;
199
193200 /**
194201 * A run's log, live, painted in the studio's own five words. The page
195202 * renders every line already written; for a run still going, this appends
src/web/studio/run.ts +8 −7
@@ -28,11 +28,11 @@ import { getUserById } from "../../core/users.ts";
2828 import { repoDir } from "../../git/repos.ts";
2929 import type { Ctx } from "../../http/context.ts";
3030 import { crumbsFor, repoBase, repoHeader, repoPalette } from "../chrome.ts";
31 import { liveRegionsJs, studioRunJs } from "../client.ts";
31 import { liveRegionsJs, openFoldJs, studioRunJs } from "../client.ts";
3232 import { html, raw, when, type Html } from "../html.ts";
3333 import { runLine } from "../describe.ts";
3434 import { page } from "../layout.ts";
35 import { badge, btn, card, listCard, row as stepRow, sha, type Tone } from "../ui.ts";
35 import { badge, btn, card, disclosure, listCard, row as stepRow, sha, type Tone } from "../ui.ts";
3636 import { previewBlock } from "../pages/apps.ts";
3737 import { costText, durationText, RUN_PAGE_CSS, runTitle, runTokens } from "../pages/runs.ts";
3838 import { placementLine, sandboxLine } from "./sandbox.ts";
@@ -299,7 +299,8 @@ export async function runView(
299299 // While the run is open every part is rendered at a fixed size (the
300300 // pin slot by CSS), so the log below never moves as numbers and pins
301301 // arrive; a run that has ended reserves nothing.
302 return html`<div data-check-progress id="check-progress" data-state="${run.state}">
302 const passed = steps.filter((x) => x.state === "ok").length;
303 return disclosure(`Steps ${passed}/${steps.length} passed`, html`<div data-check-progress id="check-progress" data-state="${run.state}">
303304 <div id="check-steps" role="status" aria-live="polite">
304305 ${listCard(
outdated

Summary "Steps" carries no outcome; a closed fold hides the verdict of the checks (finding 2, principle 1).

305306 steps.map((s) =>
@@ -332,7 +333,7 @@ export async function runView(
332333 ),
333334 )}
334335 </div>
335 </div>`;
336 </div>`, { id: "run-steps-fold", open: unfinished || run.state === "failed" });
336337 },
337338 )}
338339 ${vitalsBlock(run, logHidden, looks)}
@@ -345,7 +346,7 @@ export async function runView(
345346 Reconnecting; lines written meanwhile appear when it is back.
346347 </p>`,
347348 )}
348 ${when(!logHidden, () => logBox({
349 ${when(!logHidden, () => disclosure("Log", logBox({
349350 id: "run-log",
350351 anchors: true,
351352 who,
@@ -378,7 +379,7 @@ export async function runView(
378379 >
379380 newer below
380381 </button>`,
381 }))}
382 }), { id: "run-log-fold", open: unfinished || run.state === "failed" }))}
382383 ${when(
383384 run.kind === "agent",
384385 () => html`<p class="muted small crew-note">${directionNote(repo)}</p>`,
@@ -449,6 +450,6 @@ export async function runView(
449450 palette: repoPalette(ctx, repo),
450451 body,
451452 styleCss: RUN_PAGE_CSS,
452 scriptJs: `${liveRegionsJs}\n${studioRunJs}`,
453 scriptJs: `${liveRegionsJs}\n${studioRunJs}\n${openFoldJs}`,
453454 });
454455 }
test/run-page-folds.test.ts added +119
@@ -0,0 +1,119 @@
1 /**
2 * A finished run leads with the verdict: its log is a closed fold; a running
3 * one's is open; an anchor opens its fold.
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 { createRepo } from "../src/actions/repos.ts";
10 import { createApp, type App } from "../src/app.ts";
11 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
12 import { createSession } from "../src/core/sessions.ts";
13 import { openFoldJs } from "../src/web/client.ts";
14 import { serve, type Servers } from "../src/http/server.ts";
15 import { appendRunLog } from "../src/runs/log.ts";
16 import { seedAdmin } from "./helpers/admin.ts";
17
18 let dir: string, app: App, servers: Servers, done: string, live: string, checkOk: string, checkBad: string;
19
20 beforeAll(async () => {
21 dir = await mkdtemp(join(tmpdir(), "forge-run-folds-"));
22 app = createApp({ dataDir: dir, port: 0 });
23 servers = await serve(app);
24 const made = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "a-good-passphrase" });
25 if (!made.ok) throw new Error(made.error);
26 const repo = await createRepo(app, made.value, { name: "folds", visibility: "public" });
27 if (!repo.ok) throw new Error(String(repo.error));
28 const cookie = `forge_session=${createSession(app.db, made.value.id).token}`;
29 const get = async (id: string) => (await fetch(`${servers.url}/alice/folds/runs/${id}`, { headers: { cookie } })).text();
30 const a = createRun(app.db, { repoId: repo.value.id, kind: "agent", actorId: made.value.id, reason: "assigned" });
31 claimRun(app.db, a.id);
32 appendRunLog(dir, a.id, "hello there");
33 finishRun(app.db, a.id, { state: "ok", summary: "All done", costUsd: 0.5 });
34 done = await get(a.id);
35 const b = createRun(app.db, { repoId: repo.value.id, kind: "agent", actorId: made.value.id, reason: "assigned" });
36 claimRun(app.db, b.id);
37 appendRunLog(dir, b.id, "working");
38 live = await get(b.id);
39 const mk = async (state: "ok" | "failed") => {
40 const c = createRun(app.db, { repoId: repo.value.id, kind: "check", env: "main", commitOid: "0".repeat(40), reason: "push" });
41 claimRun(app.db, c.id);
42 appendRunLog(dir, c.id, "$ bun test");
43 finishRun(app.db, c.id, { state, summary: state });
44 return get(c.id);
45 };
46 checkOk = await mk("ok");
47 checkBad = await mk("failed");
48 }, 60_000);
49 afterAll(async () => {
50 servers.stop();
51 app.close();
52 await rm(dir, { recursive: true, force: true });
53 });
54
55 test("a finished run's log is a closed fold after the verdict", () => {
56 expect(done).toMatch(/<details id="run-log-fold" class="disclosure">/);
57 expect(done.indexOf('id="run-summary"')).toBeLessThan(done.indexOf('id="run-log-fold"'));
58 expect(done).toContain('id="run-log"');
59 });
60
61 test("a running run's log is open", () => {
62 expect(live).toMatch(/<details id="run-log-fold" class="disclosure" open>/);
63 });
64
65 test("the log's summary is the one word", () => {
66 expect(done).toContain("<summary>Log</summary>");
67 });
68
69 test("a finished passing check's steps are a closed fold whose summary carries the outcome", () => {
70 expect(checkOk).toMatch(/<details id="run-steps-fold" class="disclosure">/);
71 expect(checkOk).toContain("Steps 3/3 passed");
72 });
73
74 test("a failed check opens its steps and its log", () => {
75 expect(checkBad).toMatch(/<details id="run-steps-fold" class="disclosure" open>/);
76 expect(checkBad).toMatch(/<details id="run-log-fold" class="disclosure" open>/);
77 expect(checkBad).toMatch(/Steps \d\/3 passed/);
78 });
79
80 test("with scripts off the page still carries the closed fold and its summary, nothing hidden by script", () => {
81 expect(done).toContain("<summary>Log</summary>");
82 expect(done).not.toContain("hidden id=\"run-log-fold\"");
83 });
84
85 /** A DOM stub: nested details around a target; runs the script as the page would. */
86 function run(hash: string, ids: string[]) {
87 const outer = { open: false, parentElement: null as unknown, closest(): unknown { return outer; } };
88 const inner = { open: false, parentElement: outer, closest(): unknown { return inner; } };
89 (outer as { closest(sel: string): unknown }).closest = () => null;
90 const target = { scrolled: false, closest: (sel: string) => (sel === "details" ? inner : null), scrollIntoView() { this.scrolled = true; } };
91 (inner as { parentElement: unknown }).parentElement = { closest: (sel: string) => (sel === "details" ? outer : null) };
92 const listeners: Record<string, () => void> = {};
93 const loc = { hash };
94 new Function("location", "document", "addEventListener", openFoldJs)(
95 loc,
96 { getElementById: (id: string) => (ids.includes(id) ? target : null) },
97 (n: string, f: () => void) => (listeners[n] = f),
98 );
99 return { inner, outer, target, loc, listeners };
100 }
101
102 test("the script opens every fold around a #L12 target and scrolls to it", () => {
103 const r = run("#L12", ["L12"]);
104 expect(r.inner.open).toBe(true);
105 expect(r.outer.open).toBe(true);
106 expect(r.target.scrolled).toBe(true);
107 });
108
109 test("no hash, or a hash that matches nothing, opens nothing", () => {
110 expect(run("", ["L12"]).inner.open).toBe(false);
111 expect(run("#L99", ["L12"]).inner.open).toBe(false);
112 });
113
114 test("a later hashchange opens the fold too", () => {
115 const r = run("", ["L3"]);
116 r.loc.hash = "#L3";
117 r.listeners.hashchange!();
118 expect(r.inner.open).toBe(true);
119 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs