Public: anyone can read this; the crew can change it.
forge.json's app.looks lists every top-level page of the forge #2745
scout/forge:scout/2735-forge-json-s-app-looks-lists-every-top-l → main 1 commit fork
5 files
changed +90
−6
docs/APPS.md +1 −1
| @@ -790,7 +790,7 @@ When a deploy comes up green the forge takes a picture of it — every page | ||
| 790 | 790 | (390×844), a laptop's (1280×800), and a thumb's (200×125, desktop's own |
| 791 | 791 | aspect, small), and keeps the pictures beside the commit they are of, so a |
| 792 | 792 | person judges a change from what it is rather than from what it says. |
| 793 | `app.looks` may name at most three pages: a browser start per picture per | |
| 793 | `app.looks` may name at most 24 pages: a browser start per picture per | |
| 794 | 794 | width is the heaviest thing the forge does, and more is a manifest error |
| 795 | 795 | rather than a silent, slower deploy. The pull page shows the phone and |
| 796 | 796 | desktop pair under the checks, with the commit and a word when the head has |
forge.json +1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | "install": "", |
| 8 | 8 | "health": "/healthz", |
| 9 | 9 | "ready": 90, |
| 10 | "looks": ["/", "/board", "/boards", "/map", "/flow", "/system", "/apps", "/explore", "/family", "/front", "/releases", "/resilience", "/audit", "/contribute", "/search", "/settings", "/migrate", "/new", "/asked"], | |
| 10 | 11 | "limits": { |
| 11 | 12 | "memory": 2048, |
| 12 | 13 | "cpus": 2, |
src/apps/manifest.ts +3 −2
| @@ -68,8 +68,9 @@ const READY_DEFAULT = 30; | ||
| 68 | 68 | const READY_MAX = 600; |
| 69 | 69 | const COMMAND_MAX = 1_000; |
| 70 | 70 | /** More than this many pages is a manifest error: a browser start per |
| 71 | * picture per width is the heaviest thing the forge does. */ | |
| 72 | const LOOKS_MAX = 3; | |
| 71 | * picture per width is the heaviest thing the forge does. Room for every | |
| 72 | * top-level page of the forge itself. */ | |
| 73 | const LOOKS_MAX = 24; | |
| 73 | 74 | const LOOK_PATH_MAX = 200; |
| 74 | 75 | |
| 75 | 76 | /** |
test/apps-adversarial.test.ts +3 −3
| @@ -389,7 +389,7 @@ describe("manifest: parseManifest edge cases", () => { | ||
| 389 | 389 | if (result.ok) expect(result.value.looks).toEqual(["/"]); |
| 390 | 390 | }); |
| 391 | 391 | |
| 392 | test("app.looks names up to three pages", () => { | |
| 392 | test("app.looks names up to 24 pages", () => { | |
| 393 | 393 | const result = parseManifest( |
| 394 | 394 | JSON.stringify({ app: { run: "x", looks: ["/", "/board"] } }), |
| 395 | 395 | undefined, |
| @@ -398,10 +398,10 @@ describe("manifest: parseManifest edge cases", () => { | ||
| 398 | 398 | if (result.ok) expect(result.value.looks).toEqual(["/", "/board"]); |
| 399 | 399 | }); |
| 400 | 400 | |
| 401 | test("app.looks with more than three paths is refused", () => { | |
| 401 | test("app.looks with more than 24 paths is refused", () => { | |
| 402 | 402 | const result = parseManifest( |
| 403 | 403 | JSON.stringify({ |
| 404 | app: { run: "x", looks: ["/", "/a", "/b", "/c"] }, | |
| 404 | app: { run: "x", looks: Array.from({ length: 25 }, (_, i) => `/p${i}`) }, | |
| 405 | 405 | }), |
| 406 | 406 | undefined, |
| 407 | 407 | ); |
test/forge-looks.test.ts added +82
| @@ -0,0 +1,82 @@ | ||
| 1 | /** | |
| 2 | * forge.json's `app.looks` pictures every top-level page of the forge: each | |
| 3 | * page the router serves is named (bar the ones that are not pages, below), | |
| 4 | * and each name answers for a signed-in admin, the viewer a look is taken as. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { parseManifest } from "../src/apps/manifest.ts"; | |
| 12 | import { buildRouter, serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { adminCookie } from "./helpers/admin.ts"; | |
| 14 | ||
| 15 | /** Top-level GET routes that are not pictures of a page, and why. */ | |
| 16 | const NOT_PAGES: Readonly<Record<string, string>> = { | |
| 17 | "/llms.txt": "text for machines", | |
| 18 | "/robots.txt": "text for machines", | |
| 19 | "/releases.json": "data", | |
| 20 | "/sitemap.xml": "data", | |
| 21 | "/manifest.webmanifest": "data", | |
| 22 | "/sw.js": "script", | |
| 23 | "/audit.csv": "data", | |
| 24 | "/events": "event stream", | |
| 25 | "/mcp": "protocol endpoint", | |
| 26 | "/signin": "signed-out page; a look is of a signed-in forge", | |
| 27 | "/signup": "signed-out page", | |
| 28 | "/recover": "signed-out page", | |
| 29 | "/verify": "needs a token", | |
| 30 | "/claim": "needs a link fragment", | |
| 31 | "/first-admin": "needs a link", | |
| 32 | "/logout": "action", | |
| 33 | "/tell": "form post only", | |
| 34 | "/theme": "action", | |
| 35 | "/forges": "answers only where the forge is a family's", | |
| 36 | "/asks": "redirects to the home page's section", | |
| 37 | "/big": "redirects to /board", | |
| 38 | }; | |
| 39 | ||
| 40 | const forgeJson = JSON.parse(await Bun.file(join(import.meta.dir, "..", "forge.json")).text()); | |
| 41 | const looks: string[] = parseManifest(JSON.stringify(forgeJson), undefined).ok | |
| 42 | ? forgeJson.app.looks | |
| 43 | : []; | |
| 44 | ||
| 45 | describe("forge.json app.looks", () => { | |
| 46 | let dir: string; | |
| 47 | let app: App; | |
| 48 | let servers: Servers; | |
| 49 | let cookie: string; | |
| 50 | ||
| 51 | beforeAll(async () => { | |
| 52 | dir = await mkdtemp(join(tmpdir(), "forge-looks-")); | |
| 53 | app = createApp({ dataDir: dir, port: 0 }); | |
| 54 | servers = await serve(app); | |
| 55 | cookie = await adminCookie(app, { username: "alice", email: "[email protected]" }); | |
| 56 | }); | |
| 57 | afterAll(async () => { | |
| 58 | await servers.stop?.(); | |
| 59 | await rm(dir, { recursive: true, force: true }); | |
| 60 | }); | |
| 61 | ||
| 62 | test("the manifest is valid and names pages", () => { | |
| 63 | expect(looks.length).toBeGreaterThan(10); | |
| 64 | expect(new Set(looks).size).toBe(looks.length); | |
| 65 | }); | |
| 66 | ||
| 67 | test("every top-level page the router serves is named", () => { | |
| 68 | const pages = buildRouter() | |
| 69 | .patterns() | |
| 70 | .filter((p) => /^\/[^/:*]*$/.test(p) && !(p in NOT_PAGES)); | |
| 71 | expect(pages.filter((p) => !looks.includes(p))).toEqual([]); | |
| 72 | }); | |
| 73 | ||
| 74 | test("every name is a route, and it answers", async () => { | |
| 75 | const patterns = buildRouter().patterns(); | |
| 76 | for (const page of looks) { | |
| 77 | expect(patterns).toContain(page); | |
| 78 | const res = await fetch(servers.url + page, { headers: { cookie }, redirect: "manual" }); | |
| 79 | expect({ page, status: res.status }).toEqual({ page, status: 200 }); | |
| 80 | } | |
| 81 | }); | |
| 82 | }); |
new above
offline