GitHubivarvong
ply
main
1// The pinned fuzz stage of `npm test` (`npm run test:fuzz-pinned`): a fixed list of fuzzer runs, each with its seed
2// or its case written here, so the gate runs the same cases every time and a red run is a regression, not a new draw.
3// node test/fuzz/pinned.mjs run the list; stop at the first failure and print its replay command
4// node test/fuzz/pinned.mjs --list print the commands, run nothing
5// node test/fuzz/pinned.mjs --only codec only the entries of that fuzzer
6// node test/fuzz/pinned.mjs --random discovery (`npm run test:fuzz-random`): one fresh seed for every
7// seeded entry, printed first together with the command that replays it
8// node test/fuzz/pinned.mjs --seed 123 replay a --random run
9// node test/fuzz/pinned.mjs --timeout-s 60 per-entry timeout (default 900 s): a fuzzer that has not exited by
10// then is killed and reported as a failure with its seed
11// Every entry prints its fuzzer and seed before it starts. An unknown argument is refused (exit 2), never ignored.
12// Seeds are never taken from the clock here. An entry with `fixed` is a regression case and keeps its seed/case in
13// every mode. test/fuzz-pinned.test.js holds this list to "every command names --seed or --case".
14import { spawnSync } from 'node:child_process';
15import { randomInt } from 'node:crypto';
16import { realpathSync } from 'node:fs';
17import { fileURLToPath } from 'node:url';
19const NODE_ARGS = ['--import', './test/ts-resolve.mjs'];
20// Per entry. The slowest entry, codec --n 20000, took 148 s at load 30-45 on 16 cores (review of b706d77), so 15
21// minutes is a hang and not a slow run. `--timeout-s` changes it for a manual run; the gate script takes no flags.
22export const ENTRY_TIMEOUT_MS = 15 * 60_000;
24export const PINNED = [
25 { fuzzer: 'run', args: ['--n', '60'], seed: 1 },
26 { fuzzer: 'hostile', args: ['--n', '60'], seed: 1 },
27 { fuzzer: 'hostile', args: ['--case', '2366521731'], fixed: true },
28 { fuzzer: 'below-hash', args: ['--n', '20'], seed: 1 },
29 { fuzzer: 'below-hash', args: ['--seed', '20261030', '--n', '100', '--case', '1730047880'], fixed: true },
30 { fuzzer: 'git-semantic', args: ['--n', '20'], seed: 1 },
31 { fuzzer: 'liar', args: ['--n', '60'], seed: 1 },
32 { fuzzer: 'liar', args: ['--op', 'mergebase', '--n', '40'], seed: 1 },
33 { fuzzer: 'protocol', args: ['--n', '100'], seed: 1 },
34 { fuzzer: 'packs', args: ['--n', '40'], seed: 1 },
35 { fuzzer: 'packgen', args: ['--n', '60'], seed: 1 },
36 { fuzzer: 'codec', args: ['--n', '20000'], seed: 1 },
37 { fuzzer: 'usergiven', args: [], seed: 500 },
38 { fuzzer: 'attributes', args: ['--n', '40'], seed: 1 },
39 { fuzzer: 'linemerge', args: ['--n', '300'], seed: 1 },
40 { fuzzer: 'linemerge', args: ['--n', '200', '--runs'], seed: 1 },
41 { fuzzer: 'linemerge', args: ['--n', '150', '--driver', 'union'], seed: 1 },
42 { fuzzer: 'diffscript', args: ['--n', '60'], seed: 1 },
43 { fuzzer: 'diffscript', args: ['--n', '4', '--huge'], seed: 1 },
44];
46// The node argv of one entry. `override` replaces the seed of every entry that is not a fixed regression case.
47export function argvOf(entry, override = null) {
48 const seed = entry.fixed ? [] : ['--seed', String(override ?? entry.seed)];
49 return [...NODE_ARGS, `test/fuzz/${entry.fuzzer}.mjs`, ...entry.args, ...seed];
50}
52function label(argv) {
53 const at = flag => { const i = argv.indexOf(flag); return i < 0 ? [] : [`${flag.slice(2)}=${argv[i + 1]}`]; };
54 return [...at('--seed'), ...at('--case')].join(' ');
55}
57// One entry as a child process. A child that has not exited after `timeoutMs` is killed (SIGKILL, so a child stuck
58// in a system call dies too) and reported as hung: the stage fails instead of waiting forever.
59export function spawnEntry(argv, timeoutMs) {
60 const r = spawnSync(process.execPath, argv, { stdio: 'inherit', timeout: timeoutMs, killSignal: 'SIGKILL' });
61 if (r.error?.code === 'ETIMEDOUT') return { status: 1, hung: true };
62 return { status: r.status ?? 1, hung: false }; // killed by a signal, or not started: a failure
63}
65// Runs the entries in order and stops at the first that fails. Each entry's fuzzer and seed are printed before it
66// starts, and again with the replay command when it fails. `spawn(argv)` returns the exit status, or
67// `{ status, hung }` as spawnEntry does.
68export function runPinned(entries, { override = null, spawn, log, timeoutMs = ENTRY_TIMEOUT_MS }) {
69 for (const entry of entries) {
70 const argv = argvOf(entry, override);
71 log(`fuzz-pinned: start ${entry.fuzzer} ${label(argv)} (node ${argv.join(' ')})`);
72 const r = spawn(argv), res = typeof r === 'number' ? { status: r, hung: false } : r;
73 if (res.hung || res.status !== 0) {
74 const how = res.hung ? `hang: no exit within ${timeoutMs / 1000} s, killed` : `exit=${res.status}`;
75 log(`FUZZ-PINNED FAIL ${entry.fuzzer} ${label(argv)} ${how}`);
76 log(`replay: node ${argv.join(' ')}`);
77 return 1;
78 }
79 }
80 return 0;
81}
83const FLAGS = new Map([['--list', 0], ['--random', 0], ['--only', 1], ['--seed', 1], ['--timeout-s', 1]]);
84function usage(msg) {
85 console.error(`${msg}\nusage: node test/fuzz/pinned.mjs [--list] [--only <fuzzer>] [--random | --seed <n>] [--timeout-s <n>]`);
86 return 2;
87}
89function main(av) {
90 // Every argument is a known flag or a known flag's value; anything else is refused, never ignored.
91 const opt = new Map();
92 for (let i = 0; i < av.length; i++) {
93 const takes = FLAGS.get(av[i]);
94 if (takes === undefined) return usage(`unknown argument ${av[i]}`);
95 if (takes === 1 && i + 1 >= av.length) return usage(`${av[i]} takes a value`);
96 opt.set(av[i], takes === 1 ? av[++i] : true);
97 }
98 const only = opt.get('--only') ?? null, given = opt.get('--seed') ?? null, random = opt.has('--random');
99 const int = v => /^\d+$/.test(v) && Number.isSafeInteger(Number(v));
100 if (given !== null && !int(given)) return usage(`--seed takes a non-negative integer below 2^53, got ${given}`);
101 if (given !== null && random) return usage('--seed and --random exclude each other');
102 const secs = opt.get('--timeout-s') ?? null;
103 if (secs !== null && !(int(secs) && Number(secs) > 0)) return usage(`--timeout-s takes a positive integer, got ${secs}`);
104 const timeoutMs = secs !== null ? Number(secs) * 1000 : ENTRY_TIMEOUT_MS;
105 const entries = PINNED.filter(e => only === null || e.fuzzer === only);
106 if (entries.length === 0) return usage(`--only ${only}: no such fuzzer in the pinned list`);
107 const override = given !== null ? Number(given) : random ? randomInt(1, 1_000_000_000) : null;
108 if (given !== null) console.log(`fuzz-pinned: replaying seed=${override}`);
109 else if (random) console.log(`fuzz-pinned: random mode, seed=${override} replay: node test/fuzz/pinned.mjs --seed ${override}`);
110 if (opt.has('--list')) { for (const e of entries) console.log(`node ${argvOf(e, override).join(' ')}`); return 0; }
111 const status = runPinned(entries, { override, timeoutMs, spawn: argv => spawnEntry(argv, timeoutMs), log: l => console.log(l) });
112 if (status !== 0 && random) console.log(`fuzz-pinned: random mode failed, seed=${override} replay: node test/fuzz/pinned.mjs --seed ${override}`);
113 return status;
114}
116// Entry point when run as a script, also through a symlinked path: node resolves the main module to its real path,
117// so argv[1] and import.meta.url are compared as real paths (compared as strings, a symlinked path ran nothing and
118// exited 0).
119const real = p => { try { return realpathSync(p); } catch { return null; } };
120if (process.argv[1] && real(process.argv[1]) === real(fileURLToPath(import.meta.url))) process.exit(main(process.argv.slice(2)));
Diagnostics7 git calls · 174 ms
CallStatusSizeTime0174 ms
discover200191 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 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 KiB3 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=11990 git.response.cache=UPDATING git.response.duration_ms=3 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 · hit2 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=2 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=10Open 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=3 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=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:02005.6 KiB · hit3 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=5724 git.response.cache=HIT git.response.duration_ms=3 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=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetchtree:0200853 B · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=161 git.response.bytes=853 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=tree:0 git.fetch.wants=fb781d4e4fd58ededa1f1078d937de6f4b1316a2 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=853 git.pkt.payload.max=826 git.sideband.band1.bytes=826 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=826 git.pack.trailer=c89bc485f6ad08d875fc515f3fdd69897096847bOpen pack map
fetch2002.8 KiB161 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2909 git.response.cache=MISS git.response.duration_ms=161 git.fetch.wants=a1d22db2b7dc163a2bf1e2d73b00e8296b239fe9 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=2909 git.pkt.payload.max=2882 git.sideband.band1.bytes=2882 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
- a5e2d83cec6614c2
- Request
- 8007a76b…
- 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