GitHubivarvong

ply

main
ply7 git calls171 ms27 KiB4 cachedprotocol v2
112 lines6.8 KiBRaw
2// Inside-cell boundaries. For every cell with a definite expected outcome (landed, rejected, partial: the cells whose
3// bytes git writes, and so the bytes a fault can corrupt), take its canonical response bytes and enumerate, exhaustively,
4// every single-bit flip, every single-byte deletion, every single-byte insertion from ALPHABET at every position, and
5// every truncation. Each mutant goes through the real push path. It must answer the cell's own outcome or 'ambiguous',
6// never a different definite outcome; a rejection may only soften (cas_conflict → push_rejected: 'fresh' → 'no'), never
7// harden. Enumeration, not sampling: no randomness. PUSH_SPACE_WORKERS sets the worker count.
8//
9// The space is split into SLICES fixed slices (base j belongs to slice j % SLICES), one test file per slice
10// (push-outcome-boundary.<s>.test.js), so CI's weighted shards (vitest.config.ts) put the slices on different runners
11// and no one test holds a runner for the whole space (#263: #251 grew it from 2,772 bases / 7,419,600 mutants to
12// 4,592 / 12,981,904, and the single test passed its 30 min bound under nightly's one-runner `npm test`).
13// push-outcome-boundary.plan.test.js checks that the slice files are exactly 0..SLICES-1 and that the slices cover
14// every base exactly once, so a missing or extra slice file fails instead of silently dropping part of the space.
15import { isMainThread, parentPort, workerData, Worker } from 'node:worker_threads';
16import { availableParallelism } from 'node:os';
17import * as space from './push-outcome.space.js';
18import { runPush, sameOutcome } from './harness.js';
20export const SLICES = 4;
22// structural bytes: NUL, the band-1/band-2 designators, LF, space, a pkt-length digit, a status letter, a non-text byte
23export const ALPHABET = [0x00, 0x01, 0x02, 0x0a, 0x20, 0x30, 0x6f, 0xff];
25// The distinct (request, response bytes) pairs of the definite cells, in product order.
26export function bases() {
27 const seen = new Map();
28 space.walk(c => {
29 const want = space.expected(c);
30 if (!space.isDefinite(want)) return;
31 const r = space.render(c);
32 const key = `${JSON.stringify([r.commands, r.opts, r.limits])}|${Buffer.from(r.response.bytes).toString('hex')}`;
33 if (!seen.has(key)) seen.set(key, { r, want, id: space.cellId(c) });
34 });
35 return [...seen.values()];
38// The indexes into bases() that slice `s` of `n` owns.
39export function sliceOf(count, s, n) {
40 const out = [];
41 for (let j = s; j < count; j += n) out.push(j);
42 return out;
45export function* mutants(b) {
46 const n = b.length;
47 for (let i = 0; i < n; i++) for (let bit = 0; bit < 8; bit++) { const m = b.slice(); m[i] ^= 1 << bit; yield ['flip', m]; }
48 for (let i = 0; i < n; i++) yield ['delete', new Uint8Array([...b.subarray(0, i), ...b.subarray(i + 1)])];
49 for (let i = 0; i <= n; i++) for (const a of ALPHABET) yield ['insert', new Uint8Array([...b.subarray(0, i), a, ...b.subarray(i)])];
50 for (let i = 0; i < n; i++) yield ['truncate', b.slice(0, i)];
53// Mutants of one base: 8n flips, n deletions, 8(n+1) insertions, n truncations.
54export const mutantCount = n => 8 * n + n + ALPHABET.length * (n + 1) + n;
56async function shard(slice, slices, k, w) {
57 Error.stackTraceLimit = 0; // speed: the stacks of the millions of expected errors are never read
58 const all = bases();
59 const mine = sliceOf(all.length, slice, slices);
60 const out = { bases: all.length, sliceBases: mine.length, cases: 0, kinds: {}, same: 0, ambiguous: 0, softened: 0, violations: 0, byWant: {}, bad: [] };
61 for (let x = k; x < mine.length; x += w) {
62 const { r, want, id } = all[mine[x]];
63 for (const [kind, bytes] of mutants(r.response.bytes)) {
64 out.cases++; out.kinds[kind] = (out.kinds[kind] ?? 0) + 1;
65 const got = await runPush(r, { bytes, end: 'eof' });
66 if (sameOutcome(want, got)) out.same++;
67 else if (got.tag === 'ambiguous') out.ambiguous++;
68 else if (want.tag === 'rejected' && want.code === 'cas_conflict' && got.tag === 'rejected' && got.code === 'push_rejected') out.softened++;
69 else {
70 out.violations++;
71 const g = `${want.tag}${want.code ? `(${want.code})` : ''} -> ${got.tag}${got.code ? `(${got.code})` : ''} by ${kind}`;
72 out.byWant[g] = (out.byWant[g] ?? 0) + 1;
73 if (out.bad.length < 5) out.bad.push(`${id} ${kind}: want ${JSON.stringify(want)} got ${JSON.stringify(got)} bytes ${JSON.stringify(Buffer.from(bytes).toString('latin1'))}`);
74 }
75 }
76 }
77 return out;
80if (!isMainThread && workerData?.pushOutcomeBoundary === true) {
81 shard(workerData.slice, workerData.slices, workerData.k, workerData.w).then(r => parentPort.postMessage(r));
84// Register the test for slice `slice` (called by push-outcome-boundary.<slice>.test.js).
85export async function boundarySlice(slice) {
86 const { test } = await import('vitest');
87 const assert = (await import('node:assert/strict')).default;
88 test(`push outcome boundaries, slice ${slice}/${SLICES}: every single-byte mutant of every definite cell is its own outcome or ambiguous`, { timeout: 1_800_000 }, async () => {
89 const w = +(process.env.PUSH_SPACE_WORKERS ?? Math.min(4, availableParallelism()));
90 const t0 = performance.now();
91 const shards = await Promise.all(Array.from({ length: w }, (_, k) => new Promise((resolve, reject) => {
92 const wk = new Worker(new URL(import.meta.url), { workerData: { pushOutcomeBoundary: true, slice, slices: SLICES, k, w } });
93 wk.once('message', resolve); wk.once('error', reject);
94 })));
95 const ms = performance.now() - t0;
96 const sum = { cases: 0, kinds: {}, same: 0, ambiguous: 0, softened: 0, violations: 0, byWant: {}, bad: [] };
97 for (const s of shards) {
98 for (const k of ['cases', 'same', 'ambiguous', 'softened', 'violations']) sum[k] += s[k];
99 for (const [k, v] of Object.entries(s.byWant)) sum.byWant[k] = (sum.byWant[k] ?? 0) + v;
100 for (const [k, v] of Object.entries(s.kinds)) sum.kinds[k] = (sum.kinds[k] ?? 0) + v;
101 sum.bad.push(...s.bad);
102 }
103 console.log(` push-outcome boundaries slice ${slice}/${SLICES}: ${shards[0].sliceBases} of ${shards[0].bases} distinct definite cells (request, bytes); ${sum.cases} mutants ${JSON.stringify(sum.kinds)} in ${(ms / 1000).toFixed(1)} s on ${w} workers; own outcome ${sum.same}, ambiguous ${sum.ambiguous}, cas_conflict softened to push_rejected ${sum.softened}, violations ${sum.violations}`);
104 for (const [g, n] of Object.entries(sum.byWant).sort((a, b) => b[1] - a[1])) console.log(` ${String(n).padStart(8)} ${g}`);
105 for (const b of sum.bad.slice(0, 10)) console.log(` e.g. ${b}`);
106 assert.equal(sum.violations, 0);
107 // every mutant of every base of this slice ran: none lost to a worker that ended early
108 const all = bases();
109 const want = sliceOf(all.length, slice, SLICES).reduce((n, j) => n + mutantCount(all[j].r.response.bytes.length), 0);
110 assert.equal(sum.cases, want);
111 });
Diagnostics7 git calls · 171 ms
CallStatusSizeTime0171 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 KiB2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=11990
git.response.cache=UPDATING
git.response.duration_ms=2
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=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=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=5323b9266eea5ded637285d1c5320699f12be76e
Open 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=3
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=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetchtree:02001.4 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=157
git.response.bytes=1428
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=74d7bb09987bbe78a9c0ea8f43a1b5a4e079f538
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=1428
git.pkt.payload.max=1401
git.sideband.band1.bytes=1401
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1401
git.pack.trailer=65ea1a3aeef333a80a2dfa3f441e629d90497e8e
Open pack map
fetch2002.9 KiB157 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2952
git.response.cache=MISS
git.response.duration_ms=157
git.fetch.wants=7156f0b2189c2dbed5cb55de19912a0d3cfb8319
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=2952
git.pkt.payload.max=2925
git.sideband.band1.bytes=2925
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
a5e13fcd9c641293
Request
0a5ba547…
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