main
1import { existsSync } from 'node:fs'
2import { mkdir } from 'node:fs/promises'
3import { join } from 'node:path'
4import { ROOT } from './cf.ts'
5import type { CdConfig } from './config.ts'
6import { activeLog } from './log.ts'
7import { run } from './proc.ts'
8import { fail, pass, type StageResult } from './result.ts'
9import { writeJson } from './run-dir.ts'
11export type VisualValue = {
12 readonly pages: number
13 readonly outdir: string
14 /** Set when the check could not run here (no Chrome). Not a pass of the pages, not a Worker fault. */
15 readonly skipped: string | null
16}
18const DEFAULT_CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
19/** The run is 9 pages × 4 viewports; a healthy one takes about 15 s. */
20const VISUAL_TIMEOUT_MS = 120_000
22type Row = Readonly<Record<string, unknown>>
24function rows(stdout: string): Row[] {
25 const out: Row[] = []
26 for (const line of stdout.split('\n')) {
27 if (!line.startsWith('{')) continue
28 try {
29 out.push(JSON.parse(line) as Row)
30 } catch {
31 continue
32 }
33 }
34 return out
35}
37/**
38 * The CDP visual smoke (scripts/visual-smoke.mjs) against the live URL after promotion: 375 and
39 * 1280 px, light and dark. A page assertion that fails is a Worker failure. A run that never
40 * printed its summary line (Chrome missing or crashed) is a harness fault, never a rollback.
41 */
42export async function stageVisual(config: CdConfig, opts: { readonly runDir: string; readonly version: string }): Promise<StageResult<VisualValue>> {
43 const outdir = join(opts.runDir, 'visual')
44 await mkdir(outdir, { recursive: true })
45 const chrome = process.env.CHROME || DEFAULT_CHROME
46 const log = activeLog()
47 const started = Date.now()
48 if (!existsSync(chrome)) {
49 const skipped = `no Chrome at ${chrome}; set CHROME to run the visual smoke`
50 await writeJson(opts.runDir, 'visual.json', { kind: 'skipped', reason: skipped })
51 if (log) await log.observation({ measurement: { source: 'visual-smoke', skipped }, query: { source: 'visual-smoke' }, from: started, to: Date.now(), raw: skipped })
52 return pass('visual', { pages: 0, outdir, skipped })
53 }
54 const result = await run(process.execPath, [join(ROOT, 'scripts/visual-smoke.mjs'), config.baseUrl, outdir], {
55 cwd: ROOT,
56 timeout: VISUAL_TIMEOUT_MS,
57 // Every page must come from the version just promoted: a straggler on the old one during propagation fails it.
58 env: { ...process.env, PLY_VERSION: opts.version },
59 })
60 const parsed = rows(result.stdout)
61 const pages = parsed.filter(row => typeof row.url === 'string')
62 const summaries = parsed.filter(row => typeof row.failed === 'boolean')
63 const broken = pages.filter(row => row.ok === false).map(row => `${String(row.url)} ${String(row.w)} ${String(row.scheme)}: ${Array.isArray(row.problems) ? row.problems.join('; ') : ''}`)
64 const verdict = summaries.length === 0
65 ? { kind: 'harness_fault' as const, reason: `visual smoke exited ${result.code} without a summary: ${result.stderr.trim().split('\n').slice(-1).join('')}` }
66 : broken.length > 0 || summaries.some(row => row.failed === true)
67 ? { kind: 'fail' as const, reason: `visual smoke: ${broken.length}/${pages.length} views broken${broken.length ? `: ${broken.slice(0, 3).join(' | ')}` : ''}` }
68 : { kind: 'pass' as const, reason: `visual smoke: ${pages.length}/${pages.length} views ok` }
69 await writeJson(opts.runDir, 'visual.json', { ...verdict, version: opts.version, pages: pages.length, broken, outdir, exitCode: result.code, durationMs: Date.now() - started })
70 if (log) {
71 const ref = await log.observation({
72 measurement: { source: 'visual-smoke', pages: pages.length, broken: broken.length, exitCode: result.code },
73 query: { source: 'visual-smoke', base: config.baseUrl },
74 from: started,
75 to: Date.now(),
76 raw: JSON.stringify({ broken }),
77 })
78 await log.decision({
79 inputs: [ref],
80 rules: [{ name: 'visual_smoke', value: verdict.kind }],
81 outcome: verdict.kind === 'pass' ? 'advance' : verdict.kind === 'harness_fault' ? 'harness_fault' : 'rollback',
82 reason: verdict.reason,
83 })
84 }
85 if (verdict.kind === 'harness_fault') return fail('visual', verdict.reason, false, 'harness_fault')
86 if (verdict.kind === 'fail') return fail('visual', verdict.reason)
87 return pass('visual', { pages: pages.length, outdir, skipped: null })
88}
Diagnostics4 git calls · 22 ms
CallStatusSizeTime022 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=1 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.8 KiB · hit17 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=17 git.response.bytes=1843 git.response.cache=HIT git.response.duration_ms=17 git.fetch.wants=fc0877e74dfc772f4d902195de17392ff1813638 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1843 git.pkt.payload.max=1822 git.sideband.band1.bytes=1821 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e2e35ece774af4
- Request
- 1b828323…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format