GitHubivarvong

ply

main
ply6 git calls113 ms44 KiB4 cachedprotocol v2
1103 lines83 KiBRaw
1// Pack cache + head hint against real git through the counting proxy. The oracle for "fewer round trips" is the
2// proxy's per-stage request count (what the server actually saw); the oracle for correctness is git itself.
3import { test, beforeAll as before, afterAll as after } from 'vitest';
4import assert from 'node:assert/strict';
5import { join } from 'node:path';
6import { mkdirSync, writeFileSync, chmodSync, rmSync } from 'node:fs';
7import { git, gitAsync, tmpRoot, makeBareRepo, startGitServer, commitFiles, fsckProblems, initRepo } from './server.js';
8import { startProxy } from './proxy.js';
9import { editFile } from '../src/edit.js';
10import { cachingFetch, memoryCache, isCacheableFetch, cacheKey, parseUploadPackRequest, exchangeKind, verifyFetchAnswer } from '../src/packcache.js';
11import { pkt, pktInit, pktStep, FLUSH, DELIM } from '../src/pktline.js';
12import { lsRefsBody as lsRefsBodyR } from '../src/lsrefs.js';
13import { parsePack, resolvePack } from '../src/packresolve.js';
14import { te, concat } from '../src/bytes.js';
15import { DEFAULT_LIMITS, LIMIT_MEMORY_CACHE_BYTES, LIMIT_MEMORY_CACHE_ENTRIES } from '../src/limits.js';
16import { readFileSync } from 'node:fs';
17import { createHash } from 'node:crypto';
18import { deflateSync } from 'node:zlib';
19import { fetchBody as fetchBodyR, GitHttp } from '../src/client.js';
20import { Tracer, arrayExporter, flattenLine } from '../src/otel.js';
21import { unwrap, unwrapAsync } from './unwrap.js';
23// Throwing adapters over the Result API (0.2.0): the assertions below are about the throw.
24const fetchBody = (...a) => unwrap(fetchBodyR(...a));
25let root, cleanup, srv, proxy, bare, work, url;
26// commit on top of whatever main is now (as another writer would)
27const otherWriter = (files, msg) => { git(work, ['fetch', '-q', bare, 'refs/heads/main']); git(work, ['reset', '-q', '--hard', 'FETCH_HEAD']); return commitFiles(work, bare, files, msg); };
28const author = { name: 'pc', email: 'pc@x' };
29before(async () => {
30 ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root);
31 bare = makeBareRepo(root, 'pc'); work = join(root, 'wpc'); mkdirSync(work); initRepo(work);
32 commitFiles(work, bare, { 'a/b/c/file.txt': 'hello MARK world\n', 'README.md': '# pc\n' }, 'init');
33 proxy = await startProxy(srv.url, () => null);
34 url = `${proxy.url}/pc.git`;
35});
36after(async () => { await proxy.close?.(); await srv.close(); cleanup(); });
38const counts = () => ({ ...proxy.counts });
39const delta = (a, b) => Object.fromEntries(['ls-refs', 'fetch', 'receive-pack'].map(k => [k, (b[k] ?? 0) - (a[k] ?? 0)]));
40const spansOf = ex => ex.lines.flatMap(flattenLine);
41const headOf = () => git(bare, ['rev-parse', 'refs/heads/main']).trim();
43test('isCacheableFetch: wants-only filtered fetches only', () => {
44 const oid = 'a'.repeat(40);
45 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0' })), true);
46 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0', deepen: 1 })), true);
47 assert.equal(isCacheableFetch(fetchBody({ wants: [oid] })), false, 'no filter → blob stream, not cached');
48 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0', haves: ['b'.repeat(40)] })), false);
49 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0', deepenSince: 1 })), false);
50 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0', deepenNot: ['refs/heads/x'] })), false);
51 assert.equal(isCacheableFetch(fetchBody({ wants: [oid], filter: 'tree:0', shallows: ['c'.repeat(40)] })), false);
52});
54test('cacheKey: url, credential and body all separate entries', async () => {
55 const b = fetchBody({ wants: ['a'.repeat(40)], filter: 'tree:0' });
56 const k = await cacheKey('http://h/r', 'Basic x', b);
57 assert.notEqual(k, await cacheKey('http://h/r2', 'Basic x', b));
58 assert.notEqual(k, await cacheKey('http://h/r', 'Basic y', b));
59 assert.notEqual(k, await cacheKey('http://h/r', 'Basic x', fetchBody({ wants: ['b'.repeat(40)], filter: 'tree:0' })));
60 assert.equal(k, await cacheKey('http://h/r', 'Basic x', b.slice()));
61});
63test('pack cache: second edit at the same tree serves commit+trees from cache; server sees only ls-refs, blob, push', async () => {
64 const cache = memoryCache();
65 const f = cachingFetch(globalThis.fetch, cache);
66 const run = async (find, replace, treeCache = new Map()) => {
67 const ex = arrayExporter(); const before = counts();
68 const r = await unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find, replace, author, message: 'm' }, { tracer: new Tracer({ exporter: ex }), fetchImpl: f, cache: treeCache }));
69 return { r, d: delta(before, counts()), spans: spansOf(ex) };
70 };
71 const a = await run('MARK', 'MARK1');
72 // cold: ls-refs + commit + 4 trees (root, a, b, c) + blob + push
73 assert.deepEqual(a.d, { 'ls-refs': 1, fetch: 6, 'receive-pack': 1 });
74 assert.equal(f.stats.miss, 5); assert.equal(f.stats.hit, 0);
75 assert.equal(cache.entries.size, 5);
76 assert.ok(a.spans.filter(s => s.name === 'git.upload-pack fetch' && s.attrs['git.pack.cache'] === 'MISS').length === 5);
77 git(bare, ['update-ref', 'refs/heads/main', a.r.oldCommit]); // rewind so the same commit/trees are wanted again
78 const b = await run('MARK', 'MARK2');
79 assert.deepEqual(b.d, { 'ls-refs': 1, fetch: 1, 'receive-pack': 1 }, 'only the blob stream reaches the server');
80 assert.equal(f.stats.hit, 5);
81 assert.equal(b.spans.filter(s => s.name === 'git.upload-pack fetch' && s.attrs['git.pack.cache'] === 'HIT').length, 5);
82 assert.equal(b.r.newCommit, headOf());
83 assert.equal(git(bare, ['cat-file', '-p', 'main:a/b/c/file.txt']), 'hello MARK2 world\n');
84 assert.deepEqual(fsckProblems(bare), []);
85 git(bare, ['update-ref', 'refs/heads/main', a.r.oldCommit]);
87 // poison: flip a byte inside every cached body. Each hit now fails verification → one bust refetch each → repaired cache.
88 for (const e of cache.entries.values()) e.body[e.body.length - 30] ^= 0xff;
89 const c = await run('MARK', 'MARK3');
90 assert.deepEqual(c.d, { 'ls-refs': 1, fetch: 6, 'receive-pack': 1 }, 'every poisoned entry was refetched once');
91 assert.equal(f.stats.bust, 5);
92 assert.equal(c.spans.filter(s => s.name === 'git.upload-pack fetch' && s.attrs['git.pack.cache.bust'] === true).length, 5);
93 assert.equal(c.spans.filter(s => s.name === 'git.upload-pack fetch' && s.attrs['git.pack.cache'] === 'BUST').length, 5);
94 assert.equal(c.r.newCommit, headOf());
95 git(bare, ['update-ref', 'refs/heads/main', a.r.oldCommit]);
96 const d = await run('MARK', 'MARK4');
97 assert.deepEqual(d.d, { 'ls-refs': 1, fetch: 1, 'receive-pack': 1 }, 'cache repaired');
98 assert.deepEqual(fsckProblems(bare), []);
99 git(bare, ['update-ref', 'refs/heads/main', a.r.oldCommit]);
100});
102test('pack cache: a corrupt live response is not retried (bust only follows a HIT)', async () => {
103 let n = 0;
104 const bad = async (u, init) => { const res = await fetch(u, init); if (String(u).endsWith('git-upload-pack') && isCacheableFetch(init.body) && n++ === 0) { const b = new Uint8Array(await res.arrayBuffer()); b[b.length - 30] ^= 0xff; return new Response(b, { status: 200, headers: res.headers }); } return res; };
105 const before = counts();
106 await assert.rejects(unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'MARK', replace: 'x', author, message: 'm' }, { tracer: new Tracer(), fetchImpl: cachingFetch(bad, memoryCache()) })), e => e.code === 'pack_corrupt');
107 assert.deepEqual(delta(before, counts()), { 'ls-refs': 1, fetch: 1, 'receive-pack': 0 });
108});
110test('head hint (parallel, default): ls-refs overlaps the speculative commit fetch; stale hint corrected before any push; bogus hint harmless', async () => {
111 const base = headOf();
112 const run = async (head, find, replace, extra = {}) => {
113 const ex = arrayExporter(); const before = counts();
114 const r = await unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find, replace, author, message: 'm' }, { tracer: new Tracer({ exporter: ex }), head, ...extra }));
115 return { r, d: delta(before, counts()), spans: spansOf(ex) };
116 };
117 const a = await run(base, 'MARK', 'H1');
118 assert.deepEqual(a.d, { 'ls-refs': 1, fetch: 6, 'receive-pack': 1 }, 'ls-refs still happens, overlapped with the commit fetch');
119 assert.equal(a.r.hint, 'used'); assert.equal(a.r.attempt, 0); assert.equal(a.r.oldCommit, base); assert.equal(a.r.newCommit, headOf());
120 const root = a.spans.find(s => s.name === 'git.edit');
121 assert.equal(root.attrs['git.edit.head.hint'], base); assert.equal(root.attrs['git.edit.head.outcome'], 'used');
122 // overlap is real: ls-refs and the commit fetch spans intersect in time
123 const ls = a.spans.find(s => s.name === 'git.upload-pack ls-refs'), cf = a.spans.filter(s => s.name === 'git.upload-pack fetch')[0];
124 assert.ok(ls && cf);
126 // someone else moved the ref: the hint is stale, ls-refs wins, nothing is pushed under the stale parent
127 otherWriter({ 'other.txt': 'x\n' }, 'someone else');
128 const moved = headOf();
129 const b = await run(a.r.newCommit, 'H1', 'H2');
130 assert.equal(b.r.hint, 'stale'); assert.equal(b.r.attempt, 0);
131 assert.deepEqual(b.d, { 'ls-refs': 1, fetch: 7, 'receive-pack': 1 }, 'speculative commit fetch wasted, real commit fetched, exactly one push');
132 assert.equal(b.r.oldCommit, moved); assert.equal(b.r.newCommit, headOf());
133 assert.equal(b.spans.filter(s => s.name === 'git.edit').length, 1);
134 assert.equal(git(bare, ['cat-file', '-p', 'main:a/b/c/file.txt']), 'hello H2 world\n');
135 assert.equal(git(bare, ['cat-file', '-p', 'main:other.txt']), 'x\n', 'the other writer\'s commit is the parent, not overwritten');
136 assert.equal(+git(bare, ['rev-list', '--count', 'main']), +git(bare, ['rev-list', '--count', base]) + 3, 'H1, other, H2');
138 // a hint the server never had: speculative fetch fails, recorded, resolved path proceeds
139 const c = await run('f'.repeat(40), 'H2', 'H3');
140 assert.equal(c.r.hint, 'stale'); assert.equal(c.d['receive-pack'], 1);
141 assert.ok(c.spans.find(s => s.name === 'git.edit').attrs['git.edit.head.speculative_error']);
142 assert.equal(c.r.newCommit, headOf());
143 assert.deepEqual(fsckProblems(bare), []);
144 await assert.rejects(unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'H3', replace: 'x', author, message: 'm' }, { tracer: new Tracer(), head: 'nope' })), e => e.code === 'bad_request');
145});
147test('push: sideband on by default; hook stderr lands in git.push.remote.messages', async () => {
148 const hooks = join(bare, 'hooks'); mkdirSync(hooks, { recursive: true });
149 const hook = join(hooks, 'pre-receive'); writeFileSync(hook, '#!/bin/sh\necho "policy says hi" >&2\necho "second line" >&2\nexit 0\n'); chmodSync(hook, 0o755);
150 try {
151 const ex = arrayExporter();
152 const r = await unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'H3', replace: 'SB', author, message: 'm' }, { tracer: new Tracer({ exporter: ex }) }));
153 assert.equal(r.newCommit, headOf());
154 const push = spansOf(ex).find(s => s.name === 'git.receive-pack');
155 assert.ok(push.attrs['git.push.caps'].includes('side-band-64k'));
156 assert.deepEqual(push.attrs['git.push.remote.messages'], ['policy says hi', 'second line']);
157 // and a rejecting hook: the reason is the server's words, the code is push_rejected (not cas)
158 writeFileSync(hook, '#!/bin/sh\necho "GH006-style: protected branch, nope" >&2\nexit 1\n');
159 const ex2 = arrayExporter();
160 await assert.rejects(unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'SB', replace: 'SC', author, message: 'm' }, { tracer: new Tracer({ exporter: ex2 }) })), e => e.code === 'push_rejected' && /protected branch/.test(e.hookOutput));
161 assert.deepEqual(spansOf(ex2).find(s => s.name === 'git.receive-pack').attrs['git.push.remote.messages'], ['GH006-style: protected branch, nope']);
162 } finally { rmSync(hook, { force: true }); }
163});
165test('discover: v2 capability canary against real git', async () => {
166 const ex = arrayExporter();
167 const c = unwrap(GitHttp.create(url, { tracer: new Tracer({ exporter: ex }) }));
168 const info = await unwrapAsync(c.discover());
169 assert.equal(info.version, 2); assert.match(info.agent, /^git\/\d/); assert.equal(info.objectFormat, 'sha1');
170 assert.equal(info.filter, true, 'uploadpack.allowFilter is on in the fixture'); assert.equal(info.shallow, true);
171 const span = spansOf(ex).find(s => s.name === 'git.upload-pack discover');
172 assert.equal(span.attrs['git.server.agent'], info.agent); assert.ok(span.attrs['git.server.caps'].includes('ls-refs'));
173 assert.equal(span.attrs['git.server.filter'], true);
174 // the same local server, seen by git's own eyes
175 // git ≥ 2.48 may append the OS to its agent (`git/2.50.0-Darwin` from Homebrew's git, found 2026-10-23); the version is the claim
176 const v = git(bare, ['--version']).trim().replace(/^git version /, '');
177 assert.ok(info.agent === `git/${v}` || info.agent.startsWith(`git/${v}-`), `agent ${info.agent} vs git ${v}`);
178});
180test('tracer: isolate invocation attrs, event cap, cache put stats surface on the edit root', async () => {
181 const ex = arrayExporter();
182 const tracer = new Tracer({ exporter: ex, maxEvents: 3 });
183 const s = tracer.start('root'); for (let i = 0; i < 10; i++) s.event('e', { i }); s.end();
184 const flat = spansOf(ex)[0];
185 assert.equal(flat.events.length, 3); assert.equal(flat.droppedEvents, 7);
186 assert.equal(typeof flat.attrs['ply.isolate.invocation'], 'number'); assert.equal(typeof flat.attrs['ply.isolate.cold'], 'boolean');
187 // cache put failures are counted, not swallowed
188 const broken = { ...memoryCache(), put: async () => { throw new Error('cache full'); } };
189 const f = cachingFetch(globalThis.fetch, broken);
190 const ex2 = arrayExporter();
191 await unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'SB', replace: 'SD', author, message: 'm' }, { tracer: new Tracer({ exporter: ex2 }), fetchImpl: f }));
192 const root = spansOf(ex2).find(x => x.name === 'git.edit');
193 assert.equal(root.attrs['git.pack.cache.put.failed'], 5); assert.equal(root.attrs['git.pack.cache.put.error'], 'cache full'); assert.equal(root.attrs['git.pack.cache.miss'], 5);
194 assert.equal(typeof root.attrs['mem.alloc.inflate_chunk.max_single'], 'number');
195 const blob = spansOf(ex2).find(x => x.name === 'git.edit.blob');
196 assert.ok(blob.attrs['git.edit.blob.cpu_ms'] >= 0, 'node measures cpu'); assert.equal(blob.attrs['git.edit.blob.hasher'], 'js');
197});
199test('verify: the post-push ls-refs must show our commit; a lying answer is ambiguous, not success', async () => {
200 const ex = arrayExporter();
201 const ok = await unwrapAsync(editFile(url, { path: 'a/b/c/file.txt', find: 'SD', replace: 'V1', author, message: 'm' }, { tracer: new Tracer({ exporter: ex }), verify: true }));
202 assert.equal(ok.newCommit, headOf());
203 assert.equal(spansOf(ex).find(s => s.name === 'git.edit').attrs['git.edit.verify.ref'], ok.newCommit);
204 // a proxy that answers the second ls-refs (post-push) with the pre-push ref state
205 let n = 0, stale = null;
206 const lying = await startProxy(srv.url, ctx => {
207 if (ctx.stage !== 'ls-refs' || ctx.phase === 'request') return null; // the proxy consults faults before forwarding too
208 if (n++ === 0) { stale = ctx.bytes; return null; }
209 return { type: 'bytes', bytes: stale, name: 'stale-ls-refs' };
210 });
211 try {
212 const ex2 = arrayExporter();
213 await assert.rejects(unwrapAsync(editFile(`${lying.url}/pc.git`, { path: 'a/b/c/file.txt', find: 'V1', replace: 'V2', author, message: 'm' }, { tracer: new Tracer({ exporter: ex2 }), verify: true })), e => e.code === 'ambiguous' && /push reported ok but/.test(e.message));
214 const root = spansOf(ex2).find(s => s.name === 'git.edit');
215 assert.equal(root.attrs['git.edit.outcome'], 'ambiguous'); assert.equal(root.attrs['git.edit.verify.ref'], ok.newCommit, 'the lie is recorded verbatim');
216 assert.equal(git(bare, ['cat-file', '-p', 'main:a/b/c/file.txt']), 'hello V2 world\n', 'the push itself landed; only the receipt was untrustworthy');
217 } finally { await lying.close?.(); }
218});
220test('buffered fetchPack (general client): poisoned cache entry → one bust → repaired', async () => {
221 const cache = memoryCache();
222 const f = cachingFetch(globalThis.fetch, cache);
223 const ex = arrayExporter();
224 const c = unwrap(GitHttp.create(url, { tracer: new Tracer({ exporter: ex }), fetchImpl: f }));
225 const head = headOf();
226 const a = await unwrapAsync(c.fetchPack({ wants: [head], filter: 'tree:0', deepen: 1 }));
227 assert.equal(a.parsed.stats.count, 1); assert.equal(cache.entries.size, 1);
228 for (const e of cache.entries.values()) e.body[e.body.length - 30] ^= 0xff;
229 const b = await unwrapAsync(c.fetchPack({ wants: [head], filter: 'tree:0', deepen: 1 }));
230 assert.equal(b.parsed.stats.count, 1); assert.equal(f.stats.bust, 1);
231 const spans = spansOf(ex).filter(s => s.name === 'git.upload-pack fetch');
232 assert.deepEqual(spans.map(s => s.attrs['git.pack.cache.bust']), [false, false, true]); assert.deepEqual(spans.map(s => s.attrs['git.response.cache']), ['MISS', 'HIT', 'BUST']);
233 // The same retry against any cache tier: a HIT whose pack the client refuses is asked for once more with
234 // `x-ply-cache: bust`. The tier below serves git's answer with one flipped byte as a HIT.
235 let tierBusts = 0;
236 const tier = async (u, init) => {
237 const res = await fetch(u, init);
238 if (!String(u).endsWith('git-upload-pack') || !isCacheableFetch(init.body)) return res;
239 const h = new Headers(res.headers);
240 if (new Headers(init.headers).get('x-ply-cache') === 'bust') { tierBusts++; h.set('x-ply-pack-cache', 'BUST'); return new Response(res.body, { status: 200, headers: h }); }
241 const bytes = new Uint8Array(await res.arrayBuffer()); bytes[bytes.length - 30] ^= 0xff; h.set('x-ply-pack-cache', 'HIT');
242 return new Response(bytes, { status: 200, headers: h });
243 };
244 const ex2 = arrayExporter();
245 const c2 = unwrap(GitHttp.create(url, { tracer: new Tracer({ exporter: ex2 }), fetchImpl: tier }));
246 const viaTier = await unwrapAsync(c2.fetchPack({ wants: [head], filter: 'tree:0', deepen: 1 }));
247 assert.equal(viaTier.parsed.stats.count, 1); assert.equal(tierBusts, 1);
248 const spans2 = spansOf(ex2).filter(s => s.name === 'git.upload-pack fetch');
249 assert.deepEqual(spans2.map(s => s.attrs['git.pack.cache.bust']), [false, true]); assert.deepEqual(spans2.map(s => s.attrs['git.response.cache']), ['HIT', 'BUST']);
250 // the wrapper delegates to the same functions (getters + one of each family)
251 assert.equal(c.url, url); assert.equal(c.limits.maxRefs > 0, true); assert.equal(c.tracer instanceof Tracer, true); assert.equal(c.parent, null);
252 const o = await unwrapAsync(c.fetchObject({ oid: head, deepen: 1 })); assert.equal(o.oid, head);
253 const caps = await unwrapAsync(c.receiveCaps()); assert.ok(caps.has('report-status'));
254 assert.equal((await unwrapAsync(c.negotiate({ wants: [head], haves: [], filter: 'tree:0', deepen: 1 }))).parsed.stats.count, 1);
255 let st; for await (const _ of c.packStream({ wants: [head], filter: 'tree:0', deepen: 1 }, new Tracer().start('x'))) { st = _; } assert.ok(st);
256 await assert.rejects(unwrapAsync(c.push({ ref: 'refs/heads/main', oldOid: head, newOid: head, objects: [], pushOptions: ['x'] })), e => e.code === 'unsupported', 'push-options checked against the advertisement');
257 // with the server advertising push-options, the options ride after the command flush and reach the hook
258 git(bare, ['config', 'receive.advertisePushOptions', 'true']);
259 const hooks = join(bare, 'hooks'); mkdirSync(hooks, { recursive: true });
260 writeFileSync(join(hooks, 'pre-receive'), '#!/bin/sh\necho "opts=$GIT_PUSH_OPTION_COUNT:$GIT_PUSH_OPTION_0" >&2\nexit 0\n'); chmodSync(join(hooks, 'pre-receive'), 0o755);
261 try {
262 const { encodeTree, encodeCommit, hashObject } = await import('../src/objects.js');
263 const { TYPE } = await import('../src/objects.js');
264 const blob = new TextEncoder().encode('po\n'); const tree = unwrap(encodeTree([{ mode: '100644', name: 'po.txt', oid: hashObject('blob', blob) }]));
265 const commit = unwrap(encodeCommit({ tree: hashObject('tree', tree), parents: [head], author: 'a <a@x> 1 +0000', message: 'po\n' }));
266 const r = await unwrapAsync(c.push({ ref: 'refs/heads/main', oldOid: head, newOid: hashObject('commit', commit), objects: [{ type: TYPE.COMMIT, data: commit }, { type: TYPE.TREE, data: tree }, { type: TYPE.BLOB, data: blob }], pushOptions: ['ci.skip'] }));
267 assert.match(r.hookOutput, /opts=1:ci.skip/);
268 git(bare, ['update-ref', 'refs/heads/main', head]);
269 } finally { rmSync(join(hooks, 'pre-receive'), { force: true }); git(bare, ['config', '--unset', 'receive.advertisePushOptions']); }
270});
272test('LFS pointer: refused by default (the content is not in git), editable only with allowLfsPointer', async () => {
273 const pointer = 'version https://git-lfs.github.com/spec/v1\noid sha256:' + 'ab'.repeat(32) + '\nsize 12345\n';
274 otherWriter({ 'model.bin': pointer, 'notlfs.txt': 'version https://git-lfs.github.com/spec/v2 MARK\n' }, 'lfs pointer');
275 const ex = arrayExporter();
276 await assert.rejects(unwrapAsync(editFile(url, { path: 'model.bin', find: 'size 12345', replace: 'size 1', author, message: 'm' }, { tracer: new Tracer({ exporter: ex }) })), e => e.code === 'lfs_pointer' && e.size === pointer.length && /LFS pointer/.test(e.message));
277 const blob = spansOf(ex).find(s => s.name === 'git.edit.blob');
278 assert.equal(blob.attrs['git.edit.blob.lfs_pointer'], true);
279 assert.equal(git(bare, ['cat-file', '-p', 'main:model.bin']), pointer, 'untouched');
280 assert.equal(spansOf(ex).filter(s => s.name === 'git.receive-pack').length, 0, 'nothing pushed');
281 // the guard matches the exact v1 magic, not any file mentioning git-lfs
282 const r = await unwrapAsync(editFile(url, { path: 'notlfs.txt', find: 'MARK', replace: 'OK', author, message: 'm' }, { tracer: new Tracer() }));
283 assert.equal(r.newCommit, headOf());
284 // opt in: editing the pointer itself (e.g. retargeting an LFS object) is allowed and ordinary
285 const r2 = await unwrapAsync(editFile(url, { path: 'model.bin', find: 'size 12345', replace: 'size 54321', author, message: 'm' }, { tracer: new Tracer(), allowLfsPointer: true }));
286 assert.equal(r2.newCommit, headOf());
287 assert.equal(git(bare, ['cat-file', '-p', 'main:model.bin']), pointer.replace('12345', '54321'));
288});
290test('agent: we identify as ply, not git', async () => {
291 const { UA } = await import('../src/transport.js');
292 assert.match(UA, /^ply\//);
293 const ex = arrayExporter();
294 await unwrapAsync(editFile(url, { path: 'notlfs.txt', find: 'OK', replace: 'OK2', author, message: 'm' }, { tracer: new Tracer({ exporter: ex }) }));
295 const caps = spansOf(ex).find(s => s.name === 'git.receive-pack').attrs['git.push.caps'];
296 assert.ok(caps.includes(`agent=${UA}`), caps.join(' '));
297});
299test('negotiation, deterministic: haves in rounds — NAK rounds of unknown oids, then ACKs of shared history, ready, and a pack of only what is new', async () => {
300 const nb = makeBareRepo(root, 'nego'); const nw = join(root, 'wnego'); mkdirSync(nw); initRepo(nw);
301 const commits = []; for (let i = 0; i < 30; i++) commits.push(commitFiles(nw, nb, { 'f.txt': `v${i}\n` }, `c${i}`));
302 const c = unwrap(GitHttp.create(`${srv.url}/nego.git`, { tracer: new Tracer() }));
303 const unknown = Array.from({ length: 20 }, (_, i) => (i.toString(16).padStart(2, '0')).repeat(20));
304 const r = await unwrapAsync(c.negotiate({ wants: [commits[29]], haves: [...unknown, ...commits.slice(10, 20).reverse()], batch: 8 }));
305 assert.ok(r.rounds.length >= 3, `several rounds (${r.rounds.length})`);
306 assert.equal(r.rounds[0].acks.length, 0, 'first round: only unknown oids → no acks');
307 assert.ok(r.rounds.some(x => x.acks.length > 0), 'shared history is acknowledged');
308 assert.ok(r.common.includes(commits[19]), 'the newest shared commit is common');
309 const got = new Set(r.objects.keys());
310 assert.ok(got.has(commits[29]) && got.has(commits[20]) && !got.has(commits[19]), 'the pack starts after the common commit');
311});
313// ---- #120: the request parser against git's own requests, purity, verify-before-store ----
314const UPLOAD = { 'content-type': 'application/x-git-upload-pack-request', 'git-protocol': 'version=2' };
315const post = async (u, body) => { const r = await fetch(`${u}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body }); assert.equal(r.status, 200); return new Uint8Array(await r.arrayBuffer()); };
316const framesOf = bytes => unwrap(pktStep(pktInit(), bytes)).frames;
317const reframe = fs => concat(fs.map(f => (f.kind === 'flush' ? FLUSH : f.kind === 'delim' ? DELIM : unwrap(pkt(f.payload)))));
318const line = s => ({ kind: 'data', payload: te.encode(s) });
319const objectSet = answer => {
320 const pack = concat(framesOf(answer).filter(f => f.kind === 'data' && f.payload[0] === 1).map(f => f.payload.subarray(1)));
321 return [...unwrap(resolvePack(unwrap(parsePack(pack)))).objects.keys()].sort();
322};
323const blobOid = () => git(bare, ['rev-parse', 'main:README.md']).trim();
325test('git\'s own v2 requests (GIT_TRACE_PACKET) parse, and classify: ls-refs is refs, a shallow filtered clone is pack, a fetch with haves is not', async () => {
326 const trace = join(root, 'trace-120'); const dst = join(root, 'clone-120');
327 rmSync(trace, { force: true }); rmSync(dst, { recursive: true, force: true });
328 // async git: the server and the proxy run in this process
329 const run = async (cwd, args) => { const r = await gitAsync(cwd, ['-c', 'protocol.version=2', ...args], { GIT_TRACE_PACKET: trace }); assert.equal(r.status, 0, r.stderr); };
330 await run(root, ['clone', '-q', '--depth', '1', '--filter=blob:none', '--no-checkout', url, dst]);
331 otherWriter({ 'more.txt': 'more\n' }, 'more');
332 await run(dst, ['fetch', '-q', '--depth', '2', 'origin']);
333 // the client's writes, request by request: `<label>> <payload>`, a flush ending each request (0000 / 0001 as text)
334 const requests = []; let cur = [];
335 for (const l of readFileSync(trace, 'utf8').split('\n')) {
336 const m = /packet:\s+(\S+)> (.*)$/.exec(l);
337 if (!m || m[1] === 'upload-pack') continue;
338 if (m[2] === 'command=ls-refs' || m[2] === 'command=fetch') cur = [];
339 cur.push(m[2] === '0000' ? FLUSH : m[2] === '0001' ? DELIM : unwrap(pkt(`${m[2]}\n`)));
340 if (m[2] === '0000' && cur.length > 1) { requests.push(concat(cur)); cur = []; }
341 }
342 const parsed = requests.map(b => unwrap(parseUploadPackRequest(b)));
343 const kinds = requests.map(b => exchangeKind('POST', `${url}/git-upload-pack`, b));
344 const ls = parsed.filter(r => r.command === 'ls-refs'), fe = parsed.filter(r => r.command === 'fetch');
345 assert.ok(ls.length >= 2 && fe.length >= 2, `${ls.length} ls-refs, ${fe.length} fetch`);
346 assert.ok(ls[0].caps.some(c => c.startsWith('agent=git/')), ls[0].caps.join(' '));
347 assert.ok(ls[0].prefixes.includes('refs/heads/') && ls[0].peel && ls[0].symrefs);
348 assert.ok(kinds.filter((_, i) => parsed[i].command === 'ls-refs').every(k => k === 'refs'));
349 const clone = fe[0];
350 assert.equal(clone.deepen, 1); assert.equal(clone.filter, 'blob:none'); assert.equal(clone.haves.length, 0); assert.ok(clone.wants.length >= 1);
351 const later = fe.at(-1);
352 assert.ok(later.haves.length + later.shallows.length > 0, 'the second fetch says what it holds');
353 assert.equal(kinds[parsed.indexOf(later)], null, 'a negotiation is not pure');
354});
356test('purity oracle: a pack exchange answers the same object set before and after an unrelated ref update', async () => {
357 const head = headOf();
358 for (const opts of [{ wants: [head], filter: 'tree:0', deepen: 1 }, { wants: [blobOid()] }, { wants: [head], deepen: 2 }]) {
359 const body = fetchBody(opts);
360 assert.equal(exchangeKind('POST', `${srv.url}/pc.git/git-upload-pack`, body), 'pack');
361 const a = await post(`${srv.url}/pc.git`, body);
362 git(bare, ['update-ref', 'refs/heads/unrelated-120', git(bare, ['rev-parse', 'main~1']).trim()]);
363 otherWriter({ 'unrelated.txt': `${Math.random()}\n` }, 'unrelated'); git(bare, ['update-ref', 'refs/heads/main', head]);
364 const b = await post(`${srv.url}/pc.git`, body);
365 assert.deepEqual(objectSet(b), objectSet(a), JSON.stringify(opts));
366 git(bare, ['update-ref', '-d', 'refs/heads/unrelated-120']);
367 }
368});
370test('verifyFetchAnswer: git\'s answers pass; a flipped byte, a cut, a missing want, a lying shallow-info are refused', async () => {
371 const head = headOf();
372 const req = o => unwrap(parseUploadPackRequest(fetchBody(o)));
373 const commitReq = req({ wants: [head], filter: 'tree:0', deepen: 1 });
374 const commitAns = await post(`${srv.url}/pc.git`, fetchBody({ wants: [head], filter: 'tree:0', deepen: 1 }));
375 assert.deepEqual(unwrap(verifyFetchAnswer(commitReq, commitAns)), { objects: 1 });
376 const blobReq = req({ wants: [blobOid()] });
377 const blobAns = await post(`${srv.url}/pc.git`, fetchBody({ wants: [blobOid()] }));
378 assert.deepEqual(unwrap(verifyFetchAnswer(blobReq, blobAns, DEFAULT_LIMITS)), { objects: 1 });
379 const refused = (r, ans, code, re) => { const v = verifyFetchAnswer(r, ans); assert.equal(v.ok, false, String(re)); assert.equal(v.error.code, code); assert.match(v.error.message, re); };
380 const flipped = blobAns.slice(); flipped[flipped.length - 30] ^= 0xff;
381 refused(blobReq, flipped, 'pack_corrupt', /./);
382 refused(blobReq, blobAns.subarray(0, blobAns.length - 7), 'protocol', /trailing/);
383 refused(blobReq, blobAns.subarray(0, blobAns.length - 4), 'protocol', /without flush/);
384 refused(req({ wants: [blobOid(), head] }), blobAns, 'pack_corrupt', new RegExp(`want ${head} is not in the pack`));
385 refused(req({ wants: [head], filter: 'tree:0' }), commitAns, 'pack_corrupt', /shallow-info for a request without deepen/);
386 const fs = framesOf(commitAns);
387 const at = fs.findIndex(f => f.kind === 'data' && new TextDecoder().decode(f.payload).startsWith('shallow '));
388 assert.ok(at > 0, 'deepen 1 of a commit with parents is answered with shallow-info');
389 refused(commitReq, reframe([...fs.slice(0, at), line(`shallow ${'f'.repeat(40)}\n`), ...fs.slice(at + 1)]), 'pack_corrupt', /shallow f{40} is not a commit of the pack/);
390 refused(commitReq, reframe([...fs.slice(0, at + 1), line(`unshallow ${head}\n`), ...fs.slice(at + 1)]), 'pack_corrupt', /unshallow for a request without shallow/);
391 refused(commitReq, reframe([line('acknowledgments\n'), line('NAK\n'), { kind: 'flush' }]), 'protocol', /no packfile section/);
392 refused(blobReq, reframe([line('ERR nope\n'), { kind: 'flush' }]), 'remote_error', /nope/);
393 assert.equal(verifyFetchAnswer(blobReq, blobAns, { ...DEFAULT_LIMITS, maxPackObjects: Number.NaN }).ok, false, 'a bad limit is refused, not ignored');
394 assert.equal(verifyFetchAnswer(blobReq, blobAns, { ...DEFAULT_LIMITS, maxPackBytes: 10 }).error.code, 'limit_exceeded');
395});
397test('verifyFetchAnswer judges an answer by the request that produced it: git\'s reply to a non-done request verifies when it has a pack', async () => {
398 // Every answer here is real git upload-pack's (git 2.50 behind http-backend, protocol v2), to a request without
399 // `done`. gitprotocol-v2, fetch: output = acknowledgments flush-pkt | [acknowledgments delim-pkt] ... packfile
400 // flush-pkt. For a have the server holds it sends ACK and ready, then the pack; for one it does not hold, NAK alone.
401 otherWriter({ 'answer-by-request.txt': 'one\n' }, 'non-done answer');
402 const head = headOf(), have = git(bare, ['rev-parse', 'main~1']).trim();
403 const body = fetchBody({ wants: [head], haves: [have], done: false });
404 const request = unwrap(parseUploadPackRequest(body));
405 assert.equal(request.done, false);
406 const answer = await post(`${srv.url}/pc.git`, body);
407 // the sections as bytes, written by hand: a pkt-line is 4 hex digits of length (itself included), 0001 is the delim
408 const lead = `0014acknowledgments\n0031ACK ${have}\n000aready\n0001000dpackfile\n`;
409 assert.equal(new TextDecoder('latin1').decode(answer.subarray(0, lead.length)), lead, 'git answers ACK and ready, then the pack');
410 // the pack is what git says the have does not reach
411 const beyond = git(bare, ['rev-list', '--objects', head, `^${have}`]).trim().split('\n').length;
412 assert.deepEqual(unwrap(verifyFetchAnswer(request, answer)), { objects: beyond });
413 // the same bytes after a request that sent done: git's fetch-pack dies "expected 'packfile', received 'acknowledgments'"
414 const sentDone = verifyFetchAnswer(unwrap(parseUploadPackRequest(fetchBody({ wants: [head], haves: [have] }))), answer);
415 assert.equal(sentDone.ok, false); assert.equal(sentDone.error.code, 'protocol'); assert.match(sentDone.error.message, /expected packfile/);
416 // a have git does not hold: the round ends on its acknowledgments, which is no answer to store
417 const stranger = 'f'.repeat(40);
418 const nakBody = fetchBody({ wants: [head], haves: [stranger], done: false });
419 const nak = await post(`${srv.url}/pc.git`, nakBody);
420 assert.equal(new TextDecoder('latin1').decode(nak), '0014acknowledgments\n0008NAK\n0000', 'git answers NAK and ends the round');
421 const noPack = verifyFetchAnswer(unwrap(parseUploadPackRequest(nakBody)), nak);
422 assert.equal(noPack.ok, false); assert.equal(noPack.error.code, 'protocol'); assert.match(noPack.error.message, /no packfile section/);
423});
425// The streaming store gate judges an answer by the request that produced it, as verifyFetchAnswer does (above). The
426// answer in both tests is real git upload-pack's reply to a request without `done` for a have it holds; its lead is
427// asserted byte for byte from gitprotocol-v2 (acknowledgments, ACK, ready, delim, packfile), written out by hand.
428const ackAnswer = async () => {
429 const head = headOf(), have = git(bare, ['rev-parse', 'main~1']).trim();
430 const body = fetchBody({ wants: [head], haves: [have], done: false });
431 const answer = await post(`${srv.url}/pc.git`, body);
432 const lead = `0014acknowledgments\n0031ACK ${have}\n000aready\n0001000dpackfile\n`;
433 assert.equal(new TextDecoder('latin1').decode(answer.subarray(0, lead.length)), lead, 'git answers ACK and ready, then the pack');
434 return { head, have, body, answer };
435};
437test('cachingFetch: a streamed answer with an acknowledgments section to a request that sent done is not stored; the caller still gets every byte', async () => {
438 otherWriter({ 'gate-done.txt': 'one\n' }, 'gate: done request');
439 const { head, answer } = await ackAnswer();
440 // a pure fetch (wants, done): after `done` git's fetch-pack reads the packfile section next and dies on
441 // "expected 'packfile', received 'acknowledgments'", so these bytes are no answer to this request
442 const body = fetchBody({ wants: [head] });
443 assert.equal(unwrap(parseUploadPackRequest(body)).done, true);
444 const pending = [];
445 let origin = 0;
446 const lying = async () => { origin++; return new Response(answer.slice(), { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-result' } }); };
447 const cache = memoryCache();
448 const f = cachingFetch(lying, cache, { verifyBeforeStore: true, waitUntil: p => { pending.push(p); } });
449 const call = async () => { const res = await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body }); const got = new Uint8Array(await res.arrayBuffer()); await Promise.all(pending.splice(0)); return { got }; };
450 const first = await call();
451 assert.deepEqual(first.got, answer, 'the bytes still flow to the caller, unchanged');
452 assert.equal(cache.entries.size, 0, 'nothing stored');
453 assert.equal(f.stats.miss, 1); assert.equal(f.stats.verifyFailed, 1); assert.equal(f.stats.verifyOk, 0); assert.equal(f.stats.putOk, 0);
454 assert.match(f.stats.verifyError, /expected packfile, received acknowledgments/);
455 // so the next call asks the origin again: no hit
456 const second = await call();
457 assert.deepEqual(second.got, answer);
458 assert.equal(origin, 2); assert.equal(f.stats.hit, 0); assert.equal(f.stats.miss, 2); assert.equal(cache.entries.size, 0);
459});
461test('cachingFetch: git\'s streamed answer to a request without done (acknowledgments, ready, packfile) is stored, and the second call is a hit', async () => {
462 otherWriter({ 'gate-not-done.txt': 'one\n' }, 'gate: non-done request');
463 const { body, answer } = await ackAnswer();
464 assert.equal(unwrap(parseUploadPackRequest(body)).done, false);
465 // a negotiation round is not a pure fetch: only a caller's own shouldCache admits it
466 assert.equal(exchangeKind('POST', `${url}/git-upload-pack`, body), null);
467 const pending = [];
468 const cache = memoryCache();
469 const f = cachingFetch(globalThis.fetch, cache, { shouldCache: () => true, waitUntil: p => { pending.push(p); } });
470 const call = async () => { const got = await rawCall(f, body); await Promise.all(pending.splice(0)); return got; };
471 const before = counts();
472 const first = await call();
473 // git may pack the same objects into different bytes on another call: the object set is the oracle, not the bytes
474 assert.deepEqual(objectSet(first), objectSet(answer));
475 assert.equal(f.stats.miss, 1); assert.equal(f.stats.verifyFailed, 0, f.stats.verifyError); assert.equal(f.stats.verifyOk, 1); assert.equal(f.stats.putOk, 1);
476 assert.equal(cache.entries.size, 1, 'stored');
477 const hit = await call();
478 assert.equal(f.stats.hit, 1); assert.equal(f.stats.miss, 1);
479 assert.deepEqual(hit, first, 'the hit replays the stored answer byte for byte');
480 assert.equal(delta(before, counts()).fetch, 1, 'the origin saw one fetch for the two calls');
481});
483test('cachingFetch verifyBeforeStore: a blob fetch is cached; a tampered answer is never stored; a hit is byte-identical to the stored answer', async () => {
484 const body = fetchBody({ wants: [blobOid()] });
485 const pending = [];
486 const waitUntil = p => { pending.push(p); };
487 const settle = async () => { await Promise.all(pending.splice(0)); };
488 const call = async f => new Uint8Array(await (await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body })).arrayBuffer());
489 // without the option the blob fetch is a bypass, as before
490 const plain = cachingFetch(globalThis.fetch, memoryCache());
491 await call(plain); assert.equal(plain.stats.bypass, 1);
492 // a lying origin: the answer is tampered on the way; the client still gets it (and refuses it itself), the cache does not
493 const tamper = async (u, init) => { const res = await fetch(u, init); const b = new Uint8Array(await res.arrayBuffer()); b[b.length - 30] ^= 0xff; return new Response(b, { status: 200, headers: res.headers }); };
494 const badCache = memoryCache();
495 const lied = cachingFetch(tamper, badCache, { verifyBeforeStore: true, waitUntil });
496 await call(lied); await settle();
497 assert.equal(badCache.entries.size, 0, 'nothing stored');
498 assert.equal(lied.stats.miss, 1); assert.equal(lied.stats.verifyFailed, 1); assert.equal(lied.stats.verifyOk, 0); assert.equal(lied.stats.putOk, 0);
499 assert.ok(lied.stats.verifyError.length > 0);
500 assert.equal(lied.attrs()['git.pack.cache.verify.failed'], 1);
501 // an honest origin: stored once verified; the hit is the origin's answer byte for byte
502 const cache = memoryCache();
503 const f = cachingFetch(globalThis.fetch, cache, { verifyBeforeStore: true, waitUntil });
504 const first = await call(f); await settle();
505 assert.deepEqual(objectSet(first), [blobOid()]);
506 assert.equal(cache.entries.size, 1); assert.equal(f.stats.verifyOk, 1); assert.equal(f.stats.putOk, 1);
507 const hit = await call(f);
508 assert.equal(f.stats.hit, 1);
509 // git may answer the same request with different pack bytes (a loose object, then a packed one): the guarantee is
510 // that a hit replays the very answer that was verified and stored
511 assert.deepEqual(hit, first, 'byte-identical');
512 assert.deepEqual(hit, cache.entries.values().next().value.body);
513 // and a ply read through it: the second read of the blob comes from the cache, hash-checked by the reader
514 const c = unwrap(GitHttp.create(url, { tracer: new Tracer(), fetchImpl: f }));
515 const read = async () => new TextDecoder().decode((await unwrapAsync(c.fetchObject({ oid: blobOid() }))).data);
516 assert.equal(await read(), git(bare, ['cat-file', '-p', blobOid()])); await settle();
517 const before = counts();
518 assert.equal(await read(), git(bare, ['cat-file', '-p', blobOid()]));
519 assert.equal(delta(before, counts()).fetch, 0, 'served from the cache');
520 assert.equal(f.stats.verifyOk, 2);
521});
523test('cachingFetch verifyBeforeStore: an answer over the cap, a request that is not a fetch, and a bad limit are counted and not stored', async () => {
524 const pending = [];
525 const opts = extra => ({ verifyBeforeStore: true, waitUntil: p => { pending.push(p); }, ...extra });
526 const run = async (f, body) => { await (await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body })).arrayBuffer(); await Promise.all(pending.splice(0)); };
527 const small = memoryCache(); const fs = cachingFetch(globalThis.fetch, small, opts({ limits: { ...DEFAULT_LIMITS, maxPackBytes: 8 } }));
528 await run(fs, fetchBody({ wants: [blobOid()] }));
529 assert.equal(small.entries.size, 0); assert.equal(fs.stats.verifyFailed, 1); assert.match(fs.stats.verifyError, /exceeds limit 8/);
530 const ls = memoryCache(); const fl = cachingFetch(globalThis.fetch, ls, opts({ shouldCache: () => true }));
531 await run(fl, unwrap(lsRefsBodyR([])));
532 // ls-refs under a caller's own rule: verifyBeforeStore stores only what verifyFetchAnswer accepted, and ls-refs is no
533 // fetch, so it is never stored under the flag (README "cachingFetch"; without the flag it is, see the gate cells)
534 assert.equal(ls.entries.size, 0); assert.equal(fl.stats.verifyOk, 0); assert.equal(fl.stats.verifyFailed, 1); assert.match(fl.stats.verifyError, /no fetch/);
535 await run(fl, unwrap(lsRefsBodyR([]))); assert.equal(fl.stats.hit, 0);
536 const nan = memoryCache(); const fn = cachingFetch(globalThis.fetch, nan, opts({ limits: { ...DEFAULT_LIMITS, maxPackBytes: Number.NaN } }));
537 await run(fn, fetchBody({ wants: [blobOid()] }));
538 assert.equal(nan.entries.size, 0); assert.equal(fn.stats.verifyFailed, 1);
539});
541// gitprotocol-pack: error-line = PKT-LINE("ERR" SP explanation-text). upload-pack reports its own failures in-band,
542// inside an HTTP 200 with the upload-pack content type. The frame is built by hand: 4 hex digits of length, then the text.
543const ERR_TEXT = 'ERR upload-pack: internal error, try again\n';
544const ERR_ANSWER = te.encode((ERR_TEXT.length + 4).toString(16).padStart(4, '0') + ERR_TEXT);
545const RESULT = { 'content-type': 'application/x-git-upload-pack-result' };
546const rawCall = async (f, body) => new Uint8Array(await (await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body })).arrayBuffer());
548// The store gate's own refusals, one cell each (gate c: these five fail sites are the packcache space's). The contract
549// is README "cachingFetch": what reaches cache.put has pkt-line framing complete to the final flush, no ERR packet and,
550// when there is a packfile section, a PACK v2/v3 header and a trailing SHA-1 of the pack bytes; an answer that fails
551// is not stored, and the caller still gets the origin's bytes. Every answer here is built by hand from the protocol:
552// a pkt-line is 4 hex digits of its own length (the 4 included) and the payload (gitprotocol-common), a flush is 0000.
553test('cachingFetch: the store gate refuses an ERR packet, a missing flush, a cut pkt-line, a packfile section that is no pack and a pack with no trailer; the caller gets every byte', async () => {
554 const frame = bytes => concat([te.encode((bytes.length + 4).toString(16).padStart(4, '0')), bytes]);
555 const flush = te.encode('0000');
556 // gitprotocol-v2 ls-refs output: `<oid> SP <refname> LF` per ref, then a flush-pkt
557 const ref = frame(te.encode(`${'1'.repeat(40)} refs/heads/main\n`));
558 assert.equal(ref.length, 4 + 40 + 1 + 15 + 1);
559 // gitprotocol-v2 fetch output: the section header `packfile LF`, then sideband pkt-lines (band 1 is pack data), then
560 // a flush-pkt
561 const band1 = bytes => frame(concat([Uint8Array.of(1), bytes]));
562 const packfile = pack => concat([frame(te.encode('packfile\n')), band1(pack), flush]);
563 // gitformat-pack: "PACK", a 4-byte big-endian version (2), a 4-byte object count (0), then the entries (none), then
564 // the SHA-1 of everything before it. So the smallest pack is these 12 bytes and their 20-byte SHA-1 (node:crypto).
565 const header = Uint8Array.of(0x50, 0x41, 0x43, 0x4b, 0, 0, 0, 2, 0, 0, 0, 0);
566 const emptyPack = concat([header, new Uint8Array(createHash('sha1').update(header).digest())]);
567 const lsRefs = unwrap(lsRefsBodyR([]));
568 const fetchReq = fetchBody({ wants: ['2'.repeat(40)] });
569 const pending = [];
570 const run = async (answer, body) => {
571 let origin = 0;
572 const cache = memoryCache();
573 const f = cachingFetch(async () => { origin++; return new Response(answer.slice(), { status: 200, headers: RESULT }); }, cache, { shouldCache: () => true, waitUntil: p => { pending.push(p); } });
574 const got = [];
575 for (let i = 0; i < 2; i++) { got.push(await rawCall(f, body)); await Promise.all(pending.splice(0)); }
576 return { origin, cache, f, got };
577 };
578 const refusedCell = async (name, answer, body, error) => {
579 const { origin, cache, f, got } = await run(answer, body);
580 assert.deepEqual(got, [answer, answer], `${name}: the caller gets the origin's bytes, both times`);
581 assert.equal(cache.entries.size, 0, `${name}: nothing stored`);
582 assert.equal(origin, 2, `${name}: the second call asked the origin again`);
583 assert.deepEqual([f.stats.hit, f.stats.miss, f.stats.putOk, f.stats.verifyOk, f.stats.verifyFailed], [0, 2, 0, 0, 2], name);
584 assert.match(f.stats.verifyError, error, name);
585 };
586 // the builders are sound: the same shapes, complete, are stored and the second call is a hit
587 for (const [name, answer, body] of [['ls-refs', concat([ref, flush]), lsRefs], ['empty pack', packfile(emptyPack), fetchReq]]) {
588 const { origin, cache, f, got } = await run(answer, body);
589 assert.deepEqual(got, [answer, answer], name);
590 assert.deepEqual([origin, cache.entries.size, f.stats.hit, f.stats.putOk, f.stats.verifyFailed], [1, 1, 1, 1, 0], `${name}: ${f.stats.verifyError}`);
591 }
592 // an answer that is not a fetch's: upload-pack's in-band error-line instead of the refs
593 await refusedCell('ERR packet', ERR_ANSWER, lsRefs, /answer: an ERR packet/);
594 // the ref line and no flush-pkt after it: the output never ended
595 await refusedCell('no flush', ref, lsRefs, /answer: ended without a flush/);
596 // the ref line cut 5 bytes short (its length prefix says 61, 56 arrived): the framing is not complete
597 await refusedCell('cut pkt-line', ref.slice(0, ref.length - 5), lsRefs, /trailing 56 bytes after last pkt-line/);
598 // a packfile section whose band 1 is 32 bytes that do not begin "PACK" (the empty pack with its first byte changed)
599 const notPack = emptyPack.slice(); notPack[0] = 0x51;
600 await refusedCell('no PACK header', packfile(notPack), fetchReq, /answer: the packfile section does not start with a PACK v2\/v3 header/);
601 // a packfile section that holds the 12-byte header and ends: 12 bytes are fewer than the 20 of a trailer
602 await refusedCell('no trailer', packfile(header), fetchReq, /answer: the pack ends before its trailer/);
603});
605test('cachingFetch (default rule): an origin that answers an in-band ERR once and then recovers is not remembered as failed', async () => {
606 const head = headOf();
607 let origin = 0;
608 const flaky = async (u, init) => (origin++ === 0 ? new Response(ERR_ANSWER, { status: 200, headers: RESULT }) : fetch(u, init));
609 const cache = memoryCache(); const pending = [];
610 const f = cachingFetch(flaky, cache, { waitUntil: p => { pending.push(p); } });
611 const c = unwrap(GitHttp.create(url, { tracer: new Tracer(), fetchImpl: f }));
612 const req = { wants: [head], filter: 'tree:0', deepen: 1 };
613 const first = await c.fetchPack(req); await Promise.all(pending.splice(0));
614 assert.equal(first.ok, false); assert.equal(first.error.code, 'remote_error', 'the failure itself is reported honestly');
615 assert.equal(cache.entries.size, 0, 'a failed answer is never stored');
616 assert.equal(f.stats.putOk, 0);
617 const second = await c.fetchPack(req); await Promise.all(pending.splice(0));
618 assert.equal(second.ok, true, 'the recovered origin answers the second call');
619 // tree:0 at depth 1 of one commit is that one commit (git's own answer, as in the buffered fetchPack test above)
620 assert.equal(second.value.parsed.stats.count, 1);
621 assert.equal(origin, 2, 'the second call went to the origin, not to a stored failure');
622 assert.equal(f.stats.hit, 0);
623 // the good answer is what the cache holds now: one entry, and its pack is exactly the wanted commit
624 assert.equal(cache.entries.size, 1);
625 assert.deepEqual(objectSet(cache.entries.values().next().value.body), [head]);
626});
628test('cachingFetch: an origin body that fails part way is not stored and does not reject the store; a stored entry with no body is evicted', async () => {
629 const head = headOf();
630 const body = fetchBody({ wants: [head], filter: 'tree:0', deepen: 1 });
631 const pending = [];
632 const waitUntil = p => { pending.push(p); };
633 // the origin sends the first 10 bytes of git's answer, then the connection drops
634 const dropped = async (u, init) => {
635 const whole = new Uint8Array(await (await fetch(u, init)).arrayBuffer());
636 let sent = false;
637 const stream = new ReadableStream({ pull(ctl) { if (sent) { ctl.error(new Error('connection reset')); return; } sent = true; ctl.enqueue(whole.slice(0, 10)); } });
638 return new Response(stream, { status: 200, headers: RESULT });
639 };
640 const cache = memoryCache();
641 const f = cachingFetch(dropped, cache, { waitUntil });
642 await assert.rejects(rawCall(f, body), /connection reset/, 'the caller sees the drop');
643 // every store promise settles without rejecting (an unawaited rejection would take a node process down)
644 assert.deepEqual((await Promise.allSettled(pending.splice(0))).map(s => s.status), ['fulfilled']);
645 assert.equal(cache.entries.size, 0); assert.equal(f.stats.putOk, 0); assert.equal(f.stats.verifyFailed, 1);
646 assert.match(f.stats.verifyError, /the body failed while it was read: .*connection reset/);
647 // a store that answers a match with a bodiless response: the cache layer does not look inside a HIT. It is handed on
648 // as the store gave it, unparsed, and the caller's own reader is what refuses it (an empty body is not an answer).
649 const hollowDeleted = [];
650 const hollow = { match: async () => new Response(null, { status: 200, headers: RESULT }), put: async () => null, delete: async k => { hollowDeleted.push(k); return true; } };
651 const g = cachingFetch(globalThis.fetch, hollow, { waitUntil });
652 const before = counts();
653 const res = await g(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body });
654 assert.equal(res.headers.get('x-ply-pack-cache'), 'HIT'); assert.equal((await res.arrayBuffer()).byteLength, 0);
655 assert.equal(delta(before, counts()).fetch, 0); assert.equal(g.stats.hit, 1); assert.equal(g.counters.parsed, 0);
656 // ply's client refuses the empty HIT, the key is deleted, and the origin is asked exactly once: the caller gets the
657 // origin's own answer (one commit for this want), never the empty body
658 const viaClient = await unwrap(GitHttp.create(url, { tracer: new Tracer(), fetchImpl: g })).fetchPack({ wants: [head], filter: 'tree:0', deepen: 1 });
659 assert.equal(viaClient.ok, true, 'the empty body is never the answer: the refused HIT is retried past the cache');
660 assert.equal(viaClient.value.parsed.stats.count, 1, 'the origin\'s answer for this want is one commit');
661 assert.equal(delta(before, counts()).fetch, 1, 'the origin was asked exactly once');
662 assert.equal(hollowDeleted.length, 1, 'the refused key was deleted'); assert.equal(g.stats.bust, 1);
663});
665test('cachingFetch: a stored entry is untrusted; a tampered pack is served at most once, deleted, and refetched once (the client\'s parse is the check)', async () => {
666 const head = headOf();
667 const req = { wants: [head], filter: 'tree:0', deepen: 1 };
668 const inner = memoryCache(); const pending = [];
669 // the store, counted: what each match served and which keys were deleted
670 const served = []; const deleted = [];
671 const cache = {
672 entries: inner.entries,
673 match: async k => { const r = await inner.match(k); if (r) { const b = new Uint8Array(await r.clone().arrayBuffer()); served.push(b); } return r; },
674 put: (k, r) => inner.put(k, r),
675 delete: async k => { deleted.push(k); return inner.delete(k); },
676 };
677 const f = cachingFetch(globalThis.fetch, cache, { waitUntil: p => { pending.push(p); } });
678 const settle = async () => { await Promise.all(pending.splice(0)); };
679 const c = unwrap(GitHttp.create(url, { tracer: new Tracer(), fetchImpl: f }));
680 const first = await unwrapAsync(c.fetchPack(req)); await settle();
681 assert.equal(first.parsed.stats.count, 1); assert.equal(inner.entries.size, 1);
682 const [key] = [...inner.entries.keys()];
683 const good = inner.entries.get(key).body.slice();
684 assert.deepEqual(objectSet(good), [head]);
685 // one flipped byte inside the pack (30 bytes from the end: before the 20-byte trailer and the final flush)
686 const flipped = good.slice(); flipped[flipped.length - 30] ^= 0xff;
687 let busts = 0;
688 // and one flipped bit further in (still inside the single commit's deflate stream)
689 const flipped2 = good.slice(); flipped2[flipped2.length - 40] ^= 0x01;
690 for (const [name, poison] of [['flipped byte', flipped], ['flipped bit', flipped2]]) {
691 inner.entries.set(key, { body: poison.slice(), headers: { ...RESULT } });
692 served.length = 0; deleted.length = 0;
693 const before = counts(); const parsedBefore = f.counters.parsed; const hitsBefore = f.stats.hit;
694 // oxlint-disable-next-line no-await-in-loop -- one poison at a time
695 const got = await c.fetchPack(req); await settle();
696 assert.equal(got.ok, true, `${name}: the caller gets a good answer`);
697 assert.equal(got.value.parsed.stats.count, 1, `${name}: git's answer for this want is one commit`);
698 assert.equal(f.stats.hit, hitsBefore + 1, `${name}: the stored entry was served as a HIT, unparsed by the cache`);
699 assert.equal(served.filter(b => Buffer.compare(b, poison) === 0).length, 1, `${name}: the poisoned bytes were served exactly once`);
700 assert.deepEqual(deleted, [key], `${name}: the entry was deleted`);
701 assert.equal(delta(before, counts()).fetch, 1, `${name}: refetched from the origin exactly once`);
702 assert.equal(f.stats.bust, ++busts, `${name}: counted as a bust`);
703 assert.deepEqual(objectSet(inner.entries.get(key).body), [head], `${name}: the entry now holds a verified answer`);
704 // the only chunks the cache layer parsed are the refetched answer's, on their way to the store
705 assert.ok(f.counters.parsed > parsedBefore, `${name}: the refetch went through the store-side verifier`);
706 served.length = 0; const again = counts();
707 // oxlint-disable-next-line no-await-in-loop -- as above
708 assert.equal((await unwrapAsync(c.fetchPack(req))).parsed.stats.count, 1);
709 assert.equal(delta(again, counts()).fetch, 0, `${name}: the repaired entry is served`);
710 assert.equal(served.filter(b => Buffer.compare(b, poison) === 0).length, 0, `${name}: the poisoned bytes are never served again`);
711 }
712});
714test('cachingFetch: a stored entry tampered into an ERR, a cut, an empty body or a wrong pack trailer is served at most once, deleted, and refetched once', async () => {
715 const head = headOf();
716 const req = { wants: [head], filter: 'tree:0', deepen: 1 };
717 const inner = memoryCache(); const pending = [];
718 // the store, counted: what each match served and which keys were deleted
719 const served = []; const deleted = [];
720 const cache = {
721 entries: inner.entries,
722 match: async k => { const r = await inner.match(k); if (r) served.push(new Uint8Array(await r.clone().arrayBuffer())); return r; },
723 put: (k, r) => inner.put(k, r),
724 delete: async k => { deleted.push(k); return inner.delete(k); },
725 };
726 const f = cachingFetch(globalThis.fetch, cache, { waitUntil: p => { pending.push(p); } });
727 const settle = async () => { await Promise.all(pending.splice(0)); };
728 const c = unwrap(GitHttp.create(url, { tracer: new Tracer(), fetchImpl: f }));
729 await unwrapAsync(c.fetchPack(req)); await settle();
730 const [key] = [...inner.entries.keys()];
731 const good = inner.entries.get(key).body.slice();
732 // a pkt-line by hand (gitprotocol-common): four hex digits of the length, themselves included, then the payload
733 const line = text => Buffer.concat([Buffer.from((text.length + 4).toString(16).padStart(4, '0')), Buffer.from(text)]);
734 const err = Uint8Array.from(Buffer.concat([line('ERR upload-pack: not our ref\n'), Buffer.from('0000')]));
735 // the answer ends with the pack's 20-byte SHA-1 trailer and the 4-byte final flush: 10 from the end is inside the trailer
736 const trailer = good.slice(); trailer[trailer.length - 10] ^= 0xff;
737 const poisons = [['ERR packet', err], ['cut', good.slice(0, good.length - 40)], ['empty body', new Uint8Array(0)], ['wrong pack trailer', trailer]];
738 let busts = 0;
739 for (const [name, poison] of poisons) {
740 inner.entries.set(key, { body: poison.slice(), headers: { ...RESULT } });
741 served.length = 0; deleted.length = 0;
742 const before = counts();
743 // oxlint-disable-next-line no-await-in-loop -- one poison at a time
744 const got = await c.fetchPack(req); await settle();
745 assert.equal(got.ok, true, `${name}: the caller gets the origin's answer, not the stored failure`);
746 assert.equal(got.value.parsed.stats.count, 1, `${name}: the origin's answer for this want is one commit`);
747 assert.equal(served.filter(b => Buffer.compare(b, poison) === 0).length, 1, `${name}: the poisoned bytes were served exactly once`);
748 assert.deepEqual(deleted, [key], `${name}: the entry was deleted`);
749 assert.equal(delta(before, counts()).fetch, 1, `${name}: refetched from the origin exactly once`);
750 assert.equal(f.stats.bust, ++busts, `${name}: counted as a bust`);
751 assert.deepEqual(objectSet(inner.entries.get(key).body), [head], `${name}: the entry now holds a verified answer`);
752 served.length = 0; const again = counts();
753 // oxlint-disable-next-line no-await-in-loop -- as above
754 assert.equal((await unwrapAsync(c.fetchPack(req))).parsed.stats.count, 1);
755 assert.equal(delta(again, counts()).fetch, 0, `${name}: the repaired entry is served`);
756 assert.equal(served.filter(b => Buffer.compare(b, poison) === 0).length, 0, `${name}: the poisoned bytes are never served again`);
757 }
758});
760test('cachingFetch: a HIT is streamed from the store with no pass in the cache layer (counters, not time)', async () => {
761 const head = headOf();
762 const body = fetchBody({ wants: [head], filter: 'tree:0', deepen: 1 });
763 const inner = memoryCache(); const pending = [];
764 // the store serves its entry 16 bytes per pull, and counts the pulls
765 let pulls = 0;
766 const cache = {
767 match: async k => {
768 const e = inner.entries.get(k);
769 if (!e) return null;
770 let at = 0;
771 const stream = new ReadableStream({ pull(ctl) { pulls++; if (at >= e.body.length) { ctl.close(); return; } ctl.enqueue(e.body.slice(at, at + 16)); at += 16; } }, { highWaterMark: 0 });
772 return new Response(stream, { status: 200, headers: e.headers });
773 },
774 put: (k, r) => inner.put(k, r), delete: k => inner.delete(k),
775 };
776 const f = cachingFetch(globalThis.fetch, cache, { waitUntil: p => { pending.push(p); } });
777 const miss = await rawCall(f, body); await Promise.all(pending.splice(0));
778 assert.deepEqual(objectSet(miss), [head]); assert.equal(inner.entries.size, 1);
779 const parsed = f.counters.parsed;
780 assert.ok(parsed > 0, 'the MISS went through the store-side verifier');
781 const res = await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body });
782 assert.equal(res.headers.get('x-ply-pack-cache'), 'HIT');
783 // the response is there before a single byte of the entry was read: nothing was buffered or checked first
784 assert.equal(pulls, 0, 'no byte of the entry is read before the response is returned');
785 const reader = res.body.getReader();
786 const firstChunk = await reader.read();
787 // 16 bytes per pull: the first chunk the caller sees is the store's first chunk, not the whole entry
788 assert.equal(firstChunk.value.length, 16); assert.ok(pulls <= 2, `pulls after the first read: ${pulls}`);
789 const parts = [firstChunk.value];
790 for (;;) { const r = await reader.read(); if (r.done) break; parts.push(r.value); }
791 assert.deepEqual(concat(parts), miss, 'byte-identical to the stored answer');
792 assert.equal(f.counters.parsed, parsed, 'a HIT parses nothing in the cache layer');
793 assert.equal(f.stats.hit, 1);
794});
796// A synthetic v2 fetch answer, generated a frame at a time: `packfile\n`, then sideband-1 frames carrying a pack of
797// `packBytes` bytes (12-byte header, filler, 20-byte trailer), then a flush. The trailer is node:crypto's SHA-1 of the
798// pack bytes before it (gitformat-pack: "20-byte SHA-1 checksum of all of the above"). `lie` flips the trailer.
799const sideband1 = payload => { const f = new Uint8Array(5 + payload.length); f.set(te.encode((payload.length + 5).toString(16).padStart(4, '0'))); f[4] = 1; f.set(payload, 5); return f; };
800const syntheticAnswer = (packBytes, meter, { lie = false, endless = false } = {}) => {
801 const sha = createHash('sha1');
802 let sent = -1; // -1: the section header is next
803 return new ReadableStream({
804 pull(ctl) {
805 let frame;
806 if (sent === -1) { frame = unwrap(pkt('packfile\n')); sent = 0; }
807 else if (sent === 0) { const h = new Uint8Array([0x50, 0x41, 0x43, 0x4b, 0, 0, 0, 2, 0, 0, 0, 1]); sha.update(h); frame = sideband1(h); sent = 12; }
808 else if (endless || sent < packBytes - 20) { const n = endless ? 65515 : Math.min(65515, packBytes - 20 - sent); const filler = new Uint8Array(n).fill(sent & 0xff); sha.update(filler); frame = sideband1(filler); sent += n; }
809 else if (sent === packBytes - 20) { const t = new Uint8Array(sha.digest()); if (lie) t[0] ^= 1; frame = sideband1(t); sent = packBytes; }
810 else { ctl.enqueue(FLUSH.slice()); ctl.close(); meter.produced += 4; return; }
811 meter.produced += frame.length; ctl.enqueue(frame);
812 },
813 cancel() { meter.cancelled = true; },
814 }, { highWaterMark: 0 });
815};
817test('cachingFetch memory: a 64 MiB answer streams through the verifier into the store; ply holds a few frames, never the answer', async () => {
818 const body = fetchBody({ wants: [headOf()], filter: 'tree:0', deepen: 1 });
819 const PACK = 64 * 1024 * 1024;
820 for (const lie of [false, true]) {
821 const meter = { produced: 0, cancelled: false };
822 const origin = async () => new Response(syntheticAnswer(PACK, meter, { lie }), { status: 200, headers: RESULT });
823 // a store that holds nothing, as the Cache API does from ply's point of view: it reads the body and counts
824 let stored = 0, maxHeld = 0, putRejected = null; const deleted = [];
825 // the counter: bytes the origin has produced that the store has not been handed yet, sampled at every chunk on either side
826 const sample = () => { maxHeld = Math.max(maxHeld, meter.produced - stored); };
827 const store = {
828 match: async () => null,
829 put: async (k, res) => { const r = res.body.getReader(); try { for (;;) { const { value, done } = await r.read(); if (done) return; stored += value.length; sample(); } } catch (e) { putRejected = e; throw e; } },
830 delete: async k => { deleted.push(k); return true; },
831 };
832 const pending = [];
833 const f = cachingFetch(origin, store, { waitUntil: p => { pending.push(p); } });
834 const res = await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body });
835 let client = 0;
836 // oxlint-disable-next-line no-await-in-loop -- one stream
837 for (const r = res.body.getReader(); ;) { const { value, done } = await r.read(); if (done) break; client += value.length; sample(); }
838 assert.deepEqual((await Promise.allSettled(pending)).map(x => x.status), ['fulfilled']);
839 // frames: 13 (packfile) + ceil(PACK / 65515) pack frames of 5 bytes overhead each + the header's own frame + flush
840 assert.ok(client > PACK && client === meter.produced, `the client got the whole answer (${client})`);
841 // What sits between the origin and the store is ply's whole cache path (the verifier and the cache branch's queue):
842 // bounded by the lag window (CACHE_LAG_BYTES, 1 MiB) plus the frame in flight on each side, not by the 64 MiB
843 // answer. A design that reads the answer whole before the put holds all 64 MiB here.
844 assert.ok(maxHeld <= 1024 * 1024 + 2 * 65520, `${lie ? 'lie' : 'honest'}: at most ${maxHeld} bytes between origin and store`);
845 if (lie) {
846 // the trailer is wrong: the put's body errors at the end, the put never completes, the key is deleted, counted
847 assert.ok(putRejected !== null, 'the body handed to put was errored'); assert.match(String(putRejected), /pack trailer .* is not the SHA-1 of the pack/);
848 assert.equal(f.stats.verifyFailed, 1); assert.equal(f.stats.verifyOk, 0); assert.equal(f.stats.putOk, 0); assert.equal(deleted.length, 1);
849 } else {
850 assert.equal(putRejected, null); assert.equal(stored, client, 'every byte reached the store');
851 assert.equal(f.stats.verifyOk, 1); assert.equal(f.stats.putOk, 1); assert.equal(f.stats.verifyFailed, 0); assert.equal(deleted.length, 0);
852 }
853 }
854}, 120_000);
856test('cachingFetch: a client that abandons the answer cancels the cache branch and the origin; nothing is drained', async () => {
857 const body = fetchBody({ wants: [headOf()], filter: 'tree:0', deepen: 1 });
858 const meter = { produced: 0, cancelled: false };
859 // a hostile origin, but a finite one: 32 MiB of packfile section, 64 times the allowance below. An origin that never
860 // ends would make an implementation that drains spin in microtasks for ever (a hung worker, not a red test); this
861 // one lets the drain finish, so the byte count below fails it.
862 const ORIGIN = 32 * 1024 * 1024;
863 const origin = async () => new Response(syntheticAnswer(ORIGIN, meter), { status: 200, headers: RESULT });
864 let stored = 0; const deleted = [];
865 const store = {
866 match: async () => null,
867 put: async (k, res) => { const r = res.body.getReader(); for (;;) { const { value, done } = await r.read(); if (done) return; stored += value.length; } },
868 delete: async k => { deleted.push(k); return true; },
869 };
870 const pending = [];
871 const f = cachingFetch(origin, store, { waitUntil: p => { pending.push(p); }, limits: { ...DEFAULT_LIMITS, maxPackBytes: 8 * 1024 * 1024 } });
872 const res = await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body });
873 const reader = res.body.getReader();
874 await reader.read(); await reader.read(); await reader.read();
875 await reader.cancel(new Error('the client refused the answer'));
876 // The store promise settles within a counted number of event-loop turns (no clock): at head it settles in the
877 // cancel's own microtasks; an implementation that neither cancels nor drains never settles it, and fails here.
878 let outcome = null;
879 void Promise.allSettled(pending).then(s => { outcome = s.map(x => x.status); });
880 // oxlint-disable-next-line no-await-in-loop -- counted turns
881 for (let turn = 0; turn < 1000 && outcome === null; turn++) await new Promise(r => { setImmediate(r); });
882 assert.deepEqual(outcome, ['fulfilled'], 'the store promise settled, fulfilled, within 1000 turns of the cancel');
883 // three reads by the client; the split and the store may each be a few frames ahead (8 frames allowed). Draining
884 // reads the origin to its end: 32 MiB and its framing.
885 assert.ok(meter.produced <= 8 * 65520, `origin bytes pulled: ${meter.produced}`);
886 assert.equal(meter.cancelled, true, 'the origin was cancelled');
887 assert.equal(f.stats.verifyFailed, 1); assert.match(f.stats.verifyError, /the client abandoned it/); assert.equal(f.stats.putOk, 0);
888 assert.equal(deleted.length, 1, 'the key is deleted: a store that kept a partial entry does not keep it');
889});
891test('cachingFetch: a store whose delete fails after a refused answer, by throwing or by rejecting, never rejects the store promise', async () => {
892 const body = fetchBody({ wants: [headOf()], filter: 'tree:0', deepen: 1 });
893 const outcomes = {};
894 for (const kind of ['rejects', 'throws']) {
895 const meter = { produced: 0, cancelled: false };
896 // a wrong pack trailer: the answer is refused at its end, so the key is deleted
897 const origin = async () => new Response(syntheticAnswer(200_000, meter, { lie: true }), { status: 200, headers: RESULT });
898 let deletes = 0;
899 const store = {
900 match: async () => null,
901 put: async (k, res) => { for (const r = res.body.getReader(); ;) { const { done } = await r.read(); if (done) return; } },
902 delete: kind === 'throws' ? () => { deletes++; throw new Error('delete threw'); } : async () => { deletes++; throw new Error('delete rejected'); },
903 };
904 const pending = [];
905 const f = cachingFetch(origin, store, { waitUntil: p => { pending.push(p); } });
906 const res = await f(`${url}/git-upload-pack`, { method: 'POST', headers: UPLOAD, body });
907 await res.arrayBuffer();
908 outcomes[kind] = { settled: (await Promise.allSettled(pending)).map(x => x.status), deletes, verifyFailed: f.stats.verifyFailed, putOk: f.stats.putOk };
909 }
910 // From the contract, not from the code: the promise handed to waitUntil is fulfilled whichever way delete fails, the
911 // delete was attempted once, and the refusal is counted once.
912 const want = { settled: ['fulfilled'], deletes: 1, verifyFailed: 1, putOk: 0 };
913 assert.deepEqual(outcomes.rejects, want, 'a delete that rejects');
914 assert.deepEqual(outcomes.throws, want, 'a delete that throws synchronously ends the same way');
915});
917test('memoryCache: a fractional budget is floored, never replaced by the default; a value that is not a budget is the default', async () => {
918 const fill = async c => {
919 for (let i = 0; i < 12; i++) await c.put(`big${i}`, new Response(new Uint8Array(40_000)));
920 for (let i = 0; i < 5; i++) await c.put(`small${i}`, new Response(new Uint8Array(40)));
921 return { bytes: [...c.entries.values()].reduce((n, e) => n + e.body.length, 0), entries: c.entries.size };
922 };
923 // 100.5 -> 100 bytes: no 40,000-byte entry fits; two 40-byte entries do (80), a third would make 120
924 assert.deepEqual(await fill(memoryCache({ maxBytes: 100.5 })), { bytes: 80, entries: 2 });
925 // 1e6/3 -> 333,333 bytes: eight 40,000-byte entries (320,000; a ninth would make 360,000), then five of 40 (320,200)
926 assert.deepEqual(await fill(memoryCache({ maxBytes: 1e6 / 3 })), { bytes: 320_200, entries: 13 });
927 // 2.5 -> 2 entries: the last two puts
928 assert.deepEqual(await fill(memoryCache({ maxEntries: 2.5 })), { bytes: 80, entries: 2 });
929 // 0.5 -> 0: nothing is kept
930 assert.deepEqual(await fill(memoryCache({ maxBytes: 0.5 })), { bytes: 0, entries: 0 });
931 // not a budget (NaN, negative, infinite): the documented default, 64 MiB and 1024 entries, which holds all 17
932 for (const bad of [Number.NaN, -1, Number.POSITIVE_INFINITY]) assert.deepEqual(await fill(memoryCache({ maxBytes: bad, maxEntries: bad })), { bytes: 480_200, entries: 17 });
933});
935// The test's own accounting of what a memoryCache retains: every byte of every body it still holds, plus its header text.
936const retained = cache => [...cache.entries.values()].reduce((n, e) => n + e.body.length + Object.entries(e.headers).reduce((m, [k, v]) => m + k.length + v.length, 0), 0);
937test('memoryCache: a byte budget and an entry cap; the least recently used entry goes first', async () => {
938 // a Uint8Array body sets no content-type, so an entry is exactly its body bytes
939 const put = (c, k, n) => c.put(k, new Response(new Uint8Array(n)));
940 const c = memoryCache({ maxBytes: 100 });
941 await put(c, 'a', 40); await put(c, 'b', 40);
942 assert.deepEqual([...c.entries.keys()].sort(), ['a', 'b']); assert.equal(retained(c), 80);
943 await put(c, 'c', 40); // 120 > 100: a, the least recently used, goes; b + c = 80
944 assert.deepEqual([...c.entries.keys()].sort(), ['b', 'c']); assert.equal(retained(c), 80);
945 assert.equal((await c.match('b')).status, 200); // a read makes b the most recently used
946 await put(c, 'd', 40); // so c goes, not b
947 assert.deepEqual([...c.entries.keys()].sort(), ['b', 'd']); assert.equal(retained(c), 80);
948 await put(c, 'e', 101); // larger than the whole budget: not stored, and nothing is evicted for it
949 assert.deepEqual([...c.entries.keys()].sort(), ['b', 'd']); assert.ok(!(await c.match('e')));
950 await put(c, 'b', 100); // a put replaces: the old b (40) is gone, the new b (100) fills the budget, d goes
951 assert.deepEqual([...c.entries.keys()], ['b']); assert.equal(retained(c), 100);
952 // header text counts: 'x-a' + 97 characters is 100 bytes of headers, so a 1-byte body is over the budget of 100
953 await c.put('h', new Response(new Uint8Array(1), { headers: { 'x-a': 'v'.repeat(97) } }));
954 assert.ok(!c.entries.has('h'));
955 // the entry cap: four 1-byte entries under a cap of three
956 const few = memoryCache({ maxBytes: 100, maxEntries: 3 });
957 for (const k of ['p', 'q', 'r', 's']) await put(few, k, 1); // oxlint-disable-line no-await-in-loop -- in order
958 assert.deepEqual([...few.entries.keys()].sort(), ['q', 'r', 's']);
959 // a long run never retains more than the budget: 200 puts of 1000 bytes under 10,000 keep the last ten
960 const run = memoryCache({ maxBytes: 10_000 });
961 let peak = 0;
962 for (let i = 0; i < 200; i++) { await put(run, `k${i}`, 1000); peak = Math.max(peak, retained(run)); } // oxlint-disable-line no-await-in-loop -- in order
963 assert.equal(peak, 10_000);
964 assert.deepEqual([...run.entries.keys()].sort(), Array.from({ length: 10 }, (_, i) => `k${190 + i}`));
965 // a body over the budget is not read to its end: 1000 chunks of 1 KiB offered, the budget is 4 KiB
966 let pulled = 0;
967 const endless = new ReadableStream({ pull(ctl) { if (pulled++ < 1000) ctl.enqueue(new Uint8Array(1024)); else ctl.close(); } });
968 const tiny = memoryCache({ maxBytes: 4096 });
969 await tiny.put('big', new Response(endless));
970 assert.equal(tiny.entries.size, 0); assert.ok(pulled < 10, `read ${pulled} of 1000 chunks`);
971 // the named defaults, and a budget that is not a non-negative integer falls back to them (never unbounded)
972 assert.equal(LIMIT_MEMORY_CACHE_BYTES, 64 * 1024 * 1024); assert.equal(LIMIT_MEMORY_CACHE_ENTRIES, 1024);
973 const dflt = memoryCache({ maxBytes: Number.POSITIVE_INFINITY, maxEntries: Number.NaN });
974 for (let i = 0; i < 1030; i++) await put(dflt, `n${i}`, 1); // oxlint-disable-line no-await-in-loop -- in order
975 assert.equal(dflt.entries.size, 1024);
976});
978// ply#270. The whole answer is built by hand from the protocol docs: gitformat-pack (a 12-byte header "PACK", version 2,
979// object count; one entry whose first byte is (type 3 = blob) << 4 | size for a size under 16, then the zlib stream of
980// the content; the SHA-1 of everything before as the trailer) and gitprotocol-v2 (`packfile LF`, band-1 pkt-lines, a
981// flush-pkt). The pack is well formed and its trailer valid; it holds one blob that is not the want.
982const handPack = content => {
983 const head = Uint8Array.of(0x50, 0x41, 0x43, 0x4b, 0, 0, 0, 2, 0, 0, 0, 1);
984 assert.ok(content.length < 16);
985 const entry = concat([Uint8Array.of((3 << 4) | content.length), new Uint8Array(deflateSync(content))]);
986 const body = concat([head, entry]);
987 return concat([body, new Uint8Array(createHash('sha1').update(body).digest())]);
988};
989const framed = bytes => concat([te.encode((bytes.length + 4).toString(16).padStart(4, '0')), bytes]);
990const packAnswer = pack => concat([framed(te.encode('packfile\n')), framed(concat([Uint8Array.of(1), pack])), te.encode('0000')]);
992test('cachingFetch verifyBeforeStore (#270): an answer whose pack has a valid trailer but lacks the want is not stored; with a want it holds it is', async () => {
993 const content = te.encode('hi\n');
994 const answer = packAnswer(handPack(content));
995 // the blob it holds is git's hash of `blob 3\0hi\n`, never the want
996 const held = createHash('sha1').update(concat([te.encode('blob 3\0'), content])).digest('hex');
997 const want = 'f'.repeat(40);
998 assert.notEqual(held, want);
999 const body = fetchBody({ wants: [want] });
1000 assert.deepEqual(verifyFetchAnswer(unwrap(parseUploadPackRequest(body)), answer).error?.message, `answer: want ${want} is not in the pack (1 objects)`, 'the store-time check refuses it');
1001 const pending = [];
1002 const cache = memoryCache();
1003 const f = cachingFetch(async () => new Response(answer.slice(), { status: 200, headers: RESULT }), cache, { verifyBeforeStore: true, waitUntil: p => { pending.push(p); } });
1004 const got = await rawCall(f, body); await Promise.all(pending.splice(0));
1005 assert.deepEqual(got, answer, 'the caller still gets every byte');
1006 assert.deepEqual({ ...f.stats, verifyError: '', putError: '' }, { hit: 0, miss: 1, bust: 0, bypass: 0, putOk: 0, putFailed: 0, putError: '', verifyOk: 0, verifyFailed: 1, verifyError: '' });
1007 assert.match(f.stats.verifyError, new RegExp(`want ${want} is not in the pack`));
1008 assert.equal(cache.entries.size, 0, 'entries 0');
1009 // a want the pack does hold: the same bytes verify and are stored
1010 const right = cachingFetch(async () => new Response(answer.slice(), { status: 200, headers: RESULT }), cache, { verifyBeforeStore: true, waitUntil: p => { pending.push(p); } });
1011 await rawCall(right, fetchBody({ wants: [held] })); await Promise.all(pending.splice(0));
1012 assert.deepEqual([right.stats.verifyOk, right.stats.putOk, right.stats.verifyFailed, cache.entries.size], [1, 1, 0, 1], right.stats.verifyError);
1013});
1015test('cachingFetch verifyBeforeStore: a put that throws after verification is putFailed 1, and the caller\'s fetch is unaffected', async () => {
1016 const content = te.encode('hi\n');
1017 const answer = packAnswer(handPack(content));
1018 const held = createHash('sha1').update(concat([te.encode('blob 3\0'), content])).digest('hex');
1019 const body = fetchBody({ wants: [held] });
1020 // the oracle that this answer passes verification: verifyFetchAnswer itself, before any cachingFetch
1021 assert.equal(verifyFetchAnswer(unwrap(parseUploadPackRequest(body)), answer).ok, true);
1022 for (const [how, put] of [['throws', () => { throw thrown; }], ['rejects', async () => { await null; throw thrown; }]]) {
1023 const pending = []; let calls = 0;
1024 const cache = { ...memoryCache(), put: (...a) => { calls++; return put(...a); } };
1025 const f = cachingFetch(async () => new Response(answer.slice(), { status: 200, headers: RESULT }), cache, { verifyBeforeStore: true, waitUntil: p => { pending.push(p); } });
1026 // the fetch resolves, and the caller reads every byte, before the put is ever called
1027 const got = await rawCall(f, body);
1028 assert.deepEqual(got, answer, how);
1029 await Promise.all(pending.splice(0));
1030 assert.equal(calls, 1, `${how}: the put was called once, after verification`);
1031 assert.deepEqual([f.stats.miss, f.stats.verifyOk, f.stats.verifyFailed, f.stats.putOk, f.stats.putFailed], [1, 1, 0, 0, 1], how);
1032 // README cachingFetch: a put that throws is the 'cache.put' Err's message (naming the thrown value); one that rejects, its own
1033 assert.equal(f.stats.putError, how === 'throws' ? `caller-supplied cache.put threw: ${thrown.message}` : thrown.message, how);
1035});
1036const thrown = new Error('boom after verification');
1038test('cachingFetch: a NAK-only answer to a request without done is refused by the store gate, as verifyFetchAnswer refuses it (#270)', async () => {
1039 // git's own bytes for a round that ends on its acknowledgments (asserted against git upload-pack above)
1040 const nak = te.encode('0014acknowledgments\n0008NAK\n0000');
1041 const body = fetchBody({ wants: ['1'.repeat(40)], haves: ['2'.repeat(40)], done: false });
1042 assert.equal(verifyFetchAnswer(unwrap(parseUploadPackRequest(body)), nak).error?.message, 'answer: no packfile section');
1043 const pending = [];
1044 const cache = memoryCache();
1045 const f = cachingFetch(async () => new Response(nak.slice(), { status: 200, headers: RESULT }), cache, { shouldCache: () => true, waitUntil: p => { pending.push(p); } });
1046 assert.deepEqual(await rawCall(f, body), nak, 'the caller still gets every byte');
1047 await Promise.all(pending.splice(0));
1048 assert.deepEqual([f.stats.miss, f.stats.verifyOk, f.stats.verifyFailed, f.stats.putOk, cache.entries.size], [1, 0, 1, 0, 0]);
1049 assert.equal(f.stats.verifyError, 'answer: no packfile section');
1050});
1053test('cachingFetch verifyBeforeStore (#270): an answer the streaming gate refuses is counted with the gate\'s own reason, not the whole-answer read\'s', async () => {
1054 const content = te.encode('hi\n');
1055 const held = createHash('sha1').update(concat([te.encode('blob 3\0'), content])).digest('hex');
1056 const pack = handPack(content);
1057 // a flipped last trailer byte: the trailer is no longer the SHA-1 of the pack bytes before it
1058 const badTrailer = Uint8Array.from(pack); badTrailer[badTrailer.length - 1] ^= 0xff;
1059 const run = async answer => {
1060 const pending = []; const cache = memoryCache();
1061 const f = cachingFetch(async () => new Response(answer.slice(), { status: 200, headers: RESULT }), cache, { verifyBeforeStore: true, waitUntil: p => { pending.push(p); } });
1062 assert.deepEqual(await rawCall(f, fetchBody({ wants: [held] })), answer, 'the caller still gets every byte');
1063 await Promise.all(pending.splice(0));
1064 return { stats: f.stats, attrs: f.attrs(), entries: cache.entries.size };
1065 };
1066 // README "cachingFetch": the reason is in stats.verifyError and on the span as git.pack.cache.verify.error. The gate's
1067 // message is the reason; the cache branch read only failed because the gate errored it, so its prefix is not.
1068 // the expected reasons are derived here: an ERR on a fetch is the remote's text after `ERR ` (gitprotocol-v2), and a
1069 // wrong trailer names the trailer sent and node:crypto's SHA-1 of the pack bytes before it
1070 const sent = Buffer.from(badTrailer.subarray(badTrailer.length - 20)).toString('hex');
1071 const real = createHash('sha1').update(badTrailer.subarray(0, badTrailer.length - 20)).digest('hex');
1072 const cases = [['ERR packet', ERR_ANSWER, `remote: ${ERR_TEXT.slice(4).trimEnd()}`], ['wrong pack trailer', packAnswer(badTrailer), `answer: the pack trailer ${sent} is not the SHA-1 of the pack (${real})`]];
1073 for (const [name, answer, reason] of cases) {
1074 const r = await run(answer);
1075 assert.deepEqual([r.stats.verifyOk, r.stats.verifyFailed, r.stats.putOk, r.entries], [0, 1, 0, 0], name);
1076 assert.doesNotMatch(r.stats.verifyError, /the body failed while it was read/, name);
1077 assert.equal(r.stats.verifyError, reason, name);
1078 assert.equal(r.attrs['git.pack.cache.verify.error'], r.stats.verifyError, name);
1080});
1081test('cachingFetch verifyBeforeStore (#270): the whole-answer read is capped at three times maxPackBytes; an answer over it is not stored, one under it is', async () => {
1082 const content = te.encode('hi\n');
1083 const held = createHash('sha1').update(concat([te.encode('blob 3\0'), content])).digest('hex');
1084 const pack = handPack(content);
1085 // band-2 progress in 1-byte frames: each is 6 bytes on the wire (4 of length, the band, the byte) and 1 of progress
1086 const progress = n => concat(Array.from({ length: n }, () => framed(Uint8Array.of(2, 0x2e))));
1087 const answerWith = n => concat([framed(te.encode('packfile\n')), progress(n), framed(concat([Uint8Array.of(1), pack])), te.encode('0000')]);
1088 const maxPackBytes = 64;
1089 const run = async answer => {
1090 const pending = []; const cache = memoryCache();
1091 const f = cachingFetch(async () => new Response(answer.slice(), { status: 200, headers: RESULT }), cache, { verifyBeforeStore: true, limits: { ...DEFAULT_LIMITS, maxPackBytes }, waitUntil: p => { pending.push(p); } });
1092 await rawCall(f, fetchBody({ wants: [held] })); await Promise.all(pending.splice(0));
1093 return { f, cache };
1094 };
1095 // the pack is 12 + 1 + 11 (zlib of 'hi\n', node:zlib) + 20 = 44 bytes; the answer is (4 + 9) + 6n + (4 + 1 + 44) + 4 bytes:
1096 // n = 21 is 192, exactly 3 * 64 (stored); n = 22 is 198, over it (pack 44 and progress 22 bytes, each under 64)
1097 assert.equal(pack.length, 44); assert.equal(answerWith(21).length, 192); assert.equal(answerWith(22).length, 198);
1098 const under = await run(answerWith(21));
1099 assert.deepEqual([under.f.stats.verifyOk, under.f.stats.putOk, under.cache.entries.size], [1, 1, 1], under.f.stats.verifyError);
1100 const over = await run(answerWith(22));
1101 assert.deepEqual([over.f.stats.verifyOk, over.f.stats.verifyFailed, over.cache.entries.size], [0, 1, 0]);
1102 assert.match(over.f.stats.verifyError, /cached answer bytes 198 exceeds limit 192/);
1103});
Diagnostics6 git calls · 113 ms
CallStatusSizeTime0113 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 KiB · hit2 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=HIT
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=2
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 · 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=5323b9266eea5ded637285d1c5320699f12be76e
Open 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=105
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=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetch20021 KiB105 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=21675
git.response.cache=MISS
git.response.duration_ms=105
git.fetch.wants=d67da7ee9d4736f23b5387968cb928994e871bf0
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=5
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=21675
git.pkt.payload.max=13452
git.sideband.band1.bytes=21643
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
a5e0f82edc83332c
Request
ddb31180…
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