GitHubivarvong

ply

main
ply7 git calls91 ms33 KiB4 cachedprotocol v2
380 lines28 KiBRaw
1// The advertisement enumerator (test/space/advertisement.space.js). Two passes:
2// derived every cell of caps and refs through ply's real path (createTransport → discover / lsRefs, with an in-process
3// fetch that serves the rendered bytes: no network), compared with the table; the rule (`consistent`)
4// checked on every cell of the four decisions.
5// observed cells judged by real git 2.50: a synthetic smart-HTTP server serves the cell's advertisement and ls-refs
6// response and forwards fetch requests to `git http-backend`; `git ls-remote` / `git fetch` / `git push` /
7// `git clone` are the oracle for accept vs refuse (and, for fetch, the request lines and the pack-objects
8// invocation upload-pack makes). ply runs over real HTTP against the same server. Real http-backend
9// configurations (uploadpack.*, lsrefs.unborn, transfer.advertiseSID, a sha256 repository, receive.*) check
10// that the renderer writes what git writes.
11import { test, beforeAll as before, afterAll as after } from 'vitest';
12import assert from 'node:assert/strict';
13import http from 'node:http';
14import { join } from 'node:path';
15import { mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'node:fs';
16import { fileURLToPath } from 'node:url';
17import * as S from './advertisement.space.js';
18import { git, gitAsync, tmpRoot, makeBareRepo, startGitServer, noMaintenance, initRepo } from '../server.js';
19// ADV_SPACE_SRC=<dir>: run the space against another copy of src/ (e.g. `git archive train/1 src`) to see where it disagrees
20const SRC = process.env.ADV_SPACE_SRC ?? '../../src';
21const { createTransport, GitHttp } = await import(`${SRC}/client.js`);
22const { discover } = await import(`${SRC}/discover.js`);
23const { lsRefs } = await import(`${SRC}/lsrefs.js`);
24import { pktInit, pktStep } from '../../src/pktline.js';
25import { Tracer } from '../../src/otel.js';
26import { td } from '../../src/bytes.js';
27import { unwrap, unwrapAsync } from '../unwrap.js';
29const spanStub = { set() {}, event() {}, end() {}, error() {} };
30const tracer = { span: async (_n, _o, fn) => fn(spanStub) };
31const FX = { main: '1'.repeat(40), tag: '2'.repeat(40), peeled: '3'.repeat(40), other: '4'.repeat(40) };
32const INFO_KEYS = ['agent', 'objectFormat', 'fetch', 'filter', 'shallow', 'waitForDone', 'refInWant', 'sidebandAll', 'lsRefs', 'lsRefsUnborn', 'serverOption', 'sessionId'];
33const pick = (o, keys) => Object.fromEntries(keys.map(k => [k, o[k]]));
34const WHY_MESSAGE = { protocol: /did not answer protocol v2/, 'ls-refs': /advertise ls-refs/, fetch: /advertise fetch/, 'object-format': /object-format/, 'pkt length': /bad pkt-line length/, 'advertisement framing': /^advertisement:/, record: /^ls-refs: malformed line/, 'listing framing': /^ls-refs: (response ended|delim|unexpected|data after)/ };
36// A Result (0.2.0) or, from another src (ADV_SPACE_SRC), the value or the throw it replaced.
37const isResult = v => v !== null && typeof v === 'object' && typeof v.ok === 'boolean' && ('value' in v || 'error' in v);
38const valueOf = v => (isResult(v) ? unwrap(v) : v);
39const outcomeOf = async (fn, okMap) => { try { return { tag: 'ok', ...okMap(valueOf(await fn())) }; } catch (e) { return { tag: e.code ?? 'untyped', message: e.message }; } };
40// against another src (ADV_SPACE_SRC), only the info fields that src reports are compared (lsRefs, sidebandAll, sessionId are new)
41const capsOk = info => ({ info: pick(info, process.env.ADV_SPACE_SRC ? INFO_KEYS.filter(k => info[k] !== undefined) : INFO_KEYS) });
42const refsOk = ({ refs, head }) => ({ refs: [...refs.values()].map(r => [r.name, r.oid, r.peeled ?? null, r['symref-target'] ?? null]), head });
43function judge(want, got) {
44 const w = judgeWhy(want, got);
45 return w;
47// the disagreement class of a wrong cell, for the census: `want -> got`, or `ok -> ok(value)`, or `tag (message)`
48const wrongClass = (want, got) => (want.tag !== got.tag ? `${want.tag} -> ${got.tag}` : want.tag === 'ok' ? 'ok -> ok (another value)' : `${want.tag} (another reason)`);
49function judgeWhy(want, got) {
50 if (want.tag !== got.tag) return `want ${want.tag}${want.why ? ` (${want.why})` : ''}, got ${got.tag}: ${got.message ?? ''}`;
51 if (want.tag === 'ok') { try { assert.deepEqual(want.info ? { info: got.info } : { refs: got.refs, head: got.head }, want.info ? { info: pick(want.info, Object.keys(got.info)) } : { refs: want.refs, head: want.head }); } catch (e) { return `value: ${e.message.split('\n').slice(0, 12).join(' ')}`; } }
52 else if (want.why && WHY_MESSAGE[want.why] && !WHY_MESSAGE[want.why].test(got.message)) return `want ${want.tag} (${want.why}), message: ${got.message}`;
53 return null;
55const census = classes => Object.entries(classes).sort((a, b) => b[1] - a[1]).map(([k, n]) => `${n} ${k}`).join('; ');
57// ---- the derived pass: an in-process fetch serving the rendered cell ----
58function stubTransport(serve) {
59 const fetchImpl = async (url, init = {}) => {
60 const r = serve(init.method === 'POST' ? 'post' : 'get');
61 if (r.reset) throw new TypeError('fetch failed');
62 return new Response(r.body, { status: r.status ?? 200, headers: { 'content-type': r.contentType } });
63 };
64 return valueOf(createTransport('http://cell.invalid/r.git', { tracer, fetchImpl }));
66const lsRefsReply = body => ({ status: 200, contentType: 'application/x-git-upload-pack-result', body });
68test('caps: every cell through discover() (derived from the table)', async t => {
69 const cells = S.capsCells();
70 const tally = {}, wrong = [], rule = [], classes = {};
71 Error.stackTraceLimit = 0;
72 for (const c of cells) {
73 const want = S.expectedCaps(c);
74 const r = S.consistent('caps', want); if (r) rule.push(`${S.capsCellId(c)}: ${r}`);
75 const tr = stubTransport(() => S.renderCaps(c, FX));
76 const got = await outcomeOf(() => discover(tr), capsOk);
77 tally[want.ply.tag] = (tally[want.ply.tag] ?? 0) + 1;
78 const w = judge(want.ply, got);
79 if (w) { const k = wrongClass(want.ply, got); classes[k] = (classes[k] ?? 0) + 1; wrong.push(wrong.length < 20 ? `${S.capsCellId(c)}: ${w}` : ''); }
80 }
81 Error.stackTraceLimit = 10;
82 console.log(`caps cells=${cells.length} ${Object.entries(tally).map(([k, n]) => `${k}=${n}`).join(' ')}`);
83 if (wrong.length) console.log(`wrong: ${census(classes)}`);
84 assert.deepEqual(rule, [], 'the rule');
85 assert.equal(wrong.length, 0, `${wrong.length} wrong:\n${wrong.slice(0, 20).join('\n')}`);
86});
88test('refs: every cell through lsRefs() (derived from the table)', async t => {
89 const cells = S.refsCells();
90 const tally = {}, wrong = [], rule = [], classes = {};
91 for (const c of cells) {
92 const want = S.expectedRefs(c, FX);
93 const r = S.consistent('refs', want); if (r) rule.push(`${S.refsCellId(c)}: ${r}`);
94 const tr = stubTransport(() => lsRefsReply(S.renderRefs(c, FX)));
95 const got = await outcomeOf(() => lsRefs(tr), refsOk);
96 tally[want.ply.tag] = (tally[want.ply.tag] ?? 0) + 1;
97 const w = judge(want.ply, got);
98 if (w) { const k = wrongClass(want.ply, got); classes[k] = (classes[k] ?? 0) + 1; wrong.push(`${S.refsCellId(c)}: ${w}`); }
99 }
100 console.log(`refs cells=${cells.length} ${Object.entries(tally).map(([k, n]) => `${k}=${n}`).join(' ')}`);
101 if (wrong.length) console.log(`wrong: ${census(classes)}`);
102 assert.deepEqual(rule, [], 'the rule');
103 assert.deepEqual(wrong, []);
104});
106test('push and request: the rule holds on every cell of the table', () => {
107 assert.deepEqual(S.pushCells().map(c => S.consistent('push', S.expectedPush(c)) && S.pushCellId(c)).filter(Boolean), []);
108 assert.deepEqual(S.requestCells().map(c => S.consistent('request', S.expectedRequest(c)) && S.requestCellId(c)).filter(Boolean), []);
109});
111// ---- the observed pass ----
112let root, cleanup, backend, front, hookLog, fx, fx256;
113const routes = new Map(); // key → { kind: 'synthetic', caps?, refs } | { kind: 'proxy', repo }
114const posts = new Map(); // key → [request body Buffers]
115const observed = { caps: 0, refs: 0, push: 0, request: 0 };
117function startFront(backendUrl) {
118 const up = new URL(backendUrl);
119 const server = http.createServer((req, res) => {
120 const chunks = [];
121 req.on('data', d => chunks.push(d));
122 req.on('end', () => {
123 const body = Buffer.concat(chunks);
124 const [, key, ...rest] = req.url.split('/');
125 const route = routes.get(key);
126 if (!route) { res.writeHead(404); res.end(); return; }
127 if (req.method === 'POST') (posts.get(key) ?? posts.set(key, []).get(key)).push(body);
128 const isLsRefs = /command=ls-refs/.test(body.subarray(0, 64).toString());
129 if (route.kind === 'synthetic' && (req.method === 'GET' || isLsRefs)) {
130 const r = req.method === 'GET' ? route.caps : lsRefsReply(route.refs);
131 if (r.reset) { req.socket.destroy(); return; }
132 res.writeHead(r.status, { 'content-type': r.contentType }); res.end(Buffer.from(r.body)); return;
133 }
134 const p = http.request({ host: up.hostname, port: up.port, path: `/${route.repo}/${rest.slice(1).join('/')}`, method: req.method, headers: { ...req.headers, host: up.host } }, r => { res.writeHead(r.statusCode, r.headers); r.pipe(res); });
135 p.end(body);
136 });
137 });
138 server.keepAliveTimeout = 120_000; server.headersTimeout = 121_000;
139 return new Promise(resolve => server.listen(0, '127.0.0.1', () => resolve({ url: `http://127.0.0.1:${server.address().port}`, close: () => new Promise(r => { server.close(r); server.closeAllConnections?.(); }) })));
141let keyN = 0;
142const route = r => { const key = `k${keyN++}`; routes.set(key, r); return key; };
143const urlOf = key => `${front.url}/${key}/r.git`;
144const ply = url => unwrap(GitHttp.create(url, { tracer: new Tracer() }));
145const gitIn = async (args, cwd) => gitAsync(cwd ?? root, ['-c', 'protocol.version=2', ...args]);
146const freshRepo = name => { const d = join(root, `c-${name}-${keyN}`); rmSync(d, { recursive: true, force: true }); git(root, ['init', '-q', d]); return d; };
147// the request lines of a v2 command body, after the delim (capabilities before it: command, agent, object-format)
148const requestArgs = body => {
149 const { frames } = unwrap(pktStep(pktInit(), new Uint8Array(body)));
150 const out = { caps: [], args: [] };
151 let after = false;
152 for (const f of frames) { if (f.kind === 'delim') after = true; else if (f.kind === 'data') (after ? out.args : out.caps).push(td.decode(f.payload).replace(/\n$/, '')); }
153 return out;
154};
155const fetchBodies = key => (posts.get(key) ?? []).map(requestArgs).filter(r => r.caps.includes('command=fetch'));
157before(async () => {
158 ({ root, cleanup } = tmpRoot());
159 const hookCfg = join(root, 'gitconfig'); hookLog = join(root, 'hooklog');
160 writeFileSync(hookCfg, `[uploadpack]\n\tpackObjectsHook = ${fileURLToPath(new URL('../fuzz/pack-objects-hook.sh', import.meta.url))}\n`);
161 backend = await startGitServer(root, { GIT_CONFIG_GLOBAL: hookCfg, PLY_HOOK_LOG: hookLog });
162 front = await startFront(backend.url);
163 const work = join(root, 'work'); mkdirSync(work); initRepo(work);
164 const commit = (f, m) => { writeFileSync(join(work, f), `${m}\n`.repeat(40)); git(work, ['add', f]); git(work, ['-c', 'user.name=a', '-c', 'user.email=a@b', 'commit', '-q', '-m', m]); return git(work, ['rev-parse', 'HEAD']).trim(); };
165 commit('a', 'one'); const two = commit('b', 'two');
166 git(work, ['-c', 'user.name=a', '-c', 'user.email=a@b', 'tag', '-a', '-m', 'v1', 'v1', two]);
167 commit('c', 'three'); const main = commit('d', 'four');
168 git(work, ['checkout', '-q', '-b', 'other', two]); const other = commit('e', 'other'); git(work, ['checkout', '-q', 'main']);
169 for (const name of ['fx', 'rq-on', 'rq-off']) {
170 const bare = makeBareRepo(root, name);
171 git(work, ['push', '-q', bare, 'main', 'other', 'v1']);
172 git(bare, ['config', 'uploadpack.allowFilter', String(name !== 'rq-off')]);
173 if (name === 'fx') for (const k of ['uploadpack.allowRefInWant', 'uploadpack.allowSidebandAll']) git(bare, ['config', k, 'true']);
174 }
175 fx = { main, tag: git(work, ['rev-parse', 'v1']).trim(), peeled: two, other };
176 fx256 = { main: 'c'.repeat(64), tag: 'd'.repeat(64), peeled: 'e'.repeat(64), other: 'f'.repeat(64) };
177});
178after(async () => { await front?.close(); await backend?.close(); cleanup?.(); });
180const REAL_CONFIGS = [
181 { name: 'default (allowFilter)', config: [], cell: {} },
182 { name: 'uploadpack.allowFilter=false', config: [['uploadpack.allowFilter', 'false']], cell: { fetch: ['shallow', 'wait-for-done'] } },
183 { name: 'allowRefInWant + allowSidebandAll', config: [['uploadpack.allowRefInWant', 'true'], ['uploadpack.allowSidebandAll', 'true']], cell: { fetch: S.FETCH_FEATURES } },
184 { name: 'lsrefs.unborn=ignore', config: [['lsrefs.unborn', 'ignore']], cell: { lsRefs: 'plain' } },
185 { name: 'transfer.advertiseSID=true', config: [['transfer.advertiseSID', 'true']], cell: { sessionId: 'present' } },
186 { name: 'sha256 repository', config: [], sha256: true, cell: { objectFormat: 'sha256' } },
187];
188const capsCell = over => {
189 const c = { protocol: S.PROTOCOLS[0] };
190 for (const a of S.CAPS_AXES) {
191 const want = over[a.name] ?? (a.name === 'fetch' ? S.CANONICAL_CAPS.fetch.split(',') : S.CANONICAL_CAPS[a.name]);
192 c[a.name] = a.name === 'fetch' ? a.variants.find(v => v.tag === 'features' && v.set.join(',') === want.join(',')) : a.variants.find(v => v.tag === want);
193 }
194 return c;
195};
196// the advertisement as lines, with the run's agent and session id normalized; a capability the model has no axis for (a
197// newer git's) is dropped and reported, and so are fetch features beyond the five
198const MODELLED = /^(version 2|agent|ls-refs|fetch|server-option|object-format|session-id)(=|\n|$)/;
199const advLines = (body, extra = []) => unwrap(pktStep(pktInit(), new Uint8Array(body))).frames
200 .map(f => (f.kind === 'data' ? td.decode(f.payload) : `<${f.kind}>`))
201 .filter(l => l.startsWith('<') || MODELLED.test(l) || (extra.push(l.trim()), false))
202 .map(l => l.replace(/^agent=git\/.*\n$/, `agent=${S.AGENT}\n`).replace(/^session-id=.*\n$/, 'session-id=sid-1\n')
203 .replace(/^fetch=(.*)\n$/, (_, v) => `fetch=${v.split(' ').filter(x => S.FETCH_FEATURES.includes(x)).join(' ')}\n`));
205test('real git http-backend configurations advertise exactly what the renderer writes for their cell', async t => {
206 for (const rc of REAL_CONFIGS) {
207 const name = `real-${rc.name.replace(/\W+/g, '-')}`;
208 const bare = join(root, `${name}.git`);
209 git(root, ['init', '--bare', '-q', '-b', 'main', ...(rc.sha256 ? ['--object-format=sha256'] : []), bare]); noMaintenance(bare);
210 for (const [k, v] of [['uploadpack.allowFilter', 'true'], ['http.receivepack', 'true'], ...rc.config]) git(bare, ['config', k, v]);
211 const res = await fetch(`${backend.url}/${name}.git/info/refs?service=git-upload-pack`, { headers: { 'Git-Protocol': 'version=2' } });
212 assert.equal(res.headers.get('content-type'), 'application/x-git-upload-pack-advertisement');
213 const unmodelled = [];
214 const real = advLines(Buffer.from(await res.arrayBuffer()), unmodelled);
215 if (unmodelled.length) console.log(`${rc.name}: capabilities with no axis (this git is newer than the model): ${unmodelled.join(', ')}`);
216 const cell = capsCell(rc.cell);
217 assert.deepEqual(real, advLines(S.renderCaps(cell, fx).body), rc.name);
218 const got = await outcomeOf(() => unwrapAsync(ply(`${backend.url}/${name}.git`).discover()), capsOk);
219 if (got.info) { got.info.agent = got.info.agent.replace(/^git\/.*/, S.AGENT); got.info.fetch = got.info.fetch.filter(x => S.FETCH_FEATURES.includes(x)); if (got.info.sessionId) got.info.sessionId = 'sid-1'; }
220 assert.equal(judge(S.expectedCaps(cell).ply, got), null, `${rc.name}: ply discover`);
221 console.log(`${rc.name}: ${S.capsCellId(cell)} → ${got.tag}`);
222 }
223});
225test('caps: every cell within one deviation of git\'s default, judged by git ls-remote and git fetch', async t => {
226 const cells = S.capsCells().filter(c => S.capsDeviations(c) <= 1);
227 const bad = [];
228 for (const c of cells) {
229 const want = S.expectedCaps(c);
230 const e = c.protocol.tag === 'v2' ? S.effectiveCaps(c) : null;
231 const key = route({ kind: 'synthetic', repo: 'fx.git', caps: S.renderCaps(c, fx), refs: S.renderRefs({ record: { tag: 'plain' }, eol: { tag: 'lf' }, framing: { tag: 'flush' } }, e?.objectFormat === 'sha256' ? fx256 : fx) });
232 const id = S.capsCellId(c);
233 const ls = await gitIn(['ls-remote', urlOf(key)]);
234 const lsGot = ls.status === 0 ? 'ok' : 'refuse';
235 if (lsGot !== want.git.lsRemote) bad.push(`${id}: git ls-remote ${lsGot} (${ls.stderr.trim().split('\n').pop()}), table ${want.git.lsRemote}`);
236 const got = await outcomeOf(() => unwrapAsync(ply(urlOf(key)).discover()), capsOk);
237 const w = judge(want.ply, got); if (w) bad.push(`${id}: ply over HTTP: ${w}`);
238 // git fetch on the cells that vary the fetch command, and git's default: which features git uses, from its requests
239 if (c.protocol.tag === 'v2' && e.objectFormat === 'sha1' && want.git.lsRemote === 'ok' && (S.capsDeviations(c) === 0 || (c.fetch.tag !== 'features' || c.fetch.set.join(',') !== S.CANONICAL_CAPS.fetch))) {
240 const plain = await gitIn(['fetch', '-q', '--no-tags', '--filter=blob:none', urlOf(key), 'refs/heads/main'], freshPartial());
241 const fetchGot = plain.status === 0 ? 'ok' : 'refuse';
242 if (fetchGot !== want.git.fetch) bad.push(`${id}: git fetch ${fetchGot} (${plain.stderr.trim().split('\n').pop()}), table ${want.git.fetch}`);
243 if (fetchGot === 'ok') {
244 const args = fetchBodies(key).flatMap(b => b.args);
245 const used = new Set();
246 if (args.some(a => a.startsWith('filter '))) used.add('filter');
247 if (args.includes('sideband-all')) used.add('sideband-all');
248 if (args.some(a => a.startsWith('want-ref '))) used.add('ref-in-want');
249 // by oid: with ref-in-want git 2.50 cannot read a deepened want-ref response ("expected 'packfile', received 'shallow-info'")
250 const deep = await gitIn(['fetch', '-q', '--no-tags', '--depth=1', urlOf(key), fx.main], freshRepo('deep'));
251 if (deep.status === 0) used.add('shallow');
252 else if (!/Server does not support shallow requests/.test(deep.stderr)) bad.push(`${id}: git fetch --depth=1: ${deep.stderr.trim()}`);
253 const plyFeatures = want.ply.tag === 'ok' ? want.ply.info.fetch.filter(f => f !== 'wait-for-done') : [];
254 if ([...used].sort().join() !== plyFeatures.sort().join()) bad.push(`${id}: git uses [${[...used].sort()}], ply reads [${plyFeatures.sort()}]`);
255 if (!/filtering not recognized by server/.test(plain.stderr) !== used.has('filter')) bad.push(`${id}: git's filter warning disagrees with its request`);
256 }
257 }
258 observed.caps++;
259 }
260 console.log(`caps observed=${cells.length}`);
261 assert.deepEqual(bad, []);
262});
263const freshPartial = () => { const d = freshRepo('partial'); git(d, ['config', 'extensions.partialClone', 'origin']); git(d, ['config', 'remote.origin.promisor', 'true']); return d; };
265test('refs: every cell, judged by git ls-remote; a duplicate ref resolves to its first listing in git fetch', async t => {
266 const bad = [];
267 for (const c of S.refsCells()) {
268 const want = S.expectedRefs(c, fx);
269 const key = route({ kind: 'synthetic', repo: 'fx.git', caps: S.renderCaps(capsCell({}), fx), refs: S.renderRefs(c, fx) });
270 const ls = await gitIn(['ls-remote', urlOf(key)]);
271 const lsGot = ls.status === 0 ? 'ok' : 'refuse';
272 if (lsGot !== want.git) bad.push(`${S.refsCellId(c)}: git ls-remote ${lsGot} (${ls.stderr.trim().split('\n').pop()}), table ${want.git}`);
273 const got = await outcomeOf(() => unwrapAsync(ply(urlOf(key)).lsRefs()), refsOk);
274 const w = judge(want.ply, got); if (w) bad.push(`${S.refsCellId(c)}: ply over HTTP: ${w}`);
275 if (c.record.tag === 'duplicate' && c.eol.tag === 'lf' && c.framing.tag === 'flush') {
276 const d = freshRepo('dup');
277 const f = await gitIn(['fetch', '-q', '--no-tags', urlOf(key), 'refs/heads/main'], d);
278 assert.equal(f.status, 0, f.stderr);
279 assert.equal(git(d, ['rev-parse', 'FETCH_HEAD']).trim(), fx.main, 'git fetch takes the first listing of a ref');
280 assert.equal(got.refs?.find(r => r[0] === 'refs/heads/main')?.[1], fx.main, 'ply takes the first listing of a ref');
281 }
282 observed.refs++;
283 }
284 console.log(`refs observed=${observed.refs}`);
285 assert.deepEqual(bad, []);
286});
288test('push: request × advertised atomic × advertised push-options × object-format, judged by git push', async t => {
289 const work = join(root, 'pushwork'); mkdirSync(work); initRepo(work);
290 git(work, ['-c', 'user.name=a', '-c', 'user.email=a@b', 'commit', '-q', '--allow-empty', '-m', 'base']);
291 const base = git(work, ['rev-parse', 'HEAD']).trim();
292 git(work, ['-c', 'user.name=a', '-c', 'user.email=a@b', 'commit', '-q', '--allow-empty', '-m', 'next']);
293 const next = git(work, ['rev-parse', 'HEAD']).trim();
294 const obj = { oid: next, type: 1, data: new Uint8Array(git(work, ['cat-file', 'commit', next], { encoding: 'buffer' })) };
295 const bad = [];
296 for (const c of S.pushCells()) {
297 const want = S.expectedPush(c);
298 const name = `push-${observed.push}`; const bare = join(root, `${name}.git`);
299 git(root, ['init', '--bare', '-q', '-b', 'main', `--object-format=${c.format.tag}`, bare]); noMaintenance(bare);
300 for (const [k, v] of [['http.receivepack', 'true'], ['receive.advertiseAtomic', String(c.atomic.tag === 'on')], ['receive.advertisePushOptions', String(c.options.tag === 'on')]]) git(bare, ['config', k, v]);
301 if (c.format.tag === 'sha1') git(work, ['push', '-q', bare, `${base}:refs/heads/main`]);
302 const refsBefore = git(bare, ['for-each-ref']);
303 const atomic = c.request.tag === 'atomic' || c.request.tag === 'both', options = c.request.tag === 'options' || c.request.tag === 'both';
304 const g = await gitAsync(work, ['push', '--porcelain', ...(atomic ? ['--atomic'] : []), ...(options ? ['-o', 'x'] : []), `${backend.url}/${name}.git`, `${next}:refs/heads/g`]);
305 const gitGot = g.status === 0 ? 'ok' : 'refuse';
306 if (gitGot !== want.git.tag) bad.push(`${S.pushCellId(c)}: git push ${gitGot}, table ${want.git.tag}: ${g.stderr.trim()}`);
307 if (want.git.tag === 'refuse' && !g.stderr.includes(S.GIT_PUSH_REFUSAL[want.git.why])) bad.push(`${S.pushCellId(c)}: git's refusal is not "${S.GIT_PUSH_REFUSAL[want.git.why]}": ${g.stderr.trim()}`);
308 if (want.git.tag === 'refuse' && git(bare, ['for-each-ref']) !== refsBefore) bad.push(`${S.pushCellId(c)}: git's refused push moved a ref`);
309 let got;
310 try { await unwrapAsync(ply(`${backend.url}/${name}.git`).push({ ref: 'refs/heads/p', oldOid: '0'.repeat(40), newOid: next, objects: [obj], atomic, pushOptions: options ? ['x'] : [] })); got = { tag: 'landed' }; } catch (e) { got = { tag: e.code, message: e.message }; }
311 if (got.tag !== want.ply.tag) bad.push(`${S.pushCellId(c)}: ply ${got.tag} (${got.message ?? ''}), table ${want.ply.tag}`);
312 const landed = git(bare, ['for-each-ref', '--format=%(refname)']).split('\n').includes('refs/heads/p');
313 if (landed !== (want.ply.tag === 'landed')) bad.push(`${S.pushCellId(c)}: refs/heads/p ${landed ? 'landed' : 'absent'} after ply's ${got.tag}`);
314 if (want.ply.tag === 'unsupported' && !new RegExp({ hash: 'object-format sha256', atomic: 'advertise atomic', options: 'advertise push-options' }[want.ply.why]).test(got.message)) bad.push(`${S.pushCellId(c)}: ply's refusal names the wrong need: ${got.message}`);
315 observed.push++;
316 }
317 console.log(`push observed=${observed.push}`);
318 assert.deepEqual(bad, []);
319});
321test('request: fetch arguments ply sends, judged by git fetch\'s own request and upload-pack\'s pack-objects invocation', async t => {
322 const bad = [];
323 const hook = () => ({ args: readFileSync(`${hookLog}.args`, 'utf8').trim().replace(/^git (--shallow-file \S* )?pack-objects /, ''), stdin: readFileSync(`${hookLog}.stdin`, 'utf8').trim().split('\n').sort().join('\n') });
324 const clearHook = () => { for (const s of ['.args', '.stdin']) rmSync(`${hookLog}${s}`, { force: true }); };
325 for (const c of S.requestCells()) {
326 const want = S.expectedRequest(c);
327 const repo = c.server.tag === 'filterOn' ? 'rq-on.git' : 'rq-off.git';
328 const id = S.requestCellId(c);
329 // git, with the option that sends the flag (and --no-tags / --no-progress so nothing else differs)
330 const gkey = route({ kind: 'proxy', repo });
331 const f = c.flag.tag;
332 let g, gitHook = null;
333 if (f === 'filter') {
334 const d = join(root, `clone-${keyN}`);
335 clearHook();
336 g = await gitIn(['clone', '-q', '--bare', '--no-tags', '--single-branch', '--branch', 'main', '--filter=blob:none', urlOf(gkey), d]);
337 } else {
338 const d = freshRepo('rq');
339 if (f === 'deepenRelative') { const s = await gitIn(['fetch', '-q', '--no-tags', '--no-progress', '--depth=1', urlOf(gkey), 'refs/heads/main:refs/heads/main'], d); assert.equal(s.status, 0, s.stderr); posts.set(gkey, []); }
340 clearHook();
341 const opt = { noProgress: ['--no-tags', '--no-progress'], progress: ['--no-tags', '--progress'], includeTag: ['--no-progress'], deepenRelative: ['--no-tags', '--no-progress', '--deepen=1'] }[f];
342 g = await gitIn(['fetch', '-q', ...opt, urlOf(gkey), 'refs/heads/main:refs/heads/main'], d);
343 }
344 if ((g.status === 0 ? 'ok' : 'refuse') !== want.git) { bad.push(`${id}: git ${g.status}: ${g.stderr.trim()}`); continue; }
345 gitHook = existsSync(`${hookLog}.args`) ? hook() : null;
346 // the last request (a deepen-relative fetch is one round without `done`: the server answers ready and the pack)
347 const gb = fetchBodies(gkey).pop();
348 if (!gb) { bad.push(`${id}: no git fetch request`); continue; }
349 const flagLine = { noProgress: 'no-progress', progress: null, includeTag: 'include-tag', deepenRelative: 'deepen-relative', filter: 'filter blob:none' }[f];
350 if (flagLine && gb.args.includes(flagLine) !== want.gitSendsFlag) bad.push(`${id}: git ${want.gitSendsFlag ? 'did not send' : 'sent'} "${flagLine}"`);
351 if (f === 'progress' && gb.args.includes('no-progress')) bad.push(`${id}: git --progress sent no-progress`);
352 // ply, with git's request as its arguments
353 const val = p => gb.args.filter(a => a.startsWith(`${p} `)).map(a => a.slice(p.length + 1));
354 const req = { wants: val('want'), haves: val('have'), shallows: val('shallow'), deepen: Number(val('deepen')[0] ?? 0) || undefined, deepenRelative: gb.args.includes('deepen-relative'), includeTag: gb.args.includes('include-tag'), noProgress: gb.args.includes('no-progress'), thinPack: gb.args.includes('thin-pack'), ofsDelta: gb.args.includes('ofs-delta'), done: gb.args.includes('done'), filter: f === 'filter' ? 'blob:none' : undefined };
355 const pkey = route({ kind: 'proxy', repo });
356 clearHook();
357 // a deepen from a shallow boundary comes as a thin pack against the have: its bases are the client's objects
358 const bare = join(root, repo);
359 const external = oid => { try { const type = git(bare, ['cat-file', '-t', oid]).trim(); return { type: { commit: 1, tree: 2, blob: 3, tag: 4 }[type], data: new Uint8Array(git(bare, ['cat-file', type, oid], { encoding: 'buffer' })) }; } catch { return undefined; } };
360 const got = await outcomeOf(() => unwrapAsync(ply(urlOf(pkey)).fetchPack(req, { external })), r => ({ objects: r.objects.size }));
361 if (got.tag !== want.ply.tag) { bad.push(`${id}: ply ${got.tag} (${got.message ?? ''}), table ${want.ply.tag}`); continue; }
362 if (got.tag === 'ok') {
363 const pb = fetchBodies(pkey).pop();
364 const norm = a => [...a].sort().join('\n');
365 if (norm(pb.args) !== norm(gb.args)) bad.push(`${id}: request lines differ:\n git ${norm(gb.args).replace(/\n/g, ' | ')}\n ply ${norm(pb.args).replace(/\n/g, ' | ')}`);
366 const plyHook = hook();
367 if (!gitHook || plyHook.args !== gitHook.args || plyHook.stdin !== gitHook.stdin) bad.push(`${id}: pack-objects invocation differs: git ${JSON.stringify(gitHook)} ply ${JSON.stringify(plyHook)}`);
368 console.log(`${id}: pack-objects ${plyHook.args}`);
369 }
370 observed.request++;
371 }
372 assert.deepEqual(bad, []);
373});
375test('SPACE.md carries the generated advertisement block (node scripts/space-md.mjs --write)', async () => {
376 const doc = await import('../../scripts/space-md.mjs');
377 assert.equal(doc.currentAdvertisement(), S.mdBlock(S.observedCounts()), 'SPACE.md is stale: run node scripts/space-md.mjs --write');
378});
379// the observed counts the block states are the cells the observed tests above ran
380test('every observed cell ran', () => { assert.deepEqual(observed, S.observedCounts()); });
Diagnostics7 git calls · 91 ms
CallStatusSizeTime091 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=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=78
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
fetch2009.1 KiB78 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=9330
git.response.cache=MISS
git.response.duration_ms=78
git.fetch.wants=d888d4c763a6db591156e126b29a345613d1ffaa
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=9330
git.pkt.payload.max=9303
git.sideband.band1.bytes=9303
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
a5e2cdba3faa7929
Request
5765bd6c…
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