Public: anyone can read this; the crew can change it.

A look kind at 360 px, the narrowest phone width people still use #13233

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13229-a-look-kind-at-360-px-the-narrowest-phon → main 5 commits fork 3 threads · 3 unresolved

  • Merged. scout/13229-a-look-kind-at-360-px-the-narrowest-phon was merged into main as c9ead35.

Review

Sign in to review this change.
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
2121 the preview to serve, and the four appear. Looks fill in as the round goes, so
2222 list again if one is missing.
2323
24 ## The phone is 390 px, not 360
24 ## The phone is 390 px; the 360 px look is beside it
2525
2626 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:
1919 - **MCP** — the `pull` tool carries `looks`, the same items (no new tool).
2020 - **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.
2121
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
2228 Above the pictures on the pull page, and at the top of the terminal screen,
2329 one line counts the pages shown beside main and those main has no picture of
2430 (`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 {
266266 readonly size?: PageSize;
267267 }
268268
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} `));
270271
271272 /** `phone /x scrolls sideways` for each phone look wider than its window; empty when none. */
272273 export function sidewaysLine(groups: readonly LookRows[]): string {
src/core/looks.ts +41 −10
@@ -9,8 +9,8 @@ import type { Database } from "bun:sqlite";
99 import { id as newId } from "../kernel/id.ts";
1010
1111 /** 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"];
1414 export const isLookKind = (value: string): value is LookKind =>
1515 (LOOK_KINDS as readonly string[]).includes(value);
1616
@@ -23,6 +23,8 @@ export const LOOK_SIZES: Readonly<
2323 Record<LookKind, { readonly width: number; readonly height: number }>
2424 > = {
2525 phone: { width: 390, height: 844 },
26 /** The narrowest phone width people still use. */
27 narrow: { width: 360, height: 780 },
2628 desktop: { width: 1280, height: 800 },
2729 thumb: { width: 640, height: 400 },
2830 };
@@ -37,6 +39,7 @@ export const LOOK_WINDOWS: Readonly<
3739 Record<LookKind, { readonly width: number; readonly height: number }>
3840 > = {
3941 phone: LOOK_SIZES.phone,
42 narrow: LOOK_SIZES.narrow,
4043 desktop: LOOK_SIZES.desktop,
4144 thumb: LOOK_SIZES.desktop,
4245 };
@@ -58,7 +61,19 @@ export const LOOK_THEMES: readonly LookTheme[] = ["light", "dark"];
5861 export const DEFAULT_THEME: LookTheme = "light";
5962
6063 /** 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
outdated

Direction: NARROW_PAGES adds captures to every green deploy while the pipeline-first list is open. Defer this pull or show its cost.

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));
6277
6378 /** A look with no page recorded — every row before `app.looks` existed. */
6479 export const DEFAULT_PAGE = "/";
@@ -149,10 +164,23 @@ interface Row {
149164 * module is the only place that knows.
150165 */
outdated

A page string starting narrow: or dark: is now a storage namespace. Validate app.looks pages at the boundary so a user-named page cannot collide with it, and test it.

151166 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 =>
155179 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 };
156184
157185 const sizeOf = (r: Row): { size: LookSize } | undefined =>
158186 r.scroll_width === null ||
@@ -175,7 +203,7 @@ const toLook = (r: Row): Look => ({
175203 env: r.env,
176204 commitOid: r.commit_oid,
177205 page: unstored(r.page),
178 kind: r.kind,
206 kind: unstoredDark(r.page).startsWith(NARROW_PREFIX) ? "narrow" : r.kind,
179207 theme: r.theme,
180208 path: r.path,
181209 createdAt: r.created_at,
@@ -207,6 +235,9 @@ export interface RecordLookInput {
207235 /** Record a picture, or the reason there is none. A retake replaces. */
208236 export function recordLook(db: Database, input: RecordLookInput): Look {
209237 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)}`);
210241 const theme = input.theme ?? DEFAULT_THEME;
211242 db.query(
212243 `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 {
222253 input.appId,
223254 input.env,
224255 input.commitOid,
225 stored(page, theme),
226 input.kind,
256 stored(page, theme, input.kind),
257 storedKind(input.kind),
227258 input.path,
228259 input.error ?? null,
229260 input.takenAs ?? "owner",
@@ -252,7 +283,7 @@ export function getLook(
252283 Row,
253284 [string, string, string, string, string]
254285 >(`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));
256287 return row ? toLook(row) : undefined;
257288 }
258289
src/looks/pairs.ts +1 −1
@@ -17,7 +17,7 @@ export interface PairCounts {
1717 readonly mainEmpty: boolean;
1818 }
1919
20 const WIDTHS: readonly LookKind[] = ["phone", "desktop"];
20 const WIDTHS: readonly LookKind[] = ["phone", "narrow", "desktop"];
2121
2222 /** `taken`: the head's light, forge-taken looks; `mainLooks`: main's the reader may fetch. */
2323 export function pairCounts(
src/looks/service.ts +2 −2
@@ -54,7 +54,7 @@ import {
5454 LEGACY_THUMB_WIDTH,
5555 DARK_KINDS,
5656 DEFAULT_THEME,
57 LOOK_KINDS,
57 kindsOfPage,
5858 LOOK_THEMES,
5959 type LookTheme,
6060 LOOK_SIZES,
@@ -769,7 +769,7 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
769769 );
770770 return (pages ?? [DEFAULT_PAGE]).flatMap((page) =>
771771 LOOK_THEMES.flatMap((theme) =>
772 LOOK_KINDS.filter(
772 kindsOfPage(page).filter(
773773 (kind) =>
774774 (theme === "light" || DARK_KINDS.includes(kind)) &&
775775 !have.has(lookSlot(page, kind, theme)),
src/web/pages/looks.ts +15 −6
@@ -181,21 +181,27 @@ export function lookCard(
181181 ): Html => {
182182 const url = lookUrl(base, look);
183183 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}">
185185 <img
186186 src="${url}"
187187 width="${LOOK_SIZES[kind].width}"
188188 height="${LOOK_SIZES[kind].height}"
189189 alt="${repo.name}${page === DEFAULT_PAGE
190190 ? ""
191 : ` ${page}`} ${of} on a ${kind}${scheme}"
191 : ` ${page}`} ${of} on a ${kind === "narrow" ? "narrow phone" : kind}${scheme}"
192192 loading="lazy"
193193 />
194194 </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;
195200 };
196201 const group = (page: string): Html => {
197202 const looksOfPage = taken.filter((l) => l.page === page);
198203 const phone = pictured(looksOfPage, "phone");
204 const narrow = pictured(looksOfPage, "narrow");
199205 const desktop = pictured(looksOfPage, "desktop");
200206 const failed = looksOfPage.find(
201207 (l) => l.commitOid === headOid && l.error !== null,
@@ -220,7 +226,7 @@ export function lookCard(
220226 headKinds
221227 .map((kind) => pictured(mainOfPage.filter((l) => l.theme === theme), kind))
222228 .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));
224230 // Only the dark pictures of the commit the caption names: after a push
225231 // the light pair is retaken first, and an old head's dark pair must not
226232 // sit under the new head's words.
@@ -228,6 +234,7 @@ export function lookCard(
228234 (l) => l.page === page && l.commitOid === shown.commitOid,
229235 );
230236 const darkPhone = pictured(darkOfPage, "phone");
237 const darkNarrow = pictured(darkOfPage, "narrow");
231238 const darkDesktop = pictured(darkOfPage, "desktop");
232239 // Main's picture beside the head's; where main has none, the head stands alone.
233240 const compare = (before: readonly Look[], after: readonly Look[]): Html =>
@@ -256,8 +263,8 @@ export function lookCard(
256263 </div>
257264 </div>
258265 </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);
261268 return html`<section class="stack stack-tight">
262269 ${label}
263270 ${compare(beforeShown, lightAfter)}
@@ -370,7 +377,9 @@ export function lookNow(ctx: Ctx, repo: Repo, record: AppRecord): Html {
370377 </a>`;
371378 }
372379
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 */
374383 export function lookThumb(href: string, src: string, label?: string): Html {
375384 return html`<a class="look" data-slot="thumb" href="${href}" ${label === undefined ? html`` : html`aria-label="${label}"`}
376385 ><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
2222 expect(pairsLine(pairCounts([], [look("/", "phone")]))).toBeUndefined();
2323 expect(pairCounts([look("/", "phone")], [look("/", "phone", "dark")]).beside).toBe(0);
2424 });
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", () => {
176176 : undefined;
177177 });
178178
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. */
180180 const pictured = (env: string, commitOid: string): Promise<Look[]> =>
181181 until(() => {
182182 const rows = looksForEnv(app.db, record.id, env).filter(
183183 (l) => l.commitOid === commitOid,
184184 );
185 return rows.length === 3 ? rows : undefined;
185 return rows.length === 4 ? rows : undefined;
186186 }, 30_000);
187187
188188 interface Opened {
@@ -398,14 +398,14 @@ describe("the look", () => {
398398 const dark = looksForEnv(app.db, record.id, env, "dark").filter(
399399 (l) => l.commitOid === twoPages.commitOid,
400400 );
401 return light.length === 6 && dark.length === 4 ? true : undefined;
401 return light.length === 7 && dark.length === 5 ? true : undefined;
402402 }),
403403 ),
404404 done(previewEnv(gallery.pull.number), gallery.commitOid, gallery.repo.id).then(() =>
405405 until(() =>
406406 looksForEnv(app.db, gallery.app.id, previewEnv(gallery.pull.number)).filter(
407407 (l) => l.commitOid === gallery.commitOid,
408 ).length === 3
408 ).length === 4
409409 ? true
410410 : undefined,
411411 ),
@@ -429,13 +429,15 @@ describe("the look", () => {
429429 let first = "";
430430 let second = "";
431431
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.
434435 const production = await settled((r) => r.env === "production");
435436 expect(production.state).toBe("ok");
436437 const rows = await pictured("production", production.commitOid);
437438 expect(rows.map((l) => l.kind).sort()).toEqual([
438439 "desktop",
440 "narrow",
439441 "phone",
440442 "thumb",
441443 ]);
@@ -449,7 +451,7 @@ describe("the look", () => {
449451 // The browser was pointed at the grant door on the forge's own port,
450452 // and the grant names the owner as an admin.
451453 const taken = callsAt("production");
452 expect(taken).toHaveLength(3);
454 expect(taken).toHaveLength(4);
453455 // Taken to one side and moved in whole: nothing half-written lives
454456 // under the environment, and nothing is left behind on the side.
455457 for (const call of calls)
@@ -488,14 +490,14 @@ describe("the look", () => {
488490 });
489491
490492 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.
493495 pull = greeting.pull;
494496 first = greeting.commitOid;
495497 const env = previewEnv(pull.number);
496498 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);
499501 expect(new URL(callsAt(env)[0]!.url).hostname).toBe(`hello--${pull.number}.${DOMAIN}`);
500502 // The entries the browser recorded reach the check's summary: the
501503 // phone's LCP and the desktop's CLS, graded; the thumb adds no row.
@@ -510,8 +512,8 @@ describe("the look", () => {
510512 reason: "push",
511513 });
512514 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"]);
515517 const graded = vitalsRows(recorded);
516518 // The phone's recorded size is stored beside its entries: two screens tall.
517519 expect(graded.find((g) => g.look === "phone")!.screens).toBe("2.0");
@@ -528,19 +530,21 @@ describe("the look", () => {
528530 });
529531
530532 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.
532535 const env = previewEnv(pull.number);
533536 runtime.requestDeploy(record, repo, env, first, "redeploy");
534537 expect(
535538 (await settled((r) => r.env === env && r.reason === "redeploy")).state,
536539 ).toBe("ok");
537540 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);
540543 });
541544
542545 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.
544548 const env = previewEnv(pull.number);
545549 const again = await commitToBranch(app, alice, repo, {
546550 branch: "greeting",
@@ -552,8 +556,8 @@ describe("the look", () => {
552556 expect(
553557 (await settled((r) => r.env === env && r.commitOid === second)).state,
554558 ).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);
557561 await until(() =>
558562 looksForEnv(app.db, record.id, env).every((l) => l.commitOid === second)
559563 ? true
@@ -652,7 +656,8 @@ describe("the look", () => {
652656 });
653657
654658 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.
656661 const env = `pull-${pull.number}`;
657662 modes.set(helloHost(env), "fail");
658663 const moved = await commitToBranch(app, alice, repo, {
@@ -672,7 +677,7 @@ describe("the look", () => {
672677 // #11509: a page that gives no picture is tried once, not once per
673678 // kind, and the next try waits out its backoff.
674679 expect(callsAt(env).length - callsBefore).toBe(1);
675 expect(rows).toHaveLength(3);
680 expect(rows).toHaveLength(4);
676681 const waits = () => scheduled.filter((s) => !waitsBefore.has(s));
677682 expect(waits().map((w) => w.ms)).toEqual([30_000]);
678683 // An event for the same head inside the wait is not a reason to try sooner.
@@ -726,7 +731,8 @@ describe("the look", () => {
726731 });
727732
728733 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.
730736 const env2 = `pull-${unpictured.pull.number}`;
731737 const rows = await pictured(env2, unpictured.commitOid);
732738 expect(rows.every((l) => l.error === "the browser fell over")).toBe(true);
@@ -740,7 +746,8 @@ describe("the look", () => {
740746 });
741747
742748 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.
744751 const env = `pull-${unpictured.pull.number}`;
745752 modes.set(helloHost(env), "nobrowser");
746753 const waitsBefore = scheduled.length;
@@ -765,14 +772,15 @@ describe("the look", () => {
765772 expect(scheduled).toHaveLength(waitsBefore);
766773 const got = await until(() => {
767774 const read = readLooks(dataDir, check);
768 return read.length === 2 ? read : undefined;
775 return read.length === 3 ? read : undefined;
769776 });
770777 expect(got).toEqual([
771778 { look: "phone", skipped: "no browser" },
779 { look: "narrow", skipped: "no browser" },
772780 { look: "desktop", skipped: "no browser" },
773781 ]);
774782 // 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"]);
776784 expect(listRuns(app.db, repo.id, { kind: "check" }).find((r) => r.id === check.id)!.state).toBe("queued");
777785 modes.delete(helloHost(env));
778786 });
@@ -821,7 +829,8 @@ describe("the look", () => {
821829 });
822830
823831 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.
825834 const env = `pull-${unpictured.pull.number}`;
826835 expect(looksForEnv(app.db, record.id, env).length).toBeGreaterThan(0);
827836 const closed = await setIssueStateThrough(
@@ -841,7 +850,8 @@ describe("the look", () => {
841850 });
842851
843852 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.
845855 const gate = join(dataDir, "slow-red-test.gate");
846856 const opened = { value: slowRed.pull };
847857 const env = `pull-${slowRed.pull.number}`;
@@ -872,7 +882,7 @@ describe("the look", () => {
872882 looksForEnv(app.db, record.id, env).filter(
873883 (l) => l.commitOid === commitOid && l.error === null,
874884 ),
875 ).toHaveLength(3);
885 ).toHaveLength(4);
876886
877887 expect(
878888 (await setIssueStateThrough(app, alice, repo, opened.value, "closed")).ok,
@@ -880,7 +890,8 @@ describe("the look", () => {
880890 });
881891
882892 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.
884895 const before = callsAt("production").length;
885896 const live = runtime.envStatus(record, "production");
886897 if (live === undefined) throw new Error("production is not live");
@@ -920,7 +931,8 @@ describe("the look", () => {
920931 });
921932
922933 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.
924936 const env = `pull-${ask.pull.number}`;
925937 expect((await settled((r) => r.env === env)).state).toBe("ok");
926938 const rows = await pictured(env, ask.commitOid);
@@ -960,7 +972,8 @@ describe("the look", () => {
960972 });
961973
962974 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.
964977 const opened = { value: twoPages.pull };
965978 const env = `pull-${opened.value.number}`;
966979 const commitOid = twoPages.commitOid;
@@ -970,14 +983,14 @@ describe("the look", () => {
970983 const found = looksForEnv(app.db, record.id, env).filter(
971984 (l) => l.commitOid === commitOid,
972985 );
973 return found.length === 6 ? found : undefined;
986 return found.length === 7 ? found : undefined;
974987 }, 30_000);
975988 const home = rows.filter((l) => l.page === "/");
976989 const board = rows.filter((l) => l.page === "/board");
977 expect(home).toHaveLength(3);
990 expect(home).toHaveLength(4);
978991 expect(board).toHaveLength(3);
979992 // 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);
981994 const boardPhone = board.find((l) => l.kind === "phone")!;
982995 expect(boardPhone.path).toBe(
983996 `looks/${record.id}/${env}/${commitOid}-board-phone.png`,
@@ -1007,6 +1020,14 @@ describe("the look", () => {
10071020 `alt="hello /board #${opened.value.number} on a phone"`,
10081021 );
10091022 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`);
10101031
10111032 // Each page is also pictured in the dark, at phone and desktop, in a
10121033 // slot of its own: the same page and kind, a different file.
@@ -1014,10 +1035,10 @@ describe("the look", () => {
10141035 const found = looksForEnv(app.db, record.id, env, "dark").filter(
10151036 (l) => l.commitOid === commitOid,
10161037 );
1017 return found.length === 4 ? found : undefined;
1038 return found.length === 5 ? found : undefined;
10181039 }, 30_000);
10191040 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"]);
10211042 expect(darkCalls.every((c) => c.dark === true)).toBe(true);
10221043 const darkPhone = dark.find((l) => l.page === "/" && l.kind === "phone")!;
10231044 expect(darkPhone.path).toBe(
@@ -1331,7 +1352,8 @@ describe("the look", () => {
13311352 });
13321353
13331354 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'.
13351357 const galleryApp = gallery.app;
13361358 expect(galleryApp.access).toBe("public");
13371359 const opened = { value: gallery.pull };
@@ -1342,10 +1364,10 @@ describe("the look", () => {
13421364 const found = looksForEnv(app.db, galleryApp.id, env).filter(
13431365 (l) => l.commitOid === commit,
13441366 );
1345 return found.length === 3 ? found : undefined;
1367 return found.length === 4 ? found : undefined;
13461368 }, 30_000);
13471369 // 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"]);
13491371 const phoneCall = calls.filter((c) => c.out.includes(galleryApp.id) || c.url.includes("gallery")).find((c) => c.width === 390)!;
13501372 expect(
13511373 readGrant(dataDir, new URL(phoneCall.url).searchParams.get("t") ?? "", {
@@ -1494,7 +1516,8 @@ describe("the look", () => {
14941516 ? "a real capture — skipped: no chromium on this machine (install one, or set FORGE_CHROMIUM)"
14951517 : `a real capture through the grant door, with ${chromium}`,
14961518 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.
14981521 if (peek === undefined) throw new Error("no peek without a browser");
14991522 const enabled = { value: peek.app };
15001523 expect(
test/tui-pull-looks-section.test.ts +8 −3
@@ -7,7 +7,7 @@ import { openPull } from "../src/actions/pulls.ts";
77 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
88 import { createApp, type App as Forge } from "../src/app.ts";
99 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";
1111 import { pullLooks } from "../src/looks/readable.ts";
1212 import { recordLook, type RecordLookInput } from "../src/core/looks.ts";
1313 import type { Pull } from "../src/core/pulls.ts";
@@ -64,7 +64,10 @@ beforeAll(async () => {
6464 made[name] = { repo: r.value, pull: o.value };
6565 }
6666 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 });
6871 if (!inserted.ok) throw new Error(inserted.error);
6972 recordLook(forge.db, {
7073 appId: inserted.value.id,
@@ -79,6 +82,7 @@ beforeAll(async () => {
7982 });
8083 };
8184 take("pictured", "public", {});
85 take("pictured", "public", { kind: "narrow", note: "fits at 360 px" });
8286 take("hush", "private", {});
8387 take("ownerly", "public", { takenAs: "owner" });
8488 insertApp(forge.db, { repoId: made["plain"]!.repo.id, slug: "plain", access: "public" });
@@ -113,8 +117,9 @@ const fullUrl = (name: string) => {
113117
114118 test("a pull with a look shows its width, line and full absolute URL", async () => {
115119 const out = await text("pictured");
116 expect(out).toContain("Looks (1)");
120 expect(out).toContain("Looks (2)");
117121 expect(out).toContain("phone · alice · the empty state reads well");
122 expect(out).toContain("narrow · alice · fits at 360 px");
118123 expect(out).toContain(fullUrl("pictured"));
119124 });
120125

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs