GitHubivarvong
ply
main
1// Case generators over the combinatorial product space. Each knob has named classes so the
2// steering loop can ask for a specific region of the space by name.
3import { indexOfBytes } from '../../src/bytes.js';
5const te = new TextEncoder();
6export const KNOBS = {
7 blob: ['empty', 'tiny', 'text', 'random', 'repetitive', 'boundary', 'big', 'binaryish'],
8 pos: ['start', 'end', 'middle', 'chunk16k', 'chunk32k', 'chunk64k', 'random'],
9 find: ['one', 'short', 'medium', 'over127', 'long'],
10 replace: ['empty', 'same', 'shorter', 'longer', 'over127', 'huge', 'identical'],
11 compression: ['0', '1', '6', '9', '-1'],
12 depth: ['1', '2', '3', '4', '6', '10'],
13 outcome: ['ok', 'zero_matches', 'two_matches', 'missing_path', 'not_a_file', 'cas_conflict'],
14 siblings: ['none', 'few', 'many', 'sortedge'],
15 history: ['1', '2', '5'],
16 mode: ['100644', '100755'],
17 server: ['loose', 'packed', 'bitmap', 'midx-bitmap', 'mixed'],
18};
20const VOCAB = 'the quick brown fox jumps over lazy dog lorem ipsum dolor sit amet git pack delta inflate huffman'.split(' ');
21const SORT_EDGE_NAMES = ['a', 'a-b', 'a.b', 'a0', 'a_b', 'ab', 'A', 'a~', 'z', 'é', 'a b', 'a--', 'a.', '-a', '.hidden', 'ä', '한글', '🚀', '\ufeffREADME'];
22const BOUNDARY_SIZES = [127, 128, 255, 256, 4095, 4096, 16383, 16384, 16385, 32767, 32768, 32769, 65535, 65536, 65537, 131072];
24export function genBlob(rng, cls) {
25 switch (cls) {
26 case 'empty': return new Uint8Array(0);
27 case 'tiny': return te.encode(Array.from({ length: rng.int(1, 12) }, () => rng.pick(VOCAB)).join(' '));
28 case 'text': return genText(rng, rng.int(100, 20000));
29 case 'random': return rng.bytes(rng.int(1, 40000));
30 case 'repetitive': { const pat = rng.pick([te.encode('ab'), rng.bytes(rng.int(1, 300)), te.encode('line of text\n')]); const n = rng.int(1000, 120000); const out = new Uint8Array(n); for (let i = 0; i < n; i++) out[i] = pat[i % pat.length]; return out; }
31 case 'boundary': { const n = rng.pick(BOUNDARY_SIZES); return rng.bool(0.6) ? genText(rng, n) : rng.bytes(n); }
32 case 'big': return genText(rng, rng.int(200000, 1500000));
33 case 'binaryish': { const n = rng.int(500, 60000); const out = new Uint8Array(n); for (let i = 0; i < n; i++) out[i] = rng.bool(0.7) ? 0 : rng.u32() & 0xff; return out; }
34 default: throw new Error(`blob class ${cls}`);
35 }
36}
37function genText(rng, n) {
38 const parts = []; let len = 0;
39 while (len < n) { const w = rng.pick(VOCAB) + (rng.bool(0.15) ? '\n' : ' '); parts.push(w); len += w.length; }
40 return te.encode(parts.join('')).subarray(0, n);
41}
43export function genFind(rng, cls) {
44 const n = { one: 1, short: rng.int(2, 16), medium: rng.int(17, 100), over127: rng.int(128, 200), long: rng.int(300, 2000) }[cls];
45 // bytes outside the text vocab so uniqueness is likely; some fully random
46 return rng.bool(0.5) ? Uint8Array.from({ length: n }, () => 0xc0 + (rng.u32() % 50)) : rng.bytes(n);
47}
48export function genReplace(rng, cls, find) {
49 switch (cls) {
50 case 'empty': return new Uint8Array(0);
51 case 'same': return rng.bytes(find.length);
52 case 'shorter': return rng.bytes(rng.int(0, Math.max(0, find.length - 1)));
53 case 'longer': return rng.bytes(find.length + rng.int(1, 50));
54 case 'over127': return rng.bytes(rng.int(128, 400));
55 case 'huge': return rng.bytes(rng.int(1000, 70000));
56 case 'identical': return find.slice();
57 }
58}
60// Place find into blob at a position class; returns new blob + offset (exactly one occurrence guaranteed).
61export function placeFind(rng, blob, find, posCls) {
62 const L = blob.length;
63 let off;
64 switch (posCls) {
65 case 'start': off = 0; break;
66 case 'end': off = L; break;
67 case 'middle': off = L >> 1; break;
68 case 'chunk16k': off = chunkStraddle(rng, L, 16384, find.length); break;
69 case 'chunk32k': off = chunkStraddle(rng, L, 32768, find.length); break;
70 case 'chunk64k': off = chunkStraddle(rng, L, 65536, find.length); break;
71 default: off = rng.int(0, L);
72 }
73 const out = new Uint8Array(L + find.length);
74 out.set(blob.subarray(0, off)); out.set(find, off); out.set(blob.subarray(off), off + find.length);
75 return { blob: out, off };
76}
77function chunkStraddle(rng, L, boundary, n) {
78 const k = Math.max(1, Math.floor(L / boundary));
79 const b = boundary * rng.int(1, k);
80 return Math.max(0, Math.min(L, b - rng.int(1, Math.max(1, n - 1))));
81}
82export const countOccurrences = (hay, needle) => { let c = 0, i = 0; while ((i = indexOfBytes(hay, needle, i)) >= 0) { c++; i += Math.max(1, needle.length); } return c; };
84export function genPath(rng, depthCls, siblingsCls) {
85 const depth = parseInt(depthCls, 10);
86 const name = () => (siblingsCls === 'sortedge' ? rng.pick(SORT_EDGE_NAMES) : rng.pick(['src', 'lib', 'pkg', 'a', 'b', 'deep', 'x-y', 'n.m']) + (rng.bool(0.5) ? rng.int(0, 9) : ''));
87 const dirs = Array.from({ length: depth - 1 }, name);
88 return [...dirs, (siblingsCls === 'sortedge' ? rng.pick(SORT_EDGE_NAMES) : 'f' + rng.int(0, 999)) + rng.pick(['.txt', '.js', '', '.bin'])].join('/');
89}
91export function genSiblings(rng, cls, path) {
92 const n = { none: 0, few: rng.int(1, 4), many: rng.int(10, 40), sortedge: rng.int(6, 14) }[cls];
93 const files = {};
94 const comps = path.split('/');
95 for (let i = 0; i < n; i++) {
96 const depth = rng.int(0, comps.length - 1);
97 const base = comps.slice(0, depth);
98 let nm = cls === 'sortedge' ? rng.pick(SORT_EDGE_NAMES) : 's' + rng.int(0, 9999);
99 const asDir = rng.bool(0.3);
100 const p = [...base, nm, ...(asDir ? ['inner' + rng.int(0, 9)] : [])].join('/');
101 const clash = (x, y) => x === y || x.startsWith(y + '/') || y.startsWith(x + '/');
102 if (clash(p, path) || Object.keys(files).some(q => clash(p, q))) continue;
103 const kind = rng.weighted([['file', 8], ['exec', 1], ['symlink', 1]]);
104 files[p] = kind === 'symlink' ? { symlink: rng.pick(['../x', 'f0.txt', '/dev/null']) } : { mode: kind === 'exec' ? '100755' : '100644', data: genBlob(rng, rng.pick(['tiny', 'text', 'random', 'empty'])) };
105 }
106 return files;
107}
109// A complete case spec. hints: partial {knob: class} to steer.
110export function genCase(seedRng, hints = {}) {
111 const rng = seedRng;
112 const pick = k => hints[k] ?? rng.pick(KNOBS[k]);
113 const c = { blob: pick('blob'), pos: pick('pos'), find: pick('find'), replace: pick('replace'), compression: pick('compression'), depth: pick('depth'), outcome: pick('outcome'), siblings: pick('siblings'), history: pick('history'), mode: pick('mode'), server: pick('server') };
114 const path = genPath(rng, c.depth, c.siblings);
115 let find = genFind(rng, c.find);
116 const replace = genReplace(rng, c.replace, find);
117 let blob = genBlob(rng, c.blob);
118 let off = -1;
119 // ensure baseline has zero occurrences, then place per outcome
120 for (let tries = 0; countOccurrences(blob, find) > 0 && tries < 20; tries++) find = genFind(rng, c.find);
121 if (countOccurrences(blob, find) > 0) blob = genBlob(rng, 'random');
122 if (c.outcome !== 'zero_matches') { ({ blob, off } = placeFind(rng, blob, find, c.pos)); }
123 if (c.outcome === 'two_matches') { ({ blob } = placeFind(rng, blob, find, 'random')); }
124 const occurrences = countOccurrences(blob, find);
125 if (occurrences === 1) off = indexOfBytes(blob, find); // overlapping placements can collapse; truth is what the scanner will see
126 const files = { ...genSiblings(rng, c.siblings, path) };
127 let editPath = path;
128 if (c.outcome === 'missing_path') editPath = path + '.missing';
129 if (c.outcome === 'not_a_file') { const comps = path.split('/'); editPath = comps.length > 1 ? comps.slice(0, -1).join('/') : path; if (comps.length === 1) files[path + '/inner'] = { mode: '100644', data: new Uint8Array(0) }; }
130 if (!(c.outcome === 'not_a_file' && path.split('/').length === 1)) files[path] = { mode: c.mode, data: blob };
131 const same = find.length === replace.length && find.every((b, i) => b === replace[i]);
132 const matchOutcome = occurrences !== 1 ? 'match_count' : same ? 'noop' : 'ok';
133 // a single injected race is absorbed by editFile's one internal retry: the caller sees 'ok' on attempt 1 (run.mjs checks the
134 // attempt-0 root failed with cas_conflict and the retry's parent is the racer's commit)
135 const expected = ['ok', 'zero_matches', 'two_matches'].includes(c.outcome) ? matchOutcome : c.outcome === 'cas_conflict' ? matchOutcome : 'not_found';
136 return { knobs: c, path, editPath, find, replace, blob, off, occurrences, files, expected, compression: parseInt(c.compression, 10), history: parseInt(c.history, 10) };
137}
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=ls-refs git.upstream.dur_ms=3 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 KiB93 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=92 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=93 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 · hit4 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=4 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 · 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=919 git.response.cache=HIT git.response.duration_ms=2 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 · 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=5724 git.response.cache=HIT git.response.duration_ms=2 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 · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=853 git.response.cache=HIT git.response.duration_ms=4 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
fetch2003.2 KiB69 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=69 git.response.bytes=3260 git.response.cache=MISS git.response.duration_ms=69 git.fetch.wants=8e1e5115007fe220e8d8f60e617fb249b34b01ff 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=3260 git.pkt.payload.max=3233 git.sideband.band1.bytes=3233 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
- a5e183b6d8943014
- Request
- e8419f01…
- 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