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

A client's first page shows each of their apps with the crew's current line in plain words #14173

Merged opened this

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

Merged

mason/forge:mason/14100-a-client-s-first-page-shows-each-of-thei → main 7 commits fork 3 threads · 3 unresolved

  • Merged. mason/14100-a-client-s-first-page-shows-each-of-thei was merged into main as 2af6df6.

Review

Sign in to review this change.
14 files changed +221 −83
docs/design/areas/tell.md +11 −3
@@ -16,9 +16,17 @@ shifts and Enter sends it with the page's path as `from`. Any failure falls back
1616 ## Client home: `client-app-finished`
1717
1818 A muted line on a client's app row, `Finished <time>: <title>`, for the app's
19 newest merged pull. It sits with `client-app-about`, `client-app-agents` and
20 `client-app-doing`; it uses `muted` and adds no colour or size. The
21 terminal says the same words.
19 newest merged pull. It sits with `client-app-line` and `client-app-about`; it uses `muted` and
20 adds no colour or size. The terminal says the same words.
21
22 ## Client home: `client-app-line`
23
24 The one bold sentence under an app's name on a client's home: `Building: <title>`, `Waiting for your
25 answer`, `About to start` or `Nothing in progress` (`src/actions/client_line.ts`). It replaces the
26 former `client-app-agents` and `client-app-doing` lines, so an app row is name, sentence, about,
27 and the muted `Finished` line: no third status line (principles 1, 7). It is a `<b>` in a span
28 with no colour, size or margin of its own, so it adds no layout shift. The terminal says the same
29 sentence after the app's name.
2230
2331 ## App page: the tell line
2432
docs/features/README.md +1
@@ -345,6 +345,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide-
345345 - [A claimed child receives the credential to propose back to its parent](child-proposal-credential.md)
346346 - [A client's monthly bill](forge-bill.md)
347347 - [A forge for a client, from one link](client-forge.md)
348 - [The sentence under each of a client's apps, on the page, in the terminal and in forge_view](client-app-line.md)
348349 - [The client list's three times: sent, opened, first tell](client-link-times.md)
349350 - [A forge whose billing is none](lapsed-forge.md)
350351 - [A forge's claim link as a QR in the terminal](forge-link-qr.md)
docs/features/client-app-line.md added +19
@@ -0,0 +1,19 @@
1 # The sentence under each app
2
3 A client's first page (`/`) shows each of their apps with one plain sentence about what its crew
4 is doing now. The forge's terminal dashboard says the same sentence after the app's name
5 (`bakery: Building: the booking form.`), and the MCP `forge_view` answer carries it as `line` on
6 each app.
7
8 - `Building: <title>` while the crew is running work on the app; the title is cut and cleaned of
9 developer words.
10 - `Waiting for your answer` when the crew has finished something that waits for a person.
11 - `About to start` when work is lined up and nothing runs yet.
12 - `Nothing in progress` otherwise.
13
14 One module words it, `src/actions/client_line.ts` (`clientLines`: three reads for any number of
15 apps, plus the review waits); the page, the terminal and `forge_view` all call it, so they cannot
16 disagree (`test/client-home.test.ts`, `test/client-line.test.ts`).
17
18 To try it: sign in through a client's claim link and read the line under each app; in the
19 terminal, open the dashboard; or call `forge_view` and read `apps[].line`.
src/actions/client_line.ts added +64
@@ -0,0 +1,64 @@
1 /**
2 * The one plain sentence about what an app's crew is doing now, for a person who is not a
3 * developer: "Building: the booking form", "Waiting for your answer", "About to start" or
4 * "Nothing in progress". The client's first page and the MCP `forge_view` answer both read it, so
5 * the two say the same thing. Plain data in, plain data out; no developer word is in the template.
6 */
7 import type { Database } from "bun:sqlite";
8 import { plainWords } from "../core/app-crew.ts";
9 import { cutTitle, clientDoings } from "../core/client-apps.ts";
10 import { listOpenPullsOf } from "../core/issues.ts";
11 import { joinMany } from "../core/pulls.ts";
12 import type { Repo } from "../core/repos.ts";
13 import { reviewWaitsFor } from "../crew/review.ts";
14
15 export const IDLE_LINE = "Nothing in progress";
16 export const WAITING_LINE = "Waiting for your answer";
17 export const QUEUED_LINE = "About to start";
18
19 /** What is in hand on an app, as counts and the running title: the sentence's whole input. */
20 export interface CrewState {
21 readonly title: string | undefined;
22 readonly waitingOnPerson: boolean;
23 readonly queued: boolean;
24 }
25
26 /** The sentence for one app's state; the running work comes first, then a wait on the person. */
27 export function lineFor(state: CrewState): string {
28 if (state.title !== undefined) {
29 const said = cutTitle(plainWords(state.title).replace(/\(\s*\)/g, ""));
30 return said === "" ? "Building something new" : `Building: ${said}`;
31 }
32 if (state.waitingOnPerson) return WAITING_LINE;
33 return state.queued ? QUEUED_LINE : IDLE_LINE;
34 }
35
36 /** One sentence for each of `repos`, in two reads for the whole set plus the review waits. */
37 export function clientLines(db: Database, repos: readonly Repo[]): Map<string, string> {
38 const out = new Map<string, string>();
39 if (repos.length === 0) return out;
40 const ids = repos.map((r) => r.id);
41 const doing = clientDoings(db, ids);
42 const marks = ids.map((_, i) => `?${i + 1}`).join(",");
43 const queued = new Set(
44 db
45 .query<{ repo_id: string }, string[]>(
46 `SELECT DISTINCT repo_id FROM run WHERE kind = 'agent' AND state = 'queued' AND repo_id IN (${marks})`,
47 )
48 .all(...ids)
49 .map((r) => r.repo_id),
50 );
51 const byId = new Map(repos.map((r) => [r.id, r]));
52 const pulls = joinMany(db, listOpenPullsOf(db, ids)).flatMap((pull) => {
53 const repo = byId.get(pull.repoId);
54 return repo === undefined ? [] : [{ repo, pull }];
55 });
56 const waits = reviewWaitsFor(db, pulls);
57 const waiting = new Set(pulls.filter((p) => waits.get(p.pull.id)?.person !== undefined).map((p) => p.repo.id));
58 for (const repo of repos)
59 out.set(
60 repo.id,
61 lineFor({ title: doing.get(repo.id)?.title, waitingOnPerson: waiting.has(repo.id), queued: queued.has(repo.id) }),
62 );
63 return out;
64 }
src/actions/forge_view.ts +6 −3
@@ -12,6 +12,7 @@ import type { App } from "../app.ts";
1212 import type { User } from "../core/users.ts";
1313 import type { Ctx } from "../http/context.ts";
1414 import { appsOf } from "../web/studio/asks.ts";
15 import { clientLines, IDLE_LINE } from "./client_line.ts";
1516 import { crewNow } from "./crew_now.ts";
1617 import { readHealth } from "./health.ts";
1718
@@ -23,7 +24,7 @@ type Row = ReturnType<typeof crewNow>[number];
2324
2425 export interface ForgeView {
2526 readonly counts: { apps: number; running: number; queued: number; waiting: number };
26 readonly apps: readonly { app: string; slug: string; access: string; running: number; queued: number }[];
27 readonly apps: readonly { app: string; slug: string; access: string; line: string; running: number; queued: number }[];
2728 readonly runs: readonly Row[];
2829 readonly health: unknown;
2930 }
@@ -46,11 +47,13 @@ export function forgeView(ctx: Pick<Ctx, "app">, user: User): ForgeView {
4647 else t.queued++;
4748 tally.set(r.app, t);
4849 }
49 const apps = repos.slice(0, VIEW_APPS).map((repo) => {
50 const shown = repos.slice(0, VIEW_APPS);
51 const lines = clientLines(ctx.app.db, shown);
52 const apps = shown.map((repo) => {
5053 const name = `${repo.ownerName}/${repo.name}`;
5154 const record = records.get(repo.id)!;
5255 const t = tally.get(name) ?? { running: 0, queued: 0 };
53 return { app: name, slug: record.slug, access: record.access, ...t };
56 return { app: name, slug: record.slug, access: record.access, line: lines.get(repo.id) ?? IDLE_LINE, ...t };
outdated

An empty-string fallback can ship a blank line to MCP clients; use IDLE_LINE or fail loudly.

5457 });
5558 return {
5659 counts: {
src/core/client-apps.ts −6
@@ -134,12 +134,6 @@ export function cutTitle(title: string): string {
134134 return `${(space > 0 ? head.slice(0, space) : head).trimEnd()}…`;
135135 }
136136
137 /** The sentence about what an app's agents are on, or "" when none is running. */
138 export function doingLine(doing: ClientDoing | undefined): string {
139 const title = doing === undefined ? "" : cutTitle(doing.title);
140 return title === "" ? "" : `Working on: ${title}`;
141 }
142
143137 /**
144138 * `Finished 3 days ago: Fix the menu`, or "" for an app with nothing finished; both doors word it
145139 * so.
src/core/issues.ts +12
@@ -284,6 +284,18 @@ export function listOpenPullsVisibleTo(
284284 .map(toIssue);
285285 }
286286
287 /** Open pulls in the given repositories (ids already checked by the caller), lean rows. */
288 export function listOpenPullsOf(db: Database, repoIds: readonly string[]): Issue[] {
289 if (repoIds.length === 0) return [];
290 return db
291 .query<IssueRow, string[]>(
292 `${SELECT_LEAN} WHERE issue.kind = 'pull' AND issue.state = 'open'
293 AND issue.repo_id IN (${repoIds.map((_, i) => `?${i + 1}`).join(",")})`,
294 )
295 .all(...repoIds)
296 .map(toIssue);
297 }
298
287299 /**
288300 * Open conversations assigned to one account, across every repository —
289301 * the "on you" list. An assignee can always see what is assigned to them:
src/tui/screens/dashboard.ts +5 −10
@@ -24,14 +24,14 @@ import { forgeFlakes, forgeLane, forgeNeedList, needTermLine } from "../../actio
2424 import { ownerWaits, waitLine, withMore } from "../../actions/owner_waits.ts";
2525 import { forgeHealth } from "../../kernel/guard.ts";
2626 import { coveredByVerdict, forgeVerdict, verdictLine } from "../../kernel/guard_verdict.ts";
27 import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts";
27 import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts";
2828 import { appCrew } from "../../core/app-crew.ts";
2929 import { nextStepsFor } from "../../core/next-steps.ts";
3030 import { askRepos, askStatus, askStatusLine } from "../../core/ask-status.ts";
3131 import { AUTONOMY_FAILED_WORDS, firstAsk } from "../../actions/first_ask.ts";
3232 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
3333 import { crewCanRun, crewFirstText } from "../../web/studio/crew_key.ts";
34 import { agentsLine } from "../../web/studio/client_home.ts";
34 import { clientLines as crewSentences, IDLE_LINE } from "../../actions/client_line.ts";
3535 import { lastVisit } from "../../core/home_visit.ts";
3636 import { quietFor, quietText } from "../../web/studio/home_empty.ts";
3737 import { firstWeekText } from "../../web/first_week.ts";
@@ -393,7 +393,7 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
393393 const now = new Date();
394394 const ids = apps.map((a) => a.repo.id);
395395 const crewOf = new Map(appCrew(f.app.db, apps.map((a) => a.repo)).map((c) => [c.repo.id, c] as const));
396 const doings = clientDoings(f.app.db, ids);
396 const sentences = crewSentences(f.app.db, apps.map((a) => a.repo));
397397 const finished = clientFinished(f.app.db, ids);
398398 const mine = await askRepos(f.app, f.user);
399399 const asked = askStatus(f.app.db, mine, f.user.id, crewCanRun(f.app), f.user.isAdmin === true);
@@ -401,14 +401,9 @@ export function dashboardScreen(f: Session, ctx: Ctx): Screen {
401401 apps.length === 0
402402 ? ["Your apps will appear here."]
403403 : apps.map((a) => {
404 const doing = [
405 finishedLine(finished.get(a.repo.id), now.getTime()),
406 doingLine(doings.get(a.repo.id)),
407 ]
408 .filter((x) => x !== "")
409 .join(" ");
404 const doing = finishedLine(finished.get(a.repo.id), now.getTime());
410405 const mark = a.live === undefined ? "" : " (running, o opens it)";
411 const line = `${a.repo.name}${mark}: ${agentsLine(a.working, a.queued)}`;
406 const line = `${a.repo.name}${mark}: ${sentences.get(a.repo.id) ?? IDLE_LINE}.`;
412407 const crew = crewOf.get(a.repo.id)!.says;
413408 return `${line}${doing === "" ? "" : ` ${doing}`} ${crew[0]!.toUpperCase()}${crew.slice(1)}.`;
414409 });
src/web/studio/client_home.ts +7 −22
@@ -1,13 +1,14 @@
11 /**
22 * A client's first screen (#1812): signed in on a forge that was made for
3 * them, the home is their apps, each in one plain sentence and one more that
4 * says whether its agents are working or waiting. No map, board or settings
3 * them, the home is their apps, each with one plain sentence on what its crew is doing
4 * (`src/actions/client_line.ts`). No map, board or settings
55 * until asked (`/?all=1` is the whole home). Words only a developer knows
66 * stay off it; `test/client-home.test.ts` holds the list.
77 */
88
9 import { clientLines } from "../../actions/client_line.ts";
910 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
10 import { clientAppRows, clientDoings, clientFinished, doingLine, finishedLine } from "../../core/client-apps.ts";
11 import { clientAppRows, clientFinished, finishedLine } from "../../core/client-apps.ts";
1112 import type { User } from "../../core/users.ts";
1213 import type { Ctx } from "../../http/context.ts";
1314 import { mayDirectCrew } from "../../crew/direct.ts";
@@ -15,30 +16,17 @@ import { repoBase } from "../chrome.ts";
1516 import { html, type Html } from "../html.ts";
1617 import { btn, card } from "../ui.ts";
1718
18 /** The sentence about the agents, from how many are going and how many are lined up. */
19 export function agentsLine(working: number, queued: number): string {
20 if (working > 0)
21 return working === 1
22 ? "One agent is working on it now."
23 : `${working} agents are working on it now.`;
24 if (queued > 0) return "Its agents are about to start.";
25 return "Its agents are waiting for something to do.";
26 }
27
2819 /** The card of apps; an empty one says they will appear. The caller decides who is a client. */
2920 export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
3021 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
3122 const apps = await timePhaseAsync(ctx.request, "apps", () => clientAppRows(ctx.app, user));
3223 const now = new Date();
33 const doings = timePhase(ctx.request, "doing", () =>
34 clientDoings(ctx.app.db, apps.map((a) => a.repo.id)),
35 );
3624 const finished = timePhase(ctx.request, "finished", () =>
3725 clientFinished(ctx.app.db, apps.map((a) => a.repo.id)),
3826 );
27 const lines = timePhase(ctx.request, "line", () => clientLines(ctx.app.db, apps.map((a) => a.repo)));
3928 const rendering = performance.now();
40 const rows = apps.map(({ repo, working, queued, live }) => {
41 const doing = doingLine(doings.get(repo.id));
29 const rows = apps.map(({ repo, live }) => {
4230 const done = finishedLine(finished.get(repo.id), now.getTime());
4331 const about = repo.description !== "" ? repo.description : "An app of yours.";
4432 // The tell form with this app chosen; it sends the person back to `/`.
@@ -59,12 +47,9 @@ export async function clientApps(ctx: Ctx, user: User): Promise<Html> {
5947 <div class="bar">
6048 <a href="${repoBase(repo)}"><b>${repo.name}</b></a> ${open} ${ask}
6149 </div>
50 <span class="client-app-line"><b>${lines.get(repo.id) ?? ""}</b></span>
6251 <span class="client-app-about">${about}</span>
63 <span class="client-app-agents muted" data-agents="${working > 0 ? "working" : "waiting"}"
64 >${agentsLine(working, queued)}</span
65 >
6652 ${done !== "" ? html`<span class="client-app-finished muted">${done}</span>` : ""}
67 ${doing !== "" ? html`<span class="client-app-doing muted">${doing}</span>` : ""}
6853 </li>`;
6954 });
7055 const shown = card(
test/api-forge-view.test.ts +4 −2
@@ -153,11 +153,13 @@ describe("the forge view over the API", () => {
153153 (app.db as unknown as { query: unknown }).query = original;
154154 }
155155 expect(view.counts.apps).toBe(APPS);
156 expect(view.apps.every((a) => a.line !== "")).toBe(true);
156157 expect(view.apps.length).toBeLessThanOrEqual(VIEW_APPS);
157158 expect(view.runs.filter((r) => r.run !== null).length).toBeLessThanOrEqual(50);
158159 // 120 apps, 960 runs. `mayReadRuns` (shared with /crew/now) reads two
159 // rows per app today; anything beyond that, or a read per run, fails.
160 expect(selects.length).toBeLessThanOrEqual(2 * APPS + 20);
160 // rows per app today, 20 fixed reads before the crew sentences and 3 for them (running work,
161 // queued runs, open pulls); anything beyond that, or a read per run, fails.
162 expect(selects.length).toBeLessThanOrEqual(2 * APPS + 23);
outdated

Loosened budget; comment says 5 reads, pull says 3. Tighten to the measured number.

161163 });
162164
163165 test("foundry has a door only for an app an admin or the forge's org owns", async () => {
test/client-apps.test.ts +1 −5
@@ -1,7 +1,7 @@
11 /** What a client's apps are doing: the work running, else what was last finished (#4007, #6091). */
22 import { beforeEach, describe, expect, test } from "bun:test";
33 import type { Database } from "bun:sqlite";
4 import { clientDoings, clientFinished, doingLine, finishedLine } from "../src/core/client-apps.ts";
4 import { clientDoings, clientFinished, finishedLine } from "../src/core/client-apps.ts";
55 import { migrations } from "../src/core/schema.ts";
66 import { openDb } from "../src/kernel/db.ts";
77
@@ -76,8 +76,4 @@ describe("the lines", () => {
7676 expect(finishedLine(undefined, NOW.getTime())).toBe("");
7777 });
7878
79 test("doingLine says Working on, or nothing", () => {
80 expect(doingLine({ title: "Add rye" })).toBe("Working on: Add rye");
81 expect(doingLine(undefined)).toBe("");
82 });
8379 });
test/client-home.test.ts +43 −32
@@ -17,7 +17,8 @@ import { AppsRuntime } from "../src/apps/runtime.ts";
1717 import { getAppByRepo } from "../src/core/apps.ts";
1818 import { clientApps } from "../src/web/studio/client_home.ts";
1919 import type { Ctx } from "../src/http/context.ts";
20 import { clientAppRows, cutTitle, doingLine } from "../src/core/client-apps.ts";
20 import { forgeView } from "../src/actions/forge_view.ts";
21 import { clientAppRows, cutTitle } from "../src/core/client-apps.ts";
2122 import { addCrew, createAgentRow } from "../src/core/agents.ts";
2223 import { moveArchived } from "../src/core/repos.ts";
2324 import { createSession } from "../src/core/sessions.ts";
@@ -171,12 +172,14 @@ describe("a client's first screen", () => {
171172 .replace(/<[^>]*>/g, " ")
172173 .replace(/\s+/g, " ");
173174
174 test("the home is their apps, each a sentence and a line on its agents, with no map, board or settings", async () => {
175 test("the home is their apps, each with one sentence on its crew, with no map, board or settings", async () => {
175176 const home = main(await page(owner));
176177 const apps = home.slice(home.indexOf('id="client-apps"'));
177178 expect(apps).toContain('href="/marias/bakery"');
178 expect(apps).toMatch(/data-agents="(working|waiting)"/);
179 expect(apps).toContain("agents are waiting");
179 expect(apps).toContain('client-app-line"><b>Nothing in progress</b>');
180 expect(apps).not.toContain("agents are");
181 expect(apps).not.toContain("Working on");
182 expect(words(apps)).not.toMatch(/\b(pull|check|run|gate)\b/i);
180183 expect(home).not.toContain('id="live-chips"');
181184 for (const gone of ['href="/map"', 'href="/board"', 'href="/audit"', 'href="/settings"'])
182185 expect(home).not.toContain(gone);
@@ -299,7 +302,7 @@ describe("a client's first screen", () => {
299302 );
300303 stopped.app.start();
301304 await settleApp(stopped.app);
302 expect(stopped.app.screen.toText()).toContain("bakery: Its agents");
305 expect(stopped.app.screen.toText()).toContain("bakery: Nothing in progress");
303306 expect(stopped.app.screen.toText()).not.toContain("running");
304307 idle.feed("o");
305308 await settleApp(stopped.app);
@@ -330,31 +333,42 @@ describe("a client's first screen", () => {
330333 app.stop();
331334 });
332335
333 test("a running agent turns the line to working", async () => {
334 const repo = child.db
335 .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'")
336 .get()!;
336
337 /**
338 * A running agent run on an open issue of the bakery: the one thing the sentence says it builds.
339 */
340 const startBuilding = (runId: string): void => {
341 const repo = child.db.query<{ id: string; owner_id: string }, []>("SELECT id, owner_id FROM repo WHERE name = 'bakery'").get()!;
337342 child.db
338 .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-1', ?1, 'agent', 'running')")
339 .run(repo.id);
343 .query("INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state) VALUES ('i-' || ?1, ?2, 9100 + length(?1), 'issue', 'Add rye bread', '', ?3, 'open')")
344 .run(runId, repo.id, repo.owner_id);
345 child.db
346 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES (?1, ?2, 'agent', 'running', 'i-' || ?1)")
347 .run(runId, repo.id);
348 };
349 const stopBuilding = (runId: string): void => {
350 child.db.query("DELETE FROM run WHERE id = ?1").run(runId);
351 child.db.query("DELETE FROM issue WHERE id = 'i-' || ?1").run(runId);
352 };
353
354 test("a running agent turns the line to working", async () => {
355 startBuilding("r-client-1");
340356 const home = await page(owner);
341 expect(home).toContain('data-agents="working"');
342 expect(home).toContain("One agent is working on it now.");
343 child.db.query("DELETE FROM run WHERE id = 'r-client-1'").run();
357 expect(home).toContain('client-app-line"><b>Building: Add rye bread</b>');
358 expect(home).not.toContain("data-agents");
359 // The MCP door reads the same sentence for the same app.
360 const view = forgeView({ app: child }, getUserByName(child.db, "maria")!);
361 expect(view.apps.find((a) => a.app === "marias/bakery")?.line).toBe("Building: Add rye bread");
362 stopBuilding("r-client-1");
344363 });
345364
346365 test("the card refreshes itself: /live/client-apps answers it, to a client only", async () => {
347 const repo = child.db
348 .query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'bakery'")
349 .get()!;
350366 expect(await page(owner)).toContain('data-live-src="/live/client-apps"');
351 child.db
352 .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-2', ?1, 'agent', 'running')")
353 .run(repo.id);
367 startBuilding("r-client-2");
354368 const live = await page(owner, "/live/client-apps");
355369 expect(live).toContain('id="client-apps"');
356 expect(live).toContain("One agent is working on it now.");
357 child.db.query("DELETE FROM run WHERE id = 'r-client-2'").run();
370 expect(live).toContain('client-app-line"><b>Building: Add rye bread</b>');
371 stopBuilding("r-client-2");
358372 expect((await fetch(url("/live/client-apps"))).status).toBe(404);
359373 });
360374
@@ -426,8 +440,7 @@ describe("a client's first screen", () => {
426440 .query("INSERT INTO run (id, repo_id, kind, state) VALUES ('r-client-2', ?1, 'agent', 'queued')")
427441 .run(repo.id);
428442 const home = await page(owner);
429 expect(home).toContain("Its agents are about to start.");
430 expect(home).toContain('data-agents="waiting"');
443 expect(home).toContain('client-app-line"><b>About to start</b>');
431444 child.db.query("DELETE FROM run WHERE id = 'r-client-2'").run();
432445 });
433446
@@ -459,7 +472,7 @@ describe("a client's first screen", () => {
459472 );
460473 app.start();
461474 await settleApp(app);
462 expect(app.screen.toText()).toContain("bakery: Its agents are waiting for something to do.");
475 expect(app.screen.toText()).toContain("bakery: Nothing in progress.");
463476 expect(app.screen.toText()).toMatch(/Atlas is ready to work toward Run Maria/);
464477 expect(app.screen.toText()).not.toContain("Shipped per hour");
465478 app.stop();
@@ -536,7 +549,7 @@ describe("a client's first screen", () => {
536549
537550 test("a quiet app gets no extra line", async () => {
538551 clean();
539 expect(await row()).not.toContain("client-app-doing");
552 expect(await row()).toContain("Nothing in progress");
540553 });
541554
542555 test("work running now reads Working on, escaped", async () => {
@@ -546,7 +559,7 @@ describe("a client's first screen", () => {
546559 .query("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r-doing-1', ?1, 'agent', 'running', 'i-doing-1')")
547560 .run(ids().repo.id);
548561 const r = await row();
549 expect(r).toContain("Working on: Add &lt;b&gt;rye&lt;/b&gt; bread");
562 expect(r).toContain("Building: Add &lt;b&gt;rye&lt;/b&gt; bread");
550563 expect(r).not.toContain("<b>rye");
551564 clean();
552565 });
@@ -562,7 +575,6 @@ describe("a client's first screen", () => {
562575 expect(r).toContain("3 days ago");
563576 expect(r).toContain("Fix the menu");
564577 expect(r).not.toContain("Last change");
565 expect(r).not.toContain("client-app-doing");
566578 clean();
567579 });
568580
@@ -596,10 +608,10 @@ describe("a client's first screen", () => {
596608 clean();
597609 });
598610
599 test("the read is its own doing phase beside apps", async () => {
611 test("the read is its own line phase beside apps", async () => {
600612 const res = await fetch(url("/"), { headers: { cookie: owner } });
601613 const timing = res.headers.get("server-timing") ?? "";
602 expect(timing).toMatch(/\bdoing;/);
614 expect(timing).toMatch(/\bline;/);
603615 expect(timing).toMatch(/\bapps;/);
604616 });
605617
@@ -617,7 +629,7 @@ describe("a client's first screen", () => {
617629 );
618630 app.start();
619631 await settleApp(app);
620 expect(app.screen.toText()).toContain("Working on: Add rye bread");
632 expect(app.screen.toText()).toContain("bakery: Building: Add rye bread.");
621633 app.stop();
622634 clean();
623635 });
@@ -650,7 +662,6 @@ describe("a client's first screen", () => {
650662 expect(cut.endsWith("word…")).toBe(true);
651663 expect(cutTitle("short title")).toBe("short title");
652664 expect(cutTitle("x".repeat(200))).toBe(`${"x".repeat(79)}…`);
653 expect(doingLine(undefined)).toBe("");
654665 });
655666 });
656667 });
test/client-line.test.ts added +42
@@ -0,0 +1,42 @@
1 /**
2 * The plain sentence about an app's crew (#14100): one running app, one idle, no developer words.
3 */
4 import { beforeEach, describe, expect, test } from "bun:test";
5 import type { Database } from "bun:sqlite";
6 import { clientLines, IDLE_LINE, lineFor, QUEUED_LINE, WAITING_LINE } from "../src/actions/client_line.ts";
7 import type { Repo } from "../src/core/repos.ts";
8 import { migrations } from "../src/core/schema.ts";
9 import { openDb } from "../src/kernel/db.ts";
10
11 let db: Database;
12 const repo = (id: string): Repo => ({ id }) as Repo;
13
14 beforeEach(() => {
15 db = openDb(":memory:", migrations);
16 db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u','u','u@x','x')");
17 for (const r of ["busy", "idle", "next"]) db.run("INSERT INTO repo (id, owner_id, name) VALUES (?, 'u', ?)", [r, r]);
18 });
19
20 describe("the sentence", () => {
21 test("a running app says Building, an idle one says Nothing in progress, in words a client reads", () => {
22 db.run("INSERT INTO issue (id, repo_id, number, kind, title, author_id, state) VALUES ('i1','busy',1,'issue','the booking form (see PR #42)','u','open')");
23 db.run("INSERT INTO run (id, repo_id, kind, state, issue_id) VALUES ('r1','busy','agent','running','i1')");
24 db.run("INSERT INTO run (id, repo_id, kind, state) VALUES ('r2','next','agent','queued')");
25 const lines = clientLines(db, [repo("busy"), repo("idle"), repo("next")]);
26 expect(lines.get("busy")).toBe("Building: the booking form");
27 expect(lines.get("idle")).toBe("Nothing in progress");
28 expect(lines.get("next")).toBe(QUEUED_LINE);
29 for (const line of lines.values()) expect(line).not.toMatch(/\b(pull|check|run|gate)\b/i);
30 });
31
32 test("work running wins over a wait; a wait on the person is said plainly", () => {
33 expect(lineFor({ title: undefined, waitingOnPerson: true, queued: true })).toBe(WAITING_LINE);
34 expect(lineFor({ title: "Menu", waitingOnPerson: true, queued: false })).toBe("Building: Menu");
35 expect(lineFor({ title: undefined, waitingOnPerson: false, queued: false })).toBe(IDLE_LINE);
36 expect(lineFor({ title: "#7", waitingOnPerson: false, queued: false })).toBe("Building something new");
37 });
38
39 test("no apps, no sentences", () => {
40 expect(clientLines(db, []).size).toBe(0);
41 });
42 });
test/crew-now-review-waits.test.ts +6
@@ -13,6 +13,7 @@ import { reviewed } from "../src/crew/autonomy.ts";
1313 import { reviewWaitsFor } from "../src/crew/review.ts";
1414 import { getRepoById } from "../src/core/repos.ts";
1515 import { getPull } from "../src/core/pulls.ts";
16 import { clientLines, WAITING_LINE } from "../src/actions/client_line.ts";
1617 import { crewNow } from "../src/actions/crew_now.ts";
1718 import { createAgent } from "../src/actions/crew.ts";
1819 import { openPull } from "../src/actions/pulls.ts";
@@ -121,6 +122,11 @@ describe("crewNow's review waits", () => {
121122 expect(nine.statements).toBe(one.statements);
122123 }, 30_000);
123124
125 test("a client's sentence for the app says Waiting for your answer while a green pull waits for a person", async () => {
126 await greenAgentPull();
127 expect(clientLines(app.db, [repo]).get(repo.id)).toBe(WAITING_LINE);
128 });
129
124130 test("in a repository with reviews off, a green agent pull waits on nobody and the gate passes it (#11666)", async () => {
125131 const made = await createRepo(app, ada, { name: "meadow", visibility: "private" });
126132 if (!made.ok) throw new Error(String(made.error));

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs