main
1// Review train 2, S2 input validation (#296-1, #300-1, #300-8). Expected values come from outside the code:
2// a null argument is a caller error, so README's contract ("Every error a function returns has a code") makes it a
3// coded Err, never a throw; RFC 9110 §5.5 field-value = *field-content of field-vchar (VCHAR / obs-text 0x80-0xFF),
4// SP and HTAB, so a control character or a code point above U+00FF is no header value; and `git cat-file -t HEAD:file/`
5// on git 2.50 answers "fatal: path 'file/' does not exist in 'HEAD'" for a blob `file` (and `tree` for `dir/`).
6import { test } from 'vitest';
7import assert from 'node:assert/strict';
8import { pushRepo } from '../src/repo-node.ts';
9import { pushDir, filesFromDir } from '../src/tree-node.ts';
10import { createTransport } from '../src/http.ts';
11import { pathComps } from '../src/read.ts';
12import { DEFAULT_LIMITS, parseLimits } from '../src/limits.ts';
14const coded = async (name, fn, what) => {
15 let r;
16 try { r = await fn(); } catch (e) { assert.fail(`${name} threw ${e?.constructor?.name}: ${e?.message}`); }
17 assert.equal(r.ok, false, `${name} returned ok`);
18 assert.equal(r.error.code, 'bad_request', `${name}: ${r.error.code}`);
19 if (what !== undefined) assert.equal(r.error.what, what, `${name}: what ${r.error.what}`);
20};
22test('node entry points answer a null or mis-typed argument with bad_request naming it (#296-1)', async () => {
23 await coded('pushRepo options null', () => pushRepo('/nonexistent', 'https://example.invalid/x', {}, null), 'options');
24 await coded('pushRepo options 5', () => pushRepo('/nonexistent', 'https://example.invalid/x', {}, 5), 'options');
25 await coded('pushRepo spec null', () => pushRepo('/nonexistent', 'https://example.invalid/x', null), 'spec');
26 await coded('pushDir spec null', () => pushDir('https://example.invalid/x', null), 'spec');
27 await coded('pushDir spec omitted', () => pushDir('https://example.invalid/x'), 'spec');
28 await coded('filesFromDir dir omitted', () => filesFromDir(), 'dir');
29 await coded('pushDir spec 5', () => pushDir('https://example.invalid/x', 5), 'spec');
30 await coded('pushDir spec []', () => pushDir('https://example.invalid/x', []), 'spec');
31 await coded('pushDir options []', () => pushDir('https://example.invalid/x', { dir: '/nonexistent' }, []), 'options');
32 await coded('pushRepo spec []', () => pushRepo('/nonexistent', 'https://example.invalid/x', []), 'spec');
33 await coded('pushRepo options []', () => pushRepo('/nonexistent', 'https://example.invalid/x', {}, []), 'options');
34 await coded('filesFromDir options []', () => filesFromDir('/nonexistent', []), 'options');
35 await coded('pushDir options null', () => pushDir('https://example.invalid/x', { dir: '/nonexistent' }, null), 'options');
36 await coded('filesFromDir dir null', () => filesFromDir(null), 'dir');
37 await coded('filesFromDir options 5', () => filesFromDir('/nonexistent', 5), 'options');
38 // a well-shaped spec and options pass the shape checks: the first refusal is the unreadable directory itself
39 await coded('pushDir valid shape, missing dir', () => pushDir('https://example.invalid/x', { dir: '/nonexistent' }, {}), 'dir');
40 await coded('pushDir valid shape, options omitted', () => pushDir('https://example.invalid/x', { dir: '/nonexistent' }), 'dir');
41});
43test('a userAgent that is no RFC 9110 field-value is refused at parse (#300-1)', () => {
44 for (const ua of [' ply', 'ply ', '\tply', 'ply\t', 'ply\u0001', 'ply\u007F', 'ply☃', 'ply\t\u0000', 'a\nb', 'ply😀']) {
45 const r = createTransport('https://h/r', { userAgent: ua });
46 assert.equal(r.ok, false, JSON.stringify(ua));
47 assert.equal(r.error.code, 'bad_request');
48 assert.equal(r.error.what, 'userAgent');
49 }
50 // a field value is a string (RFC 9110 §5.5 defines it over octets): a number or null is no value, even though
51 // RegExp.test would coerce it to '5' or 'null'
52 for (const ua of [5, null, {}]) {
53 const r = createTransport('https://h/r', { userAgent: ua });
54 assert.equal(r.ok, false, String(ua));
55 assert.equal(r.error.code, 'bad_request');
56 assert.equal(r.error.what, 'userAgent');
57 }
58 // obs-text (0x80-0xFF), SP and HTAB inside a value are field-content
59 for (const ua of ['ply/1.0 (x)', 'plyé', 'a\tb', 'ply']) assert.equal(createTransport('https://h/r', { userAgent: ua }).ok, true, JSON.stringify(ua));
60});
62test('a file path with a trailing slash names a directory and is refused; a tree path keeps it (#300-8)', () => {
63 const limits = parseLimits(DEFAULT_LIMITS).value;
64 const file = pathComps('file/', limits, { allowRoot: false });
65 assert.equal(file.ok, false);
66 assert.equal(file.error.code, 'bad_request');
67 assert.equal(file.error.what, 'path');
68 assert.deepEqual(pathComps('a/file', limits, { allowRoot: false }).value, ['a', 'file']);
69 assert.deepEqual(pathComps('dir/', limits, { allowRoot: true }).value, ['dir']);
70});
72// #296-2: the stack entry points, each argument in turn replaced by null (the others a well-shaped stand-in, so the
73// shape check is what answers). Expected: README's contract, a coded Err (bad_request) naming that argument, no throw.
74// index.ts is imported dynamically: the mutation suite has no static index import (#313).
75const index = () => import('../src/index.ts');
76const O = {};
77// Each argument: [name, well-shaped stand-in, required]. README §errors: an argument of the wrong shape is a caller
78// error, a coded bad_request naming it. Wrong shapes, by the argument's TypeScript type: null, undefined (for a
79// required one), a number, and an array where an object is declared (an array is no options/pack/source record) or
80// an object where an array or bytes is declared. An omitted optional options argument is the default, never refused.
81const OBJ = [null, 5, []];
82const STACK = [
83 ['scanPackIndex', [['source', O, true], ['options', O, false]]],
84 ['resolvePackRange', [['pack', O, true], ['source', O, true], ['options', O, false]]],
85 ['planPackBatches', [['pack', O, true], ['resolved', O, true], ['options', O, true]]],
86 ['packSubset', [['source', O, true], ['pack', O, true], ['selection', [], true, [null, 5, O]], ['options', O, false]]],
87 ['planTransfer', [['pack', O, true], ['resolved', O, true], ['options', O, true]]],
88 ['copyTree', [['dst', O, true], ['from', O, true], ['options', O, true]]],
89 ['loadTransferPack', [['dst', O, true], ['source', O, true], ['saved', O, true], ['options', O, false]]],
90 ['pushPack', [['transport', O, true], ['options', O, true]]],
91];
92const show = v => (v === undefined ? 'undefined' : JSON.stringify(v));
93for (const [name, args] of STACK) {
94 test(`${name}: null, undefined, a number or an array/object of the wrong kind for each argument is bad_request naming it, never a throw (#296-2)`, async () => {
95 const fn = (await index())[name];
96 for (let i = 0; i < args.length; i++) {
97 const [what, , required, wrong = OBJ] = args[i];
98 for (const bad of required ? [...wrong, undefined] : wrong) {
99 const call = args.map(([, v], j) => (j === i ? bad : v));
100 await coded(`${name}(${args.map(([n], j) => (j === i ? show(bad) : n)).join(', ')})`, () => fn(...call), what);
101 }
102 }
103 });
104}
105// decodeSavedIndex keeps one error union (README "Results"): a wrong-shape argument is its `bad_argument` refusal,
106// by `tag` like the other seven, naming the argument.
107test('decodeSavedIndex: a wrong-shape bytes or want is the bad_argument refusal naming it, never a throw (#296-2)', async () => {
108 const { decodeSavedIndex } = await index();
109 for (const bad of [null, undefined, 5, [], O]) assert.deepEqual(decodeSavedIndex(bad, O), { ok: false, error: { tag: 'bad_argument', what: 'bytes' } }, show(bad));
110 for (const bad of [null, undefined, 5, []]) assert.deepEqual(decodeSavedIndex(new Uint8Array(0), bad), { ok: false, error: { tag: 'bad_argument', what: 'want' } }, show(bad));
111 const { describeSavedIndexRefusal } = await index();
112 assert.equal(describeSavedIndexRefusal({ tag: 'bad_argument', what: 'bytes' }), 'decodeSavedIndex: bytes must be a Uint8Array');
113 assert.equal(describeSavedIndexRefusal({ tag: 'bad_argument', what: 'want' }), 'decodeSavedIndex: want must be an object');
114});
115test('transferStatus and runTransfer answer null with a coded Err, no throw (#296-2)', async () => {
116 const { transferStatus, runTransfer } = await index();
117 for (const fn of [transferStatus, runTransfer]) await coded(fn.name, () => fn(null, null, null, null, null));
118});
120// The owner's invariant (#296): no function export of src/index.ts throws on a null argument; each returns a coded Err
121// or a value. The call shapes are generated from the exports: for every function, null in each position
122// 0..max(fn.length, 1)-1, every other argument undefined. STILL_THROWS lists, by name#position/arity, the shapes that
123// still throw a raw TypeError/Error at this commit (190 of the 328 shapes); it must only shrink: a new throwing shape
124// fails, and a shape that stops throwing fails until it is removed from the list.
125const STILL_THROWS = new Set([
126 'applyDelta#0/2',
127 'applyDelta#1/2',
128 'applyProgram#0/2',
129 'applyProgram#1/2',
130 'armor#0/1',
131 'assertNever#0/1',
132 'bestBases#1/3',
133 'bestBases#2/3',
134 'buildCommitObjects#0/1',
135 'buildPack#0/1',
136 'buildTree#0/1',
137 'cacheKey#0/3',
138 'cacheKey#1/3',
139 'cacheKey#2/3',
140 'commitChanges#0/2',
141 'commitChanges#1/2',
142 'commitView#0/1',
143 'concat#0/1',
144 'createBranch#0/2',
145 'createBranch#1/2',
146 'createTag#0/2',
147 'createTag#1/2',
148 'decideHead#0/1',
149 'deleteBranch#0/2',
150 'deleteBranch#1/2',
151 'deleteRef#0/2',
152 'deleteRef#1/2',
153 'deleteTag#0/2',
154 'deleteTag#1/2',
155 'describePack#0/1',
156 'describeSavedIndexRefusal#0/1',
157 'ed25519Signer#0/1',
158 'editFile#0/2',
159 'editFile#1/2',
160 'encodeCommit#0/1',
161 'encodeDelta#0/2',
162 'encodeDelta#1/2',
163 'encodeDeltaOps#0/3',
164 'encodeDeltaOps#1/3',
165 'encodeDeltaOps#2/3',
166 'encodePackIndex#0/2',
167 'encodePackIndex#1/2',
168 'encodeSavedIndex#0/2',
169 'encodeSavedIndex#1/2',
170 'encodeTag#0/1',
171 'encodeTree#0/1',
172 'exchangeKind#0/3',
173 'exchangeKind#1/3',
174 'exchangeKind#2/3',
175 'fail#0/2',
176 'fail#1/2',
177 'fastForward#0/2',
178 'fastForward#1/2',
179 'fetchBody#0/1',
180 'fetchObject#0/2',
181 'fetchObject#1/2',
182 'fetchPack#0/2',
183 'fetchPack#1/2',
184 'flattenLine#0/1',
185 'fromAny#0/1',
186 'fromHex#0/1',
187 'hashObject#0/2',
188 'hashObject#1/2',
189 'indexPack#0/1',
190 'inflate#0/1',
191 'inflateChunks#0/1',
192 'inflateEnd#0/1',
193 'inflateFeed#0/2',
194 'inflateFeed#1/2',
195 'inflateInit#0/1',
196 'inflatePull#0/1',
197 'inflateReset#0/2',
198 'inflateReset#1/2',
199 'inflateUnread#0/1',
200 'isCacheableFetch#0/1',
201 'isLfsPointerPrefix#0/1',
202 'isPureFetch#0/1',
203 'layoutPackIndex#0/2',
204 'layoutPackIndex#1/2',
205 'linearChain#1/3',
206 'linearChain#2/3',
207 'logWindow#0/4',
208 'logWindow#1/4',
209 'logWindow#2/4',
210 'logWindow#3/4',
211 'lookupEntry#0/4',
212 'lookupEntry#1/4',
213 'lookupEntry#2/4',
214 'lookupEntry#3/4',
215 'lsMode#0/1',
216 'lsRefs#0/1',
217 'lsRefsBody#0/1',
218 'makeDelta#0/2',
219 'makeDelta#1/2',
220 'memAttrs#0/1',
221 'memFromScan#0/2',
222 'memFromScan#1/2',
223 'mergeBranch#0/2',
224 'mergeBranch#1/2',
225 'negotiate#0/2',
226 'negotiate#1/2',
227 'objectsForPack#0/2',
228 'objectsForPack#1/2',
229 'openBlob#0/2',
230 'openBlob#1/2',
231 'packIdentity#0/1',
232 'parseCommit#0/1',
233 'parseDelta#0/1',
234 'parsePack#0/1',
235 'parsePackClose#0/1',
236 'parsePackEnd#0/1',
237 'parsePackFeed#0/2',
238 'parsePackFeed#1/2',
239 'parsePackInit#0/1',
240 'parsePackPull#0/1',
241 'parseTag#0/1',
242 'parseTree#0/1',
243 'parseUploadPackRequest#0/1',
244 'pickCommit#0/2',
245 'pickCommit#1/2',
246 'pkt#0/1',
247 'pktFinish#0/1',
248 'pktFrames#0/1',
249 'pktStep#0/2',
250 'pktStep#1/2',
251 'pkts#0/1',
252 'planDeltas#0/1',
253 'planHash#0/1',
254 'plyError#0/2',
255 'plyError#1/2',
256 'push#0/2',
257 'push#1/2',
258 'pushBody#0/1',
259 'pushTree#0/2',
260 'pushTree#1/2',
261 'pushWithOptions#0/2',
262 'pushWithOptions#1/2',
263 'rangeFromBytes#0/1',
264 'reachableObjects#0/2',
265 'reachableObjects#1/2',
266 'readBlob#0/2',
267 'readBlob#1/2',
268 'rebaseBranch#0/2',
269 'rebaseBranch#1/2',
270 'resolveCommit#0/2',
271 'resolveCommit#1/2',
272 'resolvePack#0/1',
273 'resolvedIndexOf#0/2',
274 'resolvedIndexOf#1/2',
275 'scanFinish#0/1',
276 'scanInit#0/1',
277 'scanPack#0/1',
278 'scanStep#0/2',
279 'scanStep#1/2',
280 'scannedPackOf#0/2',
281 'scannedPackOf#1/2',
282 'selectObjects#0/1',
283 'sidebandStep#0/3',
284 'sidebandStep#1/3',
285 'sidebandStep#2/3',
286 'spFinish#0/1',
287 'spStep#0/2',
288 'spStep#1/2',
289 'spliceDelta#0/1',
290 'sshPublicKey#0/1',
291 'sweepTransfers#0/1',
292 'syncRef#0/3',
293 'syncRef#1/3',
294 'syncRef#2/3',
295 'threeWay#0/3',
296 'threeWay#1/3',
297 'threeWay#2/3',
298 'toHex#0/1',
299 'transferPlanHash#0/1',
300 'treeFiles#0/2',
301 'treeFiles#1/2',
302 'treeSort#0/1',
303 'v2Step#0/2',
304 'v2Step#1/2',
305 'validateSpec#0/2',
306 'validateSpec#1/2',
307 'validateTreeSpec#0/2',
308 'validateTreeSpec#1/2',
309 'verifyFetchAnswer#0/2',
310 'verifyFetchAnswer#1/2',
311 'withCommitData#0/2',
312 'withCommitData#1/2',
313 'withDerivedWork#0/1',
314 'withGpgsig#0/2',
315 'zlibDeflate#0/1',
316]);
317test('every function export of index.ts, null in each argument position: no throw outside the shrinking allow-list (#296)', async () => {
318 const m = await index();
319 const throws = [];
320 for (const [name, fn] of Object.entries(m).sort(([a], [b]) => (a < b ? -1 : 1))) {
321 if (typeof fn !== 'function' || /^[A-Z]/u.test(name)) continue;
322 const n = Math.max(fn.length, 1);
323 for (let i = 0; i < n; i++) {
324 try { await fn(...Array.from({ length: n }, (_, j) => (j === i ? null : undefined))); } catch { throws.push(`${name}#${i}/${n}`); }
325 }
326 }
327 assert.deepEqual(throws.filter(s => !STILL_THROWS.has(s)), [], 'a call shape outside the allow-list throws');
328 assert.deepEqual([...STILL_THROWS].filter(s => !throws.includes(s)), [], 'a listed shape no longer throws: remove it from STILL_THROWS');
329});
331// The other half of the options contract: an omitted optional options argument means the defaults (README: options
332// are optional), so the call answers exactly as it does with {}; it is never bad_request naming 'options'.
333test('an omitted optional options argument answers as {} does, never bad_request options (#296-2)', async () => {
334 const m = await index();
335 const empty = () => (async function* () {})();
336 const cases = [
337 ['scanPackIndex', o => m.scanPackIndex(empty(), ...o)],
338 ['loadTransferPack', o => m.loadTransferPack(O, O, O, ...o)],
339 ];
340 for (const [name, call] of cases) {
341 const omitted = await call([]);
342 assert.notEqual(omitted.ok === false && omitted.error.what, 'options', `${name}: omitted options refused`);
343 assert.deepEqual(omitted, await call([{}]), `${name}: omitted differs from {}`);
344 }
345});
Diagnostics4 git calls · 368 ms
CallStatusSizeTime0368 ms
discover200152 B4 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 · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 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=361 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
fetch2004.4 KiB361 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=4547 git.response.cache=MISS git.response.duration_ms=361 git.fetch.wants=41a5f40747ed757ac2c949e739e1489f5ef8587e 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=4547 git.pkt.payload.max=4526 git.sideband.band1.bytes=4525 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
- a5e208808e39c69c
- Request
- 58106a6a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format