GitHubivarvong
ply
main
1// The merge cluster's machines, pure and at their one effect: the merge-base search (searchStep, #79's cap
2// clamp) and attributeDrivers' shared lookups (#79: a failed lookup is not remembered).
3import { test } from 'vitest';
4import assert from 'node:assert/strict';
5import { searchStep, attributeDrivers } from '../src/merge.js';
6import { encodeTree, hashObject, TYPE } from '../src/objects.js';
7import { buildPack } from '../src/pack.js';
8import { te, concat } from '../src/bytes.js';
9import { SIDEBAND_PACK } from '../src/format.js';
10import { plyError } from '../src/errors.js';
11import { DEFAULT_LIMITS } from '../src/limits.js';
12import { Tracer } from '../src/otel.js';
13import { unwrap, unwrapAsync } from './unwrap.js';
15const G = o => new Map(Object.entries(o).map(([k, parents]) => [k, { parents }]));
17test('merge-base search: windows double from 8 and the last step is the cap itself (#79)', () => {
18 // a graph that stays truncated at every window (b runs into an unfetched q), driven to the end
19 const cut = G({ a: ['m'], b: ['q', 'm'], m: [] });
20 const walk = c => { const cap = Math.floor(c); const seen = []; let s = cap < 1 ? { tag: 'capped' } : { tag: 'searching', depth: Math.min(8, cap) }; while (s.tag === 'searching') { seen.push(s.depth); s = searchStep(s.depth, cap, cut, 'a', 'b'); } return [...seen, s.tag]; };
21 assert.deepEqual(walk(100), [8, 16, 32, 64, 100, 'capped'], 'cap 100 searches 100 (it stopped at 64)');
22 assert.deepEqual(walk(64), [8, 16, 32, 64, 'capped']);
23 assert.deepEqual(walk(32.9), [8, 16, 32, 'capped'], 'whole commits');
24 assert.deepEqual(walk(9), [8, 9, 'capped']);
25 assert.deepEqual(walk(8), [8, 'capped']);
26 assert.deepEqual(walk(3), [3, 'capped'], 'a cap under the first window is the window (no search at all before)');
27 assert.deepEqual(walk(1), [1, 'capped']);
28 assert.deepEqual(walk(0.5), ['capped']);
29 assert.deepEqual(walk(0), ['capped']);
30 // the verdicts of a whole graph, at whatever window it was read
31 assert.deepEqual(searchStep(8, 32, G({ a: ['m'], b: ['m'], m: ['r'], r: [] }), 'a', 'b'), { tag: 'found', depth: 8, base: 'm', bases: ['m'] });
32 assert.deepEqual(searchStep(16, 32, G({ a: ['x', 'y'], b: ['y', 'x'], x: ['r'], y: ['r'], r: [] }), 'a', 'b'), { tag: 'criss-cross', depth: 16, bases: ['x', 'y'] });
33 assert.deepEqual(searchStep(8, 32, G({ a: ['r1'], r1: [], b: ['r2'], r2: [] }), 'a', 'b'), { tag: 'unrelated', depth: 8, bases: [] });
34 // #42: {c, z} with a cut below c is not yet criss-cross: search deeper
35 assert.deepEqual(searchStep(8, 32, G({ a: ['c', 'z'], b: ['c', 'z'], c: ['x'], z: [] }), 'a', 'b'), { tag: 'searching', depth: 16 });
36 assert.deepEqual(searchStep(32, 32, G({ a: ['c', 'z'], b: ['c', 'z'], c: ['x'], z: [] }), 'a', 'b'), { tag: 'capped', depth: 32 });
37});
39// A transport serving one blob for any fetch, failing the first `failures` requests with a transient network error.
40function blobServer(data, failures) {
41 const line = s => ({ kind: 'data', payload: te.encode(s) });
42 const sideband = b => ({ kind: 'data', payload: concat([Uint8Array.of(SIDEBAND_PACK), b]) });
43 const t = { limits: DEFAULT_LIMITS, tracer: new Tracer(), parent: null, objects: new Map(), quirks: {}, url: 'stub://attrs', requests: 0,
44 async *frames() {
45 t.requests++;
46 if (t.requests <= failures) throw plyError('network', 'connection reset');
47 const { pack } = await buildPack([{ type: TYPE.BLOB, data }]);
48 yield line('packfile\n'); yield sideband(pack); yield { kind: 'flush' };
49 } };
50 return t;
51}
53test('attributeDrivers: a failed lookup is forgotten, a successful one shared (#79)', async () => {
54 const attrs = te.encode('*.bin -merge\n*.u merge=union\n');
55 const blob = hashObject('blob', attrs);
56 const root = unwrap(encodeTree([{ mode: '100644', name: '.gitattributes', oid: blob }]));
57 const tree = hashObject('tree', root);
58 const t = blobServer(attrs, 1);
59 const driverFor = attributeDrivers(t, new Map([[tree, root]]), tree);
60 await assert.rejects(unwrapAsync(driverFor('a.bin')), e => e.code === 'network');
61 // it answered the cached rejection for every later path of the directory; now it asks again
62 assert.equal(await unwrapAsync(driverFor('a.bin')), 'binary');
63 assert.equal(t.requests, 2);
64 assert.equal(await unwrapAsync(driverFor('b.u')), 'union');
65 assert.equal(await unwrapAsync(driverFor('c.txt')), 'text');
66 assert.equal(t.requests, 2, 'the successful lookup is shared by every later path');
67 // concurrent lookups share one pending request, and a failure reaches each of them
68 const u = blobServer(attrs, 1);
69 const shared = attributeDrivers(u, new Map([[tree, root]]), tree);
70 const both = await Promise.allSettled([unwrapAsync(shared('x.bin')), unwrapAsync(shared('y.bin'))]);
71 assert.deepEqual(both.map(r => r.status), ['rejected', 'rejected']);
72 assert.equal(u.requests, 1);
73 assert.deepEqual(await Promise.all([unwrapAsync(shared('x.bin')), unwrapAsync(shared('y.u'))]), ['binary', 'union']);
74 assert.equal(u.requests, 2);
75});
Diagnostics6 git calls · 31 ms
CallStatusSizeTime031 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=3 git.response.bytes=191 git.server.agent=git/github-9922ec520325-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=191 git.pkt.payload.max=36
ls-refs20012 KiB2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=11990 git.response.cache=UPDATING git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=4347 git.response.cache=HIT git.response.duration_ms=3 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=10Open pack map
fetchtree:0200919 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=919 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:02005.6 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=18 git.response.bytes=5724 git.response.cache=HIT git.response.duration_ms=4 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=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetch2001.9 KiB · hit19 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1956 git.response.cache=HIT git.response.duration_ms=19 git.fetch.wants=f96440d0a4ae3655c35a6a9e2b9bab2fe0e30935 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=1956 git.pkt.payload.max=1929 git.sideband.band1.bytes=1929 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
- a5e2ce90fd95efad
- Request
- fc7afe88…
- 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