main
1// #218, the decision table of commitForWalk (src/pathtrees.ts) over a fake transport, fast enough for the mutation run
2// (vitest.stryker.config.ts). What git does with each request is test/path-trees.test.js's; this file pins which
3// requests are sent, what is learned, and which answer is returned, for every state × outcome.
4import { test } from 'vitest';
5import assert from 'node:assert/strict';
6import { commitForWalk, isPathTreesRefusal, pathTreesFilter, PATH_TREE_LEVELS } from '../src/pathtrees.js';
7import { asTransport, pathTreesOf, learnPathTrees, tree0Taken, freshQuirks } from '../src/transport.js';
8import { buildPack } from '../src/pack.js';
9import { encodeTree, encodeCommit, hashObject, TYPE } from '../src/objects.js';
10import { concat, td, te } from '../src/bytes.js';
11import { DEFAULT_LIMITS, parseLimits } from '../src/limits.js';
12import { Tracer, arrayExporter, flattenLine } from '../src/otel.js';
13import { SIDEBAND_PACK } from '../src/format.js';
14import { unwrap } from './unwrap.js';
16const author = 'Ada <ada@ex> 1700000000 +0000';
17// Built on first use inside a test, never while the file loads (#307): Stryker counts a src line reached during
18// module load as a static mutant and runs each mutant on it against the whole mutation suite instead of the tests
19// that cover it.
20let fixtureMemo = null;
21const fixture = () => (fixtureMemo ??= (() => {
22 const blob = hashObject('blob', te.encode('x\n'));
23 const sub = unwrap(encodeTree([{ mode: '100644', name: 'f.txt', oid: blob }]));
24 const subId = hashObject('tree', sub);
25 const rootTree = unwrap(encodeTree([{ mode: '40000', name: 'a', oid: subId }, { mode: '100644', name: 'r.txt', oid: blob }]));
26 const rootId = hashObject('tree', rootTree);
27 const commit = unwrap(encodeCommit({ tree: rootId, parents: [], author, message: 'root\n' }));
28 const tip = hashObject('commit', commit);
29 const C = { type: TYPE.COMMIT, data: commit };
30 const T = { type: TYPE.TREE, data: rootTree };
31 const S = { type: TYPE.TREE, data: sub };
32 return { blob, sub, subId, rootTree, rootId, commit, tip, C, T, S };
33})());
34const dat = s => ({ kind: 'data', payload: typeof s === 'string' ? te.encode(s) : s });
35const FL = { kind: 'flush' };
36async function* packFrames(objects) {
37 const { pack } = await buildPack(objects);
38 yield dat('packfile\n'); yield dat(concat([Uint8Array.of(SIDEBAND_PACK), pack])); yield FL;
39}
41// deep(filter): the answer to a combine request: 'ok' (commit + both trees), 'refuse' (git's ERR), 'depth' (git's depth
42// ERR), 'http400' (Artifacts' refusal), 'commitOnly', 'broken' (a pack without the commit), 'drop' (network).
43function fake(deep, tracer = new Tracer()) {
44 const { C, T, S } = fixture();
45 const log = [];
46 const t = asTransport({
47 kind: 'http', url: 'http://h/r.git', tracer, parent: null, limits: DEFAULT_LIMITS, signal: null, quirks: freshQuirks(), objects: null, scrub: null,
48 async *frames(_service, body) {
49 const text = td.decode(body);
50 const filter = (text.match(/filter (\S+)/) ?? [])[1] ?? '';
51 log.push(filter);
52 if (filter === 'tree:0') { yield* packFrames([C]); return; }
53 switch (deep) {
54 case 'ok': yield* packFrames([C, T, S]); return;
55 case 'commitOnly': yield* packFrames([C]); return;
56 case 'broken': yield* packFrames([T, S]); return;
57 case 'refuse': yield dat("ERR filter 'combine' not supported\n"); yield FL; return;
58 case 'depth': yield dat('ERR tree filter allows max depth 0, but got 2\n'); yield FL; return;
59 case 'http400': throw Object.assign(new Error('HTTP 400 git-upload-pack: Unsupported Git fetch filter; only blob:none is supported.'), { code: 'http', status: 400 });
60 case 'drop': throw Object.assign(new Error('network: socket hang up'), { code: 'network' });
61 }
62 throw new Error(`no answer for ${deep}`);
63 },
64 async advertise() { return { ok: false, error: { code: 'http', message: 'none' } }; },
65 }, unwrap(parseLimits(DEFAULT_LIMITS)));
66 return { t, log };
67}
68// Settle tree:0 on the record (the first contact): a tree:0 commit fetch.
69const settle = async t => { const { tip } = fixture(); assert.equal((await commitForWalk(t, tip, 0)).ok, true); assert.equal(tree0Taken(t.quirks), true); };
70const sameCommit = r => { const { rootId, commit, tip } = fixture(); assert.equal(r.ok, true); assert.equal(r.value.oid, tip); assert.deepEqual(r.value.data, commit); assert.equal(r.value.commit.tree, rootId); };
72test('pathTreesFilter and PATH_TREE_LEVELS', () => {
73 assert.equal(PATH_TREE_LEVELS, 2);
74 assert.deepEqual([1, 2, 3, 9].map(pathTreesFilter), ['combine:blob:none+tree:1', 'combine:blob:none+tree:2', 'combine:blob:none+tree:2', 'combine:blob:none+tree:2']);
75});
77test('no levels, tree:0 not settled, or a non-tree:0 record: the tree:0 commit fetch alone, nothing learned', async () => {
78 const { tip } = fixture();
79 const a = fake('ok');
80 sameCommit(await commitForWalk(a.t, tip, 0));
81 assert.deepEqual(a.log, ['tree:0']);
82 sameCommit(await commitForWalk(a.t, tip, 0));
83 assert.deepEqual(a.log, ['tree:0', 'tree:0'], 'levels 0 never asks, settled or not');
84 assert.equal(pathTreesOf(a.t.quirks), null);
85 const b = fake('ok');
86 sameCommit(await commitForWalk(b.t, tip, 2));
87 assert.deepEqual(b.log, ['tree:0'], 'first contact: tree:0 alone');
88 assert.equal(pathTreesOf(b.t.quirks), null);
89 for (const filter of ['blob:none', 'none']) {
90 const c = fake('ok'); await settle(c.t); c.t.quirks.treeFilter = filter;
91 assert.equal(tree0Taken(c.t.quirks), false, filter);
92 }
93});
95test('settled, not known: the race; ok is taken and the deep answer is used (its trees harvested)', async () => {
96 const { subId, rootId, tip } = fixture();
97 const f = fake('ok'); await settle(f.t); f.log.length = 0;
98 const r = await commitForWalk(f.t, tip, 2);
99 sameCommit(r);
100 assert.deepEqual(f.log.toSorted(), ['combine:blob:none+tree:2', 'tree:0']);
101 assert.equal(pathTreesOf(f.t.quirks), 'taken');
102 assert.equal(f.t.objects.get(rootId)?.type, TYPE.TREE);
103 assert.equal(f.t.objects.get(subId)?.type, TYPE.TREE);
104 assert.equal(f.t.objects.has(tip), false, 'the wanted commit is the answer, not harvested');
105 // taken: the deep fetch alone, K from levels
106 f.log.length = 0;
107 sameCommit(await commitForWalk(f.t, tip, 1));
108 assert.deepEqual(f.log, ['combine:blob:none+tree:1']);
109});
111test('settled, not known: a refusal (each kind) is learned refused and the tree:0 answer is used', async () => {
112 const { tip } = fixture();
113 for (const kind of ['refuse', 'depth', 'http400']) {
114 const f = fake(kind); await settle(f.t); f.log.length = 0;
115 sameCommit(await commitForWalk(f.t, tip, 2));
116 assert.deepEqual(f.log.toSorted(), ['combine:blob:none+tree:2', 'tree:0'], kind);
117 assert.equal(pathTreesOf(f.t.quirks), 'refused', kind);
118 assert.equal(f.t.objects.size, 0, kind);
119 f.log.length = 0;
120 sameCommit(await commitForWalk(f.t, tip, 2));
121 assert.deepEqual(f.log, ['tree:0'], `${kind}: refused, never asked again`);
122 }
123});
125test('settled, not known: any other failure is not learned and not used', async () => {
126 const { tip } = fixture();
127 for (const kind of ['broken', 'drop']) {
128 const f = fake(kind); await settle(f.t); f.log.length = 0;
129 sameCommit(await commitForWalk(f.t, tip, 2));
130 assert.equal(pathTreesOf(f.t.quirks), null, kind);
131 assert.equal(f.t.objects.size, 0, kind);
132 }
133});
135test('taken: a refusal falls back and is learned; another failure falls back and stays taken', async () => {
136 const { tip } = fixture();
137 for (const [kind, learned] of [['refuse', 'refused'], ['depth', 'refused'], ['http400', 'refused'], ['broken', 'taken'], ['drop', 'taken']]) {
138 const f = fake(kind); await settle(f.t); learnPathTrees(f.t.quirks, 'taken'); f.log.length = 0;
139 sameCommit(await commitForWalk(f.t, tip, 2));
140 assert.deepEqual(f.log, ['combine:blob:none+tree:2', 'tree:0'], kind);
141 assert.equal(pathTreesOf(f.t.quirks), learned, kind);
142 }
143 // the commit alone: taken, used, nothing to harvest
144 const f = fake('commitOnly'); await settle(f.t); learnPathTrees(f.t.quirks, 'taken'); f.log.length = 0;
145 sameCommit(await commitForWalk(f.t, tip, 2));
146 assert.deepEqual(f.log, ['combine:blob:none+tree:2']);
147 assert.equal(f.t.objects.size, 0);
148});
150test('isPathTreesRefusal', () => {
151 const e = (code, message, extra = {}) => Object.assign(new Error(message), { code, ...extra });
152 assert.equal(isPathTreesRefusal(e('remote_error', "remote: filter 'combine' not supported")), true);
153 assert.equal(isPathTreesRefusal(e('remote_error', 'remote: tree filter allows max depth 1, but got 2')), true);
154 assert.equal(isPathTreesRefusal(e('http', 'HTTP 400 git-upload-pack: Unsupported Git fetch filter; only blob:none is supported.', { status: 400 })), true);
155 assert.equal(isPathTreesRefusal(e('protocol', 'v2: response ended without flush', { reason: 'empty_response' })), true);
156 assert.equal(isPathTreesRefusal(e('protocol', 'v2: response ended without flush')), false);
157 assert.equal(isPathTreesRefusal(e('remote_error', 'remote: something else')), false);
158 assert.equal(isPathTreesRefusal(e('pack_corrupt', 'tree filter allows max depth 0')), false);
159 assert.equal(isPathTreesRefusal(e('http', 'HTTP 500 only blob:none is supported', { status: 500 })), false);
160 assert.equal(isPathTreesRefusal(e('timeout', 'timed out')), false);
161});
163test('spans: the deep fetch names its filter; the blob:none fallback still names what it fell back from', async () => {
164 const { tip } = fixture();
165 const ex = arrayExporter();
166 const f = fake('ok', new Tracer({ exporter: ex })); await settle(f.t); learnPathTrees(f.t.quirks, 'taken');
167 sameCommit(await commitForWalk(f.t, tip, 2));
168 const g = fake('ok', new Tracer({ exporter: ex })); g.t.quirks.treeFilter = 'blob:none';
169 sameCommit(await commitForWalk(g.t, tip, 2));
170 const spans = ex.lines.flatMap(flattenLine).filter(s => s.name === 'git.upload-pack fetch');
171 const deep = spans.filter(s => s.attrs['git.fetch.path_trees'] === 'combine:blob:none+tree:2');
172 assert.equal(deep.length, 1);
173 assert.equal(deep[0].attrs['git.pack.cache.bust'], false);
174 assert.equal(deep[0].attrs['git.fetch.wide.harvested'], 2);
175 const wide = spans.filter(s => s.attrs['git.fetch.filter.fallback'] === 'blob:none');
176 assert.equal(wide.length, 1);
177 assert.equal(wide[0].attrs['git.fetch.filter.requested'], 'tree:0');
178 assert.equal(wide[0].attrs['git.fetch.filter.learned'], false);
179 assert.equal(wide[0].attrs['git.pack.cache.bust'], false);
180});
Diagnostics4 git calls · 165 ms
CallStatusSizeTime0165 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=3 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 · hit1 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=1 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=1 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
fetch2003.1 KiB161 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=161 git.response.bytes=3179 git.response.cache=MISS git.response.duration_ms=161 git.fetch.wants=e986aafb5a1d0a9d759b9c439ea76e21fb21fa84 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=3179 git.pkt.payload.max=3158 git.sideband.band1.bytes=3157 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
- a5e2c69ea9454afc
- Request
- 63fc71ce…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format