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

Each look records whether its page scrolls sideways and how many screens tall it is, and the pull's looks name any phone page that scrolls sideways #9264

Parked opened this
Closed without merging

torque/forge:torque/9249-each-look-records-whether-its-page-scrol → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +142 −12
src/checks/looks.ts +8 −1
@@ -48,7 +48,14 @@ export function parseLooks(raw: unknown): LookVitals[] {
4848 const skipped = words(rec.skipped);
4949 if (skipped !== null) out.push({ look, skipped });
5050 else if (rec.entries && typeof rec.entries === "object" && !Array.isArray(rec.entries))
51 out.push({ look, entries: rec.entries });
51 out.push({
52 look,
53 entries: rec.entries,
54 ...(typeof rec.sideways === "boolean" ? { sideways: rec.sideways } : {}),
55 ...(typeof rec.screens === "number" && Number.isFinite(rec.screens) && rec.screens >= 0
56 ? { screens: rec.screens }
57 : {}),
58 });
5259 }
5360 return out;
5461 }
src/checks/progress.ts +3 −2
@@ -9,7 +9,7 @@
99
1010 import type { CheckSummary } from "../core/runs.ts";
1111 import { readLooks } from "./looks.ts";
12 import { checkSteps, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
12 import { checkSteps, sidewaysNotices, stepsWords, vitalsRows, type LookVitals } from "./summary.ts";
1313 import { parseTestsRow, testsRowLine } from "./tests-row.ts";
1414 import { readRunLog } from "../runs/log.ts";
1515
@@ -120,5 +120,6 @@ export function vitalsLine(looks: readonly LookVitals[]): string {
120120 ? `${g.look}: skipped: ${g.skipped}`
121121 : `${g.look}: ${g.rows.map((r) => `${r.vital} ${r.value}${r.grade === "n/a" ? "" : ` ${r.grade}`}`).join(", ")}`,
122122 );
123 return groups.length === 0 ? "" : `vitals ${groups.join("; ")}`;
123 if (groups.length === 0) return "";
124 return [`vitals ${groups.join("; ")}`, ...sidewaysNotices(looks)].join(" · ");
124125 }
src/checks/summary.ts +24 −1
@@ -220,7 +220,14 @@ export function stepsWords(steps: readonly CheckStep[]): string {
220220
221221 /** One look's recorded entries, or why it has none; plain data from the caller. */
222222 export type LookVitals =
223 | { readonly look: string; readonly entries: Entries }
223 | {
224 readonly look: string;
225 readonly entries: Entries;
226 /** scrollWidth > innerWidth; absent when the page did not say its size. */
227 readonly sideways?: boolean;
228 /** scrollHeight / innerHeight, one decimal; absent likewise. */
229 readonly screens?: number;
230 }
224231 | { readonly look: string; readonly skipped: string };
225232
226233 /** One cell row of a look's table: words only, escaped where they are rendered. */
@@ -267,3 +274,19 @@ export function vitalsRows(looks: readonly LookVitals[]): readonly LookRows[] {
267274 return { look: l.look, skipped: "", rows };
268275 });
269276 }
277
278 /**
279 * One plain line per phone look that scrolls sideways, none for a page that
280 * fits: `/preview-admin/sample/held scrolls sideways at phone width`. Words
281 * only; no verdict, so nothing here can turn a check red.
282 */
283 export function sidewaysNotices(looks: readonly LookVitals[]): readonly string[] {
284 const out: string[] = [];
285 for (const l of looks) {
286 if ("skipped" in l || l.sideways !== true) continue;
287 if (l.look !== "phone" && !l.look.startsWith("phone ")) continue;
288 const page = l.look.slice("phone".length).trim() || "/";
289 out.push(`${page} scrolls sideways at phone width`);
290 }
291 return out;
292 }
src/looks/capture.ts +27 −1
@@ -58,8 +58,23 @@ export interface LookInput {
5858 /** What the page recorded while it loaded; a type the browser lacks is an empty list. */
5959 export interface Recorded {
6060 readonly entries: Entries;
61 /** The page's own size once loaded; absent when the page did not say. */
62 readonly size?: PageSize;
6163 }
6264
65 /** The page's scroll size and the viewport's, in CSS pixels; each may be missing. */
66 export interface PageSize {
67 readonly scrollWidth?: number;
68 readonly scrollHeight?: number;
69 readonly innerWidth?: number;
70 readonly innerHeight?: number;
71 }
72
73 const SIZE_FIELDS = ["scrollWidth", "scrollHeight", "innerWidth", "innerHeight"] as const;
74
75 /** Read after load, in the same evaluation that reads the entries back. */
76 const READ_BACK = `JSON.stringify({ ...(window.__forgeVitals ?? {}), size: (() => { const d = document.documentElement; return { scrollWidth: d.scrollWidth, scrollHeight: d.scrollHeight, innerWidth: window.innerWidth, innerHeight: window.innerHeight }; })() })`;
77
6378 /**
6479 * What takes the picture: the real browser, or a test's stand-in. One that
6580 * recorded nothing returns empty entries.
@@ -172,7 +187,18 @@ export function parseRecorded(raw: unknown): Recorded {
172187 }
173188 return out;
174189 };
190 const size: Record<string, number> = {};
191 const from =
192 rec["size"] !== null && typeof rec["size"] === "object"
193 ? (rec["size"] as Record<string, unknown>)
194 : {};
195 for (const f of SIZE_FIELDS) {
196 const v = from[f];
197 // Whole, non-negative numbers; anything else is absent, not a failure.
198 if (finite(v) && Number.isInteger(v)) size[f] = v;
199 }
175200 return {
201 ...(Object.keys(size).length > 0 ? { size: size as PageSize } : {}),
176202 entries: {
177203 lcp: list("lcp", ["startTime", "size"], "startTime"),
178204 layoutShift: list("layoutShift", ["startTime", "value", "hadRecentInput"], "value"),
@@ -470,7 +496,7 @@ async function shoot(
470496 const read = await dt.send(
471497 "Runtime.evaluate",
472498 {
473 expression: "JSON.stringify(window.__forgeVitals ?? null)",
499 expression: READ_BACK,
474500 returnByValue: true,
475501 },
476502 sessionId,
src/looks/service.ts +22 −2
@@ -69,7 +69,7 @@ import { createLog } from "../kernel/log.ts";
6969 import { err, ok, type Result } from "../kernel/result.ts";
7070 import { writeCommitLooks } from "../checks/looks.ts";
7171 import type { LookVitals } from "../checks/summary.ts";
72 import { findChromium, isNoBrowser, takeLook, type Capture } from "./capture.ts";
72 import { findChromium, isNoBrowser, takeLook, type Capture, type PageSize } from "./capture.ts";
7373
7474 const log = createLog("looks");
7575
@@ -207,6 +207,25 @@ interface Pending {
207207 readonly swept?: true;
208208 }
209209
210 /**
211 * Whether the page scrolls sideways and how many screens tall it is, from
212 * what it measured; nothing when it did not say (or the viewport is zero).
213 */
214 export function pageReach(
215 size: PageSize | undefined,
216 ): { sideways?: boolean; screens?: number } {
217 const out: { sideways?: boolean; screens?: number } = {};
218 if (size?.scrollWidth !== undefined && size.innerWidth !== undefined)
219 out.sideways = size.scrollWidth > size.innerWidth;
220 if (
221 size?.scrollHeight !== undefined &&
222 size.innerHeight !== undefined &&
223 size.innerHeight > 0
224 )
225 out.screens = Math.round((size.scrollHeight / size.innerHeight) * 10) / 10;
226 return out;
227 }
228
210229 export function startLooks(app: App, options: LooksOptions): LooksHandle {
211230 const { dataDir } = app.config;
212231 const port = new URL(options.localUrl).port;
@@ -432,7 +451,8 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
432451 // The thumb is the desktop page again, as a stranger: it adds no row.
433452 if (kind !== "thumb" && theme === "light") {
434453 const look = page === "/" ? kind : `${kind} ${page}`;
435 if (shot.ok) vitals.push({ look, entries: shot.value.entries });
454 if (shot.ok)
455 vitals.push({ look, entries: shot.value.entries, ...pageReach(shot.value.size) });
436456 else if (isNoBrowser(shot.error))
437457 vitals.push({ look, skipped: "no browser" });
438458 }
src/web/studio/vitals.ts +3 −2
@@ -4,13 +4,14 @@
44 * look recorded anything.
55 */
66
7 import { vitalsRows, type LookVitals } from "../../checks/summary.ts";
7 import { sidewaysNotices, vitalsRows, type LookVitals } from "../../checks/summary.ts";
88 import { html, type Html } from "../html.ts";
99
1010 export function vitalsTable(looks: readonly LookVitals[]): Html {
1111 const groups = vitalsRows(looks);
1212 if (groups.length === 0) return html``;
13 return html`<div class="table-scroll" tabindex="0" role="region" aria-label="Web vitals per look">
13 const notices = sidewaysNotices(looks);
14 return html`${notices.map((n) => html`<p>${n}</p>`)}<div class="table-scroll" tabindex="0" role="region" aria-label="Web vitals per look">
1415 <table class="table" data-dense>
1516 <thead><tr><th>Look</th><th>Vital</th><th>Value</th><th>Thresholds</th><th>Grade</th></tr></thead>
1617 <tbody>
test/looks.test.ts +55 −3
@@ -30,8 +30,10 @@ import { setAppMembers } from "../src/core/app_members.ts";
3030 import type { Pull } from "../src/core/pulls.ts";
3131 import type { Repo } from "../src/core/repos.ts";
3232 import { createRun, listRuns, type Run } from "../src/core/runs.ts";
33 import { readLooks } from "../src/checks/looks.ts";
34 import { vitalsRows } from "../src/checks/summary.ts";
33 import { parseLooks, readLooks } from "../src/checks/looks.ts";
34 import { vitalsLine } from "../src/checks/progress.ts";
35 import { sidewaysNotices, vitalsRows } from "../src/checks/summary.ts";
36 import { vitalsTable } from "../src/web/studio/vitals.ts";
3537 import { createUser, type User } from "../src/core/users.ts";
3638 import { serve, type Servers } from "../src/http/server.ts";
3739 import { err, ok } from "../src/kernel/result.ts";
@@ -44,7 +46,7 @@ import {
4446 type Capture,
4547 type LookInput,
4648 } from "../src/looks/capture.ts";
47 import { startLooks, type LooksHandle } from "../src/looks/service.ts";
49 import { pageReach, startLooks, type LooksHandle } from "../src/looks/service.ts";
4850
4951 quietLogs();
5052
@@ -96,6 +98,10 @@ describe("the look", () => {
9698 input.width === 390
9799 ? { lcp: [{ startTime: 3100, size: 10 }] }
98100 : { layoutShift: [{ startTime: 100, value: 0.3 }] },
101 size:
102 input.width === 390
103 ? { scrollWidth: 500, scrollHeight: 2000, innerWidth: 390, innerHeight: 844 }
104 : { scrollWidth: 1280, scrollHeight: 800, innerWidth: 1280, innerHeight: 800 },
99105 });
100106 };
101107
@@ -293,6 +299,8 @@ describe("the look", () => {
293299 const recorded = readLooks(dataDir, check);
294300 expect(recorded).toHaveLength(2);
295301 expect(recorded.map((l) => l.look).sort()).toEqual(["desktop", "phone"]);
302 expect(recorded.find((l) => l.look === "phone")).toMatchObject({ sideways: true, screens: 2.4 });
303 expect(recorded.find((l) => l.look === "desktop")).toMatchObject({ sideways: false, screens: 1 });
296304 const graded = vitalsRows(recorded);
297305 expect(graded.find((g) => g.look === "phone")!.rows[0]).toMatchObject({
298306 vital: "LCP",
@@ -562,6 +570,50 @@ describe("the look", () => {
562570 expect(parseRecorded("x").entries.lcp).toEqual([]);
563571 });
564572
573 test("the page's own size is kept as whole numbers, a missing or malformed one as absent", () => {
574 expect(
575 parseRecorded({ size: { scrollWidth: 500, scrollHeight: 1688, innerWidth: 390, innerHeight: 844 } }).size,
576 ).toEqual({ scrollWidth: 500, scrollHeight: 1688, innerWidth: 390, innerHeight: 844 });
577 expect(parseRecorded({}).size).toBeUndefined();
578 expect(parseRecorded({ size: "wide" }).size).toBeUndefined();
579 expect(
580 parseRecorded({ size: { scrollWidth: -1, scrollHeight: 1.5, innerWidth: "390", innerHeight: 844 } }).size,
581 ).toEqual({ innerHeight: 844 });
582 });
583
584 test("sideways and screens are worked out from the size, one decimal", () => {
585 expect(pageReach({ scrollWidth: 500, innerWidth: 390, scrollHeight: 2000, innerHeight: 844 })).toEqual({
586 sideways: true,
587 screens: 2.4,
588 });
589 expect(pageReach({ scrollWidth: 390, innerWidth: 390, scrollHeight: 844, innerHeight: 844 })).toEqual({
590 sideways: false,
591 screens: 1,
592 });
593 expect(pageReach(undefined)).toEqual({});
594 expect(pageReach({ scrollWidth: 400 })).toEqual({});
595 });
596
597 test("a phone look that scrolls sideways is named in one line, a page that fits says nothing", () => {
598 const entries = { lcp: [], layoutShift: [], longtask: [] };
599 const looks = [
600 { look: "phone /preview-admin/sample/held", entries, sideways: true, screens: 1.2 },
601 { look: "phone", entries, sideways: false, screens: 1 },
602 { look: "desktop", entries, sideways: true, screens: 1 },
603 { look: "phone /x", entries },
604 ];
605 expect(sidewaysNotices(looks)).toEqual([
606 "/preview-admin/sample/held scrolls sideways at phone width",
607 ]);
608 expect(vitalsLine(looks)).toContain("/preview-admin/sample/held scrolls sideways at phone width");
609 expect(String(vitalsTable(looks))).toContain("scrolls sideways at phone width");
610 expect(sidewaysNotices(looks.slice(1))).toEqual([]);
611 expect(vitalsLine(looks.slice(1))).not.toContain("sideways");
612 expect(String(vitalsTable(looks.slice(1)))).not.toContain("sideways");
613 // Survives the file a check reads back.
614 expect(parseLooks(JSON.parse(JSON.stringify(looks)))[0]).toMatchObject({ sideways: true, screens: 1.2 });
615 });
616
565617 test("a closed pull's pictures go with its preview", async () => {
566618 const env = `pull-${unpictured.number}`;
567619 expect(looksForEnv(app.db, record.id, env).length).toBeGreaterThan(0);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs