Public: anyone can read this; the crew can change it.
/next with no repository shows the owner's priorities across every repository they administer, one ranked group per repository #15880
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15870-next-with-no-repository-shows-the-owner → main 0 commits fork 6 threads · 6 unresolved
14 files
changed +387
−4
docs/design/audit.md +1
| @@ -72,6 +72,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 72 | 72 | - `/talk` — `pages/talk.ts` · the person's one conversation with the forge: history, composer, Do it and Not now; replies stream in over `/talk/stream` · `/settings/confirms` (the same yes, as a list), the home tell box (one line to an app's crew) · none seen; styles in `docs/design/areas/talk.md`. |
| 73 | 73 | - `/tell` — `studio/share_tell.ts` · where a phone's share sheet lands: the shared words in a form, the last repository chosen, nothing filed until Send · the phone's share sheet (manifest `share_target`) · none seen. |
| 74 | 74 | - `/tell/share` — `studio/share_receive.ts` · the words a phone shared while signed out, held on the server through sign-in, in a form filed only on Send · the sign-in redirect after a share · none seen. |
| 75 | - `/next` — `pages/next_all.ts` · the owner's priorities, one ranked group per administered repository · the repository's Next up page, `next_up` on the MCP · none seen. | |
| 75 | 76 | - `/notes` — `pages/notes.ts` · what the person wrote, newest first, with the planner's verdict and live state in one line, and one tap to overrule it · the home tell box (Notes button), the user menu, the palette · none seen; styles in `docs/design/areas/notes.md`. |
| 76 | 77 | - `/pipeline` — `pages/pipeline.ts` · the four steps a change follows (check, review, land, live), for a newcomer · a pull page's step line, `/flow` · none seen. |
| 77 | 78 | - `/packs` — `pages/packs.ts` · the premade forges this forge ships, what each brings, how to deploy it and how a stranger helps build its apps · the user menu, the signed-out menu, the palette · none seen; uses the shared card, list and button components. |
docs/features/next-up.md +7
| @@ -38,3 +38,10 @@ The subscription's weekly reset is the sprint boundary; what the crew may still | ||
| 38 | 38 | - Sealed issues are left out of history and of the retrospective, so their cost never shapes a visible range. |
| 39 | 39 | |
| 40 | 40 | **From outside (#15840):** above the list, a writer sees each waiting report from an outsider as one row: who sent it (`@name`, "claims to be x, unproven" or "anonymous"), the one-line ask (its title, escaped, at most 140 characters) and two plain forms. *Adopt* opens the report as an issue behind the outside marker (`acceptReport`); *Decline* closes it with one line of why (`dismissReport`; empty says "Not something we will take up right now."), which the sender reads as `reason` at their status link. Both post to `POST /:owner/:name/next` (`report`, `decision` = `adopt` or `decline`, `reason`) and come back to the same page. **Offers (#15887):** an outside pull waiting for approval is the same row (sender "anonymous, offered a change", its title as the ask), posted with `offer` = the pull number. *Adopt* is the pull page's guest approval (`approveGuestPull`): the pull then runs its check and a person can still merge it. *Decline* closes the pull with the one line of why (`decideOffer`), kept on the sender's receipt: `GET /api/v1/offers/:receipt` answers it as `why`. Pinned by `test/next-outsider-offer.test.ts`. At most twenty rows show (the oldest); the heading counts all and a line links the rest on the reports page. At 360px the reason takes its own line under the buttons. **Terminal:** the reports screen lists the waiting offers beside the reports (the palette row counts both): `a` adopts an offer, `d` declines it with the typed line, both through `decideOffer`, read again on every draw (`test/tui-offers.test.ts`). The waiting offers are one statement, whatever their number (`waitingOffers`). On a report, `d` opens a prompt for one line of why (empty says the same default) and sends it to the sender's status link; the words come from `actions/outsider_decision.ts`. Pinned by `test/next-outsider-report.test.ts`. |
| 41 | ||
| 42 | ## Across repositories (#15870) | |
| 43 | ||
| 44 | `/next` (`src/web/pages/next_all.ts`) shows the top three of each repository's list for every repository you administer, one card per repository, most recently active first. A repository's name links to its own Next up page, where the moves are made; `/next` only reads. Each row is the same ranking `/:owner/:name/next` shows, and a card says how many more rows are on its list. At most 5 repositories are read per request; `?repo=owner/name` (repeatable, at most 20 names) narrows to those, and a name that is unknown or not yours to administer is left out. A repository with nothing open and ranked has no card. Signed out, the page asks you to sign in. | |
| 45 | ||
| 46 | - **Terminal:** the palette's "Next up, every repository" (`src/tui/screens/next.ts`) prints the same groups (`nextAll` in `src/core/next_all.ts`); `j`/`k` scroll. | |
| 47 | - **MCP:** `next_up` without `app` answers `{ groups: [{ repo, more, next }] }`; with `issue` and no `app` it is refused, since a move names its repository. |
src/core/empty_words.ts +2
| @@ -94,6 +94,8 @@ export const NOTE_WORDS = { | ||
| 94 | 94 | noDevicesDeclared: "No devices declared.", |
| 95 | 95 | nothingIsWaitingToBeSent: "Nothing is waiting to be sent.", |
| 96 | 96 | nothingYet: "Nothing yet.", |
| 97 | nothingOpenAndRanked: "Nothing is open and ranked.", | |
| 98 | nothingOpenAndRankedHere: "Nothing is open and ranked in those repositories.", | |
| 97 | 99 | noFlowLinesMatch: "No flow lines match.", |
| 98 | 100 | notSignedInOnAnyBrowser: "Not signed in on any browser.", |
| 99 | 101 | noAccessCodesYet: "No access codes yet. Mint one when a script, a CI job, or another machine needs to act as you.", |
src/core/next_all.ts added +89
| @@ -0,0 +1,89 @@ | ||
| 1 | /** | |
| 2 | * Next up across repositories (#15870): the repositories a person administers | |
| 3 | * that have open work to do, in the order of their last activity, each with the | |
| 4 | * top {@link GROUP_ROWS} rows of its own `nextUp`. The page `/next` and the MCP | |
| 5 | * tool `next_up` without an app both read this, so they cannot disagree. | |
| 6 | * Plain data in, plain data out; read-only. | |
| 7 | */ | |
| 8 | import type { App } from "../app.ts"; | |
| 9 | import { notStartable } from "../crew/not_startable.ts"; | |
| 10 | import { nextUp, type NextRow } from "./next_up.ts"; | |
| 11 | import { canAdmin, getRepo, listReposWritableTo, type Repo } from "./repos.ts"; | |
| 12 | import { sealedScope } from "./sealed.ts"; | |
| 13 | import type { User } from "./users.ts"; | |
| 14 | ||
| 15 | /** Rows each repository shows. */ | |
| 16 | export const GROUP_ROWS = 3; | |
| 17 | /** The most groups one answer shows (the rest are read only for their last activity). */ | |
| 18 | export const GROUPS_MAX = 5; | |
| 19 | /** The most `repo` names one request narrows to. */ | |
| 20 | export const ONLY_MAX = 20; | |
| 21 | ||
| 22 | export interface NextGroup { | |
| 23 | readonly repo: Repo; | |
| 24 | /** The newest event on the repository, else when it was made (ISO 8601). */ | |
| 25 | readonly lastActivity: string; | |
| 26 | readonly rows: readonly NextRow[]; | |
| 27 | /** All rows on its list, shown or not. */ | |
| 28 | readonly total: number; | |
| 29 | } | |
| 30 | ||
| 31 | /** `owner/name` (any case) for each name that parses; anything else is dropped. */ | |
| 32 | export function onlyNames(raw: readonly string[]): string[] { | |
| 33 | const out: string[] = []; | |
| 34 | for (const s of raw.slice(0, ONLY_MAX)) { | |
| 35 | const parts = s.trim().split("/"); | |
| 36 | if (parts.length === 2 && /^[A-Za-z0-9._-]{1,100}$/.test(parts[0]!) && /^[A-Za-z0-9._-]{1,100}$/.test(parts[1]!)) | |
| 37 | out.push(`${parts[0]}/${parts[1]}`.toLowerCase()); | |
| 38 | } | |
| 39 | return out; | |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * One group per repository `user` administers with open work, newest activity first (ties by | |
| 44 | * `owner/name`). `only` narrows to those `owner/name`s; a name that is unknown or not theirs to | |
| 45 | * administer simply is not among them. | |
| 46 | */ | |
| 47 | export function nextAll(app: App, user: User, only: readonly string[] = []): NextGroup[] { | |
| 48 | const db = app.db; | |
| 49 | const names = onlyNames(only); | |
| 50 | let repos: Repo[]; | |
| 51 | if (names.length > 0) { | |
| 52 | repos = [...new Set(names)].flatMap((n) => { | |
| 53 | const [owner, name] = n.split("/") as [string, string]; | |
| 54 | const r = getRepo(db, owner, name); | |
| 55 | return r === undefined || r.archivedAt != null ? [] : [r]; | |
| 56 | }); | |
| 57 | } else { | |
| 58 | repos = listReposWritableTo(db, user, { withoutArchived: true, limit: 200 }); | |
| 59 | } | |
| 60 | // Every administered repository is ordered by activity first, and only then walked: cutting to | |
| 61 | // GROUPS_MAX before ordering would let empty or quiet repositories crowd out the newest one. | |
| 62 | const mine = repos.filter((r) => canAdmin(db, r, user)); | |
| 63 | if (mine.length === 0) return []; | |
| 64 | const marks = mine.map((_, i) => `?${i + 1}`).join(","); | |
| 65 | const seen = new Map( | |
| 66 | db | |
| 67 | .query<{ id: string; at: string }, string[]>( | |
| 68 | `SELECT repo.id AS id, COALESCE((SELECT MAX(event.created_at) FROM event WHERE event.repo_id = repo.id), repo.created_at) AS at | |
| 69 | FROM repo WHERE repo.id IN (${marks})`, | |
| 70 | ) | |
| 71 | .all(...mine.map((r) => r.id)) | |
| 72 | .map((r) => [r.id, r.at]), | |
| 73 | ); | |
| 74 | const at = (r: Repo): string => seen.get(r.id) ?? ""; | |
| 75 | mine.sort( | |
| 76 | (a, b) => | |
| 77 | (at(a) < at(b) ? 1 : at(a) > at(b) ? -1 : 0) || | |
| 78 | `${a.ownerName}/${a.name}`.localeCompare(`${b.ownerName}/${b.name}`), | |
| 79 | ); | |
| 80 | const groups: NextGroup[] = []; | |
| 81 | for (const repo of mine) { | |
| 82 | if (groups.length >= GROUPS_MAX) break; | |
| 83 | const scope = sealedScope(db, repo, user); | |
| 84 | const next = nextUp(db, repo, scope, (ready) => notStartable(app, repo, ready, scope)); | |
| 85 | if (next.rows.length === 0) continue; | |
| 86 | groups.push({ repo, lastActivity: at(repo), rows: next.rows.slice(0, GROUP_ROWS), total: next.rows.length }); | |
| 87 | } | |
| 88 | return groups; | |
| 89 | } |
src/core/reserved.ts +1
| @@ -144,6 +144,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 144 | 144 | "tell", |
| 145 | 145 | "talk", |
| 146 | 146 | "notes", |
| 147 | "next", | |
| 147 | 148 | "templates", |
| 148 | 149 | "theme", |
| 149 | 150 | "verify", |
src/http/marks/next.json added +4
| @@ -0,0 +1,4 @@ | ||
| 1 | { | |
| 2 | "head": "/next", | |
| 3 | "mark": "open" | |
| 4 | } |
src/http/mcp/tools/next_up.ts +12 −2
| @@ -3,6 +3,7 @@ import { placeOf, rankIssue } from "../../../actions/next.ts"; | ||
| 3 | 3 | import { nextUp, TOP, type NextRow } from "../../../core/next_up.ts"; |
| 4 | 4 | import { notStartable } from "../../../crew/not_startable.ts"; |
| 5 | 5 | import { lineAfter, weekView, type WeekView } from "../../../flow/week.ts"; |
| 6 | import { nextAll } from "../../../core/next_all.ts"; | |
| 6 | 7 | import { sealedScope } from "../../../core/sealed.ts"; |
| 7 | 8 | import { bad, good, type Tool, APP_ARG, planRepo, isAnswer, issueArg } from "../shared.ts"; |
| 8 | 9 | |
| @@ -25,7 +26,7 @@ const brief = (r: NextRow, week?: WeekView, at = 0) => ({ | ||
| 25 | 26 | |
| 26 | 27 | export const tool: Tool = { |
| 27 | 28 | name: "next_up", |
| 28 | doc: "an app's one ranked list, the crew builds strictly from the top (`app`; with `issue` and `to` — `top`, `not-now` or `after:<number>` — a writer moves that issue and it saves at once; `top` lifts a gated issue past the Later gate; `undo` takes back your `not-now` of the last minute; `all` lists beyond the top ten; each row carries its cost `estimate` range and `thisWeek`, and `projection` is one sentence on what the week can ship)", | |
| 29 | doc: "an app's one ranked list (without `app`: the top three of each repository you administer, newest activity first), the crew builds strictly from the top (`app`; with `issue` and `to` — `top`, `not-now` or `after:<number>` — a writer moves that issue and it saves at once; `top` lifts a gated issue past the Later gate; `undo` takes back your `not-now` of the last minute; `all` lists beyond the top ten; each row carries its cost `estimate` range and `thisWeek`, and `projection` is one sentence on what the week can ship)", | |
| 29 | 30 | description: "The ranked list the crew builds from; `issue` + `to` (top, not-now, after:N) moves one.", |
| 30 | 31 | inputSchema: { |
| 31 | 32 | type: "object", |
| @@ -35,11 +36,20 @@ export const tool: Tool = { | ||
| 35 | 36 | to: { type: "string", pattern: "^(top|not-now|undo|after:[1-9]\\d{0,8})$" }, |
| 36 | 37 | all: { type: "boolean" }, |
| 37 | 38 | }, |
| 38 | required: ["app"], | |
| 39 | 39 | }, |
| 40 | 40 | writes: true, |
| 41 | 41 | readsWithout: "issue", |
| 42 | 42 | run(ctx, user, args) { |
| 43 | if (args["app"] === undefined) { | |
| 44 | if (args["issue"] !== undefined) return bad("invalid", "name the `app` to move an issue"); | |
| 45 | return good({ | |
| 46 | groups: nextAll(ctx.app, user).map((g) => ({ | |
| 47 | repo: `${g.repo.ownerName}/${g.repo.name}`, | |
| 48 | more: g.total - g.rows.length, | |
| 49 | next: g.rows.map((r) => brief(r)), | |
| 50 | })), | |
| 51 | }); | |
| 52 | } | |
| 43 | 53 | const repo = planRepo(ctx, user, args); |
| 44 | 54 | if (isAnswer(repo)) return repo; |
| 45 | 55 | if (args["issue"] !== undefined) { |
src/http/server.ts +2
| @@ -285,6 +285,7 @@ import { mapPage } from "../web/pages/map.ts"; | ||
| 285 | 285 | import { spaceJson, spacePage } from "../web/pages/space.ts"; |
| 286 | 286 | import { firstSubmit } from "../web/pages/first.ts"; |
| 287 | 287 | import { nextPage, nextSubmit } from "../web/pages/next.ts"; |
| 288 | import { nextAllPage } from "../web/pages/next_all.ts"; | |
| 288 | 289 | import { nextBatch } from "../web/pages/next_batch.ts"; |
| 289 | 290 | import { weekPage, weekSubmit } from "../web/pages/week.ts"; |
| 290 | 291 | import { costCsvDownload, costPage } from "../web/pages/cost.ts"; |
| @@ -1490,6 +1491,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1490 | 1491 | router.add("GET", "/:owner/:name/map", mapPage); |
| 1491 | 1492 | router.add("GET", "/:owner/:name/space", spacePage); |
| 1492 | 1493 | router.add("GET", "/:owner/:name/space.json", spaceJson); |
| 1494 | router.add("GET", "/next", nextAllPage); | |
| 1493 | 1495 | router.add("GET", "/:owner/:name/next", nextPage); |
| 1494 | 1496 | router.add("POST", "/:owner/:name/next", nextSubmit); |
| 1495 | 1497 | router.add("POST", "/:owner/:name/next/batch", nextBatch); |
src/tui/screens/next.ts +52 −1
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | |
| 15 | 15 | import { rankedWords, rankIssue, stepTo, type Place, placeOf } from "../../actions/next.ts"; |
| 16 | 16 | import { listChapters, itemsOf, chapterLineWords } from "../../core/chapters.ts"; |
| 17 | import { nextAll, type NextGroup } from "../../core/next_all.ts"; | |
| 17 | 18 | import { nextUp, type NextRow } from "../../core/next_up.ts"; |
| 18 | 19 | import { batchWords, snoozeMany, undoMany } from "../../actions/next.ts"; |
| 19 | 20 | import { setPlannerSwitch } from "../../actions/planner_switch.ts"; |
| @@ -37,7 +38,8 @@ import { truncate, wrap } from "../term/width.ts"; | ||
| 37 | 38 | import type { Session } from "../session.ts"; |
| 38 | 39 | import { issueScreen } from "./issue.ts"; |
| 39 | 40 | import { local } from "./where.ts"; |
| 40 | import { ListState, drawList, hitList, live, promptScreen, type ListRow } from "./common.ts"; | |
| 41 | import { ListState, drawList, hitList, hitScroll, live, promptScreen, Scroll, drawLines, type ListRow } from "./common.ts"; | |
| 42 | import type { PaletteEntry } from "./entries.ts"; | |
| 41 | 43 | |
| 42 | 44 | /** |
| 43 | 45 | * What reorders or reshapes the list: a rank, or an issue opening, closing or changing what it |
| @@ -269,3 +271,52 @@ export function nextScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 269 | 271 | }; |
| 270 | 272 | return screen; |
| 271 | 273 | } |
| 274 | ||
| 275 | /** | |
| 276 | * Next up across repositories (#15870): read-only, the same `nextAll` as `/next` and the MCP tool. | |
| 277 | */ | |
| 278 | const mayReadAll = (session: Session): boolean => session.user !== undefined && session.user.kind !== "agent"; | |
| 279 | ||
| 280 | /** One line for each repository, then one per row: " 1. title (#7, on it: ada)". */ | |
| 281 | export function nextAllLines(groups: readonly NextGroup[]): string[] { | |
| 282 | return groups.flatMap((g) => [ | |
| 283 | `${g.repo.ownerName}/${g.repo.name}${g.total > g.rows.length ? ` (${String(g.total - g.rows.length)} more)` : ""}`, | |
| 284 | ...g.rows.map((r) => ` ${r.place === null ? "·" : `${String(r.place)}.`} ${r.issue.title} (#${String(r.issue.number)}${r.onIt === null ? "" : `, on it: ${r.onIt}`})`), | |
| 285 | ]); | |
| 286 | } | |
| 287 | ||
| 288 | export function nextAllScreen(ctx: Ctx, groups: readonly NextGroup[]): Screen { | |
| 289 | const scroll = new Scroll(); | |
| 290 | const lines = groups.length === 0 ? ["Nothing is open and ranked."] : nextAllLines(groups); | |
| 291 | return { | |
| 292 | title: "Next up, every repository", | |
| 293 | keys: [binding(["j", "k"], "scroll"), binding(["esc", "q"], "back")], | |
| 294 | render(area, s) { | |
| 295 | const c = ctx.theme.c; | |
| 296 | const spans = lines.map((text) => [{ text, style: style(text.startsWith(" ") || groups.length === 0 ? c.mutedFg : c.fg, c.bg) }]); | |
| 297 | drawLines(s, area, c, scroll, spans); | |
| 298 | hitScroll(ctx, area, scroll, lines.length); | |
| 299 | }, | |
| 300 | key(e) { | |
| 301 | if (scroll.key(e, lines.length)) return true; | |
| 302 | if (e.key === "esc" || e.key === "q") { | |
| 303 | ctx.pop(); | |
| 304 | return true; | |
| 305 | } | |
| 306 | return false; | |
| 307 | }, | |
| 308 | }; | |
| 309 | } | |
| 310 | ||
| 311 | export const nextAllEntry: PaletteEntry = { | |
| 312 | rank: 185, | |
| 313 | id: "next-all", | |
| 314 | title: "Next up, every repository", | |
| 315 | hint: "the top of each list you administer", | |
| 316 | after: ["waiting-for-me"], | |
| 317 | offered: mayReadAll, | |
| 318 | run: (session, ctx) => { | |
| 319 | if (session.user === undefined) return; | |
| 320 | ctx.push(nextAllScreen(ctx, nextAll(session.app, session.user))); | |
| 321 | }, | |
| 322 | }; |
src/web/pages/next_all.ts added +47
| @@ -0,0 +1,47 @@ | ||
| 1 | /** | |
| 2 | * `/next` (#15870): the priorities of every repository the person administers, one ranked group per | |
| 3 | * repository, most recently active first. Read-only: moves stay on each repository's own page, | |
| 4 | * which the group's name links to. `?repo=owner/name` (repeatable) narrows to those groups. | |
| 5 | */ | |
| 6 | import { emptyNote } from "../empty_words.ts"; | |
| 7 | import { nextAll, onlyNames } from "../../core/next_all.ts"; | |
| 8 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 9 | import type { Ctx } from "../../http/context.ts"; | |
| 10 | import { pageHead, repoBase, signInFirst } from "../chrome.ts"; | |
| 11 | import { html } from "../html.ts"; | |
| 12 | import { page } from "../layout.ts"; | |
| 13 | import { listCard, row } from "../ui.ts"; | |
| 14 | ||
| 15 | export function nextAllPage(ctx: Ctx): Response { | |
outdated
Design: hand-rolled CSS ( |
||
| 16 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 17 | const user = ctx.auth.user; | |
| 18 | if (user === undefined) return signInFirst(ctx); | |
| 19 | const asked = ctx.url.searchParams.getAll("repo"); | |
| 20 | const narrowed = onlyNames(asked).length > 0; | |
| 21 | const groups = timePhase(ctx.request, "ranking", () => nextAll(ctx.app, user, asked)); | |
| 22 | const rendering = performance.now(); | |
| 23 | const body = html`<div> | |
| 24 | ${pageHead("Next up", { sub: "Your priorities in every repository you administer, most recently active first." })} | |
| 25 | ${groups.length === 0 | |
| 26 | ? narrowed | |
| 27 | ? html`${emptyNote("nothingOpenAndRankedHere")}<p><a href="/next">Show all</a></p>` | |
| 28 | : emptyNote("nothingOpenAndRanked") | |
| 29 | : groups.map( | |
| 30 | (g) => html`${listCard( | |
| 31 | g.rows.map((r, at) => | |
| 32 | row({ | |
| 33 | href: `${repoBase(g.repo)}/issues/${r.issue.number}`, | |
| 34 | title: r.issue.title, | |
| 35 | titleAttr: r.issue.title, | |
| 36 | lead: html`${r.place === null ? "·" : String(r.place)}`, | |
| 37 | meta: html`#${r.issue.number}${r.onIt === null ? "" : ` · on it: ${r.onIt}`}${at === 0 && g.total > g.rows.length ? ` · ${g.total - g.rows.length} more on its list` : ""}`, | |
| 38 | }), | |
| 39 | ), | |
| 40 | { head: html`<a href="${repoBase(g.repo)}/next">${g.repo.ownerName}/${g.repo.name}</a>`, extra: "mt" }, | |
| 41 | )}`, | |
| 42 | )} | |
| 43 | </div>`; | |
| 44 | const response = page({ ctx, title: "Next up", body }); | |
| 45 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 46 | return response; | |
outdated
Principles 1 and 8: this footer repeats the sub line above it and explains the page. Delete it. The page says what it is for once. |
||
| 47 | } |
test/forge-looks.test.ts +1
| @@ -25,6 +25,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 25 | 25 | "/desk": "a POST that leaves a note on the desk; the desk is read on the home (/), which is pictured; covered by test/desk.test.ts", |
| 26 | 26 | "/feed": "no picture: its slot went to /docs; the page is covered by its own tests", |
| 27 | 27 | "/front": "no picture: its slot went to /settings/security/controls, the security controls (#13001); covered by its own tests", |
| 28 | "/next": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/next-all.test.ts", | |
| 28 | 29 | "/pricing": "no picture: not in app.looks; the page is covered by test/pricing-order.test.ts", |
| 29 | 30 | "/templates": "no picture: not in app.looks; the page is covered by test/templates-page.test.ts", |
| 30 | 31 | "/templates.json": "data, not a page: the same rows as /templates; covered by test/templates-json.test.ts", |
test/next-all.test.ts added +165
| @@ -0,0 +1,165 @@ | ||
| 1 | /** | |
| 2 | * `/next` and `next_up` without an app (#15870): one ranked group per repository the person | |
| 3 | * administers. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { openIssue } from "../src/actions/issues.ts"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { reservedName } from "../src/core/reserved.ts"; | |
| 13 | import { GROUPS_MAX, nextAll, ONLY_MAX, onlyNames } from "../src/core/next_all.ts"; | |
| 14 | import { setRole } from "../src/actions/roles.ts"; | |
| 15 | import { createToken } from "../src/core/tokens.ts"; | |
| 16 | import { createUser, type User } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | ||
| 19 | describe("next across repositories", () => { | |
| 20 | let dataDir: string; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | let carol: User; | |
| 24 | let cookie: string; | |
| 25 | let token: string; | |
| 26 | ||
| 27 | const mk = async (username: string, first = false): Promise<User> => { | |
| 28 | const made = await createUser(app.db, { | |
| 29 | origin: "seed", trusted: true, username, email: `${username}@forge.local`, | |
| 30 | password: "a-good-passphrase", adminIfFirst: first, | |
| 31 | }); | |
| 32 | if (!made.ok) throw new Error(made.error); | |
| 33 | return made.value; | |
| 34 | }; | |
| 35 | const repoWith = async (user: User, name: string, titles: string[]) => { | |
| 36 | const made = await createRepo(app, user, { name, visibility: "public" }); | |
| 37 | if (!made.ok) throw new Error(String(made.error)); | |
| 38 | for (const title of titles) if (!openIssue(app, user, made.value, { title }).ok) throw new Error("issue"); | |
| 39 | return made.value; | |
| 40 | }; | |
| 41 | const get = (path: string, headers: Record<string, string> = { cookie }) => | |
| 42 | fetch(`${servers.url}${path}`, { headers, redirect: "manual" }); | |
| 43 | /** The page's own content: the shell around it names every repository in its palette. */ | |
| 44 | const main = async (path: string): Promise<string> => { | |
| 45 | const text = await (await get(path)).text(); | |
| 46 | return text.slice(text.indexOf("<main"), text.indexOf("</main>")); | |
| 47 | }; | |
| 48 | const tool = async (args: unknown, bearer: string = token) => { | |
| 49 | const res = await fetch(`${servers.url}/mcp`, { | |
| 50 | method: "POST", | |
| 51 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${bearer}` }, | |
| 52 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "next_up", arguments: args } }), | |
| 53 | }); | |
| 54 | const body = (await res.json()) as any; | |
| 55 | const text: string = body.result.content[0].text; | |
| 56 | try { | |
| 57 | return JSON.parse(text); | |
| 58 | } catch { | |
| 59 | return { refused: text }; | |
| 60 | } | |
| 61 | }; | |
| 62 | ||
| 63 | beforeAll(async () => { | |
| 64 | dataDir = await mkdtemp(join(tmpdir(), "forge-next-all-")); | |
| 65 | app = createApp({ dataDir, port: 0 }); | |
| 66 | servers = await serve(app); | |
| 67 | const alice = await mk("alice", true); | |
| 68 | const bob = await mk("bob"); | |
| 69 | carol = await mk("carol"); | |
| 70 | for (const u of ["bob", "carol"]) if (!setRole(app, alice, u, "member").ok) throw new Error("role"); | |
| 71 | await repoWith(carol, "older", ["Old one", "Old two"]); | |
| 72 | await repoWith(carol, "newer", ["New a", "New b", "New c", "New d"]); | |
| 73 | await repoWith(carol, "empty", []); | |
| 74 | await repoWith(bob, "theirs", ["Bobs secret-ish work"]); | |
| 75 | const res = await fetch(`${servers.url}/signin`, { | |
| 76 | method: "POST", body: new URLSearchParams({ username: "carol", password: "a-good-passphrase" }), redirect: "manual", | |
| 77 | }); | |
| 78 | cookie = (res.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 79 | token = createToken(app.db, carol.id, "t", "ro").token; | |
| 80 | }); | |
| 81 | afterAll(async () => { | |
| 82 | await servers.stop(); | |
| 83 | await rm(dataDir, { recursive: true, force: true }); | |
| 84 | }); | |
| 85 | ||
| 86 | test("two repositories are two groups, newest activity first, top three rows each", async () => { | |
| 87 | const html = await main("/next"); | |
| 88 | expect(html).toContain('href="/carol/newer/next"'); | |
| 89 | expect(html).toContain('href="/carol/older/next"'); | |
| 90 | expect(html.indexOf("carol/newer")).toBeLessThan(html.indexOf("carol/older")); | |
| 91 | expect(html).toContain("New c"); | |
| 92 | expect(html).not.toContain("New d"); | |
| 93 | expect(html).not.toContain("carol/empty"); | |
| 94 | }); | |
| 95 | ||
| 96 | test("a repository the person cannot administer is absent", async () => { | |
| 97 | const html = await main("/next"); | |
| 98 | expect(html).not.toContain("bob/theirs"); | |
| 99 | expect(html).not.toContain("Bobs secret-ish"); | |
| 100 | const asked = await main("/next?repo=bob/theirs"); | |
| 101 | expect(asked).not.toContain("Bobs secret-ish"); | |
| 102 | }); | |
| 103 | ||
| 104 | test("?repo= narrows, repeats, and ignores what is unknown", async () => { | |
| 105 | const one = await main("/next?repo=carol/older"); | |
| 106 | expect(one).toContain("carol/older"); | |
| 107 | expect(one).not.toContain("carol/newer"); | |
| 108 | const junk = await get("/next?repo=nope/none&repo=a/b/c&repo=carol/newer"); | |
| 109 | expect(junk.status).toBe(200); | |
| 110 | const text = await main("/next?repo=nope/none&repo=a/b/c&repo=carol/newer"); | |
| 111 | expect(text).toContain("carol/newer"); | |
| 112 | expect(text).not.toContain("carol/older"); | |
| 113 | expect((await get("/next?repo=nope/none")).status).toBe(200); | |
| 114 | }); | |
| 115 | ||
| 116 | test("signed out it redirects to sign in", async () => { | |
| 117 | const res = await get("/next", {}); | |
| 118 | expect(res.status).toBe(303); | |
| 119 | expect(res.headers.get("location")).toContain("/signin"); | |
| 120 | }); | |
| 121 | ||
| 122 | test("the tool without an app answers the page's groups in the page's order", async () => { | |
| 123 | const said = await tool({}); | |
| 124 | const page = nextAll(app, carol); | |
| 125 | expect(said.groups.map((g: any) => g.repo)).toEqual(page.map((g) => `${g.repo.ownerName}/${g.repo.name}`)); | |
| 126 | expect(said.groups.map((g: any) => g.repo)).toEqual(["carol/newer", "carol/older"]); | |
| 127 | expect(said.groups[0].next.map((r: any) => r.title)).toEqual(page[0]!.rows.map((r) => r.issue.title)); | |
| 128 | expect(said.groups[0].next).toHaveLength(3); | |
| 129 | expect(said.groups[0].more).toBe(1); | |
| 130 | }); | |
| 131 | ||
| 132 | test("the tool refuses an issue with no app, and moves nothing", async () => { | |
| 133 | const said = await tool({ issue: 1, to: "top" }, createToken(app.db, carol.id, "w", "rw").token); | |
| 134 | expect(said.refused).toContain("name the `app`"); | |
| 135 | expect(said.groups).toBeUndefined(); | |
| 136 | }); | |
| 137 | ||
| 138 | test("a request reads at most GROUPS_MAX repositories and names at most ONLY_MAX", async () => { | |
| 139 | expect(GROUPS_MAX).toBe(5); | |
| 140 | const names = Array.from({ length: ONLY_MAX + 5 }, (_, i) => `carol/r${i}`); | |
| 141 | expect(onlyNames(names)).toHaveLength(ONLY_MAX); | |
| 142 | for (let i = 0; i < GROUPS_MAX + 2; i++) await repoWith(carol, `many${i}`, ["x"]); | |
| 143 | expect(nextAll(app, carol)).toHaveLength(GROUPS_MAX); | |
| 144 | const all = Array.from({ length: GROUPS_MAX + 2 }, (_, i) => `carol/many${i}`); | |
| 145 | expect(nextAll(app, carol, all)).toHaveLength(GROUPS_MAX); | |
| 146 | }); | |
| 147 | ||
| 148 | test("the newest-active repository is shown even when listed last behind empty ones", async () => { | |
| 149 | // Made first, so the newest-first listing puts it after everything made below. | |
| 150 | const quiet = await repoWith(carol, "quiet", ["Quiet but newest"]); | |
| 151 | for (let i = 0; i < GROUPS_MAX + 1; i++) await repoWith(carol, `hollow${i}`, []); | |
| 152 | for (let i = 0; i < 2; i++) await repoWith(carol, `busy${i}`, ["b"]); | |
| 153 | app.db.query("UPDATE event SET created_at = '2999-01-01T00:00:00.000Z' WHERE repo_id = ?1").run(quiet.id); | |
| 154 | const groups = nextAll(app, carol); | |
| 155 | expect(groups).toHaveLength(GROUPS_MAX); | |
| 156 | expect(`${groups[0]!.repo.ownerName}/${groups[0]!.repo.name}`).toBe("carol/quiet"); | |
| 157 | expect(groups.some((g) => g.repo.name.startsWith("hollow"))).toBe(false); | |
| 158 | const html = await main("/next"); | |
| 159 | expect(html).toContain("Quiet but newest"); | |
| 160 | }); | |
| 161 | ||
| 162 | test("next is a reserved name, so no owner can take /next", () => { | |
| 163 | expect(reservedName(app.db, "next")).toBe("system"); | |
| 164 | }); | |
| 165 | }); |
test/pages-budget.test.ts +1
| @@ -55,6 +55,7 @@ const DEFAULT = { statements: 60, git: 8 }; | ||
| 55 | 55 | /** Pages that cost more today, with the most they may: lower these, never raise them. */ |
| 56 | 56 | const HEAVIER: Record<string, { statements?: number; git?: number }> = { |
| 57 | 57 | "/:owner/:name/issues/:number": { statements: 71 }, // +1: whether the repository is archived, so its pages say noindex (#14305) |
| 58 | "/next": { statements: 90 }, // a new page: measured 90 warm over the fixture's repositories, one ranking per administered repository, at most GROUPS_MAX = 5 (#15870) | |
outdated
The file says lower these, never raise. Bring |
||
| 58 | 59 | "/:owner/:name/next": { statements: 72 }, // to lower: #15940; +2: the waiting offers and the decision check beside the reports (#15887); +1: the size limits of held issues, one read of both (#15845); +2: the waiting outsider reports, the decider check and the list (#15840); +1: whether the repository is archived (#14305); +1: the wallet row, one read of the monthly cap (#13529); +1: the growth line, one read for the week, the open counts and the planner pause (#12290, #12867) |
| 59 | 60 | "/:owner/:name/pulls/:number": { statements: 117 }, // to lower: #15941; +1: what a green pull waits for (#15812); +1: whether the reports door is closed, one primary-key read per request, never from memory (#15053); +1: whether the repository is archived (#14305); +1: the desk hold on the pull, one read of the notes that link it (#12536); +1: whether a repository is the forge's own copy, one read of the source setting for the tell box (#12037); +1: the paused sentence, one read of a queued paused run on the pull (#12010); +1: the header Talk count (#10327); +1: the landing line (#10860); +1: whether a reviewer is seated, read only when Require review is off and the pull would otherwise wait on one; the page loads no crew besides (#11666) |
| 60 | 61 | "/api/v1/asks": { statements: 61 }, // +1: the stopped apps someone asked for, one read of the viewer's archived repositories (#12277) |
test/palette-roster.test.ts +3 −1
| @@ -132,10 +132,11 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 132 | 132 | ["pulls-to-land", "Pulls to land", "approved pulls, stale crew pulls, unproposed work"], |
| 133 | 133 | ["valves", "Valves", "the week's budget as a valve per repository; turn one and the crew obeys"], |
| 134 | 134 | ["waiting-for-me", "Waiting for me", "issues and pulls that wait for you"], |
| 135 | ["offers-upstream", "Offers upstream", "the receipts of what you offered from your forks"], | |
| 135 | ["next-all", "Next up, every repository", "the top of each list you administer"], | |
| 136 | 136 | ["refused-asks", "Refused first asks", "the last 20 first asks turned away"], |
| 137 | 137 | ["disks", "Disks", "machines' disk readings: 30-day write rate and projected rated-TBW date"], |
| 138 | 138 | ["telemetry", "Telemetry", "which agents may read flow and system; enter flips the grant"], |
| 139 | ["offers-upstream", "Offers upstream", "the receipts of what you offered from your forks"], | |
| 139 | 140 | ["tell-undo", "Take a tell back", "a tell you sent in the last minute, while nobody has read it"], |
| 140 | 141 | ["bottleneck", "Where the bottleneck is", "what limits the forge, what the host is tuned to, what changed"], |
| 141 | 142 | ["health-voice", "Health — spoken", "how the forge is, in two plain sentences"], |
| @@ -427,6 +428,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 427 | 428 | ["bugs", "Bugs", "open bugs and the bug clock"], |
| 428 | 429 | ["health-voice", "Health — spoken", "how the forge is, in two plain sentences"], |
| 429 | 430 | ["waiting-for-me", "Waiting for me", "issues and pulls that wait for you"], |
| 431 | ["next-all", "Next up, every repository", "the top of each list you administer"], | |
| 430 | 432 | ["offers-upstream", "Offers upstream", "the receipts of what you offered from your forks"], |
| 431 | 433 | ["tell-undo", "Take a tell back", "a tell you sent in the last minute, while nobody has read it"], |
| 432 | 434 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
new above
offline
DoS: one full
nextUpandnotStartableranking per administered repository, up to 50 per request (94 SQL statements measured). Cap lower, or cache per repo, rather than raising the page budget.