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

The board speaks the studio's five words, from the same place the pages do #478

Closed opened this
Closed without merging

mason/forge:mason/67-the-board-speaks-the-studio-s-five-words → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +357 −78
docs/STUDIO.md +13 −3
@@ -387,12 +387,22 @@ person's dev home.
387387 (**Focus** on that card opens it): no top bar, dark unless you chose a
388388 theme, four regions that fill the window. **Working now** is one card per
389389 run in flight — who, which app, what it is on, why, how long, what it has
390 cost — ordered by when it started. **Landed** is the last dozen shipped
390 cost — ordered by when it started. **Landed** is the last dozen merged
391391 changes across your apps, each with the app's production look on a phone.
392392 **Decided** is the last dozen entries in the decision ledger: which issue
393393 next, ship or show, try again — the answer, how sure the decider was, and
394 what came of it. **Today** is one row per app that runs on its own: spend
395 against the ceiling, runs, shipped, and whether it is paused — plus any
394 what came of it. The board speaks the same five words as every studio page
395 and nothing of its own: a run card's word is `runWord`'s, a landed change's
396 `pullWord`'s, and what came of a decision is where its pull or tell stands
397 now (`pullWord`/`tellWord`, `studio/words.ts`) — never the ledger's own
398 outcome — so a merge production has not served yet reads _waiting_ on the
399 wall exactly as it does on the app's page, and _shipped_ only once
400 production is serving it. Every word is coloured by `wordVariant`, the
401 same map the badge draws from, so a word added later is never uncoloured.
402 **Today** is one row per app that runs on its own: spend against the
403 ceiling, runs, shipped, and whether it is paused — the app page's own
404 reads (`autonomyStatus`, `agentRunTotals`, `mergedPullCount`) over today,
405 and its paused words (`pausedWords`) — plus any
396406 other app the crew spent on this week — and beneath it the efficiency
397407 signal: spend per shipped change over the last 7 days (the usage ledger's
398408 `cost_usd` ÷ pulls merged, `core/efficiency.ts`, every app in one grouped
src/web/pages/board.ts +130 −55
@@ -6,7 +6,9 @@
66 * matching event lands. A site admin also gets two strips above them: the
77 * forge's health, and each subscription's windows. Nothing on it
88 * needs a click, and everything on it links somewhere. It reads the same
9 * tables as the studio and adds no state of its own.
9 * tables as the studio and adds no state of its own — nor words: every
10 * run, change and decision on it is worded by `runWord`/`pullWord`/
11 * `tellWord`, the studio's own, and coloured by `wordVariant`.
1012 *
1113 * `?wall` is its one wall mode, for a screen across the room that nobody
1214 * touches: the same regions in larger type, without the key hints or a
@@ -27,26 +29,41 @@ import { listApps } from "../../core/apps.ts";
2729 import { vitals, type Vitals } from "../../kernel/vitals.ts";
2830 import { getIssue, getIssuesByIds, type Issue } from "../../core/issues.ts";
2931 import { looksForApps } from "../../core/looks.ts";
30 import { listPulls, mergedPullsForRepos, type Pull } from "../../core/pulls.ts";
32 import {
33 getPull,
34 mergedPullCount,
35 mergedPullsForRepos,
36 openPullsClosing,
37 type Pull,
38 } from "../../core/pulls.ts";
3139 import {
3240 canSeeOwnerFacts,
3341 listReposVisibleTo,
3442 type Repo,
3543 } from "../../core/repos.ts";
36 import { listActiveRuns, listRuns, type Run } from "../../core/runs.ts";
44 import { agentRunTotals, listActiveRuns, type Run } from "../../core/runs.ts";
3745 import { getUsersByIds } from "../../core/users.ts";
3846 import { autonomyStatus, startOfTodayUtc } from "../../crew/autonomy.ts";
47 import { repoDir } from "../../git/repos.ts";
3948 import type { Ctx } from "../../http/context.ts";
4049 import { repoBase, signInFirst } from "../chrome.ts";
4150 import { boardJs, liveRegionsJs } from "../client.ts";
4251 import { html, when, type Html } from "../html.ts";
4352 import { page, redirect } from "../layout.ts";
4453 import { avatar, icon, time } from "../ui.ts";
54 import { tellWord } from "../studio/tell.ts";
4555 import { voiceFor } from "../studio/voice.ts";
4656 import {
57 pausedWords,
4758 perShippedWords,
59 pullWord,
60 runWord,
61 servingHistory,
4862 windowWords,
63 wordVariant,
4964 type FigureWords,
65 type Word,
66 type WordCtx,
5067 } from "../studio/words.ts";
5168 import { lookUrl, thumbLook } from "./looks.ts";
5269
@@ -72,13 +89,6 @@ function reasonWords(reason: string): string {
7289 }
7390 }
7491
75 type StateWord = "queued" | "working" | "paused";
76
77 function stateWord(run: Run): StateWord {
78 if (run.state === "running") return "working";
79 return run.notBefore === null ? "queued" : "paused";
80 }
81
8292 const KIND_WORDS: Record<DecisionKind, string> = {
8393 next: "next issue",
8494 land: "ship or show",
@@ -102,6 +112,9 @@ interface BoardScope {
102112 * access, same as the studio. A repo the viewer can only read is on the
103113 * board (it is still theirs to watch land) but carries none of that. */
104114 readonly ownerFacts: ReadonlySet<string>;
115 /** What the studio's word functions need to see each app's production,
116 * every app sharing one render's memo of production's history. */
117 readonly words: (repo: Repo) => WordCtx;
105118 }
106119
107120 /** The scope for some repositories: the ones among them that are apps. */
@@ -111,6 +124,9 @@ function boardScope(
111124 records: ReadonlyMap<string, AppRecord>,
112125 ): BoardScope {
113126 const kept = repos.filter((r) => records.has(r.id));
127 const runtime = appsRuntime(ctx.app);
128 const history = servingHistory();
129 const contexts = new Map<string, WordCtx>();
114130 return {
115131 repos: kept,
116132 ids: kept.map((r) => r.id),
@@ -121,13 +137,37 @@ function boardScope(
121137 .filter((r) => canSeeOwnerFacts(ctx.app.db, r, ctx.auth.user))
122138 .map((r) => r.id),
123139 ),
140 words: (repo) => {
141 let made = contexts.get(repo.id);
142 if (made === undefined) {
143 made = {
144 db: ctx.app.db,
145 dir: repoDir(ctx.app.reposRoot, repo.ownerName, repo.name),
146 runtime,
147 record: records.get(repo.id),
148 history,
149 };
150 contexts.set(repo.id, made);
151 }
152 return made;
153 },
124154 };
125155 }
126156
157 /** A studio word on a card, coloured from the word itself. */
158 function wordSpan(cls: string, word: Word): Html {
159 return html`<span
160 class="${cls}"
161 data-word="${word}"
162 data-variant="${wordVariant(word)}"
163 >${word}</span
164 >`;
165 }
166
127167 // ---- the page ----
128168
129169 /** GET /board — signed in; every app the viewer can see, or `?apps=` some; `?wall` for the wall mode. */
130 export function boardPage(ctx: Ctx): Response {
170 export async function boardPage(ctx: Ctx): Promise<Response> {
131171 const user = ctx.auth.user;
132172 if (!user) return signInFirst(ctx);
133173 const db = ctx.app.db;
@@ -181,7 +221,8 @@ export function boardPage(ctx: Ctx): Response {
181221 </header>
182222 ${forgeStrip(ctx)} ${windowsStrip(ctx)}
183223 <div class="board-grid">
184 ${working(ctx, scope)} ${landed(ctx, scope)} ${decided(ctx, scope)}
224 ${await working(ctx, scope)} ${await landed(ctx, scope)}
225 ${await decided(ctx, scope)}
185226 ${today(ctx, scope)}
186227 </div>
187228 </div>`;
@@ -358,7 +399,7 @@ function windowsStrip(ctx: Ctx): Html | null {
358399
359400 // ---- working now ----
360401
361 function working(ctx: Ctx, scope: BoardScope): Html {
402 async function working(ctx: Ctx, scope: BoardScope): Promise<Html> {
362403 const db = ctx.app.db;
363404 const runs = listActiveRuns(db, scope.ids);
364405 // Working first, by when it started; then what waits, by when it was queued.
@@ -376,7 +417,10 @@ function working(ctx: Ctx, scope: BoardScope): Html {
376417 db,
377418 runs.map((r) => r.issueId).filter((id): id is string => id !== null),
378419 );
379 const rows = runs.map((run) => {
420 const words = await Promise.all(
421 runs.map((run) => runWord(scope.words(scope.byId.get(run.repoId)!), run)),
422 );
423 const rows = runs.map((run, n) => {
380424 const repo = scope.byId.get(run.repoId)!;
381425 // The same rule the app's page signs its rows by, `voiceFor`
382426 // (`studio/voice.ts`): the crew's own work reads as the app's own story
@@ -390,11 +434,12 @@ function working(ctx: Ctx, scope: BoardScope): Html {
390434 scope.ownerFacts.has(repo.id),
391435 );
392436 const issue = run.issueId === null ? undefined : about.get(run.issueId);
393 const word = stateWord(run);
437 const { word, note } = words[n]!;
394438 return html`<li>
395439 <a
396440 class="board-card board-run"
397441 data-state="${word}"
442 data-variant="${wordVariant(word)}"
398443 data-key="run:${run.id}"
399444 href="${repoBase(repo)}/runs/${run.id}"
400445 >
@@ -408,7 +453,7 @@ function working(ctx: Ctx, scope: BoardScope): Html {
408453 <span class="board-state">${word}</span>
409454 <span
410455 >${
411 word === "paused" ? "resumes soon" : reasonWords(run.reason)
456 run.notBefore === null ? reasonWords(run.reason) : note
412457 }</span
413458 >
414459 ${when(
@@ -433,7 +478,7 @@ function working(ctx: Ctx, scope: BoardScope): Html {
433478
434479 // ---- landed ----
435480
436 function landed(ctx: Ctx, scope: BoardScope): Html {
481 async function landed(ctx: Ctx, scope: BoardScope): Promise<Html> {
437482 const db = ctx.app.db;
438483 const pulls = mergedPullsForRepos(db, scope.ids, 12);
439484 // The newest production picture of each app, on a phone, in one read.
@@ -460,7 +505,10 @@ function landed(ctx: Ctx, scope: BoardScope): Html {
460505 )
461506 );
462507 };
463 const rows = pulls.map((pull: Pull) => {
508 const words = await Promise.all(
509 pulls.map((pull) => pullWord(scope.words(scope.byId.get(pull.repoId)!), pull)),
510 );
511 const rows = pulls.map((pull: Pull, n) => {
464512 const repo = scope.byId.get(pull.repoId)!;
465513 const picture = pictureOf(repo);
466514 const author = voiceFor(
@@ -488,7 +536,10 @@ function landed(ctx: Ctx, scope: BoardScope): Html {
488536 >
489537 <span class="board-landed-title">${pull.title}</span>
490538 <span class="board-when">${time(pull.mergedAt ?? pull.createdAt)}</span>
491 <span class="board-landed-meta">${repo.name} · ${author}</span>
539 <span class="board-landed-meta"
540 >${repo.name} · ${author}
541 ${wordSpan("board-word", words[n]!.word)}</span
542 >
492543 </a>
493544 </li>`;
494545 });
@@ -504,7 +555,7 @@ function landed(ctx: Ctx, scope: BoardScope): Html {
504555
505556 // ---- decided ----
506557
507 function decided(ctx: Ctx, scope: BoardScope): Html {
558 async function decided(ctx: Ctx, scope: BoardScope): Promise<Html> {
508559 const db = ctx.app.db;
509560 // The decision ledger is the owner's own record of what the crew chose —
510561 // never shown for a repository this viewer can only read.
@@ -516,15 +567,41 @@ function decided(ctx: Ctx, scope: BoardScope): Html {
516567 db,
517568 decisions.map((d) => d.issueId).filter((id): id is string => id !== null),
518569 );
519 const rows = decisions.map((d: Decision) => {
570 // What each decision was about: the issue picked for `next`, the pull
571 // for the rest. A pick names its issue by number.
572 const subjects = decisions.map((d): Issue | undefined => {
573 const issue = d.issueId === null ? undefined : about.get(d.issueId);
574 if (d.kind === "next" && /^\d+$/.test(d.answer))
575 return getIssue(db, d.repoId, Number(d.answer)) ?? issue;
576 return issue;
577 });
578 // What came of it is where that pull or tell stands now, in the studio's
579 // own words — never the ledger's private outcome, so a merge production
580 // has not served yet reads *waiting* here as it does on the app's page.
581 const closing = new Map<string, Map<number, Pull>>();
582 const words = await Promise.all(
583 decisions.map(async (d, n) => {
584 const issue = subjects[n];
585 if (issue === undefined) return undefined;
586 const repo = scope.byId.get(d.repoId)!;
587 const wordCtx = scope.words(repo);
588 if (issue.kind === "pull") {
589 const pull = getPull(db, repo.id, issue.number);
590 return pull && (await pullWord(wordCtx, pull));
591 }
592 let pulls = closing.get(repo.id);
593 if (pulls === undefined) {
594 pulls = openPullsClosing(db, repo.id);
595 closing.set(repo.id, pulls);
596 }
597 return await tellWord(wordCtx, repo, issue, pulls.get(issue.number));
598 }),
599 );
600 const rows = decisions.map((d: Decision, n) => {
520601 const repo = scope.byId.get(d.repoId)!;
521602 const base = repoBase(repo);
522 // What the decision was about: the issue picked for `next`, the pull
523 // for the rest. A pick names its issue by number.
524 let issue: Issue | undefined =
525 d.issueId === null ? undefined : about.get(d.issueId);
526 if (d.kind === "next" && /^\d+$/.test(d.answer))
527 issue = getIssue(db, repo.id, Number(d.answer)) ?? issue;
603 const issue = subjects[n];
604 const word = words[n]?.word;
528605 const href =
529606 issue === undefined
530607 ? base
@@ -552,9 +629,11 @@ function decided(ctx: Ctx, scope: BoardScope): Html {
552629 ></span>
553630 <span class="num">${Math.round(d.p * 100)}%</span>
554631 </span>
555 <span class="board-outcome" data-outcome="${d.outcome ?? ""}"
556 >${d.outcome ?? "—"}</span
557 >
632 ${
633 word === undefined
634 ? html`<span class="board-outcome">—</span>`
635 : wordSpan("board-outcome", word)
636 }
558637 <span class="board-when">${time(d.createdAt)}</span>
559638 </a>
560639 </li>`;
@@ -590,22 +669,12 @@ function today(ctx: Ctx, scope: BoardScope): Html {
590669 )
591670 .map((repo) => {
592671 const s = autonomyStatus(ctx.app, repo);
593 const runs = listRuns(db, repo.id, { kind: "agent", limit: 200 }).filter(
594 (r) => r.createdAt >= since,
595 ).length;
596 const shipped = listPulls(db, repo.id, {
597 state: "closed",
598 limit: 100,
599 }).filter((p) => p.mergedAt !== null && p.mergedAt >= since).length;
672 // The app page's own reads (`studio/app.ts`), over today rather
673 // than the week: counted by the database, not off a page of rows.
674 const runs = agentRunTotals(db, repo.id, since).runs;
675 const shipped = mergedPullCount(db, repo.id, since);
600676 const share = s.ceilingUsd > 0 ? s.spentTodayUsd / s.ceilingUsd : 0;
601 const note =
602 s.paused === "ceiling"
603 ? "at its ceiling until 00:00 UTC"
604 : s.paused === "nobody"
605 ? "nobody turned it on"
606 : s.paused === "no crew"
607 ? "no crew"
608 : repo.autonomy;
677 const note = s.paused === null ? repo.autonomy : pausedWords(s.paused);
609678 return html`<li>
610679 <a
611680 class="board-card board-app"
@@ -709,13 +778,17 @@ ${widths}
709778 .board-run-meta { grid-column: 2 / span 2; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; font-size: .9em; color: var(--muted-fg); }
710779 .board-state { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--fg); }
711780 .board-state::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--faint); }
712 .board-run[data-state="working"] { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); }
713 .board-run[data-state="working"] .board-state { color: var(--accent); }
714 .board-run[data-state="working"] .board-state::before { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
715 .board-run[data-state="working"] .board-elapsed { color: var(--accent); }
716 .board-run[data-state="queued"] .board-elapsed { color: var(--muted-fg); }
717 .board-run[data-state="paused"] .board-state { color: var(--attn); }
718 .board-run[data-state="paused"] .board-state::before { background: var(--attn); }
781 /* Coloured by the word's variant (wordVariant), never by the word, so a
782 word added later is coloured the moment it exists. */
783 .board-run[data-variant="accent"] { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); }
784 .board-run[data-variant="accent"] .board-state { color: var(--accent); }
785 .board-run[data-variant="accent"] .board-state::before { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
786 .board-run[data-variant="accent"] .board-elapsed { color: var(--accent); }
787 .board-run[data-variant="secondary"] .board-elapsed { color: var(--muted-fg); }
788 .board-run[data-variant="success"] .board-state { color: var(--success); }
789 .board-run[data-variant="success"] .board-state::before { background: var(--success); }
790 .board-run[data-variant="danger"] .board-state { color: var(--danger); }
791 .board-run[data-variant="danger"] .board-state::before { background: var(--danger); }
719792 /* Nothing on the wall animates on its own. A perpetual animation keeps the
720793 browser painting every frame all day — three pulsing dots measured at over
721794 100% CPU under software rendering. The ticking clocks are the sign of life. */
@@ -737,9 +810,11 @@ ${widths}
737810 .board-p { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: .75em; color: var(--muted-fg); }
738811 .board-p .board-bar { flex: 1; }
739812 .board-outcome { font-size: .875em; color: var(--faint); }
740 .board-outcome[data-outcome="shipped"], .board-outcome[data-outcome="green"] { color: var(--success); }
741 .board-outcome[data-outcome="red"] { color: var(--danger); }
742 .board-outcome[data-outcome="shown"], .board-outcome[data-outcome="closed"] { color: var(--attn); }
813 .board-word { font-size: .875em; color: var(--faint); margin-left: 4px; }
814 .board-outcome[data-variant="success"], .board-word[data-variant="success"] { color: var(--success); }
815 .board-outcome[data-variant="danger"], .board-word[data-variant="danger"] { color: var(--danger); }
816 .board-outcome[data-variant="accent"], .board-word[data-variant="accent"] { color: var(--accent); }
817 .board-outcome[data-variant="secondary"], .board-word[data-variant="secondary"] { color: var(--muted-fg); }
743818
744819 /* Today: each app that runs on its own, its spend against the ceiling. */
745820 .board-app { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 14px; align-items: baseline; padding: 12px 16px; }
src/web/studio/app.ts +2 −6
@@ -43,7 +43,7 @@ import {
4343 import { changesHref, tellsHref } from "./nouns.ts";
4444 import { nowCard, nowRegion } from "./now.ts";
4545 import { appPanels } from "./previews.ts";
46 import { servingHistory, type WordCtx } from "./words.ts";
46 import { pausedWords, servingHistory, type WordCtx } from "./words.ts";
4747
4848 /**
4949 * The week's decisions in one line: how many, how many the decider took
@@ -394,11 +394,7 @@ export async function studioApp(
394394 <dd>${autonomy.active} of ${autonomy.slots} in use</dd>
395395 ${autonomy.paused
396396 ? html`<dt>Paused</dt>
397 <dd>
398 ${autonomy.paused === "ceiling"
399 ? "at the ceiling, until 00:00 UTC"
400 : autonomy.paused}
401 </dd>`
397 <dd>${pausedWords(autonomy.paused)}</dd>`
402398 : null}
403399 </dl>`,
404400 {
src/web/studio/words.ts +42 −12
@@ -14,6 +14,7 @@ import type { AppsRuntime, EnvStatus } from "../../apps/runtime.ts";
1414 import type { AppRecord } from "../../core/apps.ts";
1515 import type { Efficiency } from "../../core/efficiency.ts";
1616 import type { WindowStanding } from "../../core/standing.ts";
17 import type { Paused } from "../../crew/autonomy.ts";
1718 import { whenText } from "../../crew/limits.ts";
1819 import { getIssueById } from "../../core/issues.ts";
1920 import { getPull, pullForBranch, type Pull } from "../../core/pulls.ts";
@@ -328,28 +329,57 @@ const WORD_ICON: Record<Word, Parameters<typeof icon>[0]> = {
328329 cancelled: "ban",
329330 };
330331
332 /** The colour a word is drawn in. */
333 export type WordVariant = "success" | "danger" | "accent" | "secondary";
334
335 /**
336 * Each word's colour, decided once: the badge draws it and the board
337 * colours its cards by it, so a word added to `Word` cannot render
338 * uncoloured anywhere — the `Record` will not compile without it.
339 * `cancelled` draws the same quiet, secondary look as `waiting` and
340 * `planned` — a restart is never the danger red a real failure earns.
341 */
342 const WORD_VARIANT: Record<Word, WordVariant> = {
343 working: "accent",
344 look: "success",
345 shipped: "success",
346 stopped: "danger",
347 waiting: "secondary",
348 planned: "secondary",
349 told: "secondary",
350 done: "success",
351 cancelled: "secondary",
352 };
353
354 export const wordVariant = (word: Word): WordVariant => WORD_VARIANT[word];
355
331356 /** One of the five (or six) studio words, as a badge. An id names the one a
332 * live script repaints as a run finishes (`studioRunJs`). `cancelled` draws
333 * the same quiet, secondary look as `waiting` and `planned` — a restart is
334 * never the danger red a real failure earns. */
357 * live script repaints as a run finishes (`studioRunJs`). */
335358 export function wordBadge(word: Word, id?: string): Html {
336 const variant =
337 word === "look" || word === "shipped" || word === "done"
338 ? "success"
339 : word === "stopped"
340 ? "danger"
341 : word === "working"
342 ? "accent"
343 : "secondary";
344359 return html`<span
345360 class="badge"
346 data-variant="${variant}"
361 data-variant="${wordVariant(word)}"
347362 data-word="${word}"
348363 ${id === undefined ? null : html`id="${id}"`}
349364 >${word === "working" ? icon("loader") : null}${word}</span
350365 >`;
351366 }
352367
368 /** Why an app that runs on its own is not running right now, in words —
369 * the app page's *On its own* card and the board's *Today* row both. */
370 export function pausedWords(paused: Paused): string {
371 switch (paused) {
372 case "ceiling":
373 return "at the ceiling, until 00:00 UTC";
374 case "forge ceiling":
375 return "at the forge's ceiling, until 00:00 UTC";
376 case "nobody":
377 return "nobody turned it on";
378 case "no crew":
379 return "no crew";
380 }
381 }
382
353383 // ---- what a subscription has left, and what a change costs ----
354384
355385 /** One figure as a person reads it, and whether the forge worked it out
test/board.test.ts +170 −2
@@ -2,13 +2,14 @@
22 * The board: a live wall of the crews at work. Signed in, four live
33 * regions; a run in flight and a merged pull on it; `?apps=` narrows it;
44 * `?wall` is its wall mode, where every old `/big` address lands;
5 * anonymous is sent to sign in.
5 * anonymous is sent to sign in. Its words are the studio's own.
66 */
77 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
88 import { mkdtemp, rm } from "node:fs/promises";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
1111 import { createApp, type App } from "../src/app.ts";
12 import { AppsRuntime } from "../src/apps/runtime.ts";
1213 import { enableApp } from "../src/actions/apps.ts";
1314 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1415 import { openIssue } from "../src/actions/issues.ts";
@@ -226,8 +227,11 @@ describe("the board", () => {
226227 html.indexOf('id="working"'),
227228 html.indexOf('id="landed"'),
228229 );
230 // In the studio's words (`runWord`): in flight is *working*, queued
231 // is *waiting* — the board has no words of its own.
229232 expect(working).toContain('data-state="working"');
230 expect(working).toContain('data-state="queued"');
233 expect(working).toContain('data-state="waiting"');
234 expect(working).not.toContain('data-state="queued"');
231235 expect(working.indexOf("on the cart")).toBeLessThan(
232236 working.indexOf("Make the notes page load"),
233237 );
@@ -328,6 +332,170 @@ describe("the board", () => {
328332 });
329333 });
330334
335 describe("the board speaks the studio's words", () => {
336 let dataDir: string;
337 let app: App;
338 let servers: Servers;
339 let runtime: AppsRuntime;
340 let cookie: string;
341
342 const board = async () =>
343 (
344 await fetch(`${servers.url}/board`, {
345 headers: { cookie },
346 redirect: "manual",
347 })
348 ).text();
349 const between = (html: string, from: string, to: string) =>
350 html.slice(html.indexOf(`id="${from}"`), html.indexOf(`id="${to}"`));
351
352 /** Production at this commit, as the runtime would report it — the same
353 * stand-in `test/studio.test.ts` uses for its words. */
354 const serving = (appId: string, commitOid: string): void => {
355 const envs = (runtime as unknown as { envs: Map<string, unknown> }).envs;
356 const record = { id: appId };
357 envs.set(`${appId}/production`, {
358 app: record,
359 env: "production",
360 chain: Promise.resolve(),
361 restarts: [],
362 live: {
363 commitOid,
364 handle: { port: 4321 },
365 runId: "fake",
366 since: new Date().toISOString(),
367 manifest: { tty: null },
368 },
369 });
370 };
371
372 beforeAll(async () => {
373 dataDir = await mkdtemp(join(tmpdir(), "forge-board-words-"));
374 app = createApp({ dataDir, port: 0 });
375 servers = await serve(app);
376 // Never started: nothing deploys on its own, so production stands
377 // exactly where `serving` puts it.
378 runtime = new AppsRuntime(app, {
379 domain: "board-words.test",
380 scheme: "http",
381 publicPort: servers.port,
382 forgeUrl: servers.url,
383 concurrency: 1,
384 });
385 const a = await createUser(app.db, {
386 username: "alice",
387 email: "[email protected]",
388 password: "a-good-passphrase",
389 adminIfFirst: true,
390 });
391 if (!a.ok) throw new Error(a.error);
392 cookie = (
393 (
394 await fetch(`${servers.url}/signin`, {
395 method: "POST",
396 body: new URLSearchParams({
397 username: "alice",
398 password: "a-good-passphrase",
399 }),
400 redirect: "manual",
401 })
402 ).headers.get("set-cookie") ?? ""
403 ).split(";")[0]!;
404 }, 30_000);
405
406 afterAll(async () => {
407 servers.stop();
408 app.close();
409 await rm(dataDir, { recursive: true, force: true });
410 });
411
412 test("a merge production has not served is not shipped; a run in flight is working; the regions are as they were", async () => {
413 const alice = getUserByName(app.db, "alice")!;
414 const made = await createRepo(app, alice, { name: "notes" });
415 if (!made.ok) throw new Error(String(made.error));
416 const repo = made.value;
417 const seeded = await commitToBranch(app, alice, repo, {
418 message: "Start",
419 files: [{ path: "README.md", content: "start\n" }],
420 });
421 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
422 const enabled = await enableApp(app, alice, repo, { slug: "notes" });
423 if (!enabled.ok) throw new Error(String(enabled.error));
424 const record = getAppByRepo(app.db, repo.id)!;
425
426 const branch = await commitToBranch(app, alice, repo, {
427 branch: "feature/fast",
428 base: "main",
429 message: "Faster",
430 files: [{ path: "FAST.md", content: "fast\n" }],
431 });
432 if (!branch.ok) throw new Error(JSON.stringify(branch.error));
433 const opened = await openPull(app, alice, repo, {
434 title: "Faster notes",
435 body: "",
436 baseBranch: "main",
437 headBranch: "feature/fast",
438 });
439 if (!opened.ok) throw new Error(String(opened.error));
440 recordDecision(app.db, {
441 kind: "land",
442 repoId: repo.id,
443 issueId: opened.value.id,
444 state: {},
445 answer: "ship",
446 p: 0.9,
447 by: "typesafe",
448 ms: 1,
449 });
450 const merged = await mergePull(app, alice, repo, opened.value, "squash");
451 if (!merged.ok) throw new Error(JSON.stringify(merged.error));
452 const pull = getPull(app.db, repo.id, opened.value.number)!;
453 const run = createRun(app.db, {
454 repoId: repo.id,
455 kind: "agent",
456 reason: "feedback",
457 summary: "on the list",
458 });
459 claimRun(app.db, run.id);
460
461 // Production is still on the commit before the merge.
462 serving(record.id, seeded.value.commitOid);
463 const before = await board();
464 const landed = between(before, "landed", "decided");
465 expect(landed).toContain("Faster notes");
466 expect(landed).toMatch(/data-word="waiting"\s+data-variant="secondary"/);
467 expect(landed).not.toContain('data-word="shipped"');
468 // The ledger wrote *shipped* at the merge; the board does not repeat it.
469 const decided = between(before, "decided", "today");
470 expect(decided).toContain("ship or show");
471 expect(decided).toContain('data-word="waiting"');
472 expect(decided).not.toContain(">shipped<");
473 expect(decided).not.toContain("data-outcome");
474 const working = between(before, "working", "landed");
475 expect(working).toMatch(
476 /data-state="working"\s+data-variant="accent"/,
477 );
478 expect(working).toContain("on what you said");
479 // The regions themselves are as they were.
480 expect(before).toMatch(/id="working"\s+data-live="run\.\*"/);
481 expect(before).toMatch(
482 /id="landed"\s+data-live="pull\.merged,run\.finished"/,
483 );
484 expect(before).toMatch(/id="decided"\s+data-live="run\.\*,pull\.\*"/);
485 expect(before).toMatch(/id="today"\s+data-live="run\.\*,pull\.merged"/);
486
487 // Production caught up with the merge: shipped, in both lists.
488 serving(record.id, pull.mergedOid!);
489 const after = await board();
490 expect(between(after, "landed", "decided")).toMatch(
491 /data-word="shipped"\s+data-variant="success"/,
492 );
493 expect(between(after, "decided", "today")).toContain(
494 'data-word="shipped"',
495 );
496 });
497 });
498
331499 describe("the board's forge strip", () => {
332500 let dataDir: string;
333501 let app: App;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs