GitHubivarvong

ply

main
ply6 git calls71 ms27 KiB4 cachedprotocol v2
149 lines10 KiBRaw
1// The repository's own gates, held to what GitHub documents, not to what the workflow files happen to say.
2//
3// Expected values come from the GitHub Actions documentation:
4// - `on.workflow_run` fires for the named workflow's runs; `github.event.workflow_run.conclusion`, `.event`,
5// `.head_branch`, `.head_sha` and `.head_repository.full_name` describe the run that finished. In a
6// workflow_run-triggered workflow `github.sha` is the tip of the default branch, NOT the commit the finished
7// run tested, so the tested commit must be read from `workflow_run.head_sha`.
8// - `head_branch` is the branch name in the head repository: a pull request from a fork's `main` also has
9// head_branch `main`, so `event == 'push'` and the head repository must be checked as well.
10// No YAML parser (no dependencies): the assertions are on the exact lines a reviewer would read.
11import { test } from 'vitest';
12import assert from 'node:assert/strict';
13import { readFileSync, readdirSync, mkdtempSync, mkdirSync, writeFileSync, cpSync, symlinkSync, rmSync } from 'node:fs';
14import { spawnSync } from 'node:child_process';
15import { tmpdir } from 'node:os';
16import { join } from 'node:path';
17import { fileURLToPath } from 'node:url';
19const read = (p) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');
20// Every test/**/*.test.js on disk: the directory itself, not the planner's view of it.
21const testFiles = (dir) => readdirSync(new URL(`../${dir}/`, import.meta.url), { withFileTypes: true }).flatMap((e) => {
22 if (e.isDirectory()) return e.name === 'node_modules' ? [] : testFiles(`${dir}/${e.name}`);
23 return e.name.endsWith('.test.js') ? [`${dir}/${e.name}`] : [];
24});
25// Comments are not configuration: a `# on: push` must not satisfy or fail a check.
26const code = (text) => text.split('\n').filter((l) => !/^\s*#/u.test(l)).join('\n');
28test('notify-ply-web dispatches only after ci succeeded for that exact commit on main', () => {
29 const y = code(read('.github/workflows/notify-ply-web.yml'));
30 // The trigger: ci's completion, never the push itself (a push is not yet judged by anything).
31 assert.doesNotMatch(y, /^ {2}push:/mu, 'must not trigger on push: the commit is not yet judged');
32 assert.match(y, /^on:\n {2}workflow_run:\n {4}workflows: \[ci\]\n {4}types: \[completed\]\n/mu);
33 assert.equal(read('.github/workflows/ci.yml').split('\n')[0], 'name: ci', 'workflow_run matches ci by this name');
34 // The job condition: a successful run, of a push (not a pull request), to main, of this repository.
35 const cond = /^ {4}if: >-\n((?: {6}.*\n)+)/mu.exec(y)?.[1].replace(/\s+/gu, ' ').trim();
36 assert.equal(
37 cond,
38 "github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && "
39 + "github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.head_repository.full_name == github.repository",
40 );
41 // The sha: the commit ci judged. github.sha here would be whatever main's tip is when the run finishes.
42 assert.match(y, /^ {10}COMMIT_SHA: \$\{\{ github\.event\.workflow_run\.head_sha \}\}$/mu);
43 assert.doesNotMatch(y, /github\.sha/u);
44});
46test('notify-ply-web sends the judged sha, once, from its one conditional job', () => {
47 const raw = read('.github/workflows/notify-ply-web.yml');
48 const y = code(raw);
49 // GitHub sets $GITHUB_SHA from the same context as github.sha: in a workflow_run run it is the default branch's
50 // tip, not the commit ci judged. Not even a comment may spell it: ply-web's README documented this file with it.
51 assert.doesNotMatch(raw, /GITHUB_SHA/u, 'GITHUB_SHA is the default branch tip in a workflow_run run');
52 // One job (the conditional one above) with one step: a second job or step would dispatch outside the condition.
53 const jobs = [...y.slice(y.indexOf('\njobs:\n')).matchAll(/^ {2}([A-Za-z0-9_-]+):/gmu)].map((m) => m[1]);
54 assert.deepEqual(jobs, ['dispatch']);
55 assert.equal((y.match(/^ {6}- /gmu) ?? []).length, 1, 'exactly one step');
56 // One request, to ply-web's repository_dispatch endpoint (REST: POST /repos/{owner}/{repo}/dispatches).
57 assert.equal((y.match(/dispatches/gu) ?? []).length, 1, 'exactly one dispatches call');
58 assert.equal((y.match(/\bgh api\b/gu) ?? []).length, 1);
59 assert.doesNotMatch(y, /\bcurl\b|\bwget\b/u);
60 assert.match(y, /gh api --method POST repos\/ivarvong\/ply-web\/dispatches --input - <<EOF\n/u);
61 // The body, as the REST API documents it: {event_type, client_payload}. The sha is the shell's COMMIT_SHA (the
62 // env line asserted above binds it to workflow_run.head_sha) and nothing else.
63 const body = /<<EOF\n\s*(.*)\n\s*EOF$/mu.exec(y)?.[1];
64 assert.deepEqual(JSON.parse(body ?? ''), { event_type: 'ply-main-updated', client_payload: { sha: '${COMMIT_SHA}' } });
65 // Nothing in the script can compute another sha: no command substitution, and the only shell variables read are
66 // the two the step's env declares. (`${{ ... }}` is a GitHub expression, removed before looking for shell ones.)
67 const shell = y.replace(/\$\{\{.*?\}\}/gu, '');
68 assert.doesNotMatch(shell, /\$\(|`/u, 'no command substitution');
69 const vars = new Set([...shell.matchAll(/\$\{?([A-Za-z_][A-Za-z0-9_]*)/gu)].map((m) => m[1]));
70 assert.deepEqual([...vars].sort(), ['COMMIT_SHA', 'PLY_WEB_DISPATCH_TOKEN']);
71});
73test('npm run check is the pre-push gate: typecheck, lint, the registry test, the dist check', () => {
74 const { scripts } = JSON.parse(read('package.json'));
75 assert.equal(typeof scripts.check, 'string', 'package.json has no check script');
76 const steps = scripts.check.split(' && ');
77 // No step writes into the tree: the dist check builds into a temporary directory (the test below runs it).
78 assert.deepEqual(steps, ['npm run typecheck', 'npm run lint', 'vitest run test/space/registry.test.js', 'node scripts/dist-check.mjs']);
79 // The dist check is the one CI runs, word for word, so the two cannot drift.
80 const ciDist = /^ {6}- name: dist is what consumers import\n {8}run: (.*)$/mu.exec(read('.github/workflows/ci.yml'))?.[1];
81 assert.equal(steps[3], ciDist);
82 // Documented where a contributor looks for it.
83 assert.match(read('CONTEXT.md'), /^npm run check\b/mu);
84});
86test('nightly: every job checks out the one sha the seed job resolved, never a moving main', () => {
87 const y = code(read('.github/workflows/nightly.yml'));
88 // Counted by hand in nightly.yml: fuzz, test-shard, test, pack-cut-full and sweep check the repository out.
89 const checkouts = y.match(/^ {6}- uses: actions\/checkout@/gmu) ?? [];
90 assert.equal(checkouts.length, 5);
91 const refs = [...y.matchAll(/^ {10}ref: (.*)$/gmu)].map((m) => m[1]);
92 assert.deepEqual(refs, Array.from({ length: 5 }, () => '${{ needs.seed.outputs.sha }}'));
93 // `needs.seed.outputs.sha` is empty in a job that does not need seed, and an empty ref checks out the default.
94 const jobs = y.slice(y.indexOf('\njobs:\n')).split(/^ {2}(?=[a-z-]+:$)/mu).slice(1);
95 for (const job of jobs) {
96 if (!job.includes('actions/checkout@')) continue;
97 assert.match(job, /^ {4}needs: (?:seed|\[seed(?:, [a-z-]+)*\])$/mu, `job ${job.split(':')[0]} checks out but does not need seed`);
98 }
99 // The sha is resolved once, validated as a commit id, and published as the seed job's output.
100 assert.match(y, /^ {6}sha: \$\{\{ steps\.seed\.outputs\.sha \}\}$/mu);
101 assert.match(y, /git ls-remote "https:\/\/github\.com\/\$\{GITHUB_REPOSITORY\}\.git" refs\/heads\/main/u);
102 assert.match(y, /\[\[ "\$sha" =~ \^\[0-9a-f\]\{40\}\$ \]\]/u);
103});
105test('every test file has a weight in test/durations.json, so the shard planner never guesses', () => {
106 // vitest.config.ts weighs a file with no entry as the heaviest known file (494 s on 2026-11-11). Two sub-second
107 // files without entries moved ci's replayed plan from 1052/1051/1051/1051 summed seconds per shard to
108 // 806/1298/805/1298. The convention (vitest.config.ts): a new file gets its local seconds, rounded up.
109 const known = JSON.parse(read('test/durations.json'));
110 assert.deepEqual(testFiles('test').filter((f) => !(f in known)), [], 'add each file with its local seconds, rounded up');
111 for (const [file, seconds] of Object.entries(known)) assert.ok(Number.isInteger(seconds) && seconds >= 0, `${file}: ${seconds}`);
112});
114// `npm run check` is the contributor's pre-push gate; it must judge the tree's source without rewriting the tree's
115// dist/. Run in a copy of the tree whose dist/ is known by construction, so the expectations are the copy's own
116// bytes and the two facts stated below, not anything the check prints.
117test('npm run check builds what it checks outside the tree: dist/ is not rewritten, and a stale dist/ is not what is judged', () => {
118 const root = fileURLToPath(new URL('..', import.meta.url));
119 const steps = JSON.parse(read('package.json')).scripts.check.split(' && ');
120 assert.deepEqual(steps.slice(0, 3), ['npm run typecheck', 'npm run lint', 'vitest run test/space/registry.test.js']);
121 const distStep = steps.slice(3).join(' && ');
122 assert.notEqual(distStep, '', 'check still has a dist step');
123 const dir = mkdtempSync(join(tmpdir(), 'ply-check-'));
124 try {
125 for (const p of ['src', 'scripts', 'package.json', 'tsconfig.json']) cpSync(join(root, p), join(dir, p), { recursive: true });
126 symlinkSync(join(root, 'node_modules'), join(dir, 'node_modules'));
127 mkdirSync(join(dir, 'dist'));
128 const stale = join(dir, 'dist/index.js');
129 const env = { ...process.env, NODE_OPTIONS: '', PATH: `${join(dir, 'node_modules/.bin')}:${process.env.PATH}` };
130 const run = () => spawnSync('sh', ['-c', distStep], { cwd: dir, env, encoding: 'utf8' });
132 // A stale dist/ that exports nothing, a good src: the step passes on what src builds to, and dist/ is as it was.
133 writeFileSync(stale, 'export {};\n');
134 const good = run();
135 assert.equal(good.status, 0, `${good.stdout}${good.stderr}`);
136 assert.deepEqual(readdirSync(join(dir, 'dist')), ['index.js']);
137 assert.equal(readFileSync(stale, 'utf8'), 'export {};\n');
139 // A stale dist/ that has both exports, a src whose index exports nothing: the step fails, and dist/ is as it was.
140 writeFileSync(stale, 'export const Tracer = 1;\nexport const RETRY = 1;\n');
141 writeFileSync(join(dir, 'src/index.ts'), 'export {};\n');
142 const bad = run();
143 assert.notEqual(bad.status, 0, 'the step judged the stale dist/, not the source');
144 assert.deepEqual(readdirSync(join(dir, 'dist')), ['index.js']);
145 assert.equal(readFileSync(stale, 'utf8'), 'export const Tracer = 1;\nexport const RETRY = 1;\n');
146 } finally {
147 rmSync(dir, { recursive: true, force: true });
148 }
149});
Diagnostics6 git calls · 71 ms
CallStatusSizeTime071 ms
discover200191 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
git.response.bytes=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB · hit1 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=1
git.response.bytes=11990
git.response.cache=HIT
git.response.duration_ms=1
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=1
git.fetch.filter=tree:0
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
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=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · hit3 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=919
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:02005.6 KiB · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=64
git.response.bytes=5724
git.response.cache=HIT
git.response.duration_ms=1
git.fetch.filter=tree:0
git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=5724
git.pkt.payload.max=5697
git.sideband.band1.bytes=5697
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=5697
git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetch2004.1 KiB64 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=4245
git.response.cache=MISS
git.response.duration_ms=64
git.fetch.wants=4a5a43161174c8c796ad8ab488eab8597da405df
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=4245
git.pkt.payload.max=4218
git.sideband.band1.bytes=4218
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://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e0f83a9b96332c
Request
1889fd4a…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format