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

A pull's check summary carries the phone look of /preview-admin/sample/settings#move #10346

Parked opened this
Closed without merging

mason/forge:mason/10336-a-pull-s-check-summary-carries-the-phone → main 10 commits fork 2 threads · 2 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
16 files changed +321 −33
docs/features/pull-looks.md +6
@@ -31,3 +31,9 @@ they may enter, and not those of a sealed pull. A look that failed (no
3131 picture) is never listed. Only the pull's own preview environment is read, so
3232 another pull's or app's looks never appear. A pull with no app or no looks
3333 answers `items: []`.
34
35 ## The check's vitals looks
36
37 Looks are taken for this repository's pulls, as for every app's: each time a pull's preview starts serving a head (`app.serving`), the looks service on the forge queues that head and pictures it, one environment at a time. A preview of the forge's own repository takes every page forge.json lists, then every named owner look (`PREVIEW_OWNER_LOOKS` in `src/spawn/preview-looks.ts`), at desk and phone width; `phone /preview-admin/sample/settings#move` is one of them. A head is not pictured when its preview has moved on or gone to sleep before its turn, or when it waited more than ten minutes in the queue (memory pressure holds the queue): the next deploy of the pull queues it again.
38
39 Each look's vitals and size are filed under the commit as it is taken (`writeCommitLooks`, `src/checks/looks.ts`), so `looks` of `GET …/pulls/:number/checks` (fields in [vitals-screens.md](vitals-screens.md)) lists what is taken so far, whether the check went green before the pictures or after; the list is complete once they are. The file holds every look one preview takes (`FILED_LOOKS_MAX`, `src/core/look_limits.ts`); before #10336 it kept the first twenty, the forge.json pages, and no owner look was ever listed.
docs/features/vitals-screens.md +5 −1
@@ -7,6 +7,10 @@ A check's per-look vitals say how many screens tall each look is (`scrollHeight
77
88 Report-only: neither can turn a check red. Skipped looks show no screens.
99
10 API: `GET /api/v1/repos/:owner/:name/commits/:oid/check` and `GET /api/v1/repos/:owner/:name/pulls/:number/checks` carry `looks: [{look, screens, sideways}]`, from the same file as the run page (a run with no file of its own falls back to the commit's filed looks). `screens` is the one-decimal string (`""` without a size), `sideways` is a boolean; `[]` when there are none or the reader may not read runs.
10 API: `GET /api/v1/repos/:owner/:name/commits/:oid/check` and `GET /api/v1/repos/:owner/:name/pulls/:number/checks` carry `looks: [{look, screens, sideways, size?}]`, from the same file as the run page (a run with no file of its own falls back to the commit's filed looks). `screens` is the one-decimal string (`""` without a size), `sideways` is a boolean; `[]` when there are none or the reader may not read runs.
1111
1212 The held page (`/preview-admin/sample/held`) is measured as an owner look (`PREVIEW_OWNER_LOOKS`), not a visitor look, because the visitor cap (`LOOKS_MAX`, 24) is spent; the check lists it at desktop and phone with its screens (#9508).
13
14 `size` is `{scrollWidth, innerWidth}` as the browser measured it (absent when none was recorded), so a pull can quote the width of a phone look, e.g. `phone /preview-admin/sample/settings#move` (#10336). The terminal line carries it too, on each phone look: `, 390/390 px wide` (page width / window width).
15
16 Which looks a check lists, and when, is in [pull-looks.md](pull-looks.md#the-checks-vitals-looks).
src/actions/runs.ts +8 −1
@@ -248,6 +248,8 @@ export interface LookFigures {
248248 readonly look: string;
249249 readonly screens: string;
250250 readonly sideways: boolean;
251 /** The width the page needed against the window it was taken in; absent when none was recorded. */
252 readonly size?: { readonly scrollWidth: number; readonly innerWidth: number };
251253 }
252254
253255 /**
@@ -262,7 +264,12 @@ export function looksOfCheck(
262264 ): LookFigures[] {
263265 if (!mayReadRuns(app, actor, repo)) return [];
264266 const looks = readLooks(app.config.dataDir, { id: run.id, repoId: repo.id, commitOid: run.commitOid });
265 return vitalsRows(looks).map((g) => ({ look: g.look, screens: g.screens, sideways: g.sideways }));
267 return vitalsRows(looks).map((g) => ({
outdated

Index pairing between vitalsRows output and looks[i] is fragile. Carry size on the row itself or look it up by name.

268 look: g.look,
269 screens: g.screens,
270 sideways: g.sideways,
271 ...(g.width === undefined ? {} : { size: g.width }),
272 }));
266273 }
267274
268275 /** The own green or red verdicts of a page of commits, for whoever may read the runs; empty otherwise. */
src/apps/manifest.ts +1 −4
@@ -17,6 +17,7 @@ import type { DeclaredLimits } from "./contain.ts";
1717 import { isPublicAddress } from "./egress.ts";
1818 import { isLaunch, LAUNCHES, type Launch } from "../git/builds.ts";
1919 import { parseAdapter, type AdapterSpec } from "./adapter.ts";
20 import { LOOKS_MAX } from "../core/look_limits.ts";
2021
2122 export interface AppManifest {
2223 /** The command that serves on `$PORT`. Run through `sh -c`, `exec`-ed. */
@@ -93,10 +94,6 @@ export type ManifestError =
9394 const READY_DEFAULT = 30;
9495 const READY_MAX = 600;
9596 const COMMAND_MAX = 1_000;
96 /** More than this many pages is a manifest error: a browser start per
97 * picture per width is the heaviest thing the forge does. Room for every
98 * top-level page of the forge itself. */
99 const LOOKS_MAX = 24;
10097 const LOOK_PATH_MAX = 200;
10198
10299 /**
src/checks/looks.ts +11 −7
@@ -11,6 +11,7 @@
1111 import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
1212 import { join } from "node:path";
1313 import type { LookVitals, PageSize } from "./summary.ts";
14 import { FILED_LOOKS_MAX } from "../core/look_limits.ts";
outdated

A checks module importing from apps/manifest and spawn/preview-looks couples layers just for two constants. Move the constants to a small shared module.

1415 import { runsRoot } from "../runs/log.ts";
1516
1617 export const looksPath = (dataDir: string, runId: string): string =>
@@ -29,8 +30,8 @@ export const commitLooksPath = (
2930
3031 const SAFE = /^[0-9A-Za-z]{1,64}$/;
3132
32 const MAX_BYTES = 1024 * 1024;
33 const MAX_LOOKS = 20;
33 const MAX_LOOKS = FILED_LOOKS_MAX;
34 const MAX_BYTES = MAX_LOOKS * 64 * 1024;
3435 const MAX_WORDS = 80;
3536
3637 const words = (v: unknown): string | null =>
@@ -94,10 +95,11 @@ export function readLooks(dataDir: string, run: LooksOf): LookVitals[] {
9495 }
9596
9697 /**
97 * File a commit's looks, replacing any earlier set for it: written whole
98 * beside the log and moved in, so a reader never sees half of it. What
99 * `readLooks` would drop is not written, and a set with nothing left removes
100 * the earlier file, so a stale table never outlives its replacement.
98 * File a commit's looks, written whole beside the log and moved in, so a
99 * reader never sees half of it. A look filed before keeps its place unless
100 * `looks` names it again, so the set can be filed as it grows and a run that
101 * resumes adds to it. What `readLooks` would drop is not written; a set with
102 * nothing to keep removes the file.
101103 */
102104 export function writeCommitLooks(
103105 dataDir: string,
@@ -107,7 +109,9 @@ export function writeCommitLooks(
107109 ): void {
108110 if (!SAFE.test(commitOid) || !SAFE.test(repoId)) return;
109111 const path = commitLooksPath(dataDir, repoId, commitOid);
110 const kept = parseLooks(looks);
112 const fresh = parseLooks(looks);
113 const named = new Set(fresh.map((l) => l.look));
114 const kept = parseLooks([...readFile(path).filter((l) => !named.has(l.look)), ...fresh]);
111115 if (kept.length === 0) {
112116 rmSync(path, { force: true });
113117 return;
src/checks/progress.ts +7 −3
@@ -9,7 +9,7 @@
99
1010 import type { CheckSummary } from "../core/runs.ts";
1111 import { readLooks } from "./looks.ts";
12 import { checkSteps, sidewaysLine, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
12 import { checkSteps, isPhoneLook, sidewaysLine, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
1313 import { parseTestsRow, testsRowLine } from "./tests-row.ts";
1414 import { readRunLog } from "../runs/log.ts";
1515
@@ -113,13 +113,17 @@ export function stepsLine(
113113 return [steps, tests, vitalsLine(readLooks(dataDir, run))].filter((w) => w !== "").join(" · ");
114114 }
115115
116 /** `vitals home: LCP 3100 ms needs-improvement, CLS 0.3 poor, TBT 100 ms good; mobile: skipped: no browser` */
116 /**
117 * `vitals home: LCP 3100 ms needs-improvement, CLS 0.3 poor, TBT 100 ms good; mobile: skipped: no browser`;
118 * a phone look with a size adds `, 390/390 px wide` (page width / window width).
119 */
117120 export function vitalsLine(looks: readonly LookVitals[]): string {
118121 const rows = vitalsRows(looks);
119122 const groups = rows.map((g) => {
120123 if (g.skipped !== "") return `${g.look}: skipped: ${g.skipped}`;
121124 const vitals = g.rows.map((r) => `${r.vital} ${r.value}${r.grade === "n/a" ? "" : ` ${r.grade}`}`);
122 return `${g.look}: ${vitals.join(", ")}${g.screens === "" ? "" : `, ${g.screens} screens`}`;
125 const wide = g.width === undefined || !isPhoneLook(g.look) ? "" : `, ${g.width.scrollWidth}/${g.width.innerWidth} px wide`;
126 return `${g.look}: ${vitals.join(", ")}${g.screens === "" ? "" : `, ${g.screens} screens`}${wide}`;
123127 });
124128 if (groups.length === 0) return "";
125129 const sideways = sidewaysLine(rows);
src/checks/summary.ts +7 −3
@@ -243,9 +243,12 @@ export interface LookRows {
243243 readonly screens: string;
244244 /** A phone look whose page is wider than its window; false without a size. */
245245 readonly sideways: boolean;
246 /** The width the page needed against its window, from this look's own size; absent without one. */
247 readonly width?: { readonly scrollWidth: number; readonly innerWidth: number };
246248 }
247249
248 const isPhone = (look: string): boolean => look === "phone" || look.startsWith("phone ");
250 /** A look taken at phone width: `phone`, or `phone <page>`. */
251 export const isPhoneLook = (look: string): boolean => look === "phone" || look.startsWith("phone ");
249252
250253 /** `phone /x scrolls sideways` for each phone look wider than its window; empty when none. */
251254 export function sidewaysLine(groups: readonly LookRows[]): string {
@@ -283,7 +286,8 @@ export function vitalsRows(looks: readonly LookVitals[]): readonly LookRows[] {
283286 const z = l.size;
284287 const tall = z === undefined || z.innerHeight <= 0 ? null : z.scrollHeight / z.innerHeight;
285288 const screens = tall === null ? "" : (Math.round(tall * 10) / 10).toFixed(1);
286 const sideways = z !== undefined && isPhone(l.look) && z.scrollWidth > z.innerWidth;
287 return { look: l.look, skipped: "", rows, screens, sideways };
289 const sideways = z !== undefined && isPhoneLook(l.look) && z.scrollWidth > z.innerWidth;
290 const width = z === undefined ? {} : { width: { scrollWidth: z.scrollWidth, innerWidth: z.innerWidth } };
291 return { look: l.look, skipped: "", rows, screens, sideways, ...width };
288292 });
289293 }
src/core/look_limits.ts added +23
@@ -0,0 +1,23 @@
1 /**
2 * How many looks there may be: the pages forge.json may name, and the looks
3 * one commit may file for its check. Plain numbers, no imports, so the
4 * manifest parser and the check's looks file read one value each without
5 * reaching into each other's layer.
6 */
7
8 /**
9 * More than this many pages in `app.looks` is a manifest error: a browser
10 * start per picture per width is the heaviest thing the forge does. Room
11 * for every top-level page of the forge itself.
12 */
13 export const LOOKS_MAX = 24;
14
15 /**
16 * The most looks one commit files for its check's summary. A preview of the
17 * forge takes every `LOOKS_MAX` page and every named owner look
18 * (`spawn/preview-looks.ts`), each at desk and phone, so this must hold
19 * both; `test/look-limits.test.ts` fails when the named list outgrows it.
20 * Owner looks are taken after the forge.json pages, so a cap below the sum
21 * silently drops them, the move look among them (#10336).
22 */
23 export const FILED_LOOKS_MAX = 128;
src/looks/service.ts +14 −8
@@ -410,6 +410,17 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
410410 let allOk = true;
411411 // What each look's page recorded, for the check summary's vitals table.
412412 const vitals: LookVitals[] = [];
413 // Filed under the commit: the check of it shows them whenever it exists.
414 let filed = 0;
415 const fileVitals = (): void => {
416 if (vitals.length === filed) return;
417 filed = vitals.length;
418 try {
419 writeCommitLooks(dataDir, record.repoId, item.commitOid, vitals);
420 } catch (error) {
421 log.warn("vitals not recorded", { commit: item.commitOid, error: String(error) });
422 }
423 };
413424 for (const { page, kind, theme } of wanted) {
414425 if (stopped) return;
415426 const token = signGrant(
@@ -446,6 +457,9 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
446457 vitals.push({ look, entries: shot.value.entries, ...size });
447458 } else if (isNoBrowser(shot.error))
448459 vitals.push({ look, skipped: "no browser" });
460 // Filed as each look is taken: the check turns green long before the
461 // last of fifty pictures, and its summary lists what is taken so far.
462 fileVitals();
449463 }
450464 const taken =
451465 shot.ok && kind === "thumb" ? reduceToThumb(staged) : shot;
@@ -491,14 +505,6 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
491505 recordLook(app.db, { ...row, kind, path: "", error: taken.error });
492506 }
493507 }
494 // Filed under the commit: the check of it shows them whenever it exists.
495 if (vitals.length > 0) {
496 try {
497 writeCommitLooks(dataDir, record.repoId, item.commitOid, vitals);
498 } catch (error) {
499 log.warn("vitals not recorded", { commit: item.commitOid, error: String(error) });
500 }
501 }
502508 // A full set at this head is the environment's look now; the pictures
503509 // of heads before it have nothing left to say.
504510 if (allOk)
test/check-looks-api.test.ts +32 −3
@@ -7,10 +7,11 @@ import { join } from "node:path";
77 import { createApp, type App } from "../src/app.ts";
88 import { openPull } from "../src/actions/pulls.ts";
99 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
10 import { looksPath } from "../src/checks/looks.ts";
10 import { looksPath, writeCommitLooks } from "../src/checks/looks.ts";
1111 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
1212 import { createSession } from "../src/core/sessions.ts";
1313 import { createUser } from "../src/core/users.ts";
14 import { PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts";
1415 import { serve, type Servers } from "../src/http/server.ts";
1516 import { quietLogs } from "./helpers/globals.ts";
1617
@@ -93,7 +94,7 @@ test("the commit's check carries screens and sideways; [] without a file", async
9394 const body = await get(`/api/v1/repos/alice/r/commits/${OID}/check`);
9495 expect(body.runId).toBe(run.id);
9596 expect(body.looks).toEqual([
96 { look: "phone /x", screens: "2.5", sideways: true },
97 { look: "phone /x", screens: "2.5", sideways: true, size: { scrollWidth: 500, innerWidth: 390 } },
9798 { look: "desktop", screens: "", sideways: false },
9899 ]);
99100 });
@@ -107,7 +108,35 @@ test("the pull's checks carry the same looks beside run", async () => {
107108 const body = await get(`/api/v1/repos/alice/r/pulls/${number}/checks`);
108109 expect(body.run.id).toBe(run.id);
109110 expect(body.looks).toEqual([
110 { look: "phone /x", screens: "1.3", sideways: false },
111 { look: "phone /x", screens: "1.3", sideways: false, size: { scrollWidth: 390, innerWidth: 390 } },
111112 { look: "desktop", screens: "", sideways: false },
112113 ]);
113114 });
115
116 test("a green check lists the move look with its size from the commit's filed looks, whole preview set or as it grows", async () => {
117 const move = "phone /preview-admin/sample/settings#move";
118 const size = { scrollWidth: 390, scrollHeight: 900, innerWidth: 390, innerHeight: 844 };
119 const oid = "c".repeat(40);
120 const run = createRun(app.db, { repoId, kind: "check", commitOid: oid, env: "main", branch: "main" });
121 claimRun(app.db, run.id);
122 finishRun(app.db, run.id, { state: "ok", summary: "check passed" });
123 // The check is green while looks are still being taken: what is filed so far is listed.
124 writeCommitLooks(dataDir, repoId, oid, [{ look: "desktop", entries: {} }]);
125 expect((await get(`/api/v1/repos/alice/r/commits/${oid}/check`)).looks.map((l: any) => l.look)).toEqual(["desktop"]);
126 // The preview's whole named set, the move look last, filed one look at a time.
127 const set = PREVIEW_OWNER_LOOKS.map((l) => ({
128 look: `${l.kind === "phone" ? "phone" : "desktop"} ${l.page}`,
129 entries: {},
130 ...(l.kind === "phone" && l.page.endsWith("#move") ? { size } : {}),
131 }));
132 set.sort((a, b) => Number(a.look.endsWith("#move")) - Number(b.look.endsWith("#move")));
133 for (const one of set) writeCommitLooks(dataDir, repoId, oid, [one]);
134 const body = await get(`/api/v1/repos/alice/r/commits/${oid}/check`);
135 expect(body.looks).toHaveLength(set.length + 1);
136 expect(body.looks.find((l: any) => l.look === move)).toEqual({
137 look: move,
138 screens: "1.1",
139 sideways: false,
140 size: { scrollWidth: 390, innerWidth: 390 },
141 });
142 });
test/check-looks-held.test.ts +1
@@ -89,6 +89,7 @@ test("a forge preview's check lists the held page at desktop and phone with scre
8989 look: `${kind} ${PREVIEW_HELD_PAGE}`,
9090 screens: "2.5",
9191 sideways: false,
92 size: { scrollWidth: 390, innerWidth: 390 },
9293 });
9394 }
9495 });
test/check-looks-preview.test.ts added +149
@@ -0,0 +1,149 @@
1 /**
2 * A preview of the forge's own repository, end to end (#10336): its deploy
3 * serves, the looks service takes every forge.json page and every named owner
4 * look through a stand-in browser, the check of its head goes green, and
5 * `GET …/pulls/N/checks` lists `phone /preview-admin/sample/settings#move`
6 * with its size. Owner looks are taken after the forge.json pages, so a cap
7 * on the filed looks smaller than the whole set drops this one.
8 */
9
10 import { afterAll, beforeAll, expect, test } from "bun:test";
11 import { mkdtemp, rm } from "node:fs/promises";
12 import { writeFileSync } from "node:fs";
13 import { tmpdir } from "node:os";
14 import { join } from "node:path";
15 import { createApp, type App } from "../src/app.ts";
16 import { newApp } from "../src/actions/apps.ts";
17 import { openPull } from "../src/actions/pulls.ts";
18 import { commitToBranch } from "../src/actions/repos.ts";
19 import { previewEnv } from "../src/apps/data.ts";
20 import { AppsRuntime } from "../src/apps/runtime.ts";
21 import { LOOKS_MAX } from "../src/core/look_limits.ts";
22 import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts";
23 import { createSession } from "../src/core/sessions.ts";
24 import { createUser, type User } from "../src/core/users.ts";
25 import { serve, type Servers } from "../src/http/server.ts";
26 import { ok } from "../src/kernel/result.ts";
27 import type { Capture } from "../src/looks/capture.ts";
28 import { startLooks, type LooksHandle } from "../src/looks/service.ts";
29 import { PREVIEW_MOVE_LOOK, PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts";
30 import { quietLogs } from "./helpers/globals.ts";
31
32 quietLogs();
33
34 const PNG = Buffer.from(
35 "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",
36 "base64",
37 );
38 const PHONE_SIZE = { scrollWidth: 390, scrollHeight: 1688, innerWidth: 390, innerHeight: 844 };
39
40 let dataDir: string;
41 let app: App;
42 let servers: Servers;
43 let runtime: AppsRuntime;
44 let looks: LooksHandle;
45 let cookie = "";
46 let alice: User;
47
48 /** The stand-in browser: a picture, and a size for every phone-width look. */
49 const fake: Capture = async (input) => {
50 writeFileSync(input.out, PNG);
51 return ok({ entries: {}, ...(input.width === 390 ? { size: PHONE_SIZE } : {}) });
52 };
53
54 async function until<T>(read: () => T | undefined, timeoutMs = 60_000): Promise<T> {
55 const deadline = Date.now() + timeoutMs;
56 while (Date.now() < deadline) {
57 const value = read();
58 if (value !== undefined) return value;
59 await Bun.sleep(10);
60 }
61 throw new Error("did not happen in time");
62 }
63
64 beforeAll(async () => {
65 dataDir = await mkdtemp(join(tmpdir(), "forge-check-looks-preview-"));
66 // This forge's own repository is alice/forge: its previews take the named owner looks.
67 app = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" });
68 servers = await serve(app);
69 runtime = new AppsRuntime(app, {
70 domain: "apps.test",
71 scheme: "http",
72 publicPort: servers.port,
73 forgeUrl: servers.url,
74 });
75 await runtime.start();
76 looks = startLooks(app, { localUrl: servers.url, capture: fake });
77 const made = await createUser(app.db, {
78 origin: "seed",
79 trusted: true,
80 username: "alice",
81 email: "[email protected]",
82 password: "a-good-passphrase",
83 adminIfFirst: true,
84 });
85 if (!made.ok) throw new Error(String(made.error));
86 alice = made.value;
87 cookie = `forge_session=${createSession(app.db, alice.id).token}`;
88 }, 60_000);
89
90 afterAll(async () => {
91 await looks.stop();
92 await runtime.stop();
93 servers.stop();
94 app.close();
95 await rm(dataDir, { recursive: true, force: true });
96 });
97
98 test("a green check on a preview of the forge lists the move look with its size", async () => {
99 const made = await newApp(app, alice, {
100 name: "forge",
101 visibility: "private",
102 });
103 if (!made.ok) throw new Error(String(made.error));
104 const { repo } = made.value;
105 // forge.json names as many pages as it may: every one of them is filed before the owner looks.
106 const pages = Array.from({ length: LOOKS_MAX }, (_, i) => `/page-${i}`);
107 const committed = await commitToBranch(app, alice, repo, {
108 branch: "move",
109 base: repo.defaultBranch,
110 message: "Every page",
111 files: [{ path: "forge.json", content: `${JSON.stringify({ app: { run: "bun run src/server.ts", looks: pages } }, null, 2)}\n` }],
112 });
113 if (!committed.ok) throw new Error(JSON.stringify(committed.error));
114 const head = committed.value.commitOid;
115 const pull = await openPull(app, alice, repo, { title: "Every page", baseBranch: repo.defaultBranch, headBranch: "move" });
116 if (!pull.ok) throw new Error(String(pull.error));
117 const env = previewEnv(pull.value.number);
118
119 // The preview deploys and serves; the looks service pictures it.
120 await until(() => {
121 const run = listRuns(app.db, repo.id, { kind: "deploy", limit: 50 }).find((r) => r.env === env && r.commitOid === head);
122 return run && run.state !== "queued" && run.state !== "running" ? run : undefined;
123 });
124 await until(() => (runtime.envStatus(made.value.app, env)?.state === "running" ? true : undefined));
125 await looks.idle();
126
127 // The check of that head goes green.
128 const check = createRun(app.db, { repoId: repo.id, kind: "check", issueId: pull.value.id, commitOid: head, branch: "move" });
129 claimRun(app.db, check.id);
130 finishRun(app.db, check.id, { state: "ok", summary: "check passed" });
131
132 const res = await fetch(`${servers.url}/api/v1/repos/alice/forge/pulls/${pull.value.number}/checks`, { headers: { cookie } });
133 expect(res.status).toBe(200);
134 const body = (await res.json()) as { head: string; state: string; looks: { look: string; screens: string; sideways: boolean; size?: unknown }[] };
135 expect(body.head).toBe(head);
136 expect(body.state).toBe("ok");
137 const listed = body.looks.map((l) => l.look);
138 // Every forge.json page and every owner look, at desk and phone, deduped by page.
139 const ownerPages = new Set(PREVIEW_OWNER_LOOKS.map((l) => l.page));
140 const expected = new Set([...pages, ...ownerPages]);
141 expect(listed).toHaveLength(2 * expected.size);
142 const move = body.looks.find((l) => l.look === `phone ${PREVIEW_MOVE_LOOK}`);
143 expect(move).toEqual({
144 look: `phone ${PREVIEW_MOVE_LOOK}`,
145 screens: "2.0",
146 sideways: false,
147 size: { scrollWidth: 390, innerWidth: 390 },
148 });
149 }, 120_000);
test/check-vitals-size.test.ts +18
@@ -43,3 +43,21 @@ test("the terminal line carries screens and the sideways note", () => {
4343 expect(line).toContain("desktop: skipped: no browser · phone /x scrolls sideways");
4444 expect(vitalsLine([{ look: "phone", entries: {} }])).not.toContain("screens");
4545 });
46
47 test("the terminal line carries a phone look's width beside its window, as the API's size does (#10336)", () => {
48 const move = { look: "phone /preview-admin/sample/settings#move", entries: {}, size: size(390, 1600) };
49 const desk = { look: "desktop /x", entries: {}, size: size(1280, 1600) };
50 const line = vitalsLine([desk, move]);
51 expect(line).toContain("phone /preview-admin/sample/settings#move: LCP n/a, CLS 0 good, TBT 0 ms good, 2.0 screens, 390/390 px wide");
52 expect(line).not.toContain("1280/");
53 expect(vitalsLine([{ look: "phone", entries: {} }])).not.toContain("px wide");
54 });
55
56 test("each row carries its own look's width, so nothing pairs rows with looks by place", () => {
57 const rows = vitalsRows([
58 { look: "desktop", skipped: "no browser" },
59 { look: "phone /x", entries: {}, size: size(500, 800) },
60 ]);
61 expect(rows[0]!.width).toBeUndefined();
62 expect(rows[1]!.width).toEqual({ scrollWidth: 500, innerWidth: 390 });
63 });
test/look-limits.test.ts added +20
@@ -0,0 +1,20 @@
1 /** The look caps (#10336): a commit's filed looks hold every look a preview of the forge takes. */
2 import { expect, test } from "bun:test";
3 import { FILED_LOOKS_MAX, LOOKS_MAX } from "../src/core/look_limits.ts";
4 import { parseLooks } from "../src/checks/looks.ts";
5 import { PREVIEW_MOVE_LOOK, PREVIEW_OWNER_LOOKS } from "../src/spawn/preview-looks.ts";
6
7 test("the filed cap holds every forge.json page and every named owner look, at desk and phone", () => {
8 expect(FILED_LOOKS_MAX).toBeGreaterThanOrEqual(2 * LOOKS_MAX + PREVIEW_OWNER_LOOKS.length);
9 });
10
11 test("a full preview set, forge.json pages first, keeps the move look", () => {
12 const pages = Array.from({ length: LOOKS_MAX }, (_, i) => `/p${i}`);
13 const set = [
14 ...pages.flatMap((p) => [`desktop ${p}`, `phone ${p}`]),
15 ...PREVIEW_OWNER_LOOKS.map((l) => `${l.kind} ${l.page}`),
16 ].map((look) => ({ look, entries: {} }));
17 const kept = parseLooks(set).map((l) => l.look);
18 expect(kept).toHaveLength(set.length);
19 expect(kept).toContain(`phone ${PREVIEW_MOVE_LOOK}`);
20 });
test/looks.test.ts +14
@@ -94,7 +94,12 @@ describe("the look", () => {
9494 const darkCalls: LookInput[] = [];
9595 /** The light pictures taken of one of `hello`'s environments. */
9696 const callsAt = (env: string) => calls.filter((c) => hostOf(c) === helloHost(env));
97 /** How many looks were already filed under the commit when a light picture of it was begun. */
98 const filedAtCapture: { commit: string; filed: number }[] = [];
9799 const fake: Capture = async (input) => {
100 const commit = /[0-9a-f]{40}/.exec(input.out)?.[0] ?? "";
101 if (commit !== "" && input.dark !== true)
102 filedAtCapture.push({ commit, filed: readLooks(dataDir, { id: "none", repoId: repo.id, commitOid: commit }).length });
98103 (input.dark === true ? darkCalls : calls).push(input);
99104 const mode = modes.get(hostOf(input));
100105 if (mode === "fail") return err("the browser fell over");
@@ -893,6 +898,15 @@ describe("the look", () => {
893898 );
894899 });
895900
901 test("a commit's looks are filed as each is taken, so a check that is green before the last picture lists them", async () => {
902 // Invariant: the vitals file grows look by look; it is not written only once the whole set is done.
903 const mine = filedAtCapture.filter((c) => c.commit === twoPages.commitOid);
904 expect(mine.length).toBeGreaterThanOrEqual(4);
905 expect(Math.max(...mine.map((c) => c.filed))).toBeGreaterThanOrEqual(3);
906 const check = { id: "none", repoId: repo.id, commitOid: twoPages.commitOid };
907 expect(readLooks(dataDir, check).map((l) => l.look).sort()).toEqual(["desktop", "desktop /board", "phone", "phone /board"]);
908 });
909
896910 test("app.looks naming two pages pictures both, distinctly, and the pull page groups them", async () => {
897911 // Invariant: each page `app.looks` names gets its own light and dark slots and files, grouped by page on the pull, dark folded away.
898912 const opened = { value: twoPages.pull };
test/preview-spec.test.ts +5 −3
@@ -6,7 +6,7 @@ import { tmpdir } from "node:os";
66 import { join } from "node:path";
77 import { createApp, type App } from "../src/app.ts";
88 import { AppsRuntime } from "../src/apps/runtime.ts";
9 import { previewSpec } from "../src/apps/preview_spec.ts";
9 import { PREVIEW_SPEC_TIMEOUT_MS, previewSpec } from "../src/apps/preview_spec.ts";
1010 import { newApp } from "../src/actions/apps.ts";
1111 import { openPull } from "../src/actions/pulls.ts";
1212 import { commitToBranch } from "../src/actions/repos.ts";
@@ -91,7 +91,9 @@ test("a deployed preview's findings are stored under its run, and the run still
9191 const r = listRuns(app.db, repo.id, { kind: "deploy", limit: 50 }).find((x) => x.env === env);
9292 return r && ["ok", "failed"].includes(r.state) ? r : null;
9393 }, 60_000);
94 const found = await until(() => previewFindings(app.db, run.id));
94 // previewSpec asks a page that missed once more, each pass on its own clock:
95 // on a busy machine the findings can take two of them to land.
96 const found = await until(() => previewFindings(app.db, run.id), 2 * PREVIEW_SPEC_TIMEOUT_MS + 5_000);
9597 expect(found.some((f) => f.check === "etag")).toBe(true);
9698 expect(listRuns(app.db, repo.id, { kind: "deploy", limit: 50 }).find((x) => x.id === run.id)?.state).toBe("ok");
9799 expect(specFindings(found).text).toContain("finding");
@@ -104,7 +106,7 @@ test("a deployed preview's findings are stored under its run, and the run still
104106 .then((r) => r.text());
105107 expect(page).toMatch(/Website spec: \d+ findings?/);
106108 expect(page).toContain("https://specification.website/#caching");
107 }, 90_000);
109 }, 150_000);
108110
109111 test("a webspec that cannot finish is one finding, and is stored", async () => {
110112 // Nothing listens on port 1: every fetch fails or the clock runs out.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs