main
ply4 git calls29 ms47 KiB3 cachedprotocol v2
299 lines22 KiBRaw
1// GitCache (Workers Caching) as pure functions: what is routed to the cache, under which key and policy, that a
2// credential always bypasses it, that a key is bound to its request, that a CACHE_VERSION bump misses, and that nothing in
3// src/ uses the Cache API or calls the GitCache binding outside src/gitcache.ts.
4import { test } from 'node:test';
5import assert from 'node:assert/strict';
6import { readdirSync, readFileSync, statSync } from 'node:fs';
7import { join } from 'node:path';
8import { fileURLToPath } from 'node:url';
9import { CACHE_VERSION } from '../src/cache-version.ts';
10import {
11 DISCOVER_V2_CACHE, IMMUTABLE, REFUSAL_CACHE, MAX_ROUTED_BODY, NO_STORE, REFS_CACHE, REFS_MAX_AGE_S, REFS_SWR_S, VIA_HEADER,
12 cacheableUpstream, classify, createLoopbackFetch, keyHash, keyPath, serveGitCache, type LoopbackBinding,
13} from '../src/gitcache.ts';
14import { PUBLIC_GIT_ORIGIN, PUBLIC_NAMESPACE, type TokenSource } from '../src/public.ts';
15import { git, makeBareRepo, startGitServer, tmpRoot, commitFiles } from './server.js';
16import { mkdirSync } from 'node:fs';
18/** Null and a missing value take the fallback. An empty string and 0 stay. */
19function fill<T>(value: unknown, fallback: T): T {
20 return value === null || value === void 0 ? fallback : value as T;
23/** One property. A null receiver and a missing key are holes. A stored null stays null. */
24function slot(receiver: unknown, key: string): unknown {
25 if (receiver === null || receiver === void 0) return void 0;
26 if (typeof receiver !== 'object' && typeof receiver !== 'function') return void 0;
27 return (receiver as Record<string, unknown>)[key];
31type GitCacheFailureLog = { msg: 'ply.gitcache'; error_kind: string; stage: string; error_name: string };
33function isGitCacheFailure(value: unknown): value is GitCacheFailureLog {
34 if (!value || typeof value !== 'object') return false;
35 if (!('msg' in value) || value.msg !== 'ply.gitcache') return false;
36 if (!('error_kind' in value) || typeof value.error_kind !== 'string') return false;
37 if (!('stage' in value) || typeof value.stage !== 'string') return false;
38 return 'error_name' in value && typeof value.error_name === 'string';
41const PUB = `${PUBLIC_GIT_ORIGIN}/git/${PUBLIC_NAMESPACE}/ply.git`;
42const GH = 'https://github.com/octocat/Hello-World.git';
43const TOKEN = `art_v1_${'c4c4'.repeat(10)}?expires=4102444800`;
44const pkt = (s: string) => `${(s.length + 4).toString(16).padStart(4, '0')}${s}`;
45const enc = (s: string) => new TextEncoder().encode(s);
46const OID = 'a'.repeat(40);
47const LSREFS = enc(`${pkt('command=ls-refs\n')}0001${pkt('ref-prefix HEAD\n')}0000`);
48const FETCH = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt('filter blob:none\n')}${pkt('deepen 1\n')}${pkt('done\n')}0000`);
49const BLOB = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt('done\n')}0000`);
50const HAVE = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt(`have ${'b'.repeat(40)}\n`)}${pkt('done\n')}0000`);
51const SHALLOW = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt(`shallow ${'b'.repeat(40)}\n`)}0000`);
52const SINCE = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt('deepen-since 1700000000\n')}0000`);
53const WANTREF = enc(`${pkt('command=fetch\n')}0001${pkt('want-ref refs/heads/main\n')}0000`);
55test('classify: wants-only fetch is pack (with or without a filter), ls-refs is refs, info/refs is discover, the rest is not cached', () => {
56 assert.equal(classify('POST', `${PUB}/git-upload-pack`, FETCH), 'pack');
57 assert.equal(classify('POST', `${PUB}/git-upload-pack`, BLOB), 'pack');
58 assert.equal(classify('POST', `${PUB}/git-upload-pack`, LSREFS), 'refs');
59 assert.equal(classify('GET', `${PUB}/info/refs?service=git-upload-pack`, null), 'discover');
60 for (const b of [HAVE, SHALLOW, SINCE, WANTREF, enc('0000'), enc(`${pkt('command=fetch\n')}0000`)]) assert.equal(classify('POST', `${PUB}/git-upload-pack`, b), null);
61 assert.equal(classify('POST', `${PUB}/git-upload-pack`, null), null);
62});
64test('cacheableUpstream: the public namespace and the built-in public forges, upload-pack only', () => {
65 for (const [m, u] of [['GET', `${PUB}/info/refs?service=git-upload-pack`], ['POST', `${PUB}/git-upload-pack`], ['GET', `${GH}/info/refs?service=git-upload-pack`], ['POST', `${GH}/git-upload-pack`], ['POST', 'https://gitlab.com/a/b.git/git-upload-pack']]) {
66 assert.equal(cacheableUpstream(m as string, u as string), true, u);
67 }
68 for (const [m, u] of [
69 ['POST', `${PUBLIC_GIT_ORIGIN}/git/default/ply.git/git-upload-pack`], ['POST', `${PUB}/git-receive-pack`], ['GET', `${PUB}/info/refs?service=git-receive-pack`],
70 ['POST', 'https://evil.example/a/b.git/git-upload-pack'], ['POST', 'http://github.com/a/b.git/git-upload-pack'], ['POST', 'https://github.com:443/a/b.git/git-upload-pack'],
71 ['POST', 'https://u@github.com/a/b.git/git-upload-pack'], ['POST', 'https://github.com./a/b.git/git-upload-pack'], ['POST', 'https://github.com/a/../b.git/git-upload-pack'],
72 ['POST', 'https://github.com/a/%2e%2e/b.git/git-upload-pack'], ['POST', 'https://other.artifacts.cloudflare.net/git/public-v0/ply.git/git-upload-pack'],
73 ['GET', `${GH}/info/refs?service=git-receive-pack`], ['POST', `${GH}/git-upload-pack?x=1`], ['GET', `${GH}/git-upload-pack`],
74 ]) assert.equal(cacheableUpstream(m as string, u as string), false, `${m} ${u}`);
75});
77type Call = { url: string; via: string | null; carried: Record<string, string> };
78function fakeLoopback() {
79 const calls: Call[] = [];
80 const binding: LoopbackBinding = {
81 async fetch(req) {
82 calls.push({ url: req.url, via: null, carried: Object.fromEntries(req.headers) });
83 assert.equal(req.redirect, 'manual', 'a 3xx must come back to the redirect guard');
84 return new Response('pack', { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-result', 'cf-cache-status': 'HIT' } });
85 },
86 };
87 return { calls, binding };
90test('createLoopbackFetch: anonymous public exchanges go to GitCache under /v<CACHE_VERSION>/<kind>/<sha256>; a credential never does', async () => {
91 const { calls, binding } = fakeLoopback();
92 const direct: { url: string; auth: string | null }[] = [];
93 const f = createLoopbackFetch(async (input, init) => { direct.push({ url: String(input), auth: new Headers(slot(init, 'headers') as HeadersInit).get('authorization') }); return new Response('direct'); }, () => binding);
94 const r = await f(`${PUB}/git-upload-pack`, { method: 'POST', body: FETCH, headers: { 'git-protocol': 'version=2' } });
95 assert.equal(r.headers.get('x-ply-pack-cache'), 'HIT', 'the tier reaches ply as x-ply-pack-cache');
96 assert.equal(calls.length, 1);
97 assert.equal(new URL(calls[0]!.url).pathname, keyPath('pack', await keyHash('pack', `${PUB}/git-upload-pack`, 'version=2', FETCH)));
98 assert.match(new URL(calls[0]!.url).pathname, new RegExp(`^/v${CACHE_VERSION}/pack/[0-9a-f]{64}$`));
99 await f(`${GH}/git-upload-pack`, { method: 'POST', body: LSREFS });
100 assert.match(calls[1]!.url, /\/refs\//);
101 await f(`${PUB}/info/refs?service=git-upload-pack`);
102 assert.match(calls[2]!.url, /\/discover\//);
103 // credentialed: Authorization (what ply sends for a caller's Git-Token / Git-Authorization) always goes direct
104 for (const auth of ['Bearer caller-token', 'Basic eDp5']) {
105 await f(`${PUB}/git-upload-pack`, { method: 'POST', body: FETCH, headers: { authorization: auth } });
106 await f(`${GH}/git-upload-pack`, { method: 'POST', body: LSREFS, headers: { Authorization: auth } });
107 }
108 assert.equal(calls.length, 3, 'a credentialed exchange never reaches the cache, so it can never populate a key');
109 assert.deepEqual(direct.map(d => d.auth), ['Bearer caller-token', 'Bearer caller-token', 'Basic eDp5', 'Basic eDp5']);
110 // not cacheable: haves, another namespace, receive-pack, a large body, no binding
111 await f(`${PUB}/git-upload-pack`, { method: 'POST', body: HAVE });
112 await f(`${PUBLIC_GIT_ORIGIN}/git/default/ply.git/git-upload-pack`, { method: 'POST', body: FETCH });
113 await f(`${PUB}/git-receive-pack`, { method: 'POST', body: FETCH });
114 await f(`${PUB}/git-upload-pack`, { method: 'POST', body: new Uint8Array(MAX_ROUTED_BODY + 1).fill(0x30) });
115 await createLoopbackFetch(async () => new Response('d'), () => null)(`${PUB}/git-upload-pack`, { method: 'POST', body: FETCH });
116 await createLoopbackFetch(async () => new Response('d'), null)(`${PUB}/git-upload-pack`, { method: 'POST', body: FETCH });
117 assert.equal(calls.length, 3);
118 // ply's retry after a corrupt cached pack: purge that key, then fetch it again
119 await f(`${PUB}/git-upload-pack`, { method: 'POST', body: FETCH, headers: { 'x-ply-cache': 'bust', 'git-protocol': 'version=2' } });
120 assert.match(calls[3]!.url, new RegExp(`/v${CACHE_VERSION}/bust/pack/`));
121 assert.equal(new URL(calls[4]!.url).pathname, new URL(calls[0]!.url).pathname);
122});
124function tokens(): TokenSource {
125 return { readToken: async () => TOKEN, secrets: () => [TOKEN, TOKEN.split('?')[0] as string] };
128async function gcRequest(kind: 'pack' | 'refs' | 'discover', url: string, body: Uint8Array | null, opts: Partial<{ version: number; tamperUrl: string; bust: boolean }> = {}) {
129 const hash = await keyHash(kind, url, 'version=2', body);
130 const path = opts.bust ? `/v${fill(opts.version, CACHE_VERSION)}/bust/${kind}/${hash}` : keyPath(kind, hash, opts.version);
131 const headers = new Headers({ 'x-ply-gc-url': fill(opts.tamperUrl, url), 'x-ply-gc-proto': 'version=2', 'x-ply-gc-ua': 'ply-test' });
132 if (body) headers.set('x-ply-gc-body', btoa(String.fromCharCode(...body)));
133 return new Request(`https://gitcache.internal${path}`, { headers });
136test('serveGitCache: policy per kind, the key is bound to the request, the token goes only to the public namespace, errors are scrubbed and not stored', async () => {
137 const seen: { url: string; auth: string | null; via: string | null; method: string }[] = [];
138 let answer: () => Response = () => new Response('PACK', { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-result' } });
139 const up: typeof globalThis.fetch = async (input, init) => { const h = new Headers(slot(init, 'headers') as HeadersInit); seen.push({ url: String(input), auth: h.get('authorization'), via: h.get(VIA_HEADER), method: fill(slot(init, 'method'), 'GET') }); return answer(); };
140 const purged: string[][] = [];
141 const ctx = { cache: { purge: async (o: { pathPrefixes: string[] }) => { purged.push(o.pathPrefixes); } } };
142 const pack = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH), tokens(), ctx, up);
143 assert.equal(pack.status, 200);
144 assert.equal(pack.headers.get('cache-control'), NO_STORE, 'bytes that are not a verifiable pack are passed on but never stored');
145 assert.match(fill(pack.headers.get('x-ply-gc-verified'), ''), /^failed/);
146 assert.equal(await pack.text(), 'PACK');
147 answer = () => new Response('PACK', { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-result', 'cf-ray': '0123456789abcdef-IAD' } });
148 assert.equal((await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH), tokens(), ctx, up)).headers.get('cf-ray'), '0123456789abcdef-IAD');
149 answer = () => new Response('PACK', { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-result', 'cf-ray': 'https://user:tok@github.com/secret/repo.git' } });
150 assert.equal((await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH), tokens(), ctx, up)).headers.get('cf-ray'), null, 'a non-ray cf-ray is not copied');
151 assert.equal(seen[0]!.auth, `Bearer ${TOKEN}`, 'the public namespace gets the Worker read token');
152 assert.equal(seen[0]!.via, 'gitcache');
153 const refs = await serveGitCache(await gcRequest('refs', `${GH}/git-upload-pack`, LSREFS), tokens(), ctx, up);
154 assert.equal(refs.headers.get('cache-control'), REFS_CACHE);
155 assert.equal(seen.at(-1)!.auth, null, 'a forge gets no credential');
156 answer = () => new Response(`${pkt('version 2\n')}${pkt('ls-refs\n')}0000`, { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-advertisement' } });
157 assert.equal((await serveGitCache(await gcRequest('discover', `${PUB}/info/refs?service=git-upload-pack`, null), tokens(), ctx, up)).headers.get('cache-control'), DISCOVER_V2_CACHE);
158 answer = () => new Response(`${pkt('# service=git-upload-pack\n')}0000${pkt(`${OID} HEAD\0side-band\n`)}0000`, { status: 200, headers: { 'content-type': 'application/x-git-upload-pack-advertisement' } });
159 assert.equal((await serveGitCache(await gcRequest('discover', `${GH}/info/refs?service=git-upload-pack`, null), tokens(), ctx, up)).headers.get('cache-control'), REFS_CACHE, 'a v0 advertisement carries refs');
160 // errors: not stored, and an echoed token is scrubbed here (the caller may be another isolate)
161 answer = () => new Response(`echo Bearer ${TOKEN}`, { status: 500, headers: { 'content-type': 'text/plain' } });
162 const err = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, BLOB), tokens(), ctx, up);
163 assert.equal(err.status, 500);
164 assert.equal(err.headers.get('cache-control'), NO_STORE);
165 assert.equal((await err.text()).includes('art_v1_'), false);
166 answer = () => new Response(null, { status: 307, headers: { location: '/elsewhere' } });
167 const redir = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, BLOB), tokens(), ctx, up);
168 assert.equal(redir.status, 307);
169 assert.equal(redir.headers.get('cache-control'), NO_STORE);
170 assert.equal(redir.headers.get('location'), '/elsewhere');
171 const before = seen.length;
172 // a key carrying another request's url: refused before any fetch
173 assert.equal((await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH, { tamperUrl: `${PUBLIC_GIT_ORIGIN}/git/${PUBLIC_NAMESPACE}/other.git/git-upload-pack` }), tokens(), ctx, up)).status, 400);
174 // not public: another namespace, receive-pack, a non-forge host
175 assert.equal((await serveGitCache(await gcRequest('pack', `${PUBLIC_GIT_ORIGIN}/git/default/ply.git/git-upload-pack`, FETCH), tokens(), ctx, up)).status, 403);
176 assert.equal((await serveGitCache(await gcRequest('pack', 'https://evil.example/a.git/git-upload-pack', FETCH), tokens(), ctx, up)).status, 403);
177 // a body that is not what the kind says (haves under a pack key)
178 assert.equal((await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, HAVE), tokens(), ctx, up)).status, 403);
179 // a CACHE_VERSION bump: the old key is a different path, and an old-version path is not served
180 const old = await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH, { version: CACHE_VERSION + 1 });
181 assert.notEqual(new URL(old.url).pathname, keyPath('pack', await keyHash('pack', `${PUB}/git-upload-pack`, 'version=2', FETCH)));
182 assert.equal((await serveGitCache(old, tokens(), ctx, up)).status, 404);
183 assert.equal(seen.length, before, 'none of the refused keys reached upstream');
184 // bust purges exactly that key, from GitCache itself
185 const b = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH, { bust: true }), tokens(), ctx, up);
186 assert.equal(b.status, 204);
187 assert.deepEqual(purged, [[keyPath('pack', await keyHash('pack', `${PUB}/git-upload-pack`, 'version=2', FETCH))]]);
188 assert.equal(seen.length, before);
189 const logs: string[] = [];
190 const orig = console.log;
191 console.log = (...args: unknown[]) => { logs.push(args.length > 0 ? String(args[0]) : ''); };
192 try {
193 const failed = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, FETCH, { bust: true }), tokens(), {
194 cache: { purge: async () => { throw new Error('purge secret down'); } },
195 }, up);
196 assert.equal(failed.status, 500);
197 assert.equal(failed.headers.get('x-ply-error-kind'), 'unexpected');
198 assert.equal((await failed.text()).includes('purge secret'), false);
199 const row = logs.map(line => JSON.parse(line) as unknown).find(isGitCacheFailure);
200 if (!row) throw new Error('missing gitcache failure log');
201 assert.equal(row.error_kind, 'unexpected');
202 assert.equal(row.stage, 'execute');
203 assert.equal(row.error_name, 'Error');
204 } finally {
205 console.log = orig;
206 }
207});
209test('mutable TTLs: a ref change is visible within max-age + stale-while-revalidate', () => {
210 assert.equal(REFS_CACHE, `public, max-age=${REFS_MAX_AGE_S}, stale-while-revalidate=${REFS_SWR_S}`);
211 assert.ok(REFS_MAX_AGE_S + REFS_SWR_S <= 30, 'worst-case staleness of a ref is at most 30 s');
212 assert.ok(!REFS_CACHE.includes('immutable'));
213});
215function files(dir: string): string[] {
216 return readdirSync(dir).flatMap(n => { const p = join(dir, n); return statSync(p).isDirectory() ? files(p) : [p]; });
219test('guardrails: no Cache API in src/; Workers Cache entrypoints only via their modules', () => {
220 const src = fileURLToPath(new URL('../src/', import.meta.url));
221 for (const f of files(src).filter(f => /\.(ts|tsx|js|mjs)$/.test(f))) {
222 const text = readFileSync(f, 'utf8').replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
223 // Workers Caching only — never caches.default / caches.open / cachingFetch (Cache API).
224 assert.equal(/\bcaches\s*\.\s*(default|open)\b|cachingFetch/.test(text), false, `${f} uses the Cache API`);
225 if (!f.endsWith('gitcache.ts') && !f.endsWith('pinned.ts') && !f.endsWith('blob-cache.ts') && !f.endsWith('cas-cache.ts')) {
226 assert.equal(/GitCache\?\.fetch\s*\(|GitCache\.fetch\s*\(|BlobCache\?\.fetch\s*\(|BlobCache\.fetch\s*\(/.test(text), false, `${f} calls a cache binding directly`);
227 }
228 }
229});
231test('pack verification against real git: a genuine pack is immutable; a corrupted or wrong one is passed on, never stored', async () => {
232 const { root, cleanup } = tmpRoot();
233 const srv = await startGitServer(root);
234 try {
235 const bare = makeBareRepo(root, 'v');
236 const work = join(root, 'w-v');
237 mkdirSync(work);
238 git(work, ['init', '-q', '-b', 'main']);
239 const head = commitFiles(work, bare, { 'README.md': 'verified\n', 'd/e.txt': 'x'.repeat(5000) }, 'seed');
240 const blob = git(bare, ['rev-parse', 'main:README.md']).trim();
241 const local: typeof globalThis.fetch = (input, init) => fetch(String(input).replace(PUBLIC_GIT_ORIGIN, srv.url).replace(`/git/${PUBLIC_NAMESPACE}/ply.git`, '/v.git'), init);
242 let mangle: ((b: Uint8Array) => Uint8Array) | null = null;
243 const up: typeof globalThis.fetch = async (input, init) => {
244 const r = await local(input, init);
245 if (!mangle) return r;
246 return new Response(mangle(new Uint8Array(await r.arrayBuffer())) as BodyInit, { status: r.status, headers: r.headers });
247 };
248 const body = (w: string, extra = '') => enc(`${pkt('command=fetch\n')}0001${pkt(`want ${w}\n`)}${extra}${pkt('ofs-delta\n')}${pkt('done\n')}0000`);
249 const ask = async (b: Uint8Array) => serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, b), tokens(), {}, up);
250 // a commit with its trees (blob:none, deepen 1) and a single blob: both verified, both immutable
251 for (const b of [body(head, `${pkt('filter blob:none\n')}${pkt('deepen 1\n')}`), body(blob)]) {
252 const r = await ask(b);
253 assert.equal(r.status, 200);
254 assert.equal(r.headers.get('cache-control'), IMMUTABLE, fill(r.headers.get('x-ply-gc-verified'), ''));
255 assert.match(fill(r.headers.get('x-ply-gc-verified'), ''), /^ok;objects=\d+/);
256 }
257 // flip one byte of the compressed object data (just after the 12-byte PACK header and the object header): same
258 // length, must no longer verify. (Bytes in band-2 progress text or the trailer would not change any object.)
259 mangle = b => { const c = b.slice(); const i = Buffer.from(c).indexOf('PACK') + 16; c[i] = (c[i] as number) ^ 0xff; return c; };
260 const bad = await ask(body(blob));
261 assert.equal(bad.headers.get('cache-control'), NO_STORE);
262 assert.match(fill(bad.headers.get('x-ply-gc-verified'), ''), /^failed/);
263 // a valid pack that is not what was asked for (served for another want): not stored
264 mangle = null;
265 const other = git(bare, ['rev-parse', 'main:d/e.txt']).trim();
266 const swapped: typeof globalThis.fetch = async (input, init) => local(input, { ...init, body: body(other) });
267 const wrong = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, body(blob)), tokens(), {}, swapped);
268 assert.equal(wrong.headers.get('cache-control'), NO_STORE);
269 assert.match(fill(wrong.headers.get('x-ply-gc-verified'), ''), /not in the pack/);
270 } finally {
271 await srv.close();
272 cleanup();
273 }
274});
276test('serveGitCache: a token mint that fails maps to the status ply turns back into the same code (no such repo → 404)', async () => {
277 const mint = (code: string): TokenSource => ({ readToken: async () => { throw Object.assign(new Error(code), { code }); }, secrets: () => [] });
278 const up = async () => new Response('never');
279 const missing = await serveGitCache(await gcRequest('refs', `${PUB}/git-upload-pack`, LSREFS), mint('not_found'), {}, up);
280 assert.equal(missing.status, 404);
281 assert.equal(missing.headers.get('cache-control'), NO_STORE);
282 const down = await serveGitCache(await gcRequest('refs', `${PUB}/git-upload-pack`, LSREFS), mint('upstream_5xx'), {}, up);
283 assert.equal(down.status, 502);
284 assert.equal(down.headers.get('cache-control'), NO_STORE);
285});
287test('a filter refusal (400 only blob:none is supported) is cached for an hour; any other 400 is not', async () => {
288 const filterBody = enc(`${pkt('command=fetch\n')}0001${pkt(`want ${OID}\n`)}${pkt('filter tree:0\n')}${pkt('deepen 1\n')}${pkt('done\n')}0000`);
289 let text = 'git-upload-pack: Unsupported Git fetch filter; only blob:none is supported.';
290 const up = async () => new Response(text, { status: 400, headers: { 'content-type': 'text/plain' } });
291 const refused = await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, filterBody), tokens(), {}, up);
292 assert.equal(refused.status, 400);
293 assert.equal(refused.headers.get('cache-control'), REFUSAL_CACHE);
294 assert.match(await refused.text(), /only blob:none is supported/, 'the body reaches ply, which learns the quirk from it');
295 text = 'bad request';
296 assert.equal((await serveGitCache(await gcRequest('pack', `${PUB}/git-upload-pack`, filterBody), tokens(), {}, up)).headers.get('cache-control'), NO_STORE);
297 text = 'only blob:none is supported';
298 assert.equal((await serveGitCache(await gcRequest('refs', `${PUB}/git-upload-pack`, LSREFS), tokens(), {}, up)).headers.get('cache-control'), NO_STORE, 'only a pack fetch refusal');
299});
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 ms
discover200152 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=4
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit8 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=41349
git.response.cache=HIT
git.response.duration_ms=8
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2006.3 KiB · hit17 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=16
git.response.bytes=6476
git.response.cache=HIT
git.response.duration_ms=17
git.fetch.wants=0428ac98f73e3e41249cdbfef2a2b7ae3f9eed59
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=6476
git.pkt.payload.max=6455
git.sideband.band1.bytes=6454
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e23f539d43cf56
Request
dbe2e71f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format