Public: anyone can read this; the crew can change it.
GET /review lists every ask as a row with its title, repository, age and why #4392
scout/forge:scout/4383-get-review-lists-every-ask-as-a-row-with → main 1 commit fork
6 files
changed +180
−1
docs/design/audit.md +2 −1
| @@ -33,7 +33,7 @@ their own vocabulary instead of composing the named one. | ||
| 33 | 33 | |
| 34 | 34 | ## Finding 2 — the pages, and what each is for |
| 35 | 35 | |
| 36 | There are 61 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 36 | There are 62 top-level pages, one entry each: every static `GET` route in `src/http/server.ts` | |
| 37 | 37 | that returns a page (`test/design-audit.test.ts` holds this list to the router, |
| 38 | 38 | both ways). Each entry reads `route` — module · what it is for · what |
| 39 | 39 | duplicates it · what breaks `docs/DESIGN.md`. "Breaks" counts colour literals |
| @@ -57,6 +57,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 57 | 57 | - `/boards/data` — `pages/boards.ts` · the boards' query/data surface · `/board` · none seen. |
| 58 | 58 | - `/asks` — `studio/asks_page.ts` · what the crew is waiting on me for · `/` "needs me" list · colours 2. |
| 59 | 59 | - `/asked` — `studio/asked_page.ts` · what I answered, as a record · `/asks` · none seen. |
| 60 | - `/review` — `studio/review_page.ts` · the asks about one pull or issue, a row each with its repository, age and why · `/asks`, `/` "needs me" list · none seen. | |
| 60 | 61 | - `/flow` — `pages/flow.ts` · the pipeline from ready issue to live deploy, and the bottleneck · `/system`, `/board`, `/` · none seen. A topbar button points here. |
| 61 | 62 | - `/map` — `pages/map.ts` (1,806 lines) · the dependency map of work across the forge · `/board`, issue dependency lists, `/:owner/:name/map` · colours 3, sizes 12: the largest private vocabulary. |
| 62 | 63 | - `/audit` — `pages/audit.ts` · every app's contract, who can do what · the app page's one-line policy · none seen. Names the audit of apps, not this document. |
src/core/reserved.ts +1
| @@ -108,6 +108,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 108 | 108 | "recover", |
| 109 | 109 | "www", |
| 110 | 110 | "asked", |
| 111 | "review", | |
| 111 | 112 | "claim", |
| 112 | 113 | "first-admin", |
| 113 | 114 | "forges", |
src/http/server.ts +3
| @@ -256,6 +256,7 @@ import { familyPage } from "../web/pages/family.ts"; | ||
| 256 | 256 | import { forgeLinkSubmit, forgesPage } from "../web/pages/forges.ts"; |
| 257 | 257 | import { newForgePage, newForgeSubmit } from "../web/pages/new-forge.ts"; |
| 258 | 258 | import { askedPage } from "../web/studio/asked_page.ts"; |
| 259 | import { reviewPage } from "../web/studio/review_page.ts"; | |
| 259 | 260 | import { |
| 260 | 261 | asksBulkSubmit, |
| 261 | 262 | asksBulkUndo, |
| @@ -737,6 +738,8 @@ export function buildRouter(): Router<Handler> { | ||
| 737 | 738 | router.add("POST", "/asks/decide/:id/undo", asksDecideUndo); |
| 738 | 739 | // What people asked of the crew, and what became of it (core/asked.ts). |
| 739 | 740 | router.add("GET", "/asked", askedPage); |
| 741 | // The asks that are about one pull or issue, as rows. | |
| 742 | router.add("GET", "/review", reviewPage); | |
| 740 | 743 | // The big view, folded into the board: every old address lands on its wall mode. |
| 741 | 744 | router.add("GET", "/big", bigRedirect); |
| 742 | 745 | router.add("GET", "/search", searchPage); |
src/web/studio/home.ts +1
| @@ -265,6 +265,7 @@ export async function studioHome( | ||
| 265 | 265 | ${composer(ctx, user)} |
| 266 | 266 | <div class="bar feed-head"> |
| 267 | 267 | <span class="spacer"></span> |
| 268 | <a class="small muted" href="/review">For your review</a> | |
| 268 | 269 | <a class="small muted" href="/asked">What you asked for</a> |
| 269 | 270 | </div> |
| 270 | 271 | ${flowCards(ctx, user)} |
src/web/studio/review_page.ts added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | /** | |
| 2 | * `/review`: every ask that is about one pull or issue, as a row — its title | |
| 3 | * (linking to it), its repository, how old it is and why it asks. Read from | |
| 4 | * `decisionsFor` (`asks.ts`), the same decisions the home shows, newest | |
| 5 | * first. Asks that are about no one change (a wave, a paused repository) | |
| 6 | * stay on the home. | |
| 7 | */ | |
| 8 | ||
| 9 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 10 | import { listReposVisibleTo } from "../../core/repos.ts"; | |
| 11 | import type { Ctx } from "../../http/context.ts"; | |
| 12 | import { repoBase, signInFirst } from "../chrome.ts"; | |
| 13 | import { html, type Html } from "../html.ts"; | |
| 14 | import { page } from "../layout.ts"; | |
| 15 | import { empty, listCard, row, timeAgo } from "../ui.ts"; | |
| 16 | import { decisionsFor, type Decision } from "./asks.ts"; | |
| 17 | import { changeHref } from "./nouns.ts"; | |
| 18 | ||
| 19 | /** The pull or issue the ask is about; none for a wave or a pause. */ | |
| 20 | const subject = (d: Decision) => d.pull ?? d.issue; | |
| 21 | ||
| 22 | function reviewRow(d: Decision): Html { | |
| 23 | const thing = subject(d)!; | |
| 24 | const base = repoBase(d.repo); | |
| 25 | return row({ | |
| 26 | href: d.pull ? changeHref(base, d.pull.number) : `${base}/issues/${thing.number}`, | |
| 27 | title: thing.title, | |
| 28 | meta: html`${d.repo.ownerName}/${d.repo.name} · ${timeAgo(thing.createdAt)} · ${d.why ?? d.short}`, | |
| 29 | nav: true, | |
| 30 | }); | |
| 31 | } | |
| 32 | ||
| 33 | /** GET /review — signed in only; no polling, no script. */ | |
| 34 | export function reviewPage(ctx: Ctx): Response { | |
| 35 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 36 | const user = ctx.auth.user; | |
| 37 | if (!user) return signInFirst(ctx); | |
| 38 | const decisions = timePhase(ctx.request, "asks", () => | |
| 39 | decisionsFor(ctx, listReposVisibleTo(ctx.app.db, user, { limit: 200, withoutArchived: true })) | |
| 40 | .filter((d) => subject(d) !== undefined) | |
| 41 | .sort((a, b) => Date.parse(subject(b)!.createdAt) - Date.parse(subject(a)!.createdAt)), | |
| 42 | ); | |
| 43 | const rendering = performance.now(); | |
| 44 | const body = html`<h1>For your review</h1> | |
| 45 | ${decisions.length === 0 | |
| 46 | ? empty({ title: "Nothing waits for your review." }) | |
| 47 | : listCard(decisions.map(reviewRow))} | |
| 48 | <p class="small muted"><a href="/">Back to the home</a></p>`; | |
| 49 | const response = page({ ctx, title: "For your review", body }); | |
| 50 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 51 | return response; | |
| 52 | } |
test/review-page.test.ts added +121
| @@ -0,0 +1,121 @@ | ||
| 1 | /** `/review` lists each ask about one pull or issue as a row with its title, repository, age and why (#4383). */ | |
| 2 | import { afterAll, beforeAll, expect, 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 { addCrew, createAgentRow, setCrewRole } from "../src/core/agents.ts"; | |
| 8 | import { addComment, createIssue } from "../src/core/issues.ts"; | |
| 9 | import { createRepo } from "../src/core/repos.ts"; | |
| 10 | import { submitReview } from "../src/core/reviews.ts"; | |
| 11 | import { createUser, type User } from "../src/core/users.ts"; | |
| 12 | import { BREAKER_NOTE } from "../src/crew/breaker.ts"; | |
| 13 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 14 | import { id } from "../src/kernel/id.ts"; | |
| 15 | import { quietLogs } from "./helpers/globals.ts"; | |
| 16 | ||
| 17 | quietLogs(); | |
| 18 | ||
| 19 | const ZERO = "0".repeat(40); | |
| 20 | const hoursAgo = (h: number) => new Date(Date.now() - h * 3_600_000).toISOString(); | |
| 21 | ||
| 22 | let dataDir = ""; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | let cookie = ""; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dataDir = await mkdtemp(join(tmpdir(), "forge-review-page-")); | |
| 29 | app = createApp({ dataDir, port: 0 }); | |
| 30 | servers = await serve(app); | |
| 31 | const person = async (username: string, agent: boolean): Promise<User> => { | |
| 32 | const made = await createUser(app.db, { | |
| 33 | username, | |
| 34 | email: `${username}@forge.test`, | |
| 35 | ...(agent | |
| 36 | ? { agent: true, origin: "agent" as const } | |
| 37 | : { password: "a-good-passphrase", origin: "seed" as const, trusted: true, adminIfFirst: true }), | |
| 38 | }); | |
| 39 | if (!made.ok) throw new Error(made.error); | |
| 40 | if (agent) createAgentRow(app.db, { userId: made.value.id, brief: `${username}.` }); | |
| 41 | return made.value; | |
| 42 | }; | |
| 43 | const owner = await person("alice", false); | |
| 44 | const builder = await person("builder", true); | |
| 45 | const reviewer = await person("reviewer", true); | |
| 46 | const made = await createRepo(app.db, app.reposRoot, { ownerId: owner.id, name: "wait", visibility: "public", description: "w" }); | |
| 47 | if (!made.ok) throw new Error(made.error); | |
| 48 | const repo = made.value; | |
| 49 | for (const a of [builder, reviewer]) addCrew(app.db, repo.id, a.id, owner.id); | |
| 50 | setCrewRole(app.db, repo.id, reviewer.id, "reviewer"); | |
| 51 | ||
| 52 | let seq = 0; | |
| 53 | const pull = (author: User, title: string, age: number): string => { | |
| 54 | const issueId = id(); | |
| 55 | const number = app.db | |
| 56 | .query<{ issue_seq: number }, [string]>("UPDATE repo SET issue_seq = issue_seq + 1 WHERE id = ?1 RETURNING issue_seq") | |
| 57 | .get(repo.id)!.issue_seq; | |
| 58 | app.db | |
| 59 | .query( | |
| 60 | `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at) | |
| 61 | VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'open', ?6)`, | |
| 62 | ) | |
| 63 | .run(issueId, repo.id, number, title, author.id, hoursAgo(age)); | |
| 64 | app.db | |
| 65 | .query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', ?2, ?3, ?3, ?4)`) | |
| 66 | .run(issueId, `b/${++seq}`, ZERO, repo.id); | |
| 67 | return issueId; | |
| 68 | }; | |
| 69 | const handed = pull(builder, "Handed <over>", 3); | |
| 70 | for (let r = 0; r < 3; r++) | |
| 71 | submitReview(app.db, { issueId: handed, authorId: reviewer.id, state: "changes_requested", body: `Round ${r}.`, commitOid: ZERO }); | |
| 72 | pull(owner, "Thirty hours", 30); | |
| 73 | pull(builder, "Two hours", 2); | |
| 74 | const parked = createIssue(app.db, { repoId: repo.id, authorId: owner.id, title: "Parked issue" }); | |
| 75 | if (!parked.ok) throw new Error(parked.error); | |
| 76 | addComment(app.db, { issueId: parked.value.id, authorId: builder.id, body: BREAKER_NOTE }); | |
| 77 | ||
| 78 | const res = await fetch(`${servers.url}/signin`, { | |
| 79 | method: "POST", | |
| 80 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 81 | redirect: "manual", | |
| 82 | }); | |
| 83 | cookie = `${(res.headers.get("set-cookie") ?? "").split(";")[0]!}; forge_mode=studio`; | |
| 84 | }, 30_000); | |
| 85 | ||
| 86 | afterAll(async () => { | |
| 87 | await servers.stop(); | |
| 88 | await rm(dataDir, { recursive: true, force: true }); | |
| 89 | }); | |
| 90 | ||
| 91 | test("a signed-out visitor is sent to sign in", async () => { | |
| 92 | const res = await fetch(`${servers.url}/review`, { redirect: "manual" }); | |
| 93 | expect(res.status).toBe(303); | |
| 94 | expect(res.headers.get("location")).toContain("/signin"); | |
| 95 | }); | |
| 96 | ||
| 97 | test("lists exactly the handed-over pull, the stale pull and the parked issue, each with its why", async () => { | |
| 98 | const res = await fetch(`${servers.url}/review`, { headers: { cookie } }); | |
| 99 | expect(res.status).toBe(200); | |
| 100 | const timing = res.headers.get("server-timing") ?? ""; | |
| 101 | for (const phase of ["session", "asks", "render"]) expect(timing).toContain(phase); | |
| 102 | const text = await res.text(); | |
| 103 | const rows = text.match(/<li>\s*<a href="[^"]*" class="row"[\s\S]*?<\/li>/g) ?? []; | |
| 104 | expect(rows).toHaveLength(3); | |
| 105 | const rowOf = (title: string) => rows.find((r) => r.includes(title))!; | |
| 106 | expect(rowOf("Handed <over>")).toContain("/alice/wait/pulls/"); | |
| 107 | expect(rowOf("Handed <over>")).toContain("three reviews asked for changes"); | |
| 108 | expect(rowOf("Thirty hours")).toContain("waiting 30 hours"); | |
| 109 | expect(rowOf("Thirty hours")).toContain("1d ago"); | |
| 110 | expect(rowOf("Thirty hours")).toContain("alice/wait"); | |
| 111 | expect(rowOf("Parked issue")).toContain("/alice/wait/issues/"); | |
| 112 | expect(rowOf("Parked issue")).toContain("parked after three failed runs"); | |
| 113 | expect(text).not.toContain("Two hours"); | |
| 114 | // newest first | |
| 115 | expect(text.indexOf("Handed")).toBeLessThan(text.indexOf("Thirty hours")); | |
| 116 | }); | |
| 117 | ||
| 118 | test("the home links to the page", async () => { | |
| 119 | const home = await (await fetch(`${servers.url}/`, { headers: { cookie } })).text(); | |
| 120 | expect(home).toContain('href="/review"'); | |
| 121 | }); |
new above
offline