Public: anyone can read this; the crew can change it.
Jay Moran's displays list and a display page answer on main, read-only #9477
scout/forge:scout/9466-jay-moran-s-displays-list-and-a-display → main 5 commits fork
13 files
changed +504
−0
docs/design/areas/displays.md added +12
| @@ -0,0 +1,12 @@ | ||
| 1 | # Displays | |
| 2 | ||
| 3 | `/displays` lists every display the viewer reads (the shared `.table`); `/<owner>/<repo>/display` (also served at | |
| 4 | `/<owner>/<repo>/displays/<slug>`) draws one, read only: its title, plain links to the other displays the viewer reads, | |
| 5 | and its builds as cards. Written by `src/web/pages/displays.ts` and `src/web/pages/display.ts`. | |
| 6 | ||
| 7 | Reused from `docs/DESIGN.md`: `.card` (via `card()`), `.card-body`, `.table`, `.muted`, `.small`, `.mono`, `.mt`. | |
| 8 | Only three things are new, styled inline by the page: | |
| 9 | ||
| 10 | - `.dp-cards` — the cards as an auto-fill grid of 180 px minimum columns. | |
| 11 | - `.dp-cover` — the picture at the top of a card, 4:3 so the card does not shift: the build's first screenshot. | |
| 12 | - `.dp-blank` — the cover when there is no picture the viewer may see: the build's name, centred. |
docs/design/audit.md +1
| @@ -63,6 +63,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 63 | 63 | - `/flow` — `pages/flow.ts` · the pipeline from ready issue to live deploy, and the bottleneck · `/system`, `/board`, `/` · none seen. A topbar button points here. |
| 64 | 64 | - `/talk` — `pages/talk.ts` · the person's one conversation with the forge: history, composer, Confirm and Cancel; 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`. |
| 65 | 65 | - `/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`. |
| 66 | - `/displays` — `pages/displays.ts` · every display the viewer reads, one row each (title, layout, repository, demos) · `/:owner/:name/display`, `/:owner/:name/displays`, `/:owner/:name/displays/:slug` · none seen; styles in `docs/design/areas/displays.md`. | |
| 66 | 67 | - `/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. |
| 67 | 68 | - `/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. |
| 68 | 69 | - `/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. |
docs/features/displays.md added +22
| @@ -0,0 +1,22 @@ | ||
| 1 | # Displays (#9466, read only) | |
| 2 | ||
| 3 | A display is a repository with a `display.json` on its default branch: a title, a layout (`shelf`, `grid` or `graph`) | |
| 4 | and the repositories whose showcased builds it shows. This slice only reads them. | |
| 5 | ||
| 6 | ## Where | |
| 7 | ||
| 8 | | Where | What | | |
| 9 | | --- | --- | | |
| 10 | | `/displays` | every display you may read: title, layout, repository, showcased demos | | |
| 11 | | `/<owner>/<repo>/display` | one display: its title, links to the other displays you read, and its builds as cards | | |
| 12 | | `/<owner>/<repo>/displays` | the displays that repository holds (none or one) | | |
| 13 | | `/<owner>/<repo>/displays/<slug>` | the same display, by the slug of its title; any other slug is a 404 | | |
| 14 | | terminal: palette → **Displays** | the `/displays` list, one line each | | |
| 15 | ||
| 16 | ## What a reader sees | |
| 17 | ||
| 18 | - A card leads with the build's first screenshot when you read its repository, else with its name. | |
| 19 | - A build whose repository you cannot read shows its name and version alone: no repository, link, pin or commit. | |
| 20 | - A private display is not listed and answers 404; a guest sees public repositories' displays only. | |
| 21 | - A bad `display.json` shows its error on the display page and a "display.json failed" row in the list. | |
| 22 | - There is no JavaScript on the page and no write route: making and editing displays is a later pull. |
src/core/reserved.ts +1
| @@ -67,6 +67,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 67 | 67 | "contribute", |
| 68 | 68 | "deploy-to", |
| 69 | 69 | "pipeline", |
| 70 | "displays", | |
| 70 | 71 | "events", |
| 71 | 72 | "bring", |
| 72 | 73 | "explore", |
src/http/server.ts +8
| @@ -185,6 +185,8 @@ import { | ||
| 185 | 185 | branchesPage, |
| 186 | 186 | } from "../web/pages/branches.ts"; |
| 187 | 187 | import { iterationsPage, noteSubmit } from "../web/pages/iterations.ts"; |
| 188 | import { displayNamedPage, displayPage } from "../web/pages/display.ts"; | |
| 189 | import { displaysPage, repoDisplaysPage } from "../web/pages/displays.ts"; | |
| 188 | 190 | import { buildsPage, deletePinSubmit, newBuildPage, pinBuildSubmit, previewBuildSubmit } from "../web/pages/builds.ts"; |
| 189 | 191 | import { shotImage, shotsPage } from "../web/pages/build_shots.ts"; |
| 190 | 192 | import { cartArt, cartPage } from "../web/pages/build_cart.ts"; |
| @@ -1255,6 +1257,8 @@ export function buildRouter(): Router<Handler> { | ||
| 1255 | 1257 | router.add("POST", "/:owner/-/subscriptions", orgSubscriptionsSave); |
| 1256 | 1258 | |
| 1257 | 1259 | // Owner profile (a person or org) is a single segment — after all literals. |
| 1260 | // Every display the viewer may read; before /:owner, which would take it for a person. | |
| 1261 | router.add("GET", "/displays", displaysPage); | |
| 1258 | 1262 | router.add("GET", "/:owner", ownerProfile); |
| 1259 | 1263 | |
| 1260 | 1264 | // Parameterized repo pages match last, so they can never shadow a literal. |
| @@ -1286,6 +1290,10 @@ export function buildRouter(): Router<Handler> { | ||
| 1286 | 1290 | router.add("GET", "/:owner/:name/builds/:label/cart", cartPage); |
| 1287 | 1291 | router.add("GET", "/:owner/:name/builds/:label/cart.png", cartArt); |
| 1288 | 1292 | router.add("GET", "/:owner/:name/iterations", iterationsPage); |
| 1293 | // Displays, read only: every one the viewer may read, and one display (`display/config.ts`). | |
| 1294 | router.add("GET", "/:owner/:name/display", displayPage); | |
| 1295 | router.add("GET", "/:owner/:name/displays", repoDisplaysPage); | |
| 1296 | router.add("GET", "/:owner/:name/displays/:display", displayNamedPage); | |
| 1289 | 1297 | router.add("POST", "/:owner/:name/builds", pinBuildSubmit); |
| 1290 | 1298 | router.add("POST", "/:owner/:name/builds/preview", previewBuildSubmit); |
| 1291 | 1299 | router.add("POST", "/:owner/:name/builds/:label/delete", deletePinSubmit); |
src/tui/screens/displays.ts added +59
| @@ -0,0 +1,59 @@ | ||
| 1 | /** | |
| 2 | * Displays in the terminal (#9466): every display the viewer reads, one line | |
| 3 | * each — title, layout, repository, showcased demos — as `/displays` lists | |
| 4 | * them. Gated by the same read the page makes (`listedDisplays`): a guest | |
| 5 | * sees public repositories' displays alone. Read-only; Esc closes it. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { ListedDisplay } from "../../display/known.ts"; | |
| 9 | import { listedDisplays } from "../../display/known.ts"; | |
| 10 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 11 | import { binding } from "../app/keys.ts"; | |
| 12 | import { style } from "../term/style.ts"; | |
| 13 | import { truncate } from "../term/width.ts"; | |
| 14 | import { fill, len, split } from "../ui/layout.ts"; | |
| 15 | import { runAsync } from "./common.ts"; | |
| 16 | import type { PaletteEntry } from "./entries.ts"; | |
| 17 | ||
| 18 | const LAYOUT_WORD = { shelf: "Shelf", grid: "Grid", graph: "Graph" } as const; | |
| 19 | ||
| 20 | /** One line per display, in the page's words; a line saying so when there are none. */ | |
| 21 | export function displayLines(rows: readonly ListedDisplay[]): string[] { | |
| 22 | if (rows.length === 0) return ["No displays"]; | |
| 23 | return rows.map((d) => { | |
| 24 | const repo = `${d.repo.ownerName}/${d.repo.name}`; | |
| 25 | if (!d.config.ok) return `display.json failed · ${repo}`; | |
| 26 | const demos = d.demos === undefined ? "None" : String(d.demos); | |
| 27 | return `${d.config.value.title} · ${LAYOUT_WORD[d.config.value.layout]} · ${repo} · ${demos} demos`; | |
| 28 | }); | |
| 29 | } | |
| 30 | ||
| 31 | export function displaysScreen(ctx: Ctx, rows: readonly ListedDisplay[]): Screen { | |
| 32 | const lines = displayLines(rows); | |
| 33 | return { | |
| 34 | title: "Displays", | |
| 35 | keys: [binding(["esc"], "close")], | |
| 36 | render(area, s) { | |
| 37 | const c = ctx.theme.c; | |
| 38 | const [body] = split(area, "v", [fill(1), len(0)]); | |
| 39 | lines.slice(0, body!.h).forEach((l, i) => s.text(body!.x, body!.y + i, truncate(l, body!.w), style(c.fg, c.bg), body!.x + body!.w)); | |
| 40 | }, | |
| 41 | key(e) { | |
| 42 | if (e.key === "esc" || e.key === "q") ctx.pop(); | |
| 43 | return true; | |
| 44 | }, | |
| 45 | }; | |
| 46 | } | |
| 47 | ||
| 48 | /** Offered to everyone: what a reader sees is cut inside, as the page cuts it. */ | |
| 49 | export const entry: PaletteEntry = { | |
| 50 | id: "displays", | |
| 51 | title: "Displays", | |
| 52 | hint: "every display you may read, with its demos", | |
| 53 | after: ["bugs"], | |
| 54 | offered: () => true, | |
| 55 | run: (session, ctx) => | |
| 56 | runAsync(ctx, async () => { | |
| 57 | ctx.push(displaysScreen(ctx, await listedDisplays(session.app, session.user))); | |
| 58 | }), | |
| 59 | }; |
src/tui/screens/entries.ts +2
| @@ -20,6 +20,7 @@ import { entry as cloud } from "./cloud.ts"; | ||
| 20 | 20 | import { entry as connections } from "./connections.ts"; |
| 21 | 21 | import { entry as crewHandover } from "./crewhandover.ts"; |
| 22 | 22 | import { entry as crewSplits } from "./crewsplits.ts"; |
| 23 | import { entry as displays } from "./displays.ts"; | |
| 23 | 24 | import { entry as domains } from "./domains.ts"; |
| 24 | 25 | import { entry as edgeOnly } from "./edgeonly.ts"; |
| 25 | 26 | import { entry as feed } from "./feed.ts"; |
| @@ -72,6 +73,7 @@ export const ENTRIES: readonly PaletteEntry[] = [ | ||
| 72 | 73 | sentinel, |
| 73 | 74 | boards, |
| 74 | 75 | bugs, |
| 76 | displays, | |
| 75 | 77 | homePins, |
| 76 | 78 | system, |
| 77 | 79 | loopStalls, |
src/web/pages/display.ts added +136
| @@ -0,0 +1,136 @@ | ||
| 1 | /** | |
| 2 | * A repository's display page, `/<owner>/<repo>/display`, read only: the | |
| 3 | * builds its `display.json` holds (`display/config.ts`), as whoever is | |
| 4 | * looking may read them, drawn as cards under the display's title, with links | |
| 5 | * to the other displays the viewer reads, plain anchors, no script. | |
| 6 | * | |
| 7 | * Showcase publishes the demo (`display/items.ts`): a viewer who reads the | |
| 8 | * display sees every showcased demo on it. One whose repository the viewer | |
| 9 | * cannot read shows its name and version alone — no repository, link, pin | |
| 10 | * or commit — never a guess at where it lives. | |
| 11 | * | |
| 12 | * A bad `display.json` shows its error here. Ticking, reordering, titles, | |
| 13 | * capture and the shelf look are writes and the Arcade host; they are not | |
| 14 | * in this page. | |
| 15 | */ | |
| 16 | ||
| 17 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 18 | import { checkDisplay, readDisplay, type DisplayConfig } from "../../display/config.ts"; | |
| 19 | import { displayItems, type DisplayItem } from "../../display/items.ts"; | |
| 20 | import { displaySelections, type DisplaySelection } from "../../display/selections.ts"; | |
| 21 | import type { Repo } from "../../core/repos.ts"; | |
| 22 | import { readShots } from "../../git/shots.ts"; | |
| 23 | import { repoDir } from "../../git/repos.ts"; | |
| 24 | import type { Ctx } from "../../http/context.ts"; | |
| 25 | import { slug } from "../../arcade/shelf.ts"; | |
| 26 | import { crumbsFor, loadRepo, notFoundPage, repoBase, repoHeader, repoPalette } from "../chrome.ts"; | |
| 27 | import { html, type Html } from "../html.ts"; | |
| 28 | import { page } from "../layout.ts"; | |
| 29 | import { card, icon } from "../ui.ts"; | |
| 30 | ||
| 31 | const DISPLAY_CSS = /* css */ ` | |
| 32 | .dp-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px;margin:14px 0 0;padding:0;list-style:none} | |
| 33 | .dp-cards .card{height:100%;overflow:hidden} | |
| 34 | .dp-cards a{display:block;color:inherit;text-decoration:none} | |
| 35 | .dp-cover{display:block;width:100%;aspect-ratio:4/3;object-fit:cover} | |
| 36 | .dp-blank{display:flex;align-items:center;justify-content:center;padding:8px;text-align:center;overflow-wrap:anywhere} | |
| 37 | `; | |
| 38 | ||
| 39 | /** The display's error, where its page would be. */ | |
| 40 | function brokenPage(ctx: Ctx, repo: Repo, message: string): Response { | |
| 41 | return page({ | |
| 42 | ctx, | |
| 43 | title: `Display · ${repo.name}`, | |
| 44 | crumbs: crumbsFor(repo), | |
| 45 | palette: repoPalette(ctx, repo), | |
| 46 | body: html`${repoHeader(ctx, repo, "none")} | |
| 47 | <div class="mt"> | |
| 48 | ${card(html`<p class="mono">${message}</p> | |
| 49 | <p class="muted small">Fix <a href="${repoBase(repo)}/blob/${repo.defaultBranch}/display.json">display.json</a> on ${repo.defaultBranch}.</p>`, { | |
| 50 | head: html`${icon("alert")}<h2>Display failed</h2>`, | |
| 51 | tone: "danger", | |
| 52 | })} | |
| 53 | </div>`, | |
| 54 | }); | |
| 55 | } | |
| 56 | ||
| 57 | /** The other displays the viewer reads, as plain links: no script, so it works with JavaScript off. */ | |
| 58 | function othersOf(repo: Repo, displays: readonly DisplaySelection[]): Html { | |
| 59 | const here = `${repo.ownerName}/${repo.name}`; | |
| 60 | const others = displays.filter((d) => d.id !== here); | |
| 61 | if (others.length === 0) return html``; | |
| 62 | return html`<nav class="muted small" aria-label="Other displays">Other displays: ${others.map((d, i) => html`${i === 0 ? "" : " · "}<a href="${repoBase(d.repo)}/display">${d.title}</a>`)}</nav>`; | |
| 63 | } | |
| 64 | ||
| 65 | /** The picture a card leads with: the build's first screenshot when the viewer reads its repository, else its name. */ | |
| 66 | async function coverOf(ctx: Ctx, item: DisplayItem): Promise<Html> { | |
| 67 | const alt = `${item.demo.name} ${item.demo.version}`; | |
| 68 | if (item.open) { | |
| 69 | const shots = await readShots(repoDir(ctx.app.reposRoot, item.repo.ownerName, item.repo.name), item.pin.label); | |
| 70 | const first = shots.items[0]; | |
| 71 | if (first !== undefined) { | |
| 72 | const src = `${repoBase(item.repo)}/builds/${encodeURIComponent(item.pin.label)}/shots/${encodeURIComponent(first.file)}`; | |
| 73 | return html`<img class="dp-cover" src="${src}" alt="${alt}" width="200" height="150" loading="lazy" />`; | |
| 74 | } | |
| 75 | } | |
| 76 | return html`<span class="dp-cover dp-blank muted small">${item.demo.name}</span>`; | |
| 77 | } | |
| 78 | ||
| 79 | async function cardOf(ctx: Ctx, item: DisplayItem): Promise<Html> { | |
| 80 | const name = item.open ? item.repo.name : item.demo.name; | |
| 81 | const version = item.open ? item.pin.label : item.demo.version; | |
| 82 | const inner = html`${await coverOf(ctx, item)}<div class="card-body"><b>${name}</b> <span class="mono muted small">${version}</span></div>`; | |
| 83 | // Where a build lives is for a reader of its repository alone. | |
| 84 | const body = item.open ? html`<a href="${repoBase(item.repo)}/iterations">${inner}</a>` : inner; | |
| 85 | return html`<li data-build="${item.open ? item.key : item.id}">${card(body, { pad: false })}</li>`; | |
| 86 | } | |
| 87 | ||
| 88 | async function view(ctx: Ctx, repo: Repo, config: DisplayConfig): Promise<Response> { | |
| 89 | const viewer = ctx.auth.user; | |
| 90 | const items = await timePhaseAsync(ctx.request, "items", () => displayItems(ctx.app, repo, config, viewer)); | |
| 91 | const displays = await timePhaseAsync(ctx.request, "selections", () => displaySelections(ctx.app, viewer)); | |
| 92 | const cards = await timePhaseAsync(ctx.request, "cards", () => Promise.all(items.map((i) => cardOf(ctx, i)))); | |
| 93 | return timePhase(ctx.request, "render", () => | |
| 94 | page({ | |
| 95 | ctx, | |
| 96 | title: `${config.title} · ${repo.name}`, | |
| 97 | crumbs: crumbsFor(repo), | |
| 98 | palette: repoPalette(ctx, repo), | |
| 99 | body: html`${repoHeader(ctx, repo, "none")} | |
| 100 | <div class="dp" id="dp" data-layout="${config.layout}"> | |
| 101 | <h2 class="mt">${config.title}</h2> | |
| 102 | ${othersOf(repo, displays)} | |
| 103 | ${items.length === 0 | |
| 104 | ? html`<p class="muted" id="dp-none">No builds on this display</p>` | |
| 105 | : html`<ul class="dp-cards" id="dp-cards" aria-label="Builds on this display">${cards}</ul>`} | |
| 106 | </div>`, | |
| 107 | styleCss: DISPLAY_CSS, | |
| 108 | }), | |
| 109 | ); | |
| 110 | } | |
| 111 | ||
| 112 | // GET /:owner/:name/display — the display, read only; a repository with no display.json is a 404. | |
| 113 | export async function displayPage(ctx: Ctx): Promise<Response> { | |
| 114 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 115 | const repo = loadRepo(ctx); | |
| 116 | if (!repo) return notFoundPage(ctx); | |
| 117 | const config = await timePhase(ctx.request, "read", () => readDisplay(ctx.app, repo)); | |
| 118 | if (config === undefined) { | |
| 119 | await checkDisplay(ctx.app, repo); | |
| 120 | return timePhase(ctx.request, "render", () => notFoundPage(ctx)); | |
| 121 | } | |
| 122 | if (!config.ok) return timePhase(ctx.request, "render", () => brokenPage(ctx, repo, config.error)); | |
| 123 | return view(ctx, repo, config.value); | |
| 124 | } | |
| 125 | ||
| 126 | // GET /:owner/:name/displays/:display — the display this repository holds, by the slug of its title; any other is a 404. | |
| 127 | export async function displayNamedPage(ctx: Ctx): Promise<Response> { | |
| 128 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 129 | const repo = loadRepo(ctx); | |
| 130 | if (!repo) return notFoundPage(ctx); | |
| 131 | const config = await timePhase(ctx.request, "read", () => readDisplay(ctx.app, repo)); | |
| 132 | if (config === undefined) return notFoundPage(ctx); | |
| 133 | if (!config.ok) return timePhase(ctx.request, "render", () => brokenPage(ctx, repo, config.error)); | |
| 134 | if (slug(config.value.title) !== ctx.params.display) return notFoundPage(ctx); | |
| 135 | return view(ctx, repo, config.value); | |
| 136 | } |
src/web/pages/displays.ts added +72
| @@ -0,0 +1,72 @@ | ||
| 1 | /** | |
| 2 | * `/displays`: every display the viewer may read — each repository with a | |
| 3 | * `display.json` on its default branch (`display/config.ts`) — one row | |
| 4 | * each: title, layout, repository, and how many showcased demos it shows. | |
| 5 | * A row opens the display. Read only: making a display is a later pull. | |
| 6 | * | |
| 7 | * Both read through the display cache (`display/known.ts`), so a warm page | |
| 8 | * reads no git. | |
| 9 | */ | |
| 10 | ||
| 11 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 12 | import { listedDisplays, type ListedDisplay } from "../../display/known.ts"; | |
| 13 | import type { Ctx } from "../../http/context.ts"; | |
| 14 | import { crumbsFor, loadRepo, notFoundPage, pageHead, repoBase, repoHeader, repoPalette } from "../chrome.ts"; | |
| 15 | import { html, type Html } from "../html.ts"; | |
| 16 | import { page } from "../layout.ts"; | |
| 17 | import { empty } from "../ui.ts"; | |
| 18 | ||
| 19 | const LAYOUT_WORD = { shelf: "Shelf", grid: "Grid", graph: "Graph" } as const; | |
| 20 | ||
| 21 | // GET /displays — every display the viewer may read. | |
| 22 | export async function displaysPage(ctx: Ctx): Promise<Response> { | |
| 23 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 24 | const rows = await timePhaseAsync(ctx.request, "displays", () => listedDisplays(ctx.app, ctx.auth.user)); | |
| 25 | return timePhase(ctx.request, "render", () => page({ ctx, title: "Displays", body: html`${pageHead("Displays")}${table(rows)}` })); | |
| 26 | } | |
| 27 | ||
| 28 | // GET /:owner/:name/displays — the displays this repository holds (none or one), as the viewer may read them. | |
| 29 | export async function repoDisplaysPage(ctx: Ctx): Promise<Response> { | |
| 30 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 31 | const repo = loadRepo(ctx); | |
| 32 | if (!repo) return notFoundPage(ctx); | |
| 33 | const rows = (await timePhaseAsync(ctx.request, "displays", () => listedDisplays(ctx.app, ctx.auth.user))).filter((d) => d.repo.id === repo.id); | |
| 34 | return timePhase(ctx.request, "render", () => | |
| 35 | page({ | |
| 36 | ctx, | |
| 37 | title: `Displays · ${repo.name}`, | |
| 38 | crumbs: crumbsFor(repo), | |
| 39 | palette: repoPalette(ctx, repo), | |
| 40 | body: html`${repoHeader(ctx, repo, "none")}<div class="mt">${table(rows)}</div>`, | |
| 41 | }), | |
| 42 | ); | |
| 43 | } | |
| 44 | ||
| 45 | function table(rows: readonly ListedDisplay[]): Html { | |
| 46 | return html`${rows.length === 0 | |
| 47 | ? empty({ icon: "pin", title: "No displays" }) | |
| 48 | : html`<div class="table-scroll" role="region" tabindex="0" aria-label="Displays"> | |
| 49 | <table class="table" data-dense data-by="displays"> | |
| 50 | <thead> | |
| 51 | <tr> | |
| 52 | <th scope="col">Title</th> | |
| 53 | <th scope="col">Layout</th> | |
| 54 | <th scope="col">Repository</th> | |
| 55 | <th scope="col">Demos</th> | |
| 56 | </tr> | |
| 57 | </thead> | |
| 58 | <tbody> | |
| 59 | ${rows.map((d) => { | |
| 60 | const base = repoBase(d.repo); | |
| 61 | const name = `${d.repo.ownerName}/${d.repo.name}`; | |
| 62 | return html`<tr data-display="${name}"> | |
| 63 | <td><a href="${base}/display">${d.config.ok ? d.config.value.title : "display.json failed"}</a></td> | |
| 64 | <td>${d.config.ok ? LAYOUT_WORD[d.config.value.layout] : "None"}</td> | |
| 65 | <td><a class="mono" href="${base}">${name}</a></td> | |
| 66 | <td data-demos>${d.demos === undefined ? "None" : String(d.demos)}</td> | |
| 67 | </tr>`; | |
| 68 | })} | |
| 69 | </tbody> | |
| 70 | </table> | |
| 71 | </div>`}`; | |
| 72 | } |
test/displays.test.ts added +185
| @@ -0,0 +1,185 @@ | ||
| 1 | /** Displays, read only: /displays lists, /:owner/:name/display shows (#9466). */ | |
| 2 | import { afterAll, beforeAll, describe, 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 { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 9 | import { createSession } from "../src/core/sessions.ts"; | |
| 10 | import { createUser, type User } from "../src/core/users.ts"; | |
| 11 | import { displayLines } from "../src/tui/screens/displays.ts"; | |
| 12 | import { listedDisplays } from "../src/display/known.ts"; | |
| 13 | import { pinBuild, type Demo } from "../src/git/builds.ts"; | |
| 14 | import { storeShot, writeShots } from "../src/git/shots.ts"; | |
| 15 | import { repoDir } from "../src/git/repos.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | import { proveAll } from "./helpers/verified.ts"; | |
| 18 | ||
| 19 | const demo = (name: string, version: string, showcase: boolean): Demo => ({ name, version, page: "/", showcase, launch: "shots" }); | |
| 20 | ||
| 21 | describe("displays, read only", () => { | |
| 22 | let dataDir: string; | |
| 23 | let app: App; | |
| 24 | let servers: Servers; | |
| 25 | let alice: User; | |
| 26 | let bob: User; | |
| 27 | let tick = 0; | |
| 28 | const cookie = (u: User) => `forge_session=${createSession(app.db, u.id).token}`; | |
| 29 | const get = (path: string, u?: User) => | |
| 30 | fetch(`${servers.url}${path}`, { headers: u === undefined ? {} : { cookie: cookie(u) }, redirect: "manual" }); | |
| 31 | const repo = (name: string): Repo => getRepo(app.db, "alice", name)!; | |
| 32 | const commit = async (name: string, files: { path: string; content: string }[], message = "c") => { | |
| 33 | const made = await commitToBranch(app, alice, repo(name), { message, files }); | |
| 34 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 35 | return made.value.commitOid; | |
| 36 | }; | |
| 37 | const pin = async (name: string, label: string, d: Demo) => { | |
| 38 | const oid = await commit(name, [{ path: `${label}.txt`, content: label }], label); | |
| 39 | const pinned = await pinBuild(repoDir(app.reposRoot, "alice", name), { | |
| 40 | label, oid, note: "", source: "commit", tagger: { name: "alice", email: "[email protected]" }, at: 1_800_000_000 + tick++ * 60, demo: d, | |
| 41 | }); | |
| 42 | if (!pinned.ok) throw new Error(pinned.error); | |
| 43 | }; | |
| 44 | ||
| 45 | beforeAll(async () => { | |
| 46 | dataDir = await mkdtemp(join(tmpdir(), "forge-displays-read-")); | |
| 47 | app = createApp({ dataDir, port: 0 }); | |
| 48 | servers = await serve(app); | |
| 49 | for (const name of ["alice", "bob"]) { | |
| 50 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: name, email: `${name}@forge.local`, password: "a-good-passphrase", adminIfFirst: true }); | |
| 51 | if (!made.ok) throw new Error(made.error); | |
| 52 | if (name === "alice") alice = made.value; | |
| 53 | else bob = made.value; | |
| 54 | } | |
| 55 | proveAll(app); | |
| 56 | for (const [name, visibility] of [["karts", "public"], ["secret", "private"], ["night", "public"], ["hidden", "private"], ["broken", "public"], ["plain", "public"]] as const) { | |
| 57 | const made = await createRepo(app, alice, { name, visibility }); | |
| 58 | if (!made.ok) throw new Error(String(made.error)); | |
| 59 | } | |
| 60 | await pin("karts", "fiesta", demo("krazy-karts", "1.0", true)); | |
| 61 | await pin("karts", "draft", demo("krazy-karts", "2.0", false)); | |
| 62 | await pin("secret", "hush", demo("secret-game", "0.1", true)); | |
| 63 | const png = Uint8Array.from(Buffer.from("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==", "base64")); | |
| 64 | for (const [name, label] of [["karts", "fiesta"], ["secret", "hush"]] as const) { | |
| 65 | const dir = repoDir(app.reposRoot, "alice", name); | |
| 66 | const stored = await storeShot(dir, png); | |
| 67 | if (!stored.ok) throw new Error(stored.error); | |
| 68 | const wrote = await writeShots(dir, label, undefined, [{ caption: "", oid: stored.value.oid, type: stored.value.type, size: stored.value.size }]); | |
| 69 | if (!wrote.ok) throw new Error(wrote.error); | |
| 70 | } | |
| 71 | await commit("night", [{ path: "display.json", content: JSON.stringify({ title: "Arcade & night", layout: "grid", sources: ["alice/karts", "alice/secret"] }) }]); | |
| 72 | await commit("hidden", [{ path: "display.json", content: JSON.stringify({ title: "Hidden night", layout: "grid", sources: ["alice/karts"] }) }]); | |
| 73 | await commit("broken", [{ path: "display.json", content: "{ nope" }]); | |
| 74 | }, 60_000); | |
| 75 | ||
| 76 | afterAll(async () => { | |
| 77 | servers.stop(); | |
| 78 | app.close(); | |
| 79 | await rm(dataDir, { recursive: true, force: true }); | |
| 80 | }); | |
| 81 | ||
| 82 | test("/displays lists the displays the viewer reads, with their showcased demos counted", async () => { | |
| 83 | const mine = await (await get("/displays", alice)).text(); | |
| 84 | expect(mine).toContain('data-display="alice/night"'); | |
| 85 | expect(mine).toContain('href="/alice/night/display"'); | |
| 86 | expect(mine).toContain("Arcade & night"); | |
| 87 | expect(mine).not.toContain("Arcade & night"); | |
| 88 | expect(mine).toContain('data-display="alice/hidden"'); | |
| 89 | expect(mine).toContain("display.json failed"); | |
| 90 | expect(mine).not.toContain('data-display="alice/plain"'); | |
| 91 | expect(mine).toMatch(/data-display="alice\/night"[\s\S]*?<td data-demos>2<\/td>/); | |
| 92 | const stranger = await (await get("/displays")).text(); | |
| 93 | expect(stranger).toContain('data-display="alice/night"'); | |
| 94 | expect(stranger).not.toContain('data-display="alice/hidden"'); | |
| 95 | }); | |
| 96 | ||
| 97 | test("a display page shows its title and builds, and a reader of the repository sees where they live", async () => { | |
| 98 | const r = await get("/alice/night/display", alice); | |
| 99 | expect(r.status).toBe(200); | |
| 100 | const text = await r.text(); | |
| 101 | expect(text).toContain("Arcade & night"); | |
| 102 | expect(text).toContain("<b>karts</b>"); | |
| 103 | expect(text).toContain("fiesta"); | |
| 104 | expect(text).not.toContain("draft"); | |
| 105 | expect(text).toContain('data-build="alice/karts:fiesta"'); | |
| 106 | expect(text).toContain('data-build="alice/secret:hush"'); | |
| 107 | }); | |
| 108 | ||
| 109 | test("a viewer who cannot read a source sees its name and version, never where it lives", async () => { | |
| 110 | const text = await (await get("/alice/night/display", bob)).text(); | |
| 111 | expect(text).toContain("secret-game"); | |
| 112 | expect(text).toContain("0.1"); | |
| 113 | expect(text).not.toContain("alice/secret"); | |
| 114 | expect(text).not.toContain("hush"); | |
| 115 | expect(text).toContain('data-build="alice/karts:fiesta"'); | |
| 116 | }); | |
| 117 | ||
| 118 | test("answers with the security floor, and no write route exists", async () => { | |
| 119 | const r = await get("/alice/night/display"); | |
| 120 | expect(r.headers.get("content-security-policy")).toBeTruthy(); | |
| 121 | expect(r.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 122 | expect(r.headers.get("referrer-policy")).toBeTruthy(); | |
| 123 | const list = await get("/displays"); | |
| 124 | expect(list.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 125 | const post = await fetch(`${servers.url}/alice/night/display/builds`, { method: "POST", headers: { cookie: cookie(alice), origin: servers.url }, body: new URLSearchParams(), redirect: "manual" }); | |
| 126 | expect(post.status).toBe(404); | |
| 127 | }); | |
| 128 | ||
| 129 | test("a bad display.json shows its error; no display, an unknown repo, or a private display to a stranger is a 404", async () => { | |
| 130 | const broken = await get("/alice/broken/display", alice); | |
| 131 | expect(broken.status).toBe(200); | |
| 132 | expect(await broken.text()).toContain("Display failed"); | |
| 133 | expect((await get("/alice/plain/display", alice)).status).toBe(404); | |
| 134 | expect((await get("/alice/nothing/display", alice)).status).toBe(404); | |
| 135 | expect((await get("/alice/hidden/display", bob)).status).toBe(404); | |
| 136 | }); | |
| 137 | ||
| 138 | test("a card leads with the build's first screenshot for a reader of its repository, and with its name for anyone else", async () => { | |
| 139 | const mine = await (await get("/alice/night/display", alice)).text(); | |
| 140 | expect(mine).toContain('src="/alice/karts/builds/fiesta/shots/01.png"'); | |
| 141 | expect(mine).toContain('src="/alice/secret/builds/hush/shots/01.png"'); | |
| 142 | const theirs = await (await get("/alice/night/display", bob)).text(); | |
| 143 | expect(theirs).toContain('src="/alice/karts/builds/fiesta/shots/01.png"'); | |
| 144 | expect(theirs).not.toContain("builds/hush"); | |
| 145 | expect(theirs).toMatch(/dp-blank[^>]*>secret-game</); | |
| 146 | expect((await get("/alice/karts/builds/fiesta/shots/01.png")).status).toBe(200); | |
| 147 | }); | |
| 148 | ||
| 149 | test("the other displays are plain links, with no select and no script to open them", async () => { | |
| 150 | const mine = await (await get("/alice/night/display", alice)).text(); | |
| 151 | expect(mine).toContain('aria-label="Other displays"'); | |
| 152 | expect(mine).toContain('href="/alice/hidden/display"'); | |
| 153 | expect(mine).not.toContain("<select"); | |
| 154 | expect(mine).not.toContain("dp-pick"); | |
| 155 | expect(mine).not.toContain("location.assign"); | |
| 156 | const theirs = await (await get("/alice/night/display", bob)).text(); | |
| 157 | expect(theirs).not.toContain("/alice/hidden/display"); | |
| 158 | }); | |
| 159 | ||
| 160 | test("the issue's paths answer: /:owner/:name/displays lists, /:owner/:name/displays/:display shows, an unknown display is a 404", async () => { | |
| 161 | const list = await get("/alice/night/displays", alice); | |
| 162 | expect(list.status).toBe(200); | |
| 163 | const text = await list.text(); | |
| 164 | expect(text).toContain('data-display="alice/night"'); | |
| 165 | expect(text).not.toContain('data-display="alice/hidden"'); | |
| 166 | const one = await get("/alice/night/displays/arcade-night", bob); | |
| 167 | expect(one.status).toBe(200); | |
| 168 | expect(one.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 169 | expect(await one.text()).toContain("Arcade & night"); | |
| 170 | expect((await get("/alice/night/displays/nothing", alice)).status).toBe(404); | |
| 171 | expect((await get("/alice/plain/displays/plain", alice)).status).toBe(404); | |
| 172 | expect((await get("/alice/hidden/displays", bob)).status).toBe(404); | |
| 173 | expect((await get("/alice/hidden/displays/hidden-night", bob)).status).toBe(404); | |
| 174 | }); | |
| 175 | ||
| 176 | test("the terminal's Displays lines are cut as the page is: a guest sees no private display", async () => { | |
| 177 | const seen = displayLines(await listedDisplays(app, alice)).join("\n"); | |
| 178 | expect(seen).toContain("Arcade & night · Grid · alice/night · 2 demos"); | |
| 179 | expect(seen).toContain("display.json failed · alice/broken"); | |
| 180 | const guest = displayLines(await listedDisplays(app, undefined)).join("\n"); | |
| 181 | expect(guest).toContain("alice/night"); | |
| 182 | expect(guest).not.toContain("alice/hidden"); | |
| 183 | expect(displayLines([])).toEqual(["No displays"]); | |
| 184 | }); | |
| 185 | }); |
test/forge-looks.test.ts +1
| @@ -24,6 +24,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 24 | 24 | "/asked": "no picture: the cap of 24 looks went to /notes, the page that now leads with a person's thoughts; /asked is covered by test/asked.test.ts", |
| 25 | 25 | "/forges": "no picture: the cap of 24 looks went to the preview's /waves and /milestones; the page is covered by its own tests", |
| 26 | 26 | "/family": "no picture: the cap of 24 looks went to the preview's /waves and /milestones; the page is covered by its own tests", |
| 27 | "/displays": "no picture: the cap of 24 looks is spent; the list is covered by test/displays.test.ts", | |
| 27 | 28 | "/llms.txt": "plain markdown for machines, not a page to picture", |
| 28 | 29 | "/agents": "/llms.txt drawn as a page for an assistant; no picture: the cap of 24 looks is spent, and test/agents-page.test.ts covers it", |
| 29 | 30 | "/robots.txt": "plain text for crawlers", |
test/palette-roster.test.ts +4
| @@ -84,6 +84,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 84 | 84 | ["home-pins", "Pinned panels", "the panels pinned to home: reorder and unpin"], |
| 85 | 85 | ["now", "Now", "what check, review, land and live count, with the rows"], |
| 86 | 86 | ["forge-view", "Forge view", "the forge's counts, and Foundry when it is installed"], |
| 87 | ["displays", "Displays", "every display you may read, with its demos"], | |
| 87 | 88 | ["origin-apps", "Origin apps", "your OAuth apps for connecting origins; a adds, d removes"], |
| 88 | 89 | ["system-memory", "System memory", "RSS beside the JS heap, hourly for 24 h"], |
| 89 | 90 | ["flow", "Flow", "the pipeline's bottleneck and throughput"], |
| @@ -187,6 +188,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 187 | 188 | ["proposal-tokens", "Proposal tokens", "mint, list and revoke what a child proposes with"], |
| 188 | 189 | ["can", "What I can do", "your role and what it allows here"], |
| 189 | 190 | ["bugs", "Bugs", "open bugs and the bug clock"], |
| 191 | ["displays", "Displays", "every display you may read, with its demos"], | |
| 190 | 192 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
| 191 | 193 | ["archived", "Archived repositories", "put away, not gone: open one or wake it"], |
| 192 | 194 | ["cloud", "Cloud accounts", "provider tokens, what they are used for, today's calls"], |
| @@ -251,6 +253,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 251 | 253 | ["model", "Model budget", "what your crew may spend, and add your own subscription"], |
| 252 | 254 | ["can", "What I can do", "your role and what it allows here"], |
| 253 | 255 | ["bugs", "Bugs", "open bugs and the bug clock"], |
| 256 | ["displays", "Displays", "every display you may read, with its demos"], | |
| 254 | 257 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
| 255 | 258 | ["archived", "Archived repositories", "put away, not gone: open one or wake it"], |
| 256 | 259 | ["bulk", "Bulk actions", "your last bulk actions; u undoes one inside its day"], |
| @@ -287,6 +290,7 @@ test("signed out, the palette offers sign-in and the public entries", () => { | ||
| 287 | 290 | ["api", "API", "the forge's endpoints; run a GET"], |
| 288 | 291 | ["changelog", "Changelog", "the last 30 releases and their pulls"], |
| 289 | 292 | ["bugs", "Bugs", "open bugs and the bug clock"], |
| 293 | ["displays", "Displays", "every display you may read, with its demos"], | |
| 290 | 294 | ["audit", "Who can do what", "each app's doors from its contract.json: yes, own or no"], |
| 291 | 295 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 292 | 296 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
test/security-floor-routes.test.ts +1
| @@ -60,6 +60,7 @@ const UNSEEDED: Record<string, string> = { | ||
| 60 | 60 | "/:owner/:name/builds/:label/cart.png": CART, |
| 61 | 61 | "/:owner/:name/builds/:label/shots": SHOT, |
| 62 | 62 | "/:owner/:name/builds/:label/shots/:file": SHOT, |
| 63 | "/:owner/:name/displays/:display": "needs a display the repository declares; the seed declares none", | |
| 63 | 64 | "/:owner/:name/looks/:env/:commit/:kind.png": LOOK, |
| 64 | 65 | "/:owner/:name/milestones/:number/limb/:op": LIMB, |
| 65 | 66 | "/:owner/:name/variants/:group": VARIANT, |
new above
offline