main
ply4 git calls34 ms45 KiB3 cachedprotocol v2
140 lines10.0 KiBRaw
1// Post-deploy visual smoke: headless Chrome over the raw DevTools protocol (Node's global WebSocket; no puppeteer).
2// Loads the viewer at 375×812 and 1280×800 in light and dark mode and fails (exit 1) when a page looks broken:
3// - an SVG wider than 64 px (icons render at 16 px; an unstyled page draws them at 300 px),
4// - horizontal page overflow,
5// - no stylesheet with rules applied, or an icon whose computed width is not 16 px,
6// - a stylesheet href that is not the content-hashed /view.<hash>.css (a stale cached sheet could pair with new HTML),
7// - a tree page with no li[data-oid] rows (the scraping contract, README "Machine-readable markup"), or no ply strip,
8// - a footer build token (ply=…, ply-web=…) broken across lines, an error-page headline that starts lowercase, or a
9// missing-repo page whose "Repository root" link points back at the missing repo.
10// Default pages: home, /r/ply, a file, the /r index, and the failure pages (missing repo/ref/path, missing GitHub repo).
11// STALE_CSS=<file> fulfils every request for STALE_CSS_URL (default <base>/view.css) with that file, which is what a
12// browser that cached an old unversioned sheet does. A hashed href never hits it, so the run must still pass.
13//
14// usage: node scripts/visual-smoke.mjs [base=https://ply.ivar.workers.dev] [outdir=<tmp>] [-- url ...]
15// env: CHROME (default: macOS Google Chrome), STALE_CSS, STALE_CSS_URL,
16// PLY_VERSION=<version id>: every request carries Cloudflare-Workers-Version-Overrides: ply="<id>" (a 0% canary).
17// The last line lists every x-ply-request-id the Worker answered with (requestIds) and, per request, the x-ply-version that
18// answered it (requests: [{ id, version, url }], read by the telemetry gate); with PLY_VERSION, a
19// response from another version (x-ply-version) fails the run.
20// Run after a deploy, next to `npm run cd -- smoke --version <id>`.
21import { spawn } from 'node:child_process';
22import { mkdtempSync, writeFileSync, readFileSync, mkdirSync } from 'node:fs';
23import { tmpdir } from 'node:os';
24import { join } from 'node:path';
26const args = process.argv.slice(2);
27const dash = args.indexOf('--');
28const [base = 'https://ply.ivar.workers.dev', outdirArg] = dash === -1 ? args : args.slice(0, dash);
29const outdir = outdirArg ?? mkdtempSync(join(tmpdir(), 'ply-visual-'));
30mkdirSync(outdir, { recursive: true });
31const PUBLIC = '5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0';
32const urls = dash !== -1 ? args.slice(dash + 1) : [
33 `${base}/view`,
34 `${base}/r/ply`,
35 `${base}/view/${PUBLIC}/ply.git?path=src/fetchpack.ts`,
36 // The namespace index and every failure page (#29): missing repo, ref and path in public-v0, missing GitHub repo.
37 `${base}/r`,
38 `${base}/r/no-such-repo`,
39 `${base}/r/ply?ref=no-such-ref`,
40 `${base}/r/ply?path=no-such-file.txt`,
41 `${base}/view/github.com/ivarvong/no-such-repo-x`,
42];
43const CHROME = process.env.CHROME ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
44const stale = process.env.STALE_CSS ? readFileSync(process.env.STALE_CSS).toString('base64') : null;
45const staleUrl = process.env.STALE_CSS_URL ?? `${base}/view.css`;
46const port = 9300 + Math.floor(Math.random() * 500);
47const chrome = spawn(CHROME, ['--headless=new', `--remote-debugging-port=${port}`, `--user-data-dir=${mkdtempSync(join(tmpdir(), 'cdp-'))}`, '--no-first-run', '--hide-scrollbars', 'about:blank'], { stdio: 'ignore' });
48const sleep = ms => new Promise(r => setTimeout(r, ms));
50async function target() {
51 for (let i = 0; i < 50; i++) {
52 try { const t = (await (await fetch(`http://127.0.0.1:${port}/json/list`)).json()).find(x => x.type === 'page'); if (t) return t.webSocketDebuggerUrl; } catch { /* not up yet */ }
53 await sleep(100);
54 }
55 throw new Error('chrome did not start');
58const ws = new WebSocket(await target());
59await new Promise(r => ws.addEventListener('open', r, { once: true }));
60let id = 0; const pending = new Map(); const handlers = [];
61ws.addEventListener('message', ev => {
62 const m = JSON.parse(ev.data);
63 if (m.id && pending.has(m.id)) { const { res, rej } = pending.get(m.id); pending.delete(m.id); if (m.error) rej(new Error(m.error.message)); else res(m.result); }
64 else if (m.method) handlers.forEach(h => h(m));
65});
66const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pending.set(i, { res, rej }); ws.send(JSON.stringify({ id: i, method, params })); });
67const once = name => new Promise(r => { const h = m => { if (m.method === name) { handlers.splice(handlers.indexOf(h), 1); r(m.params); } }; handlers.push(h); });
69await send('Page.enable'); await send('Runtime.enable'); await send('Network.enable');
70await send('Network.setCacheDisabled', { cacheDisabled: true });
71const VERSION = process.env.PLY_VERSION ?? '';
72if (VERSION) await send('Network.setExtraHTTPHeaders', { headers: { 'Cloudflare-Workers-Version-Overrides': `ply="${VERSION}"` } });
73const requestIds = []; const requests = []; const wrongVersion = [];
74handlers.push(m => {
75 if (m.method !== 'Network.responseReceived') return;
76 const h = Object.fromEntries(Object.entries(m.params.response.headers ?? {}).map(([k, v]) => [k.toLowerCase(), v]));
77 if (h['x-ply-request-id']) { requestIds.push(h['x-ply-request-id']); requests.push({ id: h['x-ply-request-id'], version: h['x-ply-version'] ?? null, url: m.params.response.url }); }
78 if (VERSION && h['x-ply-request-id'] && h['x-ply-version'] !== VERSION) wrongVersion.push(`${m.params.response.url} → ${h['x-ply-version']}`);
79});
80const cssRequested = new Set(); const staleServed = new Set();
81await send('Fetch.enable', { patterns: [{ urlPattern: '*.css*', requestStage: 'Request' }] });
82handlers.push(m => {
83 if (m.method !== 'Fetch.requestPaused') return;
84 const url = m.params.request.url;
85 cssRequested.add(url);
86 if (stale && url.split('?')[0] === staleUrl) {
87 staleServed.add(url);
88 send('Fetch.fulfillRequest', { requestId: m.params.requestId, responseCode: 200, responseHeaders: [{ name: 'content-type', value: 'text/css' }], body: stale });
89 } else send('Fetch.continueRequest', { requestId: m.params.requestId });
90});
92const PROBE = `(() => {
93 const svgs = [...document.querySelectorAll('svg')].filter(s => s.getBoundingClientRect().width > 0);
94 const icon = document.querySelector('svg.i');
95 return {
96 title: document.title,
97 maxSvgPx: Math.round(Math.max(0, ...svgs.map(s => s.getBoundingClientRect().width))),
98 iconPx: icon ? getComputedStyle(icon).width : null,
99 overflowPx: document.documentElement.scrollWidth - innerWidth,
100 sheets: [...document.styleSheets].map(s => { try { return { href: s.href, rules: s.cssRules.length }; } catch { return { href: s.href, rules: -1 }; } }),
101 tree: !!document.querySelector('ul.files'),
102 rows: document.querySelectorAll('li[data-oid]').length,
103 strip: !!document.querySelector('a.ply-strip[href="#diagnostics"] .ply-strip-track .wf-bar'),
104 // the footer build line: each token (ply=…, ply-web=…) must sit on one line
105 buildTokensBroken: [...document.querySelectorAll('.site-footer .build > span')].filter(s => s.getClientRects().length > 1).map(s => s.textContent),
106 headline: document.querySelector('h1.display')?.textContent ?? null,
107 kicker: document.querySelector('.error-kicker')?.textContent ?? null,
108 upLinks: [...document.querySelectorAll('.error-card .lede a')].map(a => [a.textContent, a.getAttribute('href')]),
109 };
110})()`;
112let failed = false;
113for (const url of urls) for (const [w, h, mobile] of [[375, 812, true], [1280, 800, false]]) for (const scheme of ['light', 'dark']) {
114 await send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 2, mobile });
115 await send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: scheme }] });
116 const loaded = once('Page.loadEventFired'); await send('Page.navigate', { url }); await loaded; await sleep(300);
117 const r = (await send('Runtime.evaluate', { expression: PROBE, returnByValue: true })).result.value;
118 const problems = [];
119 if (r.maxSvgPx > 64) problems.push(`svg ${r.maxSvgPx}px wide`);
120 if (r.overflowPx > 0) problems.push(`horizontal overflow ${r.overflowPx}px`);
121 if (!r.sheets.some(s => s.rules > 50)) problems.push('no stylesheet with rules applied');
122 if (r.iconPx && r.iconPx !== '16px') problems.push(`icon ${r.iconPx}`);
123 if (!r.sheets.some(s => /\/view\.[0-9a-f]{12}\.css$/.test(s.href ?? ''))) problems.push(`stylesheet not content-hashed: ${r.sheets.map(s => s.href).join(' ')}`);
124 if (r.tree && r.rows === 0) problems.push('tree page has no li[data-oid] rows');
125 if (r.tree && !r.strip) problems.push('tree page has no ply strip (the git calls under the title)');
126 if (r.buildTokensBroken.length) problems.push(`footer build token wraps inside itself: ${r.buildTokensBroken.join(', ')}`);
127 if (r.kicker && r.headline && /^\p{Ll}/u.test(r.headline)) problems.push(`headline not sentence case: ${r.headline}`);
128 // an error page never links "Repository root" back to the repository it just failed to find
129 const rootLink = r.upLinks.find(([text]) => text === 'Repository root');
130 if (rootLink && /HTTP 404 · repo/.test(r.kicker ?? '')) problems.push(`missing-repo page links Repository root → ${rootLink[1]}`);
131 const name = `${url.replace(/^https?:\/\//, '').replace(/[^a-z0-9]+/gi, '_').slice(0, 60)}-${w}-${scheme}${stale ? '-stale' : ''}.png`;
132 const shot = await send('Page.captureScreenshot', { format: 'png', captureBeyondViewport: false });
133 writeFileSync(join(outdir, name), Buffer.from(shot.data, 'base64'));
134 if (problems.length) failed = true;
135 console.log(JSON.stringify({ ok: !problems.length, url, w, scheme, problems, shot: join(outdir, name), maxSvgPx: r.maxSvgPx, iconPx: r.iconPx, overflowPx: r.overflowPx, rows: r.rows, headline: r.headline, upLinks: r.upLinks, sheets: r.sheets }));
137if (wrongVersion.length) failed = true;
138console.log(JSON.stringify({ cssRequested: [...cssRequested], staleCss: stale ? { url: staleUrl, servedFor: [...staleServed] } : null, version: VERSION || null, requestIds, requests, wrongVersion, failed }));
139ws.close(); chrome.kill();
140process.exit(failed ? 1 : 0);
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=2
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=61
Open pack map
fetch2004.3 KiB · hit29 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=29
git.response.bytes=4384
git.response.cache=HIT
git.response.duration_ms=29
git.fetch.wants=1507a0258fc0e959df33205130cb235fbac00efa
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=4384
git.pkt.payload.max=4363
git.sideband.band1.bytes=4362
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
a5e2d2cb6aa0cf3a
Request
4a049180…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format