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});
Diagnostics4 git calls · 460 ms
CallStatusSizeTime0460 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=454 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=3 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=55Open pack map
fetch2001.9 KiB454 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1950 git.response.cache=MISS git.response.duration_ms=454 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=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1950 git.pkt.payload.max=1929 git.sideband.band1.bytes=1928 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
- a5e1b5820b0a5b65
- Request
- cc02fbeb…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format