Public: anyone can read this; the crew can change it.
Review: one clean page where the owner decides - each item says what, why it needs you, the crew's recommendation, and the buttons to act #3254
scout/forge:scout/3247-review-one-clean-page-where-the-owner-de → main 2 commits fork
10 files
changed +634
−7
README.md +3 −1
| @@ -712,7 +712,9 @@ and `forge sync` below is what acts on it. | ||
| 712 | 712 | |
| 713 | 713 | **What an ask row waits for.** Every ask row carries one word, `waitingFor` (`src/core/waiting_for.ts`, computed once), and who it waits on, e.g. "ready to land · on you". The first that applies wins: `conflicts with main` (the last sweep found files stopping the pull, on its author), `ready to land` (a green change to look at and ship), `a review` (a review or a hand-over), `assigned to you` (the pull or issue is assigned to the viewer), otherwise `a decision`. It shows as a chip on each row of `/asks`, as `waitingFor: {word, on}` in `GET /api/v1/asks` and the MCP `asks` tool, and in the terminal's On you card. A grouped row shares one word (the weightiest of its items), and the terminal's card shows its row's word. |
| 714 | 714 | |
| 715 | **Muting a repository from /asks**: each ask row on `/asks` carries a "Mute owner/name" chip. A muted repository's asks leave `/asks`, `/api/v1/asks` and the phone's pushes (the same per-user mute the On you card uses, no new table); `/asks` says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them. The home itself renders no asks, no for-you list and no count: the top bar carries a plain Asks link to `/asks`, and the terminal's dashboard keeps its On you card on purpose (a different door). | |
| 715 | **`/review`: one column where the owner decides.** The asks that only a person can settle, one article each, newest first: a pull request handed over after three rounds of changes, a stopped one, one waiting on a person's review, a green one waiting more than 24 hours, and a question the crew put (a parked issue, a declined direction). Each says what it is (title, repository, age), why it needs a person (one sentence), the crew's recommendation (approve / change / reply, with its reason) and the evidence (check, diff stat for the first ten, preview link, the preview's picture). The buttons post to `POST /review/act` (same-origin, `rw`) and come back to the list: **Merge** (`mergePull`, the landing gate), **Close**, **Request changes** and **Reply** with the text box. Keys: `j`/`k` move, `m` merges, `c` closes, `r` writes, Ctrl/Cmd+Enter sends. The home shows one line, "N waiting on you, oldest Xh", linking here, and nothing at zero. Items are `askCandidatesFor`'s, filtered by `isReviewAsk` (`web/studio/asks.ts`), so mutes and dismissals hold. No dependency added. | |
| 716 | ||
| 717 | **Muting a repository from /asks**: each ask row on `/asks` carries a "Mute owner/name" chip. A muted repository's asks leave `/asks`, `/api/v1/asks` and the phone's pushes (the same per-user mute the On you card uses, no new table); `/asks` says "N muted repositories still ask" with a "Listen again" button, and an app's own page still counts them. The home itself renders no asks and no for-you list; its one line is `/review`'s (below): the top bar carries a plain Asks link to `/asks`, and the terminal's dashboard keeps its On you card on purpose (a different door). | |
| 716 | 718 | |
| 717 | 719 | **A wave proposal is one card.** With "plans need a nod" on, a plan the planner writes is kept as a proposal and opens nothing. It is one row in the asks list (`/asks`, `/api/v1/asks`, MCP `asks`, the terminal's On you card) with its title, its why and its issue titles, all escaped, and it asks the app's owner only. Three taps, each one POST that leaves you on the page you were on: **Approve** opens the issues with their links, exactly as an unheld plan would; **Redirect** takes a text box and hands your words to the planner as a new run on the direction issue; **Later** hides it until you bring it back, from the "N waves put aside" line under the asks on `/asks` (each with a "Bring back" button). A proposal is decided once. The same four verbs (`approve`, `redirect`, `later`, `again`) are on every door, all calling `actions/proposals.ts`: the page (`/asks/proposal/<id>/<verb>`), the API (`POST /api/v1/asks/proposal/<id>/<verb>`, a `rw` token, `{"words": …}` for redirect), the MCP tool `asks_proposal` (`id`, `verb`, `words`), and in the terminal `y` approve, `R` redirect, `l` later and `B` bring every put-aside wave back, on a wave row of the On you card. |
| 718 | 720 |
src/core/reserved.ts +1
| @@ -58,6 +58,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 58 | 58 | "api", |
| 59 | 59 | "apps", |
| 60 | 60 | "asks", |
| 61 | "review", | |
| 61 | 62 | "assets", |
| 62 | 63 | "audit", |
| 63 | 64 | "audit.csv", |
src/http/server.ts +4
| @@ -265,6 +265,7 @@ import { | ||
| 265 | 265 | asksMute, |
| 266 | 266 | asksPage, |
| 267 | 267 | } from "../web/studio/asks_page.ts"; |
| 268 | import { reviewAct, reviewPage } from "../web/studio/review_page.ts"; | |
| 268 | 269 | import { homeArchive, homeArchived, homeArchiveUndo } from "../web/studio/home_archive.ts"; |
| 269 | 270 | import { liveFeedFragment } from "../web/studio/feed.ts"; |
| 270 | 271 | import { serviceWorker } from "../web/sw.ts"; |
| @@ -701,6 +702,9 @@ export function buildRouter(): Router<Handler> { | ||
| 701 | 702 | router.add("GET", "/board/returns", returnsPage); |
| 702 | 703 | // One screen for "is everything fine?": what asks the viewer (docs/STUDIO.md). |
| 703 | 704 | router.add("GET", "/asks", asksPage); |
| 705 | // One column where the owner decides: what only a person can settle. | |
| 706 | router.add("GET", "/review", reviewPage); | |
| 707 | router.add("POST", "/review/act", reviewAct); | |
| 704 | 708 | router.add("POST", "/asks/bulk", asksBulkSubmit); |
| 705 | 709 | router.add("POST", "/asks/bulk/:id/undo", asksBulkUndo); |
| 706 | 710 | router.add("POST", "/asks/listen", asksListen); |
src/web/studio/asks.ts +49 −5
| @@ -136,6 +136,8 @@ export interface Decision { | ||
| 136 | 136 | /** Where the pull's preview opens, when its repository is an app. */ |
| 137 | 137 | readonly preview?: string | undefined; |
| 138 | 138 | readonly consequence: Consequence; |
| 139 | /** When its cause last changed: how long it has waited (`/review`). */ | |
| 140 | readonly since: string; | |
| 139 | 141 | /** For "setting": the key, its value, its default, and who set it and when. */ |
| 140 | 142 | readonly setting?: SettingAway | undefined; |
| 141 | 143 | /** What it waits for, and on whom (`core/waiting_for.ts`). */ |
| @@ -1115,12 +1117,14 @@ export function askLinesFor( | ||
| 1115 | 1117 | export function decisionsFor( |
| 1116 | 1118 | ctx: Ctx, |
| 1117 | 1119 | allRepos: readonly Repo[], |
| 1118 | options: { evenDismissed?: boolean } = {}, | |
| 1120 | options: { evenDismissed?: boolean; keep?: (c: { kind: DecisionKind; since: string }) => boolean } = {}, | |
| 1119 | 1121 | ): Decision[] { |
| 1120 | 1122 | const db = ctx.app.db; |
| 1121 | const candidates = options.evenDismissed | |
| 1122 | ? scoredFor(db, ctx.auth.user, allRepos) | |
| 1123 | : waitingOn(db, ctx.auth.user, allRepos); | |
| 1123 | const candidates = ( | |
| 1124 | options.evenDismissed | |
| 1125 | ? scoredFor(db, ctx.auth.user, allRepos) | |
| 1126 | : waitingOn(db, ctx.auth.user, allRepos) | |
| 1127 | ).filter(options.keep ?? (() => true)); | |
| 1124 | 1128 | // The pictures, in one read: a green pull's row leads with its preview. |
| 1125 | 1129 | const repoIds = [...new Set(candidates.map((c) => c.repo.id))]; |
| 1126 | 1130 | const records = appsForRepos(db, repoIds); |
| @@ -1142,7 +1146,7 @@ export function decisionsFor( | ||
| 1142 | 1146 | look && lookUrl(repoBase(repo), look) |
| 1143 | 1147 | ); |
| 1144 | 1148 | }; |
| 1145 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting"> => { | |
| 1149 | const worded = (c: Scored): Omit<Decision, "consequence" | "waiting" | "since"> => { | |
| 1146 | 1150 | if (c.kind === "assigned") { |
| 1147 | 1151 | const thing = c.pull ?? c.issue!; |
| 1148 | 1152 | return { |
| @@ -1271,6 +1275,7 @@ export function decisionsFor( | ||
| 1271 | 1275 | ...worded(c), |
| 1272 | 1276 | preview: previewOf(c), |
| 1273 | 1277 | consequence: c.consequence, |
| 1278 | since: c.since, | |
| 1274 | 1279 | waiting: c.waiting, |
| 1275 | 1280 | })); |
| 1276 | 1281 | } |
| @@ -1424,6 +1429,45 @@ export function askCountFor(ctx: Ctx, user: User | undefined): number { | ||
| 1424 | 1429 | ); |
| 1425 | 1430 | } |
| 1426 | 1431 | |
| 1432 | /** How long a green change may wait before it is a person's to decide (`/review`). */ | |
| 1433 | export const REVIEW_AFTER_MS = 86_400_000; | |
| 1434 | ||
| 1435 | /** | |
| 1436 | * Whether an ask belongs on `/review`: a change handed over, stopped or | |
| 1437 | * waiting on a reviewer who is a person; a question the crew put to the | |
| 1438 | * owner; a green change that has waited past `REVIEW_AFTER_MS`. Every other | |
| 1439 | * ask is one the crew decides, or a setting, not a verdict on work. | |
| 1440 | */ | |
| 1441 | export function isReviewAsk(c: { kind: DecisionKind; since: string }, now = Date.now()): boolean { | |
| 1442 | switch (c.kind) { | |
| 1443 | case "handover": | |
| 1444 | case "stopped": | |
| 1445 | case "review": | |
| 1446 | case "declined": | |
| 1447 | case "parked": | |
| 1448 | return true; | |
| 1449 | case "look": | |
| 1450 | return now - Date.parse(c.since) > REVIEW_AFTER_MS; | |
| 1451 | default: | |
| 1452 | return false; | |
| 1453 | } | |
| 1454 | } | |
| 1455 | ||
| 1456 | /** How many wait on the viewer for `/review`, and since when the oldest has. */ | |
| 1457 | export function reviewWaiting( | |
| 1458 | ctx: Ctx, | |
| 1459 | user: User | undefined, | |
| 1460 | now = Date.now(), | |
| 1461 | ): { count: number; oldest: string | undefined } { | |
| 1462 | if (!user) return { count: 0, oldest: undefined }; | |
| 1463 | const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200, withoutArchived: true }); | |
| 1464 | const waiting = waitingOn(ctx.app.db, user, repos).filter((c) => isReviewAsk(c, now)); | |
| 1465 | return { | |
| 1466 | count: waiting.length, | |
| 1467 | oldest: waiting.reduce<string | undefined>((a, c) => (a === undefined || c.since < a ? c.since : a), undefined), | |
| 1468 | }; | |
| 1469 | } | |
| 1470 | ||
| 1427 | 1471 | /** The single sentence the asks page leads with, and the dashboard links with. */ |
| 1428 | 1472 | export function askSentence(count: number): string { |
| 1429 | 1473 | return count === 0 |
src/web/studio/change.ts +1
| @@ -474,6 +474,7 @@ async function changeConversation( | ||
| 474 | 474 | ? { |
| 475 | 475 | kind: "look", |
| 476 | 476 | id: `own:${pull.id}`, |
| 477 | since: pull.updatedAt, | |
| 477 | 478 | repo, |
| 478 | 479 | pull, |
| 479 | 480 | who: pull.authorName, |
src/web/studio/home.ts +10 −1
| @@ -54,6 +54,8 @@ import { timePhase, timePhaseAsync } from "../../core/route_timing.ts"; | ||
| 54 | 54 | import { kpiCache, panelCache } from "./home_cache.ts"; |
| 55 | 55 | import { pinnedPanels } from "./pinned.ts"; |
| 56 | 56 | import { homeTabs } from "./home_tabs.ts"; |
| 57 | import { reviewWaiting } from "./asks.ts"; | |
| 58 | import { waitingLine } from "./review_page.ts"; | |
| 57 | 59 | import { crewKeyNote } from "./crew.ts"; |
| 58 | 60 | import { everydayCard } from "../pages/everyday.ts"; |
| 59 | 61 | import { nextStepsCard, nextStepsOf } from "../pages/next-steps.ts"; |
| @@ -197,6 +199,13 @@ export function liveOnYouFragment(ctx: Ctx): Response { | ||
| 197 | 199 | return fragment(onYouRegion(ctx, user), { request: ctx.request }); |
| 198 | 200 | } |
| 199 | 201 | |
| 202 | /** One line to `/review` when anything waits on the owner; absent at zero, never the list. */ | |
| 203 | function reviewLine(ctx: Ctx, user: User): Html | null { | |
| 204 | const { count, oldest } = timePhase(ctx.request, "review", () => reviewWaiting(ctx, user)); | |
| 205 | if (count === 0) return null; | |
| 206 | return html`<p class="small" id="review-waiting"><a href="/review">${waitingLine(count, oldest)}</a></p>`; | |
| 207 | } | |
| 208 | ||
| 200 | 209 | /** |
| 201 | 210 | * Home, signed in, is the feed (#599), for every viewer whatever the mode |
| 202 | 211 | * (#625): like opening X — the composer on top, then one timeline of posts |
| @@ -252,7 +261,7 @@ export async function studioHome( | ||
| 252 | 261 | const ceilingUsd = ctx.app.config.crewCeilingUsd; |
| 253 | 262 | const kpiOpts = { dataDir: ctx.app.config.dataDir, ...(ceilingUsd === undefined ? {} : { ceilingUsd }) }; |
| 254 | 263 | const body = html`<h1 class="sr-only">Home</h1> |
| 255 | ${ask} ${address} ${figures | |
| 264 | ${ask} ${address} ${reviewLine(ctx, user)} ${figures | |
| 256 | 265 | ? timePhase(ctx.request, "kpis", () => kpiRow(ctx.app.db, kpiOpts), () => kpiCache(ctx.app.db)) |
| 257 | 266 | : liveLine(ctx)} |
| 258 | 267 | ${figures |
src/web/studio/review.ts added +106
| @@ -0,0 +1,106 @@ | ||
| 1 | /** | |
| 2 | * What waits on the owner, as `/review` reads it: each item one decision — | |
| 3 | * what it is, why it needs a person, what the crew recommends, and the | |
| 4 | * evidence to decide on. The items are the asks (`asks.ts`) that only a | |
| 5 | * person can settle, read once; nothing here decides, and nothing the crew | |
| 6 | * can settle itself is in it. Newest first. | |
| 7 | */ | |
| 8 | ||
| 9 | import { latestRunsForIssues, type Run } from "../../core/runs.ts"; | |
| 10 | import { pullDiff } from "../../core/pulls.ts"; | |
| 11 | import { repoDir } from "../../git/repos.ts"; | |
| 12 | import type { Ctx } from "../../http/context.ts"; | |
| 13 | import { listReposVisibleTo } from "../../core/repos.ts"; | |
| 14 | import { decisionsFor, isReviewAsk, type Decision } from "./asks.ts"; | |
| 15 | import { testsClause } from "./words.ts"; | |
| 16 | ||
| 17 | /** What the crew would do, and why. */ | |
| 18 | export interface Recommendation { | |
| 19 | readonly verb: "approve" | "close" | "change" | "reply"; | |
| 20 | readonly reason: string; | |
| 21 | } | |
| 22 | ||
| 23 | /** What to decide on, without clicking away. */ | |
| 24 | export interface Evidence { | |
| 25 | readonly check?: { readonly state: Run["state"]; readonly note: string }; | |
| 26 | readonly stat?: { readonly files: number; readonly additions: number; readonly deletions: number }; | |
| 27 | readonly preview?: string | undefined; | |
| 28 | readonly picture?: string | undefined; | |
| 29 | } | |
| 30 | ||
| 31 | export interface ReviewItem { | |
| 32 | readonly decision: Decision; | |
| 33 | readonly why: string; | |
| 34 | readonly recommendation: Recommendation; | |
| 35 | readonly evidence: Evidence; | |
| 36 | } | |
| 37 | ||
| 38 | /** Items whose diff is read for the page: a git read each, so bounded. */ | |
| 39 | export const EVIDENCE_LIMIT = 10; | |
| 40 | /** Items on one page; the rest follow as these are settled. */ | |
| 41 | export const REVIEW_LIMIT = 50; | |
| 42 | ||
| 43 | /** The first sentence: one line of why. */ | |
| 44 | const firstSentence = (text: string): string => text.split(/(?<=[.?!])\s/)[0] ?? text; | |
| 45 | ||
| 46 | /** The decisions only a person can settle, newest first. */ | |
| 47 | export function reviewDecisions(ctx: Ctx): Decision[] { | |
| 48 | const user = ctx.auth.user; | |
| 49 | if (!user) return []; | |
| 50 | const now = Date.now(); | |
| 51 | const repos = listReposVisibleTo(ctx.app.db, user, { limit: 200, withoutArchived: true }); | |
| 52 | return decisionsFor(ctx, repos, { keep: (c) => isReviewAsk(c, now) }).sort((a, b) => | |
| 53 | a.since < b.since ? 1 : a.since > b.since ? -1 : 0, | |
| 54 | ); | |
| 55 | } | |
| 56 | ||
| 57 | /** The crew's recommendation for one decision, in the owner's words. */ | |
| 58 | export function recommend(d: Decision, check: Run | undefined): Recommendation { | |
| 59 | switch (d.kind) { | |
| 60 | case "look": { | |
| 61 | const clause = testsClause(check ?? null); | |
| 62 | return { verb: "approve", reason: `The check is green${clause === "" ? "" : `, ${clause}`}, and nothing is asking for changes.` }; | |
| 63 | } | |
| 64 | case "review": | |
| 65 | return { verb: "approve", reason: `It is green and no reviewer is left to ask: ${d.short.replace(/^green; waits for a review — /, "")}.` }; | |
| 66 | case "handover": | |
| 67 | return { verb: "change", reason: "Three reviews asked for changes with no approval between; the crew's loop is spent. Say what to try, or close it if the approach is wrong." }; | |
| 68 | case "stopped": | |
| 69 | return { verb: "change", reason: `${d.short}. Say what to try, or close it.` }; | |
| 70 | default: | |
| 71 | return { verb: "reply", reason: "The crew will not go on until you answer." }; | |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | /** Items with their evidence; the diff of the first `EVIDENCE_LIMIT` pulls is read, in parallel. */ | |
| 76 | export async function reviewItems(ctx: Ctx, decisions: readonly Decision[] = reviewDecisions(ctx)): Promise<ReviewItem[]> { | |
| 77 | const shown = decisions.slice(0, REVIEW_LIMIT); | |
| 78 | const pulls = shown.flatMap((d) => (d.pull === undefined ? [] : [d.pull.id])); | |
| 79 | const checks = latestRunsForIssues(ctx.app.db, pulls); | |
| 80 | return Promise.all( | |
| 81 | shown.map(async (d, at): Promise<ReviewItem> => { | |
| 82 | const check = d.pull === undefined ? undefined : checks.get(d.pull.id); | |
| 83 | const stat = | |
| 84 | d.pull !== undefined && at < EVIDENCE_LIMIT | |
| 85 | ? await pullDiff(repoDir(ctx.app.reposRoot, d.repo.ownerName, d.repo.name), d.pull) | |
| 86 | .then((r) => r.diff) | |
| 87 | .catch(() => undefined) | |
| 88 | : undefined; | |
| 89 | return { | |
| 90 | decision: d, | |
| 91 | why: firstSentence(d.says), | |
| 92 | recommendation: recommend(d, check), | |
| 93 | evidence: { | |
| 94 | ...(check === undefined | |
| 95 | ? {} | |
| 96 | : { check: { state: check.state, note: check.state === "ok" ? "green" : check.state === "failed" ? "red" : check.state } }), | |
| 97 | ...(stat === undefined || stat.files.length === 0 | |
| 98 | ? {} | |
| 99 | : { stat: { files: stat.files.length, additions: stat.additions, deletions: stat.deletions } }), | |
| 100 | preview: d.preview, | |
| 101 | picture: d.picture, | |
| 102 | }, | |
| 103 | }; | |
| 104 | }), | |
| 105 | ); | |
| 106 | } |
src/web/studio/review_page.ts added +217
| @@ -0,0 +1,217 @@ | ||
| 1 | /** | |
| 2 | * `/review`: one column where the owner decides. Each item says what it is, | |
| 3 | * why it needs a person, what the crew recommends and the evidence, and | |
| 4 | * carries the buttons to act — Merge (through `mergePull`, the landing | |
| 5 | * gate), Close, Request changes with a box, Reply. Every button posts to | |
| 6 | * `/review/act` and comes back here, to the next item. Keys: j/k move, m | |
| 7 | * merges, c closes, r writes (Ctrl/Cmd+Enter sends it). The data is | |
| 8 | * `review.ts`; nothing here decides what is an item. | |
| 9 | */ | |
| 10 | ||
| 11 | import { mergePull, submitReview } from "../../actions/pulls.ts"; | |
| 12 | import { addCommentThrough, setIssueStateThrough } from "../../actions/issues.ts"; | |
| 13 | import { notePhase } from "../../core/route_timing.ts"; | |
| 14 | import type { Ctx } from "../../http/context.ts"; | |
| 15 | import { repoBase, signInFirst } from "../chrome.ts"; | |
| 16 | import { field, readForm } from "../form.ts"; | |
| 17 | import { html, type Html } from "../html.ts"; | |
| 18 | import { flashTo, page } from "../layout.ts"; | |
| 19 | import { originError } from "../pages/thread.ts"; | |
| 20 | import { btn, empty, timeAgo } from "../ui.ts"; | |
| 21 | import { askAnchor } from "./asks.ts"; | |
| 22 | import { reviewDecisions, reviewItems, type ReviewItem } from "./review.ts"; | |
| 23 | ||
| 24 | /** The most a typed answer may be: the forge's comment bound is larger, this keeps a box honest. */ | |
| 25 | const WORDS_MAX = 10_000; | |
| 26 | ||
| 27 | /** Hours as the home line says them: "5h", or days past two. */ | |
| 28 | export function waited(since: string, now = Date.now()): string { | |
| 29 | const hours = Math.max(0, Math.floor((now - Date.parse(since)) / 3_600_000)); | |
| 30 | return hours < 48 ? `${hours}h` : `${Math.floor(hours / 24)}d`; | |
| 31 | } | |
| 32 | ||
| 33 | /** "3 waiting on you, oldest 26h": the one line the home and this page share. */ | |
| 34 | export const waitingLine = (count: number, oldest: string | undefined, now = Date.now()): string => | |
| 35 | `${count} waiting on you${oldest === undefined ? "" : `, oldest ${waited(oldest, now)}`}`; | |
| 36 | ||
| 37 | const itemLink = (item: ReviewItem): string => { | |
| 38 | const d = item.decision; | |
| 39 | const base = repoBase(d.repo); | |
| 40 | return d.pull !== undefined ? `${base}/pulls/${d.pull.number}` : `${base}/issues/${d.issue!.number}`; | |
| 41 | }; | |
| 42 | ||
| 43 | function evidenceLine(item: ReviewItem): Html | null { | |
| 44 | const e = item.evidence; | |
| 45 | const bits: Html[] = []; | |
| 46 | if (e.check !== undefined) bits.push(html`<span>check ${e.check.note}</span>`); | |
| 47 | if (e.stat !== undefined) | |
| 48 | bits.push( | |
| 49 | html`<span>${e.stat.files} ${e.stat.files === 1 ? "file" : "files"} +${e.stat.additions} −${e.stat.deletions}</span>`, | |
| 50 | ); | |
| 51 | if (e.preview !== undefined) bits.push(html`<a href="${e.preview}">preview</a>`); | |
| 52 | if (bits.length === 0) return null; | |
| 53 | return html`<p class="small muted">${bits.map((b, i) => html`${i > 0 ? " · " : null}${b}`)}</p>`; | |
| 54 | } | |
| 55 | ||
| 56 | function itemCard(item: ReviewItem, current: boolean): Html { | |
| 57 | const d = item.decision; | |
| 58 | const thing = d.pull ?? d.issue!; | |
| 59 | const noun = d.pull !== undefined ? "Pull request" : "Issue"; | |
| 60 | const canMerge = d.pull !== undefined && d.kind !== "stopped"; | |
| 61 | const writes = d.pull !== undefined ? "Request changes" : "Reply"; | |
| 62 | return html`<article | |
| 63 | data-review-item | |
| 64 | id="r-${askAnchor(d.id)}" | |
| 65 | ${current ? html`aria-current="true"` : null} | |
| 66 | > | |
| 67 | <h2> | |
| 68 | <a href="${itemLink(item)}">${thing.title}</a> | |
| 69 | </h2> | |
| 70 | <p class="muted small"> | |
| 71 | ${noun} #${thing.number} · ${d.repo.ownerName}/${d.repo.name} · ${d.who} · waiting ${waited(d.since)} | |
| 72 | </p> | |
| 73 | <p>${item.why}</p> | |
| 74 | <p> | |
| 75 | <strong>Crew recommends: ${item.recommendation.verb}.</strong> ${item.recommendation.reason} | |
| 76 | </p> | |
| 77 | ${evidenceLine(item)} | |
| 78 | ${item.evidence.picture !== undefined | |
| 79 | ? html`<img src="${item.evidence.picture}" alt="The preview, as the crew last saw it" loading="lazy" />` | |
| 80 | : null} | |
| 81 | <form method="post" action="/review/act" data-review-act> | |
| 82 | <input type="hidden" name="ask" value="${d.id}" /> | |
| 83 | <textarea | |
| 84 | name="body" | |
| 85 | rows="2" | |
| 86 | maxlength="${WORDS_MAX}" | |
| 87 | placeholder="${d.pull !== undefined ? "What should change, or a word for the crew" : "Your answer"}" | |
| 88 | aria-label="${writes}" | |
| 89 | ></textarea> | |
| 90 | <div class="bar"> | |
| 91 | ${canMerge ? btn("Merge", { name: "do", value: "merge", variant: "primary", size: "sm" }) : null} | |
| 92 | ${btn("Close", { name: "do", value: "close", size: "sm" })} | |
| 93 | ${d.pull !== undefined | |
| 94 | ? btn("Request changes", { name: "do", value: "changes", size: "sm" }) | |
| 95 | : null} | |
| 96 | ${d.pull === undefined | |
| 97 | ? btn("Reply", { name: "do", value: "reply", size: "sm", variant: "primary" }) | |
| 98 | : btn("Reply", { name: "do", value: "reply", size: "sm" })} | |
| 99 | <span class="muted small"><kbd>m</kbd> merge · <kbd>c</kbd> close · <kbd>r</kbd> write</span> | |
| 100 | </div> | |
| 101 | </form> | |
| 102 | </article>`; | |
| 103 | } | |
| 104 | ||
| 105 | const reviewJs = ` | |
| 106 | (function () { | |
| 107 | var items = Array.prototype.slice.call(document.querySelectorAll('[data-review-item]')); | |
| 108 | if (!items.length) return; | |
| 109 | var at = 0; | |
| 110 | function show(n) { | |
| 111 | if (n < 0 || n >= items.length) return; | |
| 112 | items[at].removeAttribute('aria-current'); | |
| 113 | at = n; | |
| 114 | items[at].setAttribute('aria-current', 'true'); | |
| 115 | items[at].scrollIntoView({ block: 'nearest' }); | |
| 116 | } | |
| 117 | function press(sel) { | |
| 118 | var b = items[at].querySelector(sel); | |
| 119 | if (b) b.click(); | |
| 120 | } | |
| 121 | window.addEventListener('keydown', function (e) { | |
| 122 | if (e.metaKey || e.altKey) return; | |
| 123 | var t = e.target; | |
| 124 | var typing = t && (t.tagName === 'TEXTAREA' || t.tagName === 'INPUT' || t.isContentEditable); | |
| 125 | if (typing) { | |
| 126 | if (e.ctrlKey && e.key === 'Enter') { e.preventDefault(); press('button[value=changes],button[value=reply]'); } | |
| 127 | return; | |
| 128 | } | |
| 129 | if (e.ctrlKey) return; | |
| 130 | var k = e.key; | |
| 131 | if (k === 'j') show(at + 1); | |
| 132 | else if (k === 'k') show(at - 1); | |
| 133 | else if (k === 'm') press('button[value=merge]'); | |
| 134 | else if (k === 'c') press('button[value=close]'); | |
| 135 | else if (k === 'r') { var box = items[at].querySelector('textarea'); if (box) box.focus(); } | |
| 136 | else return; | |
| 137 | e.preventDefault(); | |
| 138 | e.stopPropagation(); | |
| 139 | }, true); | |
| 140 | items.forEach(function (el, i) { | |
| 141 | el.addEventListener('focusin', function () { if (i !== at) show(i); }); | |
| 142 | }); | |
| 143 | })(); | |
| 144 | `; | |
| 145 | ||
| 146 | /** GET /review */ | |
| 147 | export async function reviewPage(ctx: Ctx): Promise<Response> { | |
| 148 | if (!ctx.auth.user) return signInFirst(ctx); | |
| 149 | let started = performance.now(); | |
| 150 | const decisions = reviewDecisions(ctx); | |
| 151 | notePhase(ctx.request, "items", performance.now() - started); | |
| 152 | started = performance.now(); | |
| 153 | const items = await reviewItems(ctx, decisions); | |
| 154 | notePhase(ctx.request, "evidence", performance.now() - started); | |
| 155 | started = performance.now(); | |
| 156 | const oldest = decisions.reduce<string | undefined>((a, d) => (a === undefined || d.since < a ? d.since : a), undefined); | |
| 157 | const body = | |
| 158 | items.length === 0 | |
| 159 | ? html`<div id="review" class="stack"> | |
| 160 | <h1>Review</h1> | |
| 161 | ${empty({ icon: "check", title: "Nothing is waiting on you", note: "Pull requests and questions the crew cannot settle itself land here." })} | |
| 162 | </div>` | |
| 163 | : html`<div id="review" class="stack"> | |
| 164 | <h1>Review</h1> | |
| 165 | <p class="muted" id="review-line">${waitingLine(decisions.length, oldest)}</p> | |
| 166 | ${items.map((item, i) => itemCard(item, i === 0))} | |
| 167 | ${decisions.length > items.length | |
| 168 | ? html`<p class="muted small">${decisions.length - items.length} more follow as these are settled.</p>` | |
| 169 | : null} | |
| 170 | </div>`; | |
| 171 | const response = page({ ctx, title: "Review", body, scriptJs: reviewJs }); | |
| 172 | notePhase(ctx.request, "render", performance.now() - started); | |
| 173 | return response; | |
| 174 | } | |
| 175 | ||
| 176 | /** POST /review/act — one verb on one item, then back to the list. */ | |
| 177 | export async function reviewAct(ctx: Ctx): Promise<Response> { | |
| 178 | const user = ctx.auth.user; | |
| 179 | if (!user) return signInFirst(ctx); | |
| 180 | const form = await readForm(ctx, "rw"); | |
| 181 | if (form instanceof Response) return form; | |
| 182 | const say = (message: string, tone?: "danger") => flashTo(ctx, "/review", tone === undefined ? { message } : { tone, message }); | |
| 183 | const d = reviewDecisions(ctx).find((x) => x.id === field(form, "ask")); | |
| 184 | if (d === undefined) return say("That is no longer waiting on you.", "danger"); | |
| 185 | const thing = d.pull ?? d.issue; | |
| 186 | if (thing === undefined) return say("That is no longer waiting on you.", "danger"); | |
| 187 | const words = field(form, "body").trim(); | |
| 188 | const verb = field(form, "do"); | |
| 189 | const app = ctx.app; | |
| 190 | const noun = d.pull !== undefined ? "pull request" : "issue"; | |
| 191 | ||
| 192 | if (verb === "merge") { | |
| 193 | if (d.pull === undefined || d.kind === "stopped") return say("Only a pull request that is not failing can be merged here.", "danger"); | |
| 194 | const merged = await mergePull(app, user, d.repo, d.pull, "squash"); | |
| 195 | if (merged.ok) return say(`Merged #${d.pull.number}.`); | |
| 196 | const error = merged.error; | |
| 197 | const why = | |
| 198 | typeof error === "string" ? error : "kind" in error ? ("files" in error ? `${error.kind}: ${error.files.join(", ")}` : error.kind) : "refused"; | |
| 199 | return say(`Not merged: ${why.replace(/_/g, " ")}.`, "danger"); | |
| 200 | } | |
| 201 | if (verb === "close") { | |
| 202 | const closed = await setIssueStateThrough(app, user, d.repo, thing, "closed"); | |
| 203 | return closed.ok ? say(`Closed ${noun} #${thing.number}.`) : say(originError(closed.error) ?? `The ${noun} could not be closed.`, "danger"); | |
| 204 | } | |
| 205 | if (verb === "changes" || verb === "reply") { | |
| 206 | if (words === "") return say("Write something first.", "danger"); | |
| 207 | if (words.length > WORDS_MAX) return say("That is too long.", "danger"); | |
| 208 | if (verb === "changes") { | |
| 209 | if (d.pull === undefined) return say("Only a pull request takes changes; reply instead.", "danger"); | |
| 210 | const sent = await submitReview(app, user, d.repo, d.pull, { state: "changes_requested", body: words }); | |
| 211 | return sent.ok ? say(`Asked for changes on #${d.pull.number}.`) : say(originError(sent.error) ?? "That could not be sent.", "danger"); | |
| 212 | } | |
| 213 | const sent = await addCommentThrough(app, user, d.repo, thing, words); | |
| 214 | return sent.ok ? say(`Replied on #${thing.number}.`) : say(originError(sent.error) ?? "That could not be sent.", "danger"); | |
| 215 | } | |
| 216 | return say("Pick merge, close, request changes or reply.", "danger"); | |
| 217 | } |
src/web/studio/style.ts +13
| @@ -57,6 +57,18 @@ const rowActions = part(/* css */ ` | ||
| 57 | 57 | .studio-ask-actions { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; } |
| 58 | 58 | `); |
| 59 | 59 | |
| 60 | /** `/review`: one quiet column; the current item has a rule beside it (`review_page.ts`). Selectors by id and attribute: no class of its own. */ | |
| 61 | const review = part(/* css */ ` | |
| 62 | #review { max-width: 720px; } | |
| 63 | #review article { border-left: 3px solid transparent; padding: 4px 0 12px 12px; border-bottom: 1px solid var(--border); } | |
| 64 | #review article[aria-current="true"] { border-left-color: var(--accent); } | |
| 65 | #review h2 { font-size: 16px; margin: 0; } | |
| 66 | #review article p { margin: 4px 0; } | |
| 67 | #review textarea { width: 100%; min-height: 56px; resize: vertical; margin-top: 6px; } | |
| 68 | #review .bar { flex-wrap: wrap; gap: 8px; margin-top: 6px; } | |
| 69 | #review img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 6px 0; } | |
| 70 | `); | |
| 71 | ||
| 60 | 72 | /** The phone: one document, narrower. Each rule belongs to a component above |
| 61 | 73 | * and only ever applies at 600px and under, so nothing changes on a desktop. */ |
| 62 | 74 | const phone = part(/* css */ ` |
| @@ -87,6 +99,7 @@ export const studioCss = `@layer components {\n${[ | ||
| 87 | 99 | wordBadges, |
| 88 | 100 | rows, |
| 89 | 101 | rowActions, |
| 102 | review, | |
| 90 | 103 | part(feedCss), |
| 91 | 104 | phone, |
| 92 | 105 | ].join("\n\n")}\n}`; |
test/review.test.ts added +230
| @@ -0,0 +1,230 @@ | ||
| 1 | /** | |
| 2 | * `/review` (#3247): the one page where the owner decides. A handed-over | |
| 3 | * pull, a green pull waiting past a day and a question the crew put are on | |
| 4 | * it and nothing else is; the home says "3 waiting on you"; every button | |
| 5 | * acts and the list moves on. | |
| 6 | */ | |
| 7 | ||
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { createAgent } from "../src/actions/crew.ts"; | |
| 14 | import { openPull } from "../src/actions/pulls.ts"; | |
| 15 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 16 | import { addCrew, setCrewRole } from "../src/core/agents.ts"; | |
| 17 | import { addComment, createIssue, getIssueById, listComments } from "../src/core/issues.ts"; | |
| 18 | import { getPull } from "../src/core/pulls.ts"; | |
| 19 | import type { Repo } from "../src/core/repos.ts"; | |
| 20 | import { submitReview } from "../src/core/reviews.ts"; | |
| 21 | import { createRun } from "../src/core/runs.ts"; | |
| 22 | import { createSession } from "../src/core/sessions.ts"; | |
| 23 | import { createUser, type User } from "../src/core/users.ts"; | |
| 24 | import { BREAKER_NOTE } from "../src/crew/breaker.ts"; | |
| 25 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 26 | import { id } from "../src/kernel/id.ts"; | |
| 27 | import { quietLogs } from "./helpers/globals.ts"; | |
| 28 | ||
| 29 | quietLogs(); | |
| 30 | ||
| 31 | const HOUR = 3_600_000; | |
| 32 | const ZERO = "0".repeat(40); | |
| 33 | ||
| 34 | describe("/review", () => { | |
| 35 | let dataDir: string; | |
| 36 | let app: App; | |
| 37 | let servers: Servers; | |
| 38 | let owner: User; | |
| 39 | let reviewer: User; | |
| 40 | let repo: Repo; | |
| 41 | let cookie = ""; | |
| 42 | let seq = 0; | |
| 43 | ||
| 44 | const green = (issueId: string, oid: string, hoursAgo: number) => { | |
| 45 | const run = createRun(app.db, { repoId: repo.id, kind: "check", issueId, commitOid: oid }); | |
| 46 | app.db | |
| 47 | .query("UPDATE run SET state = 'ok', created_at = ?2, finished_at = ?2 WHERE id = ?1") | |
| 48 | .run(run.id, new Date(Date.now() - hoursAgo * HOUR).toISOString()); | |
| 49 | }; | |
| 50 | ||
| 51 | /** A real pull by the owner: a branch with one file, opened. */ | |
| 52 | const realPull = async (title: string, hoursGreen: number) => { | |
| 53 | const branch = `work/${++seq}`; | |
| 54 | const committed = await commitToBranch(app, owner, repo, { | |
| 55 | branch, | |
| 56 | base: "main", | |
| 57 | message: title, | |
| 58 | files: [{ path: `f${seq}.md`, content: "x\n" }], | |
| 59 | }); | |
| 60 | if (!committed.ok) throw new Error(String(committed.error)); | |
| 61 | const opened = await openPull(app, owner, repo, { title, body: "", baseBranch: "main", headBranch: branch }); | |
| 62 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 63 | green(opened.value.id, opened.value.headOid, hoursGreen); | |
| 64 | return opened.value; | |
| 65 | }; | |
| 66 | ||
| 67 | /** A pull three reviews have asked changes of, as rows: handed to a person. */ | |
| 68 | const handedPull = (title: string) => { | |
| 69 | const issueId = id(); | |
| 70 | const number = app.db | |
| 71 | .query<{ issue_seq: number }, [string]>("UPDATE repo SET issue_seq = issue_seq + 1 WHERE id = ?1 RETURNING issue_seq") | |
| 72 | .get(repo.id)!.issue_seq; | |
| 73 | app.db | |
| 74 | .query( | |
| 75 | `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at) | |
| 76 | VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'open', ?6)`, | |
| 77 | ) | |
| 78 | .run(issueId, repo.id, number, title, owner.id, new Date(Date.now() - 3 * HOUR).toISOString()); | |
| 79 | app.db | |
| 80 | .query( | |
| 81 | `INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) | |
| 82 | VALUES (?1, 'main', ?2, ?3, ?3, ?4)`, | |
| 83 | ) | |
| 84 | .run(issueId, `crew/${++seq}`, ZERO, repo.id); | |
| 85 | const said = addComment(app.db, { issueId, authorId: owner.id, body: "Have a look." }); | |
| 86 | if (!said.ok) throw new Error(said.error); | |
| 87 | app.db.query("UPDATE comment SET created_at = ?2 WHERE id = ?1").run(said.value.id, new Date(Date.now() - 2 * HOUR).toISOString()); | |
| 88 | for (let r = 0; r < 3; r++) | |
| 89 | submitReview(app.db, { issueId, authorId: reviewer.id, state: "changes_requested", body: `Round ${r}.`, commitOid: ZERO }); | |
| 90 | return { issueId, number }; | |
| 91 | }; | |
| 92 | ||
| 93 | /** An issue the crew parked: its newest comment is the breaker's note. */ | |
| 94 | const parkedIssue = (title: string) => { | |
| 95 | const made = createIssue(app.db, { repoId: repo.id, authorId: owner.id, title, body: "" }); | |
| 96 | if (!made.ok) throw new Error(String(made.error)); | |
| 97 | const note = addComment(app.db, { issueId: made.value.id, authorId: reviewer.id, body: BREAKER_NOTE }); | |
| 98 | if (!note.ok) throw new Error(note.error); | |
| 99 | return made.value; | |
| 100 | }; | |
| 101 | ||
| 102 | const get = async (path: string) => { | |
| 103 | const response = await fetch(`${servers.url}${path}`, { headers: { cookie } }); | |
| 104 | expect(response.status).toBe(200); | |
| 105 | return response.text(); | |
| 106 | }; | |
| 107 | const post = (fields: Record<string, string>, extra: Record<string, string> = {}) => | |
| 108 | fetch(`${servers.url}/review/act`, { | |
| 109 | method: "POST", | |
| 110 | headers: { cookie, origin: servers.url, ...extra }, | |
| 111 | body: new URLSearchParams(fields), | |
| 112 | redirect: "manual", | |
| 113 | }); | |
| 114 | ||
| 115 | beforeAll(async () => { | |
| 116 | dataDir = await mkdtemp(join(tmpdir(), "forge-review-")); | |
| 117 | app = createApp({ dataDir, port: 0 }); | |
| 118 | const made = await createUser(app.db, { | |
| 119 | origin: "seed", | |
| 120 | trusted: true, | |
| 121 | username: "keeper", | |
| 122 | email: "[email protected]", | |
| 123 | password: "a-good-passphrase", | |
| 124 | adminIfFirst: true, | |
| 125 | }); | |
| 126 | if (!made.ok) throw new Error(made.error); | |
| 127 | owner = made.value; | |
| 128 | const agent = await createAgent(app, owner, { username: "plumb" }); | |
| 129 | if (!agent.ok) throw new Error(String(agent.error)); | |
| 130 | reviewer = agent.value.user; | |
| 131 | const r = await createRepo(app, owner, { name: "shop", visibility: "public" }); | |
| 132 | if (!r.ok) throw new Error(String(r.error)); | |
| 133 | repo = r.value; | |
| 134 | addCrew(app.db, repo.id, reviewer.id, owner.id); | |
| 135 | setCrewRole(app.db, repo.id, reviewer.id, "reviewer"); | |
| 136 | const seeded = await commitToBranch(app, owner, repo, { | |
| 137 | message: "seed", | |
| 138 | files: [{ path: "README.md", content: "# shop\n" }], | |
| 139 | }); | |
| 140 | if (!seeded.ok) throw new Error(String(seeded.error)); | |
| 141 | cookie = `forge_session=${createSession(app.db, owner.id).token}`; | |
| 142 | servers = await serve(app); | |
| 143 | }); | |
| 144 | ||
| 145 | afterAll(async () => { | |
| 146 | servers?.stop(); | |
| 147 | app?.close(); | |
| 148 | await rm(dataDir, { recursive: true, force: true }); | |
| 149 | }); | |
| 150 | ||
| 151 | test("lists exactly the handed-over pull, the stale pull and the question; home counts three", async () => { | |
| 152 | const empty = await get("/review"); | |
| 153 | expect(empty).toContain("Nothing is waiting on you"); | |
| 154 | expect(await get("/")).not.toContain("waiting on you"); | |
| 155 | ||
| 156 | handedPull("Handed over"); | |
| 157 | await realPull("Stale green", 30); | |
| 158 | await realPull("Fresh green", 1); | |
| 159 | parkedIssue("A question"); | |
| 160 | ||
| 161 | const page = await get("/review"); | |
| 162 | expect(page).toContain("Handed over"); | |
| 163 | expect(page).toContain("Stale green"); | |
| 164 | expect(page).toContain("A question"); | |
| 165 | expect(page).not.toContain("Fresh green"); | |
| 166 | expect(page.match(/<article[^>]*data-review-item/g)?.length).toBe(3); | |
| 167 | expect(page).toContain("3 waiting on you, oldest 30h"); | |
| 168 | // Each item: why, the crew's recommendation, the buttons. | |
| 169 | expect(page).toContain("Crew recommends: approve."); | |
| 170 | expect(page).toContain("Crew recommends: change."); | |
| 171 | expect(page).toContain("Crew recommends: reply."); | |
| 172 | expect(page).toContain("check green"); | |
| 173 | expect(page).toContain('value="merge"'); | |
| 174 | expect(page).toContain('value="changes"'); | |
| 175 | expect(page).toContain("Pull request #"); | |
| 176 | ||
| 177 | const home = await get("/"); | |
| 178 | expect(home).toContain('<a href="/review">3 waiting on you, oldest 30h</a>'); | |
| 179 | expect(home).not.toContain("Crew recommends"); | |
| 180 | expect(home).not.toContain("data-review-item"); | |
| 181 | }); | |
| 182 | ||
| 183 | test("a signed-out reader is sent to sign in", async () => { | |
| 184 | const response = await fetch(`${servers.url}/review`, { redirect: "manual" }); | |
| 185 | expect(response.status).toBe(303); | |
| 186 | expect(response.headers.get("location")).toContain("/signin"); | |
| 187 | }); | |
| 188 | ||
| 189 | test("reply answers the question and the item leaves", async () => { | |
| 190 | const q = parkedIssue("Second question"); | |
| 191 | const before = (await get("/review")).match(/<article[^>]*data-review-item/g)?.length ?? 0; | |
| 192 | const empty = await post({ ask: `parked:${q.id}`, do: "reply", body: "" }); | |
| 193 | expect(empty.status).toBe(303); | |
| 194 | expect(listComments(app.db, q.id).length).toBe(1); | |
| 195 | const sent = await post({ ask: `parked:${q.id}`, do: "reply", body: "Try the other way." }); | |
| 196 | expect(sent.headers.get("location")).toBe("/review"); | |
| 197 | expect(listComments(app.db, q.id).at(-1)?.body).toBe("Try the other way."); | |
| 198 | expect((await get("/review")).match(/<article[^>]*data-review-item/g)?.length).toBe(before - 1); | |
| 199 | }); | |
| 200 | ||
| 201 | test("request changes records the review; close closes the pull; merge lands a stale green pull", async () => { | |
| 202 | const stale = await realPull("Mergeable", 26); | |
| 203 | const handed = handedPull("To close"); | |
| 204 | const changes = await realPull("Needs work", 25); | |
| 205 | ||
| 206 | expect((await post({ ask: `look:${changes.id}`, do: "changes", body: "" })).status).toBe(303); | |
| 207 | await post({ ask: `look:${changes.id}`, do: "changes", body: "Rename the file." }); | |
| 208 | const rows = app.db | |
| 209 | .query<{ state: string; body: string }, [string]>("SELECT state, body FROM review WHERE issue_id = ?1") | |
| 210 | .all(changes.id); | |
| 211 | expect(rows).toEqual([{ state: "changes_requested", body: "Rename the file." }]); | |
| 212 | ||
| 213 | await post({ ask: `handover:${handed.issueId}`, do: "close" }); | |
| 214 | expect(getIssueById(app.db, handed.issueId)?.state).toBe("closed"); | |
| 215 | ||
| 216 | const merged = await post({ ask: `look:${stale.id}`, do: "merge" }); | |
| 217 | expect(merged.headers.get("location")).toBe("/review"); | |
| 218 | expect(getPull(app.db, repo.id, stale.number)?.mergedAt).not.toBeNull(); | |
| 219 | expect((await get("/review")).includes("Mergeable")).toBe(false); | |
| 220 | }); | |
| 221 | ||
| 222 | test("an item that is not waiting on the owner cannot be acted on; a foreign origin is refused", async () => { | |
| 223 | const fresh = await realPull("Quiet green", 1); | |
| 224 | await post({ ask: `look:${fresh.id}`, do: "close" }); | |
| 225 | expect(getIssueById(app.db, fresh.id)?.state).toBe("open"); | |
| 226 | const foreign = await post({ ask: `look:${fresh.id}`, do: "close" }, { origin: "https://evil.example" }); | |
| 227 | expect(foreign.status).toBe(403); | |
| 228 | expect(getIssueById(app.db, fresh.id)?.state).toBe("open"); | |
| 229 | }); | |
| 230 | }); |
new above
offline