Public: anyone can read this; the crew can change it.
A look kind at 360 px, the narrowest phone width people still use #13233
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13229-a-look-kind-at-360-px-the-narrowest-phon → main 5 commits fork 3 threads · 3 unresolved
11 files
changed +205
−67
docs/features/home-looks.md +8 −4
| @@ -21,9 +21,13 @@ A pull touching `src/web/studio/home.ts` needs no extra step: push, wait for | ||
| 21 | 21 | the preview to serve, and the four appear. Looks fill in as the round goes, so |
| 22 | 22 | list again if one is missing. |
| 23 | 23 | |
| 24 | ## The phone is 390 px, not 360 | |
| 24 | ## The phone is 390 px; the 360 px look is beside it | |
| 25 | 25 | |
| 26 | 26 | The phone look is `LOOK_SIZES.phone` (`src/core/looks.ts`): 390 × 844, the |
| 27 | width every phone look of every page uses. Desktop is 1280 × 800. No 360 px | |
| 28 | look is taken; a page that fits 390 px is not proof it fits 360. Adding one is | |
| 29 | a change to the looks service's sizes, not to this page. | |
| 27 | width every page's phone look uses. Desktop is 1280 × 800. A `narrow` look is | |
| 28 | also taken at 360 × 780, the narrowest phone width people still use, light and | |
| 29 | dark, for **the home page only** (`NARROW_PAGES`; `kindsOfPage`). Other pages | |
| 30 | in `app.looks` are not taken at 360 px: each would cost another browser | |
| 31 | capture per deploy. The pull page shows it beside the phone picture under the | |
| 32 | caption `360 px`; a `narrow` look that scrolls sideways is counted in the | |
| 33 | check's `phone … scrolls sideways` line like a phone one. |
docs/features/pull-looks.md +6
| @@ -19,6 +19,12 @@ One list, one rule (`pullLooks` in `src/looks/readable.ts`), three doors: | ||
| 19 | 19 | - **MCP** — the `pull` tool carries `looks`, the same items (no new tool). |
| 20 | 20 | - **Terminal** — `I` on a pull opens its looks; the pull screen's conversation also lists them under a `Looks` heading (none, no heading), each with its width, who, the line it says and the absolute URL on its own line. It is the same `pullLooks` read as the API and MCP, so a reader sees only what they may fetch. |
| 21 | 21 | |
| 22 | The home page is pictured at four widths: `phone` (390 px), `narrow` (360 px, | |
| 23 | home only), `desktop` and the `thumb`. In the API, MCP and terminal the 360 px | |
| 24 | look is `width: "narrow"`; on the pull page it sits beside the phone picture | |
| 25 | under the caption `360 px`, and its dark twin in the dark fold. It counts in the | |
| 26 | pairs line like the other widths. | |
| 27 | ||
| 22 | 28 | Above the pictures on the pull page, and at the top of the terminal screen, |
| 23 | 29 | one line counts the pages shown beside main and those main has no picture of |
| 24 | 30 | (`4 pages beside main · 1 new to this pull`); when main has no pictures at all |
src/checks/summary.ts +2 −1
| @@ -266,7 +266,8 @@ export interface LookRows { | ||
| 266 | 266 | readonly size?: PageSize; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | const isPhone = (look: string): boolean => look === "phone" || look.startsWith("phone "); | |
| 269 | const isPhone = (look: string): boolean => | |
| 270 | ["phone", "narrow"].some((k) => look === k || look.startsWith(`${k} `)); | |
| 270 | 271 | |
| 271 | 272 | /** `phone /x scrolls sideways` for each phone look wider than its window; empty when none. */ |
| 272 | 273 | export function sidewaysLine(groups: readonly LookRows[]): string { |
src/core/looks.ts +41 −10
| @@ -9,8 +9,8 @@ import type { Database } from "bun:sqlite"; | ||
| 9 | 9 | import { id as newId } from "../kernel/id.ts"; |
| 10 | 10 | |
| 11 | 11 | /** The three widths a page is pictured at. */ |
| 12 | export type LookKind = "phone" | "desktop" | "thumb"; | |
| 13 | export const LOOK_KINDS: readonly LookKind[] = ["phone", "desktop", "thumb"]; | |
| 12 | export type LookKind = "phone" | "narrow" | "desktop" | "thumb"; | |
| 13 | export const LOOK_KINDS: readonly LookKind[] = ["phone", "narrow", "desktop", "thumb"]; | |
| 14 | 14 | export const isLookKind = (value: string): value is LookKind => |
| 15 | 15 | (LOOK_KINDS as readonly string[]).includes(value); |
| 16 | 16 | |
| @@ -23,6 +23,8 @@ export const LOOK_SIZES: Readonly< | ||
| 23 | 23 | Record<LookKind, { readonly width: number; readonly height: number }> |
| 24 | 24 | > = { |
| 25 | 25 | phone: { width: 390, height: 844 }, |
| 26 | /** The narrowest phone width people still use. */ | |
| 27 | narrow: { width: 360, height: 780 }, | |
| 26 | 28 | desktop: { width: 1280, height: 800 }, |
| 27 | 29 | thumb: { width: 640, height: 400 }, |
| 28 | 30 | }; |
| @@ -37,6 +39,7 @@ export const LOOK_WINDOWS: Readonly< | ||
| 37 | 39 | Record<LookKind, { readonly width: number; readonly height: number }> |
| 38 | 40 | > = { |
| 39 | 41 | phone: LOOK_SIZES.phone, |
| 42 | narrow: LOOK_SIZES.narrow, | |
| 40 | 43 | desktop: LOOK_SIZES.desktop, |
| 41 | 44 | thumb: LOOK_SIZES.desktop, |
| 42 | 45 | }; |
| @@ -58,7 +61,19 @@ export const LOOK_THEMES: readonly LookTheme[] = ["light", "dark"]; | ||
| 58 | 61 | export const DEFAULT_THEME: LookTheme = "light"; |
| 59 | 62 | |
| 60 | 63 | /** The kinds also pictured in the dark: a thumb is the desktop page reduced, and stays light. */ |
| 61 | export const DARK_KINDS: readonly LookKind[] = ["phone", "desktop"]; | |
| 64 | export const DARK_KINDS: readonly LookKind[] = ["phone", "narrow", "desktop"]; | |
| 65 | ||
| 66 | /** | |
| 67 | * The pages also pictured at 360 px: the home page only. A look reuses the | |
| 68 | * host's warm browser (a context per picture), so this is two more page | |
| 69 | * loads per green head, light and dark; every page at a third phone-ish | |
| 70 | * width would be two per page for little the 390 picture does not show. | |
| 71 | */ | |
| 72 | export const NARROW_PAGES: readonly string[] = ["/"]; | |
| 73 | ||
| 74 | /** The kinds one page is pictured at. */ | |
| 75 | export const kindsOfPage = (page: string): readonly LookKind[] => | |
| 76 | LOOK_KINDS.filter((k) => k !== "narrow" || NARROW_PAGES.includes(page)); | |
| 62 | 77 | |
| 63 | 78 | /** A look with no page recorded — every row before `app.looks` existed. */ |
| 64 | 79 | export const DEFAULT_PAGE = "/"; |
| @@ -149,10 +164,23 @@ interface Row { | ||
| 149 | 164 | * module is the only place that knows. |
| 150 | 165 | */ |
outdated
A page string starting |
||
| 151 | 166 | const DARK_PREFIX = "dark:"; |
| 152 | const stored = (page: string, theme: LookTheme): string => | |
| 153 | theme === "dark" ? `${DARK_PREFIX}${page}` : page; | |
| 154 | const unstored = (page: string): string => | |
| 167 | /** | |
| 168 | * The `kind` column's CHECK admits phone, desktop and thumb, and cannot be | |
| 169 | * widened without a rebuild. A 360 px look is filed as a phone under a page | |
| 170 | * no other can have, the same way a dark one is, and decoded here. | |
| 171 | */ | |
| 172 | const NARROW_PREFIX = "narrow:"; | |
| 173 | const stored = (page: string, theme: LookTheme, kind: LookKind = "phone"): string => { | |
| 174 | const base = kind === "narrow" ? `${NARROW_PREFIX}${page}` : page; | |
| 175 | return theme === "dark" ? `${DARK_PREFIX}${base}` : base; | |
| 176 | }; | |
| 177 | const storedKind = (kind: LookKind): LookKind => (kind === "narrow" ? "phone" : kind); | |
| 178 | const unstoredDark = (page: string): string => | |
| 155 | 179 | page.startsWith(DARK_PREFIX) ? page.slice(DARK_PREFIX.length) : page; |
| 180 | const unstored = (page: string): string => { | |
| 181 | const p = unstoredDark(page); | |
| 182 | return p.startsWith(NARROW_PREFIX) ? p.slice(NARROW_PREFIX.length) : p; | |
| 183 | }; | |
| 156 | 184 | |
| 157 | 185 | const sizeOf = (r: Row): { size: LookSize } | undefined => |
| 158 | 186 | r.scroll_width === null || |
| @@ -175,7 +203,7 @@ const toLook = (r: Row): Look => ({ | ||
| 175 | 203 | env: r.env, |
| 176 | 204 | commitOid: r.commit_oid, |
| 177 | 205 | page: unstored(r.page), |
| 178 | kind: r.kind, | |
| 206 | kind: unstoredDark(r.page).startsWith(NARROW_PREFIX) ? "narrow" : r.kind, | |
| 179 | 207 | theme: r.theme, |
| 180 | 208 | path: r.path, |
| 181 | 209 | createdAt: r.created_at, |
| @@ -207,6 +235,9 @@ export interface RecordLookInput { | ||
| 207 | 235 | /** Record a picture, or the reason there is none. A retake replaces. */ |
| 208 | 236 | export function recordLook(db: Database, input: RecordLookInput): Look { |
| 209 | 237 | const page = input.page ?? DEFAULT_PAGE; |
| 238 | // Every page is a path (`app.looks` holds them to `/`, attachments are | |
| 239 | // `/attached-…`): one that is not could pass for a dark or 360 px row. | |
| 240 | if (!page.startsWith("/")) throw new Error(`a look's page is a path: ${JSON.stringify(page)}`); | |
| 210 | 241 | const theme = input.theme ?? DEFAULT_THEME; |
| 211 | 242 | db.query( |
| 212 | 243 | `INSERT INTO look (id, app_id, env, commit_oid, page, kind, path, error, taken_as, attached_by, note, theme, |
| @@ -222,8 +253,8 @@ export function recordLook(db: Database, input: RecordLookInput): Look { | ||
| 222 | 253 | input.appId, |
| 223 | 254 | input.env, |
| 224 | 255 | input.commitOid, |
| 225 | stored(page, theme), | |
| 226 | input.kind, | |
| 256 | stored(page, theme, input.kind), | |
| 257 | storedKind(input.kind), | |
| 227 | 258 | input.path, |
| 228 | 259 | input.error ?? null, |
| 229 | 260 | input.takenAs ?? "owner", |
| @@ -252,7 +283,7 @@ export function getLook( | ||
| 252 | 283 | Row, |
| 253 | 284 | [string, string, string, string, string] |
| 254 | 285 | >(`SELECT * FROM look WHERE app_id = ?1 AND env = ?2 AND commit_oid = ?3 AND page = ?4 AND kind = ?5`) |
| 255 | .get(appId, env, commitOid, stored(page, theme), kind); | |
| 286 | .get(appId, env, commitOid, stored(page, theme, kind), storedKind(kind)); | |
| 256 | 287 | return row ? toLook(row) : undefined; |
| 257 | 288 | } |
| 258 | 289 |
src/looks/pairs.ts +1 −1
| @@ -17,7 +17,7 @@ export interface PairCounts { | ||
| 17 | 17 | readonly mainEmpty: boolean; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | const WIDTHS: readonly LookKind[] = ["phone", "desktop"]; | |
| 20 | const WIDTHS: readonly LookKind[] = ["phone", "narrow", "desktop"]; | |
| 21 | 21 | |
| 22 | 22 | /** `taken`: the head's light, forge-taken looks; `mainLooks`: main's the reader may fetch. */ |
| 23 | 23 | export function pairCounts( |
src/looks/service.ts +2 −2
| @@ -54,7 +54,7 @@ import { | ||
| 54 | 54 | LEGACY_THUMB_WIDTH, |
| 55 | 55 | DARK_KINDS, |
| 56 | 56 | DEFAULT_THEME, |
| 57 | LOOK_KINDS, | |
| 57 | kindsOfPage, | |
| 58 | 58 | LOOK_THEMES, |
| 59 | 59 | type LookTheme, |
| 60 | 60 | LOOK_SIZES, |
| @@ -769,7 +769,7 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 769 | 769 | ); |
| 770 | 770 | return (pages ?? [DEFAULT_PAGE]).flatMap((page) => |
| 771 | 771 | LOOK_THEMES.flatMap((theme) => |
| 772 | LOOK_KINDS.filter( | |
| 772 | kindsOfPage(page).filter( | |
| 773 | 773 | (kind) => |
| 774 | 774 | (theme === "light" || DARK_KINDS.includes(kind)) && |
| 775 | 775 | !have.has(lookSlot(page, kind, theme)), |
src/web/pages/looks.ts +15 −6
| @@ -181,21 +181,27 @@ export function lookCard( | ||
| 181 | 181 | ): Html => { |
| 182 | 182 | const url = lookUrl(base, look); |
| 183 | 183 | const scheme = look.theme === "dark" ? " in the dark" : ""; |
| 184 | return html`<a class="look" data-slot="${kind}" href="${url}"> | |
| 184 | const shot = html`<a class="look" ${kind === "narrow" ? html`` : html`data-slot="${kind}"`} href="${url}"> | |
| 185 | 185 | <img |
| 186 | 186 | src="${url}" |
| 187 | 187 | width="${LOOK_SIZES[kind].width}" |
| 188 | 188 | height="${LOOK_SIZES[kind].height}" |
| 189 | 189 | alt="${repo.name}${page === DEFAULT_PAGE |
| 190 | 190 | ? "" |
| 191 | : ` ${page}`} ${of} on a ${kind}${scheme}" | |
| 191 | : ` ${page}`} ${of} on a ${kind === "narrow" ? "narrow phone" : kind}${scheme}" | |
| 192 | 192 | loading="lazy" |
| 193 | 193 | /> |
| 194 | 194 | </a>`; |
| 195 | // The 360 px picture sits in the phone's slot, a figure like an attached | |
| 196 | // one, its caption the width the alt text leaves out. | |
| 197 | return kind === "narrow" | |
| 198 | ? html`<figure data-slot="phone">${shot}<figcaption class="muted small">360 px</figcaption></figure>` | |
| 199 | : shot; | |
| 195 | 200 | }; |
| 196 | 201 | const group = (page: string): Html => { |
| 197 | 202 | const looksOfPage = taken.filter((l) => l.page === page); |
| 198 | 203 | const phone = pictured(looksOfPage, "phone"); |
| 204 | const narrow = pictured(looksOfPage, "narrow"); | |
| 199 | 205 | const desktop = pictured(looksOfPage, "desktop"); |
| 200 | 206 | const failed = looksOfPage.find( |
| 201 | 207 | (l) => l.commitOid === headOid && l.error !== null, |
| @@ -220,7 +226,7 @@ export function lookCard( | ||
| 220 | 226 | headKinds |
| 221 | 227 | .map((kind) => pictured(mainOfPage.filter((l) => l.theme === theme), kind)) |
| 222 | 228 | .filter((l): l is Look => l !== undefined); |
| 223 | const beforeShown = beforeOf("light", [phone, desktop].filter((l) => l !== undefined).map((l) => l.kind)); | |
| 229 | const beforeShown = beforeOf("light", [phone, narrow, desktop].filter((l) => l !== undefined).map((l) => l.kind)); | |
| 224 | 230 | // Only the dark pictures of the commit the caption names: after a push |
| 225 | 231 | // the light pair is retaken first, and an old head's dark pair must not |
| 226 | 232 | // sit under the new head's words. |
| @@ -228,6 +234,7 @@ export function lookCard( | ||
| 228 | 234 | (l) => l.page === page && l.commitOid === shown.commitOid, |
| 229 | 235 | ); |
| 230 | 236 | const darkPhone = pictured(darkOfPage, "phone"); |
| 237 | const darkNarrow = pictured(darkOfPage, "narrow"); | |
| 231 | 238 | const darkDesktop = pictured(darkOfPage, "desktop"); |
| 232 | 239 | // Main's picture beside the head's; where main has none, the head stands alone. |
| 233 | 240 | const compare = (before: readonly Look[], after: readonly Look[]): Html => |
| @@ -256,8 +263,8 @@ export function lookCard( | ||
| 256 | 263 | </div> |
| 257 | 264 | </div> |
| 258 | 265 | </div>`; |
| 259 | const lightAfter = [phone, desktop].filter((l): l is Look => l !== undefined); | |
| 260 | const darkAfter = [darkPhone, darkDesktop].filter((l): l is Look => l !== undefined); | |
| 266 | const lightAfter = [phone, narrow, desktop].filter((l): l is Look => l !== undefined); | |
| 267 | const darkAfter = [darkPhone, darkNarrow, darkDesktop].filter((l): l is Look => l !== undefined); | |
| 261 | 268 | return html`<section class="stack stack-tight"> |
| 262 | 269 | ${label} |
| 263 | 270 | ${compare(beforeShown, lightAfter)} |
| @@ -370,7 +377,9 @@ export function lookNow(ctx: Ctx, repo: Repo, record: AppRecord): Html { | ||
| 370 | 377 | </a>`; |
| 371 | 378 | } |
| 372 | 379 | |
| 373 | /** A small picture as a thumbnail that opens the pull; `label` names the link for a screen reader. */ | |
| 380 | /** | |
| 381 | * A small picture as a thumbnail that opens the pull; `label` names the link for a screen reader. | |
| 382 | */ | |
| 374 | 383 | export function lookThumb(href: string, src: string, label?: string): Html { |
| 375 | 384 | return html`<a class="look" data-slot="thumb" href="${href}" ${label === undefined ? html`` : html`aria-label="${label}"`} |
| 376 | 385 | ><img src="${src}" width="30" height="40" alt="" loading="lazy" |
test/look-narrow.test.ts added +53
| @@ -0,0 +1,53 @@ | ||
| 1 | /** The 360 px look: a kind of its own, stored without widening the table's CHECK (#13229). */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { DARK_KINDS, LOOK_WINDOWS, getLook, kindsOfPage, lookSlot, looksForEnv, recordLook } from "../src/core/looks.ts"; | |
| 4 | import { openDb } from "../src/kernel/db.ts"; | |
| 5 | import { migrations } from "../src/core/schema.ts"; | |
| 6 | import { parseManifest } from "../src/apps/manifest.ts"; | |
| 7 | ||
| 8 | test("360 px is a window of its own, pictured light and dark, on the home page only", () => { | |
| 9 | expect(LOOK_WINDOWS.narrow.width).toBe(360); | |
| 10 | expect(DARK_KINDS).toContain("narrow"); | |
| 11 | expect(kindsOfPage("/")).toContain("narrow"); | |
| 12 | expect(kindsOfPage("/about")).not.toContain("narrow"); | |
| 13 | expect(lookSlot("/", "narrow")).toBe("narrow"); | |
| 14 | expect(lookSlot("/", "narrow", "dark")).toBe("narrow-dark"); | |
| 15 | }); | |
| 16 | ||
| 17 | test("a narrow look round-trips beside the phone look of the same page and theme", () => { | |
| 18 | const db = openDb(":memory:", migrations); | |
| 19 | db.query("PRAGMA foreign_keys = OFF").run(); | |
| 20 | const base = { appId: "a", env: "production", commitOid: "c".repeat(40), path: "x.png" }; | |
| 21 | recordLook(db, { ...base, kind: "phone" }); | |
| 22 | recordLook(db, { ...base, kind: "narrow" }); | |
| 23 | recordLook(db, { ...base, kind: "narrow", theme: "dark" }); | |
| 24 | expect(getLook(db, "a", "production", base.commitOid, "/", "narrow")?.kind).toBe("narrow"); | |
| 25 | expect(getLook(db, "a", "production", base.commitOid, "/", "phone")?.kind).toBe("phone"); | |
| 26 | expect(getLook(db, "a", "production", base.commitOid, "/", "narrow", "dark")?.theme).toBe("dark"); | |
| 27 | const all = looksForEnv(db, "a", "production", "any"); | |
| 28 | expect(all.map((l) => `${l.kind}/${l.theme}/${l.page}`).sort()).toEqual([ | |
| 29 | "narrow/dark//", | |
| 30 | "narrow/light//", | |
| 31 | "phone/light//", | |
| 32 | ]); | |
| 33 | }); | |
| 34 | ||
| 35 | test("a page named like a storage prefix cannot pass for a 360 px or dark look", () => { | |
| 36 | // Refused at the boundary: app.looks entries are paths, so `narrow:/x` never becomes a page. | |
| 37 | const manifest = (page: string) => | |
| 38 | parseManifest(JSON.stringify({ app: { run: "bun x.ts", looks: [page] } }), undefined); | |
| 39 | expect(manifest("/x").ok).toBe(true); | |
| 40 | for (const page of ["narrow:/x", "dark:/x", "dark:narrow:/"]) { | |
| 41 | expect(manifest(page).ok).toBe(false); | |
| 42 | } | |
| 43 | const db = openDb(":memory:", migrations); | |
| 44 | db.query("PRAGMA foreign_keys = OFF").run(); | |
| 45 | const base = { appId: "a", env: "production", commitOid: "c".repeat(40), path: "x.png" }; | |
| 46 | // And refused where a row is written, whatever the caller. | |
| 47 | expect(() => recordLook(db, { ...base, kind: "phone", page: "narrow:/x" })).toThrow(); | |
| 48 | expect(() => recordLook(db, { ...base, kind: "phone", page: "dark:/x" })).toThrow(); | |
| 49 | // A path that merely contains the word is its own phone look. | |
| 50 | recordLook(db, { ...base, kind: "phone", page: "/narrow:/x" }); | |
| 51 | const all = looksForEnv(db, "a", "production", "any"); | |
| 52 | expect(all.map((l) => `${l.kind}/${l.theme}/${l.page}`)).toEqual(["phone/light//narrow:/x"]); | |
| 53 | }); |
test/looks-pairs.test.ts +6
| @@ -22,3 +22,9 @@ test("no main pictures says so once; no head pictures says nothing; dark does no | ||
| 22 | 22 | expect(pairsLine(pairCounts([], [look("/", "phone")]))).toBeUndefined(); |
| 23 | 23 | expect(pairCounts([look("/", "phone")], [look("/", "phone", "dark")]).beside).toBe(0); |
| 24 | 24 | }); |
| 25 | ||
| 26 | test("a 360 px look counts as a width: a pull with only that picture still pairs", () => { | |
| 27 | const c = pairCounts([look("/", "narrow")], [look("/", "narrow")]); | |
| 28 | expect(c).toEqual({ pages: 1, beside: 1, fresh: 0, mainEmpty: false }); | |
| 29 | expect(pairCounts([look("/", "narrow")], [look("/", "phone")]).beside).toBe(0); | |
| 30 | }); |
test/looks.test.ts +63 −40
| @@ -176,13 +176,13 @@ describe("the look", () => { | ||
| 176 | 176 | : undefined; |
| 177 | 177 | }); |
| 178 | 178 | |
| 179 | /** All three looks of a commit, once they are recorded — pictured or not. */ | |
| 179 | /** All the looks of a commit, once they are recorded — pictured or not. */ | |
| 180 | 180 | const pictured = (env: string, commitOid: string): Promise<Look[]> => |
| 181 | 181 | until(() => { |
| 182 | 182 | const rows = looksForEnv(app.db, record.id, env).filter( |
| 183 | 183 | (l) => l.commitOid === commitOid, |
| 184 | 184 | ); |
| 185 | return rows.length === 3 ? rows : undefined; | |
| 185 | return rows.length === 4 ? rows : undefined; | |
| 186 | 186 | }, 30_000); |
| 187 | 187 | |
| 188 | 188 | interface Opened { |
| @@ -398,14 +398,14 @@ describe("the look", () => { | ||
| 398 | 398 | const dark = looksForEnv(app.db, record.id, env, "dark").filter( |
| 399 | 399 | (l) => l.commitOid === twoPages.commitOid, |
| 400 | 400 | ); |
| 401 | return light.length === 6 && dark.length === 4 ? true : undefined; | |
| 401 | return light.length === 7 && dark.length === 5 ? true : undefined; | |
| 402 | 402 | }), |
| 403 | 403 | ), |
| 404 | 404 | done(previewEnv(gallery.pull.number), gallery.commitOid, gallery.repo.id).then(() => |
| 405 | 405 | until(() => |
| 406 | 406 | looksForEnv(app.db, gallery.app.id, previewEnv(gallery.pull.number)).filter( |
| 407 | 407 | (l) => l.commitOid === gallery.commitOid, |
| 408 | ).length === 3 | |
| 408 | ).length === 4 | |
| 409 | 409 | ? true |
| 410 | 410 | : undefined, |
| 411 | 411 | ), |
| @@ -429,13 +429,15 @@ describe("the look", () => { | ||
| 429 | 429 | let first = ""; |
| 430 | 430 | let second = ""; |
| 431 | 431 | |
| 432 | test("a green production deploy is pictured at all three widths as the owner, the thumb reduced from the desktop page", async () => { | |
| 433 | // Invariant: production's head gets phone, desktop and thumb, each taken through the grant door as the owner, staged aside and moved in whole. | |
| 432 | test("a green production deploy is pictured at every width as the owner, the thumb reduced from the desktop page", async () => { | |
| 433 | // Invariant: production's head gets phone, 360 px, desktop and thumb, each taken through the | |
| 434 | // grant door as the owner, staged aside and moved in whole. | |
| 434 | 435 | const production = await settled((r) => r.env === "production"); |
| 435 | 436 | expect(production.state).toBe("ok"); |
| 436 | 437 | const rows = await pictured("production", production.commitOid); |
| 437 | 438 | expect(rows.map((l) => l.kind).sort()).toEqual([ |
| 438 | 439 | "desktop", |
| 440 | "narrow", | |
| 439 | 441 | "phone", |
| 440 | 442 | "thumb", |
| 441 | 443 | ]); |
| @@ -449,7 +451,7 @@ describe("the look", () => { | ||
| 449 | 451 | // The browser was pointed at the grant door on the forge's own port, |
| 450 | 452 | // and the grant names the owner as an admin. |
| 451 | 453 | const taken = callsAt("production"); |
| 452 | expect(taken).toHaveLength(3); | |
| 454 | expect(taken).toHaveLength(4); | |
| 453 | 455 | // Taken to one side and moved in whole: nothing half-written lives |
| 454 | 456 | // under the environment, and nothing is left behind on the side. |
| 455 | 457 | for (const call of calls) |
| @@ -488,14 +490,14 @@ describe("the look", () => { | ||
| 488 | 490 | }); |
| 489 | 491 | |
| 490 | 492 | test("a pull's preview is pictured at its own host, and what the page recorded reaches a check made afterwards", async () => { |
| 491 | // Invariant: a green preview gets its three looks at `hello--<n>`, and the phone's LCP and desktop's CLS reach the vitals of a check | |
| 492 | // created after the look. | |
| 493 | // Invariant: a green preview gets its four looks at `hello--<n>`, and the phone's LCP and | |
| 494 | // desktop's CLS reach the vitals of a check created after the look. | |
| 493 | 495 | pull = greeting.pull; |
| 494 | 496 | first = greeting.commitOid; |
| 495 | 497 | const env = previewEnv(pull.number); |
| 496 | 498 | expect((await settled((r) => r.env === env)).state).toBe("ok"); |
| 497 | expect(await pictured(env, first)).toHaveLength(3); | |
| 498 | expect(callsAt(env)).toHaveLength(3); | |
| 499 | expect(await pictured(env, first)).toHaveLength(4); | |
| 500 | expect(callsAt(env)).toHaveLength(4); | |
| 499 | 501 | expect(new URL(callsAt(env)[0]!.url).hostname).toBe(`hello--${pull.number}.${DOMAIN}`); |
| 500 | 502 | // The entries the browser recorded reach the check's summary: the |
| 501 | 503 | // phone's LCP and the desktop's CLS, graded; the thumb adds no row. |
| @@ -510,8 +512,8 @@ describe("the look", () => { | ||
| 510 | 512 | reason: "push", |
| 511 | 513 | }); |
| 512 | 514 | const recorded = readLooks(dataDir, check); |
| 513 | expect(recorded).toHaveLength(2); | |
| 514 | expect(recorded.map((l) => l.look).sort()).toEqual(["desktop", "phone"]); | |
| 515 | expect(recorded).toHaveLength(3); | |
| 516 | expect(recorded.map((l) => l.look).sort()).toEqual(["desktop", "narrow", "phone"]); | |
| 515 | 517 | const graded = vitalsRows(recorded); |
| 516 | 518 | // The phone's recorded size is stored beside its entries: two screens tall. |
| 517 | 519 | expect(graded.find((g) => g.look === "phone")!.screens).toBe("2.0"); |
| @@ -528,19 +530,21 @@ describe("the look", () => { | ||
| 528 | 530 | }); |
| 529 | 531 | |
| 530 | 532 | test("the same head green again is not pictured again", async () => { |
| 531 | // Invariant: a redeploy of an already-pictured head takes no new picture and leaves its three rows. | |
| 533 | // Invariant: a redeploy of an already-pictured head takes no new picture and leaves its four | |
| 534 | // rows. | |
| 532 | 535 | const env = previewEnv(pull.number); |
| 533 | 536 | runtime.requestDeploy(record, repo, env, first, "redeploy"); |
| 534 | 537 | expect( |
| 535 | 538 | (await settled((r) => r.env === env && r.reason === "redeploy")).state, |
| 536 | 539 | ).toBe("ok"); |
| 537 | 540 | await looks.idle(); |
| 538 | expect(callsAt(env)).toHaveLength(3); | |
| 539 | expect(looksForEnv(app.db, record.id, env)).toHaveLength(3); | |
| 541 | expect(callsAt(env)).toHaveLength(4); | |
| 542 | expect(looksForEnv(app.db, record.id, env)).toHaveLength(4); | |
| 540 | 543 | }); |
| 541 | 544 | |
| 542 | 545 | test("a newer head is pictured, and the older head's pictures go", async () => { |
| 543 | // Invariant: a new green head of a preview is pictured once and replaces the older head's rows and files; production's are untouched. | |
| 546 | // Invariant: a new green head of a preview is pictured once and replaces the older head's rows | |
| 547 | // and files; production's are untouched. | |
| 544 | 548 | const env = previewEnv(pull.number); |
| 545 | 549 | const again = await commitToBranch(app, alice, repo, { |
| 546 | 550 | branch: "greeting", |
| @@ -552,8 +556,8 @@ describe("the look", () => { | ||
| 552 | 556 | expect( |
| 553 | 557 | (await settled((r) => r.env === env && r.commitOid === second)).state, |
| 554 | 558 | ).toBe("ok"); |
| 555 | expect(await pictured(env, second)).toHaveLength(3); | |
| 556 | expect(callsAt(env)).toHaveLength(6); | |
| 559 | expect(await pictured(env, second)).toHaveLength(4); | |
| 560 | expect(callsAt(env)).toHaveLength(8); | |
| 557 | 561 | await until(() => |
| 558 | 562 | looksForEnv(app.db, record.id, env).every((l) => l.commitOid === second) |
| 559 | 563 | ? true |
| @@ -652,7 +656,8 @@ describe("the look", () => { | ||
| 652 | 656 | }); |
| 653 | 657 | |
| 654 | 658 | test("a picture that could not be taken is recorded with its reason, and the page says so", async () => { |
| 655 | // Invariant: a failed capture is a row with its reason and no path; the pull keeps its last good pictures and says the head moved, and why. | |
| 659 | // Invariant: a failed capture is a row with its reason and no path; the pull keeps its last | |
| 660 | // good pictures and says the head moved, and why. | |
| 656 | 661 | const env = `pull-${pull.number}`; |
| 657 | 662 | modes.set(helloHost(env), "fail"); |
| 658 | 663 | const moved = await commitToBranch(app, alice, repo, { |
| @@ -672,7 +677,7 @@ describe("the look", () => { | ||
| 672 | 677 | // #11509: a page that gives no picture is tried once, not once per |
| 673 | 678 | // kind, and the next try waits out its backoff. |
| 674 | 679 | expect(callsAt(env).length - callsBefore).toBe(1); |
| 675 | expect(rows).toHaveLength(3); | |
| 680 | expect(rows).toHaveLength(4); | |
| 676 | 681 | const waits = () => scheduled.filter((s) => !waitsBefore.has(s)); |
| 677 | 682 | expect(waits().map((w) => w.ms)).toEqual([30_000]); |
| 678 | 683 | // An event for the same head inside the wait is not a reason to try sooner. |
| @@ -726,7 +731,8 @@ describe("the look", () => { | ||
| 726 | 731 | }); |
| 727 | 732 | |
| 728 | 733 | test("a pull that never had a picture says so, with the reason, and links none", async () => { |
| 729 | // Invariant: a pull whose every capture failed shows the Look card's "No picture of" with the browser's reason and no picture URL. | |
| 734 | // Invariant: a pull whose every capture failed shows the Look card's "No picture of" with the | |
| 735 | // browser's reason and no picture URL. | |
| 730 | 736 | const env2 = `pull-${unpictured.pull.number}`; |
| 731 | 737 | const rows = await pictured(env2, unpictured.commitOid); |
| 732 | 738 | expect(rows.every((l) => l.error === "the browser fell over")).toBe(true); |
| @@ -740,7 +746,8 @@ describe("the look", () => { | ||
| 740 | 746 | }); |
| 741 | 747 | |
| 742 | 748 | test("with no browser the check's summary says so and stays green", async () => { |
| 743 | // Invariant: NO_BROWSER is recorded for the check as "no browser" per look, words only, and leaves the check's state alone. | |
| 749 | // Invariant: NO_BROWSER is recorded for the check as "no browser" per look, words only, and | |
| 750 | // leaves the check's state alone. | |
| 744 | 751 | const env = `pull-${unpictured.pull.number}`; |
| 745 | 752 | modes.set(helloHost(env), "nobrowser"); |
| 746 | 753 | const waitsBefore = scheduled.length; |
| @@ -765,14 +772,15 @@ describe("the look", () => { | ||
| 765 | 772 | expect(scheduled).toHaveLength(waitsBefore); |
| 766 | 773 | const got = await until(() => { |
| 767 | 774 | const read = readLooks(dataDir, check); |
| 768 | return read.length === 2 ? read : undefined; | |
| 775 | return read.length === 3 ? read : undefined; | |
| 769 | 776 | }); |
| 770 | 777 | expect(got).toEqual([ |
| 771 | 778 | { look: "phone", skipped: "no browser" }, |
| 779 | { look: "narrow", skipped: "no browser" }, | |
| 772 | 780 | { look: "desktop", skipped: "no browser" }, |
| 773 | 781 | ]); |
| 774 | 782 | // Words only: the table has no verdict to turn a check red. |
| 775 | expect(vitalsRows(got).map((g) => g.skipped)).toEqual(["no browser", "no browser"]); | |
| 783 | expect(vitalsRows(got).map((g) => g.skipped)).toEqual(["no browser", "no browser", "no browser"]); | |
| 776 | 784 | expect(listRuns(app.db, repo.id, { kind: "check" }).find((r) => r.id === check.id)!.state).toBe("queued"); |
| 777 | 785 | modes.delete(helloHost(env)); |
| 778 | 786 | }); |
| @@ -821,7 +829,8 @@ describe("the look", () => { | ||
| 821 | 829 | }); |
| 822 | 830 | |
| 823 | 831 | test("a closed pull's pictures go with its preview", async () => { |
| 824 | // Invariant: closing a pull deletes its preview's look rows and folder, and its page shows no Look card. | |
| 832 | // Invariant: closing a pull deletes its preview's look rows and folder, and its page shows no | |
| 833 | // Look card. | |
| 825 | 834 | const env = `pull-${unpictured.pull.number}`; |
| 826 | 835 | expect(looksForEnv(app.db, record.id, env).length).toBeGreaterThan(0); |
| 827 | 836 | const closed = await setIssueStateThrough( |
| @@ -841,7 +850,8 @@ describe("the look", () => { | ||
| 841 | 850 | }); |
| 842 | 851 | |
| 843 | 852 | test("a look is taken from `app.serving`, while the deploy's tests are still running, and a red check afterward does not remove it", async () => { |
| 844 | // Invariant: the look is taken on `app.serving` while the deploy's test still runs, and that test failing afterward leaves the pictures. | |
| 853 | // Invariant: the look is taken on `app.serving` while the deploy's test still runs, and that | |
| 854 | // test failing afterward leaves the pictures. | |
| 845 | 855 | const gate = join(dataDir, "slow-red-test.gate"); |
| 846 | 856 | const opened = { value: slowRed.pull }; |
| 847 | 857 | const env = `pull-${slowRed.pull.number}`; |
| @@ -872,7 +882,7 @@ describe("the look", () => { | ||
| 872 | 882 | looksForEnv(app.db, record.id, env).filter( |
| 873 | 883 | (l) => l.commitOid === commitOid && l.error === null, |
| 874 | 884 | ), |
| 875 | ).toHaveLength(3); | |
| 885 | ).toHaveLength(4); | |
| 876 | 886 | |
| 877 | 887 | expect( |
| 878 | 888 | (await setIssueStateThrough(app, alice, repo, opened.value, "closed")).ok, |
| @@ -880,7 +890,8 @@ describe("the look", () => { | ||
| 880 | 890 | }); |
| 881 | 891 | |
| 882 | 892 | test("two events for one environment, back to back, leave one queued look — at the newer commit", async () => { |
| 883 | // Invariant: a second app.serving for an environment replaces the queued first, so the superseded commit is never pictured. | |
| 893 | // Invariant: a second app.serving for an environment replaces the queued first, so the | |
| 894 | // superseded commit is never pictured. | |
| 884 | 895 | const before = callsAt("production").length; |
| 885 | 896 | const live = runtime.envStatus(record, "production"); |
| 886 | 897 | if (live === undefined) throw new Error("production is not live"); |
| @@ -920,7 +931,8 @@ describe("the look", () => { | ||
| 920 | 931 | }); |
| 921 | 932 | |
| 922 | 933 | test("the app's head shows production as a thumb", async () => { |
| 923 | // Invariant: the studio's app head shows production's thumb, and falls back to its desktop picture when no thumb row exists. | |
| 934 | // Invariant: the studio's app head shows production's thumb, and falls back to its desktop | |
| 935 | // picture when no thumb row exists. | |
| 924 | 936 | const env = `pull-${ask.pull.number}`; |
| 925 | 937 | expect((await settled((r) => r.env === env)).state).toBe("ok"); |
| 926 | 938 | const rows = await pictured(env, ask.commitOid); |
| @@ -960,7 +972,8 @@ describe("the look", () => { | ||
| 960 | 972 | }); |
| 961 | 973 | |
| 962 | 974 | test("app.looks naming two pages pictures both, distinctly, and the pull page groups them", async () => { |
| 963 | // Invariant: each page `app.looks` names gets its own light and dark slots and files, grouped by page on the pull, dark folded away. | |
| 975 | // Invariant: each page `app.looks` names gets its own light and dark slots and files, grouped | |
| 976 | // by page on the pull, dark folded away. | |
| 964 | 977 | const opened = { value: twoPages.pull }; |
| 965 | 978 | const env = `pull-${opened.value.number}`; |
| 966 | 979 | const commitOid = twoPages.commitOid; |
| @@ -970,14 +983,14 @@ describe("the look", () => { | ||
| 970 | 983 | const found = looksForEnv(app.db, record.id, env).filter( |
| 971 | 984 | (l) => l.commitOid === commitOid, |
| 972 | 985 | ); |
| 973 | return found.length === 6 ? found : undefined; | |
| 986 | return found.length === 7 ? found : undefined; | |
| 974 | 987 | }, 30_000); |
| 975 | 988 | const home = rows.filter((l) => l.page === "/"); |
| 976 | 989 | const board = rows.filter((l) => l.page === "/board"); |
| 977 | expect(home).toHaveLength(3); | |
| 990 | expect(home).toHaveLength(4); | |
| 978 | 991 | expect(board).toHaveLength(3); |
| 979 | 992 | // Two pages of one commit never collide on disk. |
| 980 | expect(new Set(rows.map((l) => l.path)).size).toBe(6); | |
| 993 | expect(new Set(rows.map((l) => l.path)).size).toBe(7); | |
| 981 | 994 | const boardPhone = board.find((l) => l.kind === "phone")!; |
| 982 | 995 | expect(boardPhone.path).toBe( |
| 983 | 996 | `looks/${record.id}/${env}/${commitOid}-board-phone.png`, |
| @@ -1007,6 +1020,14 @@ describe("the look", () => { | ||
| 1007 | 1020 | `alt="hello /board #${opened.value.number} on a phone"`, |
| 1008 | 1021 | ); |
| 1009 | 1022 | expect(page).toContain(`alt="hello #${opened.value.number} on a phone"`); |
| 1023 | // The 360 px picture is the home page's alone, and is captioned. | |
| 1024 | // In the phone's slot (no width rule of its own), the caption saying the width the alt leaves | |
| 1025 | // out. | |
| 1026 | expect(page).toContain(`alt="hello #${opened.value.number} on a narrow phone"`); | |
| 1027 | expect(page).toContain(`<figure data-slot="phone"><a class="look" href=`); | |
| 1028 | expect(page).toContain(`<figcaption class="muted small">360 px</figcaption>`); | |
| 1029 | expect(page).not.toContain(`360 px"`); | |
| 1030 | expect(page).not.toContain(`/board #${opened.value.number} on a narrow phone`); | |
| 1010 | 1031 | |
| 1011 | 1032 | // Each page is also pictured in the dark, at phone and desktop, in a |
| 1012 | 1033 | // slot of its own: the same page and kind, a different file. |
| @@ -1014,10 +1035,10 @@ describe("the look", () => { | ||
| 1014 | 1035 | const found = looksForEnv(app.db, record.id, env, "dark").filter( |
| 1015 | 1036 | (l) => l.commitOid === commitOid, |
| 1016 | 1037 | ); |
| 1017 | return found.length === 4 ? found : undefined; | |
| 1038 | return found.length === 5 ? found : undefined; | |
| 1018 | 1039 | }, 30_000); |
| 1019 | 1040 | expect(dark.every((l) => l.theme === "dark")).toBe(true); |
| 1020 | expect(dark.map((l) => l.kind).sort()).toEqual(["desktop", "desktop", "phone", "phone"]); | |
| 1041 | expect(dark.map((l) => l.kind).sort()).toEqual(["desktop", "desktop", "narrow", "phone", "phone"]); | |
| 1021 | 1042 | expect(darkCalls.every((c) => c.dark === true)).toBe(true); |
| 1022 | 1043 | const darkPhone = dark.find((l) => l.page === "/" && l.kind === "phone")!; |
| 1023 | 1044 | expect(darkPhone.path).toBe( |
| @@ -1331,7 +1352,8 @@ describe("the look", () => { | ||
| 1331 | 1352 | }); |
| 1332 | 1353 | |
| 1333 | 1354 | test("a public app's previews are taken as nobody, so a reader of its pull sees the Look card; a picture taken as the owner stays the writers' (#738)", async () => { |
| 1334 | // Invariant: a public app's preview pictures carry no grant identity and are served to readers and strangers; owner-taken ones stay the writers'. | |
| 1355 | // Invariant: a public app's preview pictures carry no grant identity and are served to readers | |
| 1356 | // and strangers; owner-taken ones stay the writers'. | |
| 1335 | 1357 | const galleryApp = gallery.app; |
| 1336 | 1358 | expect(galleryApp.access).toBe("public"); |
| 1337 | 1359 | const opened = { value: gallery.pull }; |
| @@ -1342,10 +1364,10 @@ describe("the look", () => { | ||
| 1342 | 1364 | const found = looksForEnv(app.db, galleryApp.id, env).filter( |
| 1343 | 1365 | (l) => l.commitOid === commit, |
| 1344 | 1366 | ); |
| 1345 | return found.length === 3 ? found : undefined; | |
| 1367 | return found.length === 4 ? found : undefined; | |
| 1346 | 1368 | }, 30_000); |
| 1347 | 1369 | // All three taken as nobody, and the browser was told so. |
| 1348 | expect(rows.map((l) => l.takenAs)).toEqual(["nobody", "nobody", "nobody"]); | |
| 1370 | expect(rows.map((l) => l.takenAs)).toEqual(["nobody", "nobody", "nobody", "nobody"]); | |
| 1349 | 1371 | const phoneCall = calls.filter((c) => c.out.includes(galleryApp.id) || c.url.includes("gallery")).find((c) => c.width === 390)!; |
| 1350 | 1372 | expect( |
| 1351 | 1373 | readGrant(dataDir, new URL(phoneCall.url).searchParams.get("t") ?? "", { |
| @@ -1494,7 +1516,8 @@ describe("the look", () => { | ||
| 1494 | 1516 | ? "a real capture — skipped: no chromium on this machine (install one, or set FORGE_CHROMIUM)" |
| 1495 | 1517 | : `a real capture through the grant door, with ${chromium}`, |
| 1496 | 1518 | async () => { |
| 1497 | // Invariant: a real Chromium sent through the grant door pictures the page at the window's size, records every entry type, and arrives as the owner. | |
| 1519 | // Invariant: a real Chromium sent through the grant door pictures the page at the window's | |
| 1520 | // size, records every entry type, and arrives as the owner. | |
| 1498 | 1521 | if (peek === undefined) throw new Error("no peek without a browser"); |
| 1499 | 1522 | const enabled = { value: peek.app }; |
| 1500 | 1523 | expect( |
test/tui-pull-looks-section.test.ts +8 −3
| @@ -7,7 +7,7 @@ import { openPull } from "../src/actions/pulls.ts"; | ||
| 7 | 7 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 8 | 8 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 9 | 9 | import { previewEnv } from "../src/apps/data.ts"; |
| 10 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 10 | import { createApp as insertApp, getAppByRepo } from "../src/core/apps.ts"; | |
| 11 | 11 | import { pullLooks } from "../src/looks/readable.ts"; |
| 12 | 12 | import { recordLook, type RecordLookInput } from "../src/core/looks.ts"; |
| 13 | 13 | import type { Pull } from "../src/core/pulls.ts"; |
| @@ -64,7 +64,10 @@ beforeAll(async () => { | ||
| 64 | 64 | made[name] = { repo: r.value, pull: o.value }; |
| 65 | 65 | } |
| 66 | 66 | const take = (name: string, access: "public" | "private", extra: Partial<RecordLookInput>) => { |
| 67 | const inserted = insertApp(forge.db, { repoId: made[name]!.repo.id, slug: name, access }); | |
| 67 | const existing = getAppByRepo(forge.db, made[name]!.repo.id); | |
| 68 | const inserted = existing | |
| 69 | ? { ok: true as const, value: existing } | |
| 70 | : insertApp(forge.db, { repoId: made[name]!.repo.id, slug: name, access }); | |
| 68 | 71 | if (!inserted.ok) throw new Error(inserted.error); |
| 69 | 72 | recordLook(forge.db, { |
| 70 | 73 | appId: inserted.value.id, |
| @@ -79,6 +82,7 @@ beforeAll(async () => { | ||
| 79 | 82 | }); |
| 80 | 83 | }; |
| 81 | 84 | take("pictured", "public", {}); |
| 85 | take("pictured", "public", { kind: "narrow", note: "fits at 360 px" }); | |
| 82 | 86 | take("hush", "private", {}); |
| 83 | 87 | take("ownerly", "public", { takenAs: "owner" }); |
| 84 | 88 | insertApp(forge.db, { repoId: made["plain"]!.repo.id, slug: "plain", access: "public" }); |
| @@ -113,8 +117,9 @@ const fullUrl = (name: string) => { | ||
| 113 | 117 | |
| 114 | 118 | test("a pull with a look shows its width, line and full absolute URL", async () => { |
| 115 | 119 | const out = await text("pictured"); |
| 116 | expect(out).toContain("Looks (1)"); | |
| 120 | expect(out).toContain("Looks (2)"); | |
| 117 | 121 | expect(out).toContain("phone · alice · the empty state reads well"); |
| 122 | expect(out).toContain("narrow · alice · fits at 360 px"); | |
| 118 | 123 | expect(out).toContain(fullUrl("pictured")); |
| 119 | 124 | }); |
| 120 | 125 |
new above
offline
Direction: NARROW_PAGES adds captures to every green deploy while the pipeline-first list is open. Defer this pull or show its cost.