main
1// Push commands are parsed once at the push edge (#156): planPush turns the caller's plain-string commands into a
2// ParsedCommands (Refname refs, Oid oids, at least one) and nothing after it sees a raw string. Every outcome of the
3// old checks holds, cell by cell, including the empty list: 'protocol', nothing sent, no span, and every other refusal
4// first. PUSH_COMMANDS_SRC=<dir> runs the same cells against another copy of src/ (the parity run in the report).
5import { test } from 'vitest';
6import assert from 'node:assert/strict';
7import { withLimits } from '../src/limits.js';
8import { checkPushCaps } from '../src/receivecaps.js';
9import { unwrap } from './unwrap.js';
11const SRC = process.env.PUSH_COMMANDS_SRC ?? '../src';
12const { push, planPush } = await import(`${SRC}/push.js`);
14const A = 'a'.repeat(40), B = 'b'.repeat(40), Z = '0'.repeat(40);
15// a transport double: counts requests and spans, answers nothing (no cell here reaches a request)
16const counting = (limits = {}) => {
17 const t = { limits: withLimits(limits), parent: null, sentN: 0, spans: 0, tracer: { span: async (_n, _o, fn) => { t.spans++; return fn({ set() {}, event() {}, error() {} }); } }, async *frames() { t.sentN++; } };
18 return t;
19};
20const outcome = async (opts, limits = {}) => {
21 const t = counting(limits);
22 const r = await push(t, opts);
23 return { code: r.ok ? 'ok' : r.error.code, what: r.ok ? null : r.error.what ?? null, sent: t.sentN, spans: t.spans };
24};
26test('the empty list: protocol, nothing sent, no span; every other refusal first', async () => {
27 assert.deepEqual(await outcome({ commands: [] }), { code: 'protocol', what: null, sent: 0, spans: 0 });
28 assert.deepEqual(await outcome({ commands: [], atomic: true }), { code: 'bad_request', what: null, sent: 0, spans: 0 });
29 assert.deepEqual(await outcome({ commands: [], objects: [{ type: 3, data: new Uint8Array(1), base: { tag: 'ofs', index: 0 } }] }), { code: 'bad_request', what: 'base', sent: 0, spans: 0 });
30 assert.deepEqual(await outcome({ commands: [] }, { maxPackBytes: NaN }), { code: 'bad_request', what: 'maxPackBytes', sent: 0, spans: 0 });
31 assert.deepEqual(await outcome({ commands: [] }, { maxReportLines: -1 }), { code: 'bad_request', what: 'maxReportLines', sent: 0, spans: 0 });
32 assert.deepEqual(await outcome({ commands: [] }, { maxRefs: 'x' }), { code: 'bad_request', what: 'maxRefs', sent: 0, spans: 0 });
33 const checked = unwrap(checkPushCaps(new Set(['push-options']), { pushOptions: ['a\nb'] }));
34 assert.deepEqual(await outcome({ commands: [], checked }), { code: 'bad_request', what: 'push option', sent: 0, spans: 0 });
35});
37test('each command: the ref first (receive-pack\'s rules, deleting or not), then both oids; the first bad command wins', async () => {
38 const cells = [
39 [{ ref: 'refs/heads/main', oldOid: Z, newOid: A }, 'ok'],
40 [{ ref: 'refs/heads/main', oldOid: A, newOid: Z }, 'ok'],
41 [{ ref: 'refs/foo', oldOid: A, newOid: Z }, 'ok'], // one level: deletable
42 [{ ref: 'refs/foo', oldOid: Z, newOid: A }, 'bad_request:ref'],
43 [{ ref: 'refs/@', oldOid: A, newOid: Z }, 'bad_request:ref'],
44 [{ ref: 'main', oldOid: Z, newOid: A }, 'bad_request:ref'],
45 [{ ref: 'refs/heads/main', oldOid: A.toUpperCase(), newOid: B }, 'bad_request:null'],
46 [{ ref: 'refs/heads/main', oldOid: A, newOid: B.slice(1) }, 'bad_request:null'],
47 [{ ref: 'refs/heads/a b', oldOid: 'x', newOid: B }, 'bad_request:ref'], // the ref is read first
48 ];
49 for (const [c, want] of cells) {
50 const o = await outcome({ commands: [c], objects: [] });
51 const got = o.code === 'bad_request' ? `${o.code}:${o.what}` : o.code === 'ambiguous' ? 'ok' : o.code;
52 assert.equal(got, want, JSON.stringify(c));
53 }
54 const two = await outcome({ commands: [{ ref: 'refs/heads/ok', oldOid: Z, newOid: A }, { ref: 'refs/heads/main', oldOid: 'x', newOid: B }] });
55 assert.deepEqual([two.code, two.sent], ['bad_request', 0]);
56});
58test('the single-ref form: a missing field is refused like a bad one, before anything is sent', async () => {
59 assert.deepEqual(await outcome({ oldOid: Z, newOid: A }), { code: 'bad_request', what: 'ref', sent: 0, spans: 0 });
60 assert.deepEqual(await outcome({ ref: 'refs/heads/main', newOid: A }), { code: 'bad_request', what: null, sent: 0, spans: 0 });
61 assert.deepEqual(await outcome({ ref: 'refs/heads/main', oldOid: Z }), { code: 'bad_request', what: null, sent: 0, spans: 0 });
62});
64test('the plan carries the parsed commands: the same text, at least one', () => {
65 const plan = unwrap(planPush({ commands: [{ ref: 'refs/heads/x', oldOid: Z, newOid: A }, { ref: 'refs/heads/y', oldOid: A, newOid: Z }] }, withLimits()));
66 assert.deepEqual(plan.commands.map(c => [c.ref, c.oldOid, c.newOid]), [['refs/heads/x', Z, A], ['refs/heads/y', A, Z]]);
67 assert.equal(plan.needPack, true);
68 assert.ok(plan.caps.includes('delete-refs'));
69 const single = unwrap(planPush({ ref: 'refs/heads/x', oldOid: Z, newOid: A }, withLimits()));
70 assert.deepEqual(single.commands.map(c => c.ref), ['refs/heads/x']);
71});
73// The one difference from the old check, for untyped callers only: the 40-hex pattern read its argument as a string
74// (RegExp.test), so an array or a String object holding 40 hex passed and was written as its text. parseOid takes only a
75// string. A typed caller cannot pass either (Command's oids are strings). Not run against another src (it differs there).
76test('an oid that is not a string is bad_request (the old pattern read [hex] and new String(hex) as their text)', { skip: Boolean(process.env.PUSH_COMMANDS_SRC) }, async () => {
77 for (const v of [[A], new String(A), 1, null]) {
78 const o = await outcome({ commands: [{ ref: 'refs/heads/main', oldOid: v, newOid: B }] });
79 assert.deepEqual([o.code, o.sent], ['bad_request', 0], String(v));
80 }
81});
83test('maxRefs bounds the commands: exactly maxRefs pass planning, one more is limit_exceeded with nothing sent', async () => {
84 const cmds = n => Array.from({ length: n }, (_, i) => ({ ref: `refs/heads/b${i}`, oldOid: A, newOid: Z }));
85 assert.equal(unwrap(planPush({ commands: cmds(2) }, withLimits({ maxRefs: 2 }))).commands.length, 2);
86 const over = await outcome({ commands: cmds(3) }, { maxRefs: 2 });
87 assert.deepEqual(over, { code: 'limit_exceeded', what: 'push commands', sent: 0, spans: 0 });
88});
90// Each object's base, checked by planPush before anything is built (#156: the tagged base replaced baseIndex/baseOid).
91test('planPush checks every base before anything is built: an ofs base names an earlier object, a ref base is an id', { skip: Boolean(process.env.PUSH_COMMANDS_SRC) }, () => {
92 const data = Uint8Array.of(1, 2, 3);
93 const plan = objects => planPush({ ref: 'refs/heads/main', oldOid: Z, newOid: 'a'.repeat(40), objects }, {});
94 const refused = (objects, message, got) => {
95 const r = plan(objects);
96 assert.deepEqual([r.ok, r.error.code, r.error.what, r.error.message, r.error.got], [false, 'bad_request', 'base', message, got]);
97 };
98 for (const index of [0, 1, -1, 0.5, '0', undefined]) refused([{ type: 3, data, base: { tag: 'ofs', index } }], 'push: an ofs base must name an earlier object', index ?? null);
99 for (const oid of ['', 'A'.repeat(40), 'a'.repeat(39), 7, undefined]) refused([{ type: 3, data, base: { tag: 'ref', oid } }], 'push: a ref base must be an object id', oid ?? null);
100 // a JavaScript caller's base outside the three tags, and the flag fields the tagged base replaced, are refused, not ignored
101 const shape = "push: an object's base is { tag: 'none' }, { tag: 'ofs', index } or { tag: 'ref', oid }";
102 refused([{ type: 3, data, base: { tag: 'thin' } }], shape, 'thin');
103 refused([{ type: 3, data, base: {} }], shape, null);
104 refused([{ type: 3, data }, { type: 3, data, baseIndex: 0 }], shape, 'baseIndex/baseOid');
105 refused([{ type: 3, data, baseOid: 'a'.repeat(40) }], shape, 'baseIndex/baseOid');
106 // the first bad object is the refusal
107 refused([{ type: 3, data, base: { tag: 'ref', oid: 'x' } }, { type: 3, data, base: { tag: 'ofs', index: 5 } }], 'push: a ref base must be an object id', 'x');
108 assert.ok(plan([{ type: 3, data }, { type: 3, data, base: { tag: 'ofs', index: 0 } }, { type: 3, data, base: { tag: 'ref', oid: 'a'.repeat(40) } }, { type: 3, data, base: { tag: 'none' } }]).ok);
109});
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 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=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 · hit6 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=25 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=6 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
fetch2002.5 KiB · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2602 git.response.cache=HIT git.response.duration_ms=25 git.fetch.wants=ab50bac1ac0c4e6724988ffa0b80b0621aa1c4b4 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=2602 git.pkt.payload.max=2581 git.sideband.band1.bytes=2580 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
- a5e2c188ece289da
- Request
- f0e123ac…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format