main
1// parseTree answers exactly what it answered before #207 (test/oracle/parsetree-ref.ts, the c91c9cf parser): the same
2// entries (mode, name, oid, offsets) or the same refusal (code and message), on random trees built to reach every
3// refusal: bad and canonicalized modes, missing separators, short ids, null ids, every .git/.gitmodules spelling,
4// duplicates, order with directory keys, and the entry cap. The large run is test/fuzz/parsetree.mjs.
5import { test } from 'vitest';
6import assert from 'node:assert/strict';
7import { rng } from './dotnames-corpus.js';
8import { randomTree, judgeTrees } from './parsetree-corpus.js';
9import { assertFetched, parseTree, encodeTree, encodeCommit } from '../src/objects.js';
10import { treeEntries } from '../src/fetch.js';
11import { DEFAULT_LIMITS, parseLimits } from '../src/limits.js';
12import { unwrap } from './unwrap.js';
14// A fetched tree is parsed once (#208): assertFetched's answer is the tree's entries (none for any other type), and
15// treeEntries hands that very array to the reader when its entry cap is the one the check ran under, else parses.
16// Built on first use inside a test, never while the file loads (#307): Stryker counts a src line reached during
17// module load as a static mutant and runs each mutant on it against the whole mutation suite instead of the tests
18// that cover it.
19let fixtureMemo = null;
20const fixture = () => (fixtureMemo ??= (() => {
21 const tree = unwrap(encodeTree([{ mode: '100644', name: 'a', oid: '1'.repeat(40) }, { mode: '40000', name: 'd', oid: '2'.repeat(40) }]));
22 return { tree };
23})());
24test('assertFetched answers a tree with its entries, any other type with none', () => {
25 const { tree } = fixture();
26 const r = unwrap(assertFetched('tree', tree));
27 assert.equal(r.tag, 'some');
28 assert.deepEqual(r.value.map(e => [e.mode, e.name, e.oid]), unwrap(parseTree(tree)).map(e => [e.mode, e.name, e.oid]));
29 const commit = unwrap(encodeCommit({ tree: '3'.repeat(40), author: 'a <a@b> 0 +0000' }));
30 for (const [type, data] of [['blob', tree], ['commit', commit], ['ofs_delta', tree], ['ref_delta', tree]]) assert.deepEqual(unwrap(assertFetched(type, data)), { tag: 'none' }, type);
31 // a refusal is still the refusal
32 assert.equal(assertFetched('tree', tree.subarray(0, tree.length - 1)).ok, false);
33});
34test('treeEntries: the check parse when the entry cap matches, the reader\'s own parse when it does not', () => {
35 const { tree } = fixture();
36 const checked = unwrap(assertFetched('tree', tree)).value;
37 const fetched = (t, max) => ({ type: 2, data: tree, oid: '4'.repeat(40), size: tree.length, bust: false, tree: t === null ? { tag: 'none' } : { tag: 'some', value: { entries: t, maxTreeEntries: max } } });
38 const limits = unwrap(parseLimits(DEFAULT_LIMITS));
39 assert.equal(unwrap(treeEntries(fetched(checked, limits.maxTreeEntries), limits)), checked, 'the same array: not parsed again');
40 const other = unwrap(treeEntries(fetched(checked, limits.maxTreeEntries + 1), limits));
41 assert.notEqual(other, checked, 'another cap: parsed under the reader\'s limits');
42 assert.deepEqual(other.map(e => e.name), ['a', 'd']);
43 const harvested = unwrap(treeEntries(fetched(null, 0), limits));
44 assert.deepEqual(harvested.map(e => e.name), ['a', 'd']);
45 // the reader's cap binds when it is not the check's: one entry allowed
46 const one = unwrap(parseLimits({ maxTreeEntries: 1 }));
47 assert.equal(treeEntries(fetched(checked, limits.maxTreeEntries), one).error.code, 'limit_exceeded');
48});
50test('random trees: the same entries or the same refusal as before (seeded)', () => {
51 const r = rng(Number(process.env.PARSETREE_SEED ?? 207));
52 const n = process.env.MUTATION === '1' ? 4_000 : 40_000;
53 const stats = { n: 0, accepted: 0, refused: {} };
54 const bad = judgeTrees((function* () { for (let i = 0; i < n; i++) yield randomTree(r); })(), stats);
55 assert.equal(bad, null, JSON.stringify(bad));
56 // not vacuous: trees are accepted, and every refusal parseTree has is reached
57 assert.ok(stats.accepted > n / 20, `${stats.accepted} accepted`);
58 for (const why of ['tree: malformed entry', 'tree: empty mode', 'tree: malformed mode', 'tree: empty name', 'tree: zero-padded mode', 'tree: full pathname', 'tree: bad name', 'tree: large pathname', 'tree: null shaN', 'tree: .gitmodules is a symbolic link', 'tree: .gitmodules is not a blob', 'tree: .gitattributes is not a blob', 'tree: duplicate entry "…"', 'tree: not strictly sorted']) {
59 assert.ok(stats.refused[why] > 0, `${why} never reached: ${JSON.stringify(stats.refused)}`);
60 }
61 assert.ok(Object.keys(stats.refused).some(k => k.startsWith('short read')), 'short read never reached');
62 assert.ok(Object.keys(stats.refused).some(k => k.startsWith('tree entries')), 'entry cap never reached');
63});
Diagnostics4 git calls · 235 ms
CallStatusSizeTime0235 ms
discover200152 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=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=230 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 KiB230 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1964 git.response.cache=MISS git.response.duration_ms=230 git.fetch.wants=a194af54bb63d5a544b8373792bb84f90ff24762 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=1964 git.pkt.payload.max=1943 git.sideband.band1.bytes=1942 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
- a5e2ff4a4d64f3c9
- Request
- cf9cd495…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format