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

A crew with builders and no reviewer says so loudly: settings, the tick line and the crew page #16842

Merged opened this in answer to

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

Merged

scout/forge:scout/3512-a-crew-with-builders-and-no-reviewer-say → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/3512-a-crew-with-builders-and-no-reviewer-say was merged into main as 30b53d2.

Review

Sign in to review this change.
6 files changed +252 −3
docs/features/crew-roles.md +1
@@ -11,3 +11,4 @@ An agent declares its **roles** in its own config: any of planner, builder, revi
1111 - **No silent moves.** Taking a role off an agent that still holds that seat on a repository is refused (`role_held`); move it off that repository's team first.
1212 - **A dispatch keeps to the seat.** An assigned issue, feedback, a red check, a conflict, a converge and a resolve run only for a builder (the direction issue only for a planner); a review only for a reviewer. An issue assigned to a planner or reviewer gets one comment saying so.
1313 - **`/migrate`** offers builders only; `crew=<name>` naming anyone else is refused in a sentence and the first builder stays the default.
14 - **No reviewer says so (#3512).** A crew with a builder and no reviewer shows "Nobody reviews this crew's pulls: agent pulls wait for you" on Settings → Crew and in the terminal's About card (a Warning row with the same count), with a *Make <name> the reviewer* button for each member who declares the role (admins only; the terminal's `r` does the same for the first). The autonomy tick line adds `review="no reviewer"` and `waits for a reviewer=N` (open agent pulls). Code: `reviewerGap` in `src/crew/seats.ts`.
src/crew/autonomy_tick.ts +11
@@ -34,6 +34,7 @@ import { sweepRepeats } from "./repeat_checks.ts";
3434 import { moveRequested, tallyRequested, tallyWords } from "./requested.ts";
3535 import { reserveOf, reserveWords } from "./reserve.ts";
3636 import { sweepReviews } from "./review.ts";
37 import { NO_REVIEWER_TICK, reviewerGap } from "./seats.ts";
3738 import { sentinelTick } from "./sentinel.ts";
3839 import { closedToday } from "./stale_pulls.ts";
3940 import { sweepStaleReds } from "./stale_reds.ts";
@@ -206,6 +207,8 @@ export async function autonomyTick(
206207 // The standing reserve the planner keeps: startable/target (#3237).
207208 reserve: reserveWords(reserveOf(held.startable.length, status.slots)),
208209 held: heldWords(held),
210 // A crew with builders and no reviewer says so, and counts the pulls that wait (#3512).
211 ...noReviewerFields(app, current),
209212 // What the picker passes over among the startable, so no ready issue goes unexplained
210213 // (#8924).
211214 passed: passedWords(pickFilter(app, current, held.startable, now).passed),
@@ -285,3 +288,11 @@ export function flowVitals(db: App["db"], now: Date, dataDir?: string): { pulls:
285288 const misses = vitalsMisses(v);
286289 return { pulls: vitalsWords(v), ...(misses.length === 0 ? {} : { offTarget: misses.join("; ") }) };
287290 }
291
292 /**
293 * `review="no reviewer" waits_for_a_reviewer=3` while the crew has builders and nobody to review.
294 */
295 export function noReviewerFields(app: App, repo: Repo): Record<string, string | number> {
296 const gap = reviewerGap(app.db, repo);
297 return gap === undefined ? {} : { review: NO_REVIEWER_TICK, "waits for a reviewer": gap.waiting };
298 }
src/crew/seats.ts +33
@@ -7,6 +7,7 @@
77
88 import type { Database } from "bun:sqlite";
99 import { listCrewRoles, type CrewRole } from "../core/agents.ts";
10 import { listOpenPulls } from "../core/pulls.ts";
1011 import type { Repo } from "../core/repos.ts";
1112
1213 export type Seat = {
@@ -64,3 +65,35 @@ export function seatsOf(db: Database, repo: Repo, crewOff = false): Seats {
6465 }),
6566 };
6667 }
68
69 /** The warning's words: the crew page, the settings card and the tick line say the same. */
70 export const NO_REVIEWER_WORDS = "Nobody reviews this crew's pulls: agent pulls wait for you.";
71
72 /** The tick line's word for it, and for the pulls that wait. */
73 export const NO_REVIEWER_TICK = "no reviewer";
74
75 export type ReviewerGap = {
76 /** Agent pulls open now, each waiting for a reviewer the crew does not have. */
77 waiting: number;
78 /** Crew members who declare the reviewer role: one click makes any of them the reviewer. */
79 candidates: string[];
80 };
81
82 /**
83 * A crew with builders and no reviewer (#3512), or undefined. Reviews are off and agent pulls
84 * wait for a person; nothing else says so. `candidates` are seated members who declare
85 * `reviewer` and could take the seat.
86 */
87 export function reviewerGap(db: Database, repo: Pick<Repo, "id">): ReviewerGap | undefined {
88 const crew = listCrewRoles(db, repo.id);
89 if (!crew.some((c) => c.role === "builder") || crew.some((c) => c.role === "reviewer")) return undefined;
90 return {
91 waiting: listOpenPulls(db, repo.id).filter((p) => p.authorIsAgent).length,
92 candidates: crew.filter((c) => c.agent.roles.includes("reviewer")).map((c) => c.agent.user.username),
93 };
94 }
95
96 /** The warning with the pulls that wait: the page and the terminal say the same. */
97 export function reviewerGapWords(gap: ReviewerGap): string {
98 return gap.waiting === 0 ? NO_REVIEWER_WORDS : `${NO_REVIEWER_WORDS} ${gap.waiting} wait${gap.waiting === 1 ? "s" : ""} now.`;
99 }
src/tui/screens/about.ts +22 −2
@@ -38,10 +38,10 @@ import { rejoinableParent, rejoinParent, severPreview, undoSever, undoableSever
3838 import { upstreamOffer, type UpstreamOffer } from "../../actions/offer_upstream.ts";
3939 import { listRefs } from "../../git/read.ts";
4040 import { directionNote } from "../../crew/direct.ts";
41 import { seatsOf } from "../../crew/seats.ts";
41 import { reviewerGap, reviewerGapWords, seatsOf } from "../../crew/seats.ts";
4242 import { crewOffInPreview } from "../../crew/preview.ts";
4343 import { addToCrew } from "../../actions/crew.ts";
44 import { listAgents, listCrewRoles } from "../../core/agents.ts";
44 import { listAgents, listCrewRoles, setCrewRole } from "../../core/agents.ts";
4545 import { whyRepo } from "../../flow/why.ts";
4646 import { setCrewOutsiders, updateRepoSettings } from "../../actions/repos.ts";
4747 import { showProvenance } from "../../actions/provenance.ts";
@@ -153,6 +153,10 @@ export function aboutScreen(
153153 return listAgents(f.db).find((a) => a.roles.includes("maintainer") && !held.has(a.user.id));
154154 })();
155155 const mayMaintain = (): boolean => may() && f.user?.kind !== "agent" && nextMaintainer() !== undefined;
156 // The reviewer's seat, the first member who declares it (the settings page's one click).
157 const nextReviewer = (): string | undefined =>
158 repo === undefined ? undefined : reviewerGap(f.db, repo)?.candidates[0];
159 const mayReview = (): boolean => may() && f.user?.kind !== "agent" && nextReviewer() !== undefined;
156160 const mayFill = (): boolean => may() && f.user?.kind !== "agent" && emptySeat() !== undefined;
157161 const checking = (): boolean =>
158162 repo !== undefined && followShown(f.app, repo, f.user)?.enabled === true;
@@ -295,6 +299,7 @@ export function aboutScreen(
295299 ),
296300 ]),
297301 ...(mayFill() ? [binding(["p"], `fill ${emptySeat()!.role}`)] : []),
302 ...(mayReview() ? [binding(["r"], `make ${nextReviewer()} the reviewer`)] : []),
298303 ...(mayMaintain() ? [binding(["m"], "add maintainer")] : []),
299304 binding(["esc"], "close"),
300305 ];
@@ -408,6 +413,15 @@ export function aboutScreen(
408413 ctx.invalidate();
409414 return true;
410415 }
416 if (e.key === "r" && repo !== undefined && mayReview()) {
417 const name = nextReviewer()!;
418 const agent = listCrewRoles(f.db, repo.id).find((c) => c.agent.user.username === name)!.agent;
419 setCrewRole(f.db, repo.id, agent.user.id, "reviewer");
420 rows = factRows();
421 ctx.toast(`${name} is a reviewer here`, "success");
422 ctx.invalidate();
423 return true;
424 }
411425 if (e.key === "m" && repo !== undefined && mayMaintain()) {
412426 const agent = nextMaintainer()!;
413427 const done = addToCrew(f.app, f.user, repo, agent.user.username, "maintainer");
@@ -896,6 +910,12 @@ export function movingRow(f: Session, repo: Repo | undefined): [string, string][
896910 /** The three seats, in the crew card's words: who fills each, and what an empty one costs. */
897911 export function seatRows(f: Session, repo: Repo | undefined): [string, string][] {
898912 if (repo === undefined) return [];
913 const gap = reviewerGap(f.db, repo);
914 const who = gap === undefined || gap.candidates.length === 0 ? "" : ` r makes ${gap.candidates.join(" or ")} the reviewer.`;
915 return [...seatLines(f, repo), ...(gap === undefined ? [] : [["Warning", reviewerGapWords(gap) + who] as [string, string]])];
916 }
917
918 function seatLines(f: Session, repo: Repo): [string, string][] {
899919 return seatsOf(f.db, repo, crewOffInPreview()).seats.map((x): [string, string] => [
900920 x.role[0]!.toUpperCase() + x.role.slice(1),
901921 x.by.length > 0
src/web/studio/crew.ts +19 −1
@@ -29,7 +29,7 @@ import { listAllAgents, listCrew } from "../../actions/crew.ts";
2929 import { listCrewRoles, type Agent, type CrewRole } from "../../core/agents.ts";
3030 import { getAppByRepo } from "../../core/apps.ts";
3131 import { canAdmin, canSeeOwnerFacts, type Repo } from "../../core/repos.ts";
32 import { seatsOf, type Seat } from "../../crew/seats.ts";
32 import { reviewerGap, reviewerGapWords, seatsOf, type Seat } from "../../crew/seats.ts";
3333 import { autonomyStatus } from "../../crew/autonomy_status.ts";
3434 import { governorSeen } from "../../crew/governed.ts";
3535 import { governorRows, weekCardDl } from "./governor_rows.ts";
@@ -225,11 +225,29 @@ function teamCard(
225225 ? `Auto mode is on (${team.mode}): the team works on its own.`
226226 : "Auto mode is off: the team works when asked. Turn it on under On its own. A list's number is how many work at once; 0 pauses it.";
227227 const nobody = crew.length > 0 ? null : nobodyLine(ctx, everyone.length > 0);
228 const gap = reviewerGap(ctx.app.db, repo);
229 const noReviewer =
230 gap === undefined
231 ? null
232 : html`<p class="small" data-no-reviewer="${String(gap.waiting)}">${reviewerGapWords(gap)}</p>
outdated

Principles 1 and 8 and validity: <form> inside <p> is invalid HTML (the p closes early). Sentence in a <p>, buttons in a following row. Drop role="alert" for a static warning.

233 ${
234 admin && gap.candidates.length > 0
235 ? html`<div class="row-fields">
236 ${gap.candidates.map(
237 (u) => html`<form method="post" action="${base}/settings/crew/${encodeURIComponent(u)}/role">
238 <input type="hidden" name="role" value="reviewer" />
outdated

This action exists on the page but not in the terminal; the terminal must be able to seat the reviewer too.

239 ${btn(`Make ${u} the reviewer`, { size: "sm" })}
240 </form>`,
241 )}
242 </div>`
243 : null
244 }`;
228245 return html`<section class="settings-block" id="team">
229246 <h2>Your team</h2>
230247 <p class="small" id="auto-mode" data-auto="${team.auto ? "on" : "off"}">
231248 ${intro}
232249 </p>
250 ${noReviewer}
233251 ${nobody}
234252 <ul class="list setting-list">
235253 ${rows}
test/crew-no-reviewer.test.ts added +166
@@ -0,0 +1,166 @@
1 /** A crew with builders and no reviewer says so: settings, the tick line, one click (#3512). */

Missing tests: autonomyTick's real line, waiting > 0, non-admin sees no button, TUI Warning row.

2 import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test";
3 import { mkdtemp, rm } from "node:fs/promises";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { createApp, type App } from "../src/app.ts";
7 import { addToCrew, createAgent } from "../src/actions/crew.ts";
8 import { addTeamMember, createOrg, createTeam } from "../src/core/orgs.ts";
9 import { createRepo, getRepoById, type Repo } from "../src/core/repos.ts";
10 import { createUser, getUserByName, type User } from "../src/core/users.ts";
11 import { openPull } from "../src/actions/pulls.ts";
12 import { commitToBranch, updateRepoSettings } from "../src/actions/repos.ts";
13 import { autonomyTick, noReviewerFields } from "../src/crew/autonomy_tick.ts";
14 import { logLevel, setLogLevel } from "../src/kernel/log.ts";
15 import type { KeyEvent } from "../src/tui/term/input.ts";
16 import type { Ctx, Screen } from "../src/tui/app/app.ts";
17 import { localSource } from "../src/view/local.ts";
18 import { aboutScreen, seatRows } from "../src/tui/screens/about.ts";
19 import type { Session } from "../src/tui/session.ts";
20 import { NO_REVIEWER_WORDS, reviewerGap } from "../src/crew/seats.ts";
21 import { serve, type Servers } from "../src/http/server.ts";
22 import { quietLogs } from "./helpers/globals.ts";
23
24 quietLogs();
25 const PASSWORD = "a-long-crew-passphrase";
26
27 describe("a crew with no reviewer", () => {
28 let dir = "";
29 let app: App;
30 let servers: Servers;
31 let alice: User;
32 let repo: Repo;
33 let cookie = "";
34 let ward: Repo | undefined;
35 const settings = async () => (await fetch(`${servers.url}/alice/yard/settings`, { headers: { cookie } })).text();
36
37 beforeAll(async () => {
38 dir = await mkdtemp(join(tmpdir(), "forge-noreview-"));
39 app = createApp({ dataDir: dir, port: 0 });
40 servers = await serve(app);
41 const made = await createUser(app.db, { origin: "seed", username: "alice", email: "[email protected]", password: PASSWORD, adminIfFirst: true, trusted: true });
42 if (!made.ok) throw new Error("user");
43 alice = made.value;
44 const r = await createRepo(app.db, app.reposRoot, { ownerId: alice.id, name: "yard", visibility: "public" });
45 if (!r.ok) throw new Error("repo");
46 repo = r.value;
47 const seeded = await commitToBranch(app, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# yard\n" }] });
48 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
49 await createAgent(app, alice, { username: "quill", roles: ["builder"] });
50 await createAgent(app, alice, { username: "juniper", roles: ["builder", "reviewer"] });
51 const set = await updateRepoSettings(app, alice, repo, { autonomy: "autonomous", autonomyDirection: "Keep the yard tidy.", autonomySlots: 1, autonomyBy: alice.id });
52 if (!set.ok) throw new Error(JSON.stringify(set.error));
53 const res = await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "alice", password: PASSWORD }), redirect: "manual" });
54 cookie = (res.headers.get("set-cookie") ?? "").split(";")[0]!;
55 }, 30_000);
56
57 afterAll(async () => {
58 await servers.stop();
59 await rm(dir, { recursive: true, force: true });
60 });
61
62 test("no builders: no gap; builders and no reviewer: the warning, the tick words, the button", async () => {
63 expect(reviewerGap(app.db, repo)).toBeUndefined();
64 expect(noReviewerFields(app, repo)).toEqual({});
65 expect(addToCrew(app, alice, repo, "quill", "builder").ok).toBe(true);
66 expect(addToCrew(app, alice, repo, "juniper", "builder").ok).toBe(true);
67 expect(reviewerGap(app.db, repo)).toEqual({ waiting: 0, candidates: ["juniper"] });
68 expect(noReviewerFields(app, repo)).toEqual({ review: "no reviewer", "waits for a reviewer": 0 });
69 const html = await settings();
70 expect(html).toContain("Nobody reviews this crew&#39;s pulls");
71 expect(html).toContain("Make juniper the reviewer");
72 expect(html).not.toContain("Make quill the reviewer");
73 });
74
75 test("the tick line itself says review=no reviewer and counts what waits", async () => {
76 const lines: string[] = [];
77 const level = logLevel();
78 setLogLevel("info");
79 const spies = (["log", "info"] as const).map((m) => spyOn(console, m).mockImplementation((...a: unknown[]) => void lines.push(a.join(" "))));
80 try {
81 await autonomyTick(app, new Date(), async () => 0);
82 } finally {
83 for (const x of spies) x.mockRestore();
84 setLogLevel(level);
85 }
86 const tick = lines.find((l) => l.includes("[autonomy] tick") && l.includes("alice/yard"));
87 expect(tick).toBeDefined();
88 expect(tick).toContain("no reviewer");
89 expect(tick).toContain("waits for a reviewer");
90 });
91
92 test("an open agent pull waits: counted, worded, and the terminal row says so", async () => {
93 const quill = getUserByName(app.db, "quill")!;
94 const c = await commitToBranch(app, alice, repo, { branch: "work", base: "main", message: "work", files: [{ path: "w.md", content: "x\n" }] });
95 if (!c.ok) throw new Error(JSON.stringify(c.error));
96 const o = await openPull(app, alice, repo, { title: "work", body: "", baseBranch: "main", headBranch: "work" });
97 if (!o.ok) throw new Error(String(o.error));
98 app.db.query("UPDATE issue SET author_id = ?2 WHERE id = ?1").run(o.value.id, quill.id);
99 expect(reviewerGap(app.db, repo)?.waiting).toBe(1);
100 expect(noReviewerFields(app, repo)["waits for a reviewer"]).toBe(1);
101 expect(await settings()).toContain("1 waits now.");
102 const row = seatRows({ app, db: app.db, user: alice } as unknown as Session, repo).find(([k]) => k === "Warning");
103 expect(row?.[1]).toContain("1 waits now.");
104 expect(row?.[1]).toContain("r makes juniper the reviewer");
105 });
106
107 test("a writer who is not an admin sees the warning and no button", async () => {
108 const made = await createUser(app.db, { origin: "seed", username: "bob", email: "[email protected]", password: PASSWORD, trusted: true });
109 if (!made.ok) throw new Error("user");
110 const org = createOrg(app.db, "acme", alice.id);
111 if (!org.ok) throw new Error("org");
112 const writers = createTeam(app.db, org.value.id, "Writers", "write");
113 if (!writers.ok) throw new Error("team");
114 addTeamMember(app.db, writers.value, made.value.id);
115 const r = await createRepo(app.db, app.reposRoot, { ownerId: org.value.id, name: "ward", visibility: "public" });
116 if (!r.ok) throw new Error("repo");
117 ward = r.value;
118 expect(addToCrew(app, alice, r.value, "quill", "builder").ok).toBe(true);
119 expect(addToCrew(app, alice, r.value, "juniper", "builder").ok).toBe(true);
120 const res = await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username: "bob", password: PASSWORD }), redirect: "manual" });
121 const bob = (res.headers.get("set-cookie") ?? "").split(";")[0]!;
122 const page = await fetch(`${servers.url}/acme/ward/settings`, { headers: { cookie: bob } });
123 expect(page.status).toBe(200);
124 const body = await page.text();
125 expect(body).toContain("Nobody reviews this crew&#39;s pulls");
126 expect(body).not.toContain("Make juniper the reviewer");
127 // The admin sees the same page with the button.
128 const admin = await (await fetch(`${servers.url}/acme/ward/settings`, { headers: { cookie } })).text();
129 expect(admin).toContain("Make juniper the reviewer");
130 });
131
132 test("the click seats the reviewer and the warning goes", async () => {
133 const res = await fetch(`${servers.url}/alice/yard/settings/crew/juniper/role`, {
134 method: "POST",
135 headers: { cookie, origin: servers.url },
136 body: new URLSearchParams({ role: "reviewer" }),
137 redirect: "manual",
138 });
139 expect(res.status).toBeLessThan(400);
140 expect(reviewerGap(app.db, repo)).toBeUndefined();
141 expect(noReviewerFields(app, repo)).toEqual({});
142 expect(await settings()).not.toContain("Make juniper the reviewer");
143 expect(NO_REVIEWER_WORDS).toContain("Nobody reviews");
144 });
145
146 test("the terminal's r seats the reviewer for an admin, and a writer is not offered it", () => {
147 const repoNow = getRepoById(app.db, ward!.id)!;
148 const rKey: KeyEvent = { type: "key", key: "r", ctrl: false, alt: false, shift: false };
149 const toasts: string[] = [];
150 const ctx = { invalidate() {}, toast: (m: string) => void toasts.push(m), push() {}, pop() {}, copy() {} } as unknown as Ctx;
151 const card = (user: User) => {
152 const f = { app, db: app.db, user } as unknown as Session;
153 return aboutScreen(f, ctx, {} as Screen, localSource(app, repoNow, user), undefined, "main");
154 };
155 const bob = getUserByName(app.db, "bob")!;
156 const asBob = card(bob);
157 expect(asBob.keys.some((b) => b.keys.includes("r"))).toBe(false);
158 asBob.key!(rKey);
159 expect(reviewerGap(app.db, repoNow)).toBeDefined();
160 const asAlice = card(alice);
161 expect(asAlice.keys.some((b) => b.keys.includes("r"))).toBe(true);
162 asAlice.key!(rKey);
163 expect(reviewerGap(app.db, repoNow)).toBeUndefined();
164 expect(toasts.join(" ")).toContain("juniper");
165 });
166 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs