Artifactspublic-v0

ply

main
ply4 git calls378 ms41 KiB2 cachedprotocol v2
144 lines9.1 KiBRaw
1// Real-git oracles for the codec layer: our bytes vs git's bytes, our parse vs git's pack writer.
2import { test, beforeAll as before, afterAll as after } from 'vitest';
3import assert from 'node:assert/strict';
4import { join } from 'node:path';
5import { mkdirSync, writeFileSync, symlinkSync } from 'node:fs';
6import { git, gitBuf, tmpRoot, makeBareRepo, startGitServer, commitFiles, initRepo } from './server.js';
7import { Rng } from './fuzz/prng.js';
8import { genBlob } from './fuzz/gen.js';
9import { parseTree, encodeTree, hashObject, TYPE_NAME } from '../src/objects.js';
10import { parsePack, resolvePack, buildPack, makeDelta } from '../src/pack.js';
11import { GitHttp } from '../src/client.js';
12import { Tracer, arrayExporter } from '../src/otel.js';
13import { toHex } from '../src/sha1.js';
14import { unwrap, unwrapAsync } from './unwrap.js';
16const SEED = parseInt(process.env.SEED ?? '7', 10);
17let root, cleanup, srv, bare, work;
18before(async () => {
19 ({ root, cleanup } = tmpRoot());
20 bare = makeBareRepo(root, 'o');
21 work = join(root, 'work'); mkdirSync(work); initRepo(work);
22 srv = await startGitServer(root);
23});
24after(async () => { await srv.close(); cleanup(); });
26const EDGE = ['a', 'a-b', 'a.b', 'a0', 'a_b', 'ab', 'A', 'a~', 'z', 'é', 'a b', 'a--', '-a', '.h', 'ä', '한', '🚀', 'b'];
28test('tree encoding: our tree oid == git write-tree for sort-edge names, modes, symlinks', () => {
29 const rng = new Rng(SEED);
30 for (let round = 0; round < 8; round++) {
31 const files = {};
32 const dirs = new Set();
33 for (const n of EDGE) {
34 const r = rng.float();
35 if (r < 0.35) files[n] = { mode: '100644', data: genBlob(rng, 'tiny') };
36 else if (r < 0.5) files[n] = { mode: '100755', data: genBlob(rng, 'tiny') };
37 else if (r < 0.7) { files[`${n}/inner${rng.int(0, 3)}`] = { mode: '100644', data: genBlob(rng, 'tiny') }; dirs.add(n); }
38 }
39 // staged with plumbing, not the filesystem: 'A' and 'a' coexist in git but not on a case-insensitive disk (macOS)
40 const sub = join(root, `tree${round}`); mkdirSync(sub); git(sub, ['init', '-q']);
41 const stage = (mode, path, data) => git(sub, ['update-index', '--add', '--cacheinfo', `${mode},${gitBuf(sub, ['hash-object', '-w', '--stdin'], data).toString().trim()},${path}`]);
42 for (const [p, v] of Object.entries(files)) stage(v.mode, p, v.data);
43 if (rng.bool(0.5) && !files.lnk) stage('120000', 'lnk', 'a');
44 const treeOid = git(sub, ['write-tree']).trim();
45 const raw = gitBuf(sub, ['cat-file', 'tree', treeOid]);
46 const entries = unwrap(parseTree(new Uint8Array(raw)));
47 assert.equal(hashObject('tree', unwrap(encodeTree(entries))), treeOid, `round ${round}`);
48 // shuffle then re-encode must still match (sort is ours, not git's order)
49 const shuffled = [...entries].sort(() => rng.float() - 0.5);
50 assert.equal(hashObject('tree', unwrap(encodeTree(shuffled))), treeOid);
51 // git ls-tree agreement on modes
52 const ls = git(sub, ['ls-tree', treeOid]).trim().split('\n').map(l => l.split(/\s+/)[0]);
53 assert.deepEqual(entries.map(e => e.mode.padStart(6, '0')), ls);
54 }
55});
57test('blob/commit oids == git hash-object', () => {
58 const rng = new Rng(SEED + 1);
59 for (const cls of ['empty', 'tiny', 'text', 'random', 'boundary', 'binaryish']) {
60 const d = genBlob(rng, cls);
61 assert.equal(hashObject('blob', d), gitBuf(work, ['hash-object', '--stdin'], d).toString().trim(), cls);
62 }
63});
65test('git pack-objects (ofs-delta, varied window/depth/compression) parses and resolves to git cat-file truth', async () => {
66 const rng = new Rng(SEED + 2);
67 // repo with history so deltas exist
68 const sub = join(root, 'packrepo'); mkdirSync(sub); initRepo(sub);
69 let text = genBlob(rng, 'text');
70 for (let i = 0; i < 6; i++) {
71 const files = {};
72 for (let f = 0; f < 5; f++) { const o = rng.int(0, text.length); text = new Uint8Array([...text.subarray(0, o), ...rng.bytes(rng.int(1, 40)), ...text.subarray(o)]); files[`d${f % 2}/f${f}.txt`] = text; }
73 files[`bin${i}`] = genBlob(rng, rng.pick(['random', 'repetitive', 'boundary', 'empty']));
74 for (const [p, v] of Object.entries(files)) { mkdirSync(join(sub, p, '..'), { recursive: true }); writeFileSync(join(sub, p), v); }
75 git(sub, ['add', '-A']); git(sub, ['-c', 'user.name=x', '-c', 'user.email=x@x', 'commit', '-q', '-m', `c${i}`]);
76 }
77 const truth = new Map(git(sub, ['cat-file', '--batch-check', '--batch-all-objects']).trim().split('\n').map(l => { const [oid, type, size] = l.split(' '); return [oid, { type, size: +size }]; }));
78 for (const [window, depth, comp] of [[10, 50, 0], [1, 1, 1], [250, 50, 9], [0, 0, 6], [5, 2, -1]]) {
79 const pack = new Uint8Array(gitBuf(sub, ['-c', `pack.compression=${comp}`, 'pack-objects', '--delta-base-offset', `--window=${window}`, `--depth=${depth}`, '--all', '--stdout', '--revs'], 'HEAD\n'));
80 const parsed = unwrap(parsePack(pack));
81 assert.equal(parsed.stats.count, truth.size, `all objects (w${window} d${depth} c${comp})`);
82 const r = unwrap(resolvePack(parsed));
83 for (const [oid, t] of truth) {
84 const o = r.objects.get(oid);
85 assert.ok(o, `missing ${oid}`);
86 assert.equal(TYPE_NAME[o.type], t.type); assert.equal(o.data.length, t.size);
87 assert.ok(Buffer.from(o.data).equals(gitBuf(sub, ['cat-file', t.type, oid])), `content ${oid}`);
88 }
89 // chain depth vs verify-pack
90 const pdir = join(root, `vp-${window}-${depth}-${comp}`); mkdirSync(pdir);
91 writeFileSync(join(pdir, 'p.pack'), pack);
92 git(sub, ['index-pack', join(pdir, 'p.pack')]);
93 const vp = git(sub, ['verify-pack', '-v', join(pdir, 'p.pack')]).split('\n').filter(l => /^[0-9a-f]{40} (commit|tree|blob)/.test(l));
94 for (const l of vp) {
95 const [oid, , , , offset, chain] = l.trim().split(/\s+/);
96 const o = r.objects.get(oid);
97 assert.equal(o.offset, +offset, `offset ${oid}`);
98 assert.equal(o.chain, chain ? +chain : 0, `chain ${oid}`);
99 }
100 if (depth > 0 && window > 0) assert.ok(parsed.stats.ofsDelta > 0, 'git produced ofs deltas');
101 if (comp === 0) assert.ok(parsed.stats.inflate.stored > 0, 'level 0 → stored blocks seen');
102 }
103});
105test('thin pack from our buildPack is accepted by git index-pack --fix-thin and yields the expected oid', async () => {
106 const rng = new Rng(SEED + 3);
107 const base = genBlob(rng, 'text');
108 const baseOid = gitBuf(work, ['hash-object', '-w', '--stdin'], base).toString().trim();
109 const target = new Uint8Array([...base.subarray(0, 100), ...rng.bytes(300), ...base.subarray(200)]);
110 const { pack } = await buildPack([{ type: 3, data: makeDelta(base, target).delta, base: { tag: 'ref', oid: baseOid } }]);
111 const out = gitBuf(work, ['index-pack', '--stdin', '--fix-thin', '-v'], pack).toString();
112 const targetOid = hashObject('blob', target);
113 assert.ok(Buffer.from(gitBuf(work, ['cat-file', 'blob', targetOid])).equals(Buffer.from(target)), out);
114});
116test('v2 fetch filter=blob:none deepen=1 returns exactly git rev-list --objects --filter=blob:none set; tree:0 returns one', async () => {
117 const head = commitFiles(work, bare, { 'a/b/c.txt': 'c', 'a/d.txt': 'd', 'e/f/g/h.txt': 'h', 'top.txt': 'top' }, 'one');
118 const head2 = commitFiles(work, bare, { 'top.txt': 'top2' }, 'two');
119 const tracer = new Tracer({ exporter: arrayExporter() });
120 const c = unwrap(GitHttp.create(`${srv.url}/o.git`, { tracer }));
121 const { refs } = await unwrapAsync(c.lsRefs(['refs/heads/main']));
122 assert.equal(refs.get('refs/heads/main').oid, head2);
123 const r = await unwrapAsync(c.fetchPack({ wants: [head2], filter: 'blob:none', deepen: 1 }));
124 const expected = git(bare, ['rev-list', '--objects', '--no-object-names', '--filter=blob:none', '--max-count=1', head2]).trim().split('\n').sort();
125 assert.deepEqual([...r.objects.keys()].sort(), expected);
126 assert.ok(r.parsed.stats.byType.blob === undefined);
127 const r0 = await unwrapAsync(c.fetchPack({ wants: [head2], filter: 'tree:0', deepen: 1 }));
128 assert.equal(r0.parsed.stats.count, 1);
129 // deepen 1 on a 2-commit history reports shallow
130 const span = tracer.exporter.lines.flatMap(l => l.resourceSpans[0].scopeSpans[0].spans).find(s => s.name === 'git.upload-pack fetch');
131 assert.ok(span.attributes.find(a => a.key === 'git.fetch.shallow').value.arrayValue.values.length === 1);
132 // tree:N is NOT a subset of blob:none: it includes blobs at depth < N (oracle-verified; top.txt comes back).
133 const r3 = await unwrapAsync(c.fetchPack({ wants: [head2], filter: 'tree:2', deepen: 1 }));
134 assert.ok([...r3.objects.values()].some(o => TYPE_NAME[o.type] === 'blob'), 'tree:2 includes depth-1 blobs');
135 // combine:blob:none+tree:N is the real "trees to depth N, no blobs" filter, a strict subset of blob:none.
136 const r4 = await unwrapAsync(c.fetchPack({ wants: [head2], filter: 'combine:blob:none+tree:2', deepen: 1 }));
137 assert.ok([...r4.objects.values()].every(o => TYPE_NAME[o.type] !== 'blob'));
138 assert.ok(r4.parsed.stats.count < r.parsed.stats.count);
139 for (const oid of r4.objects.keys()) assert.ok(r.objects.has(oid));
140 // want an arbitrary blob by oid
141 const blobOid = git(bare, ['rev-parse', `${head}:a/b/c.txt`]).trim();
142 const rb = await unwrapAsync(c.fetchPack({ wants: [blobOid] }));
143 assert.equal(new TextDecoder().decode(rb.objects.get(blobOid).data), 'c');
144});
Diagnostics4 git calls · 378 ms
CallStatusSizeTime0378 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
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 · 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=145
git.response.cache=HIT
git.response.duration_ms=2
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 1020038 KiB · hit6 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=369
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=6
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=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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2003.5 KiB369 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3535
git.response.cache=MISS
git.response.duration_ms=369
git.fetch.wants=4c1be95acf5497642af0ad28ade080efbe3fd279
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=3535
git.pkt.payload.max=3514
git.sideband.band1.bytes=3513
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.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e264a40aefdf63
Request
7d153ab3…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format