main
1// Command oids on a push (#81, the planPush site the push-outcome space owns). Every pair of six shapes, judged
2// against one `git receive-pack --stateless-rpc` each. ply accepts only lowercase 40-hex; git accepts any case of
3// 40 hex, so an uppercase oid is a typed bad_request before the wire (format.ts: uppercase is not an object id here).
4import { test } from 'vitest';
5import assert from 'node:assert/strict';
6import { spawnSync } from 'node:child_process';
7import { mkdtempSync, rmSync } from 'node:fs';
8import { tmpdir } from 'node:os';
9import { join } from 'node:path';
10import { pkt, FLUSH } from '../../src/pktline.js';
11import { concat, te } from '../../src/bytes.js';
12import { planPush } from '../../src/push.js';
13import { DEFAULT_LIMITS } from '../../src/limits.js';
14import { createHash } from 'node:crypto';
15import { unwrap } from '../unwrap.js';
17const ENV = { ...Object.fromEntries(Object.entries(process.env).filter(([k]) => !k.startsWith('GIT_'))), GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', GIT_AUTHOR_NAME: 'a', GIT_AUTHOR_EMAIL: 'a@x', GIT_COMMITTER_NAME: 'a', GIT_COMMITTER_EMAIL: 'a@x', GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000' };
18const ZERO = '0'.repeat(40);
19const LOWER = /^[0-9a-f]{40}$/u;
20const ANY_CASE = /^[0-9a-fA-F]{40}$/u;
22test('push command oids: 6 × 6 shapes, ply against receive-pack', () => {
23 const root = mkdtempSync(join(tmpdir(), 'ply-oid-'));
24 try {
25 const dir = join(root, 'srv.git');
26 spawnSync('git', ['init', '-q', '--bare', dir], { env: ENV });
27 const tree = spawnSync('git', ['mktree'], { cwd: dir, env: ENV, input: '' }).stdout.toString().trim();
28 const commit = spawnSync('git', ['commit-tree', tree, '-m', 'c'], { cwd: dir, env: ENV }).stdout.toString().trim();
29 assert.match(commit, LOWER);
30 const shapes = [
31 ['lower', commit],
32 ['upper', commit.toUpperCase()],
33 ['len39', commit.slice(0, 39)],
34 ['len41', `${commit}a`],
35 ['nonhex', `g${commit.slice(1)}`],
36 ['empty', ''],
37 ];
38 const head = new Uint8Array(12); head.set(te.encode('PACK')); head[7] = 2;
39 const pack = concat([head, new Uint8Array(createHash('sha1').update(head).digest())]);
40 let cells = 0, disagreed = 0;
41 for (const [oldTag, oldOid] of shapes) for (const [newTag, newOid] of shapes) {
42 const where = `${oldTag}/${newTag}`;
43 const ref = `refs/heads/c${cells}`;
44 const planned = planPush({ ref, oldOid, newOid }, DEFAULT_LIMITS);
45 const plyOk = planned.ok;
46 if (!plyOk) {
47 assert.equal(planned.error.code, 'bad_request', where);
48 assert.equal(planned.error.message, 'push: oids must be 40-hex', where);
49 }
50 assert.equal(plyOk, LOWER.test(oldOid) && LOWER.test(newOid), where);
51 const line = unwrap(pkt(te.encode(`${oldOid} ${newOid} ${ref}\0report-status\n`)));
52 const git = spawnSync('git', ['receive-pack', '--stateless-rpc', dir], { env: ENV, input: concat([line, FLUSH, ...(newOid === ZERO ? [] : [pack])]) });
53 const gitOk = ANY_CASE.test(oldOid) && ANY_CASE.test(newOid);
54 if (gitOk) {
55 assert.equal(git.status, 0, `${where}: ${git.stderr}`);
56 assert.match(git.stdout.toString(), /unpack ok\n/u, where);
57 } else {
58 assert.equal(git.status, 128, where);
59 assert.match(git.stderr.toString(), /protocol error: expected old\/new\/ref/u, where);
60 }
61 if (gitOk && !plyOk) disagreed++;
62 cells++;
63 }
64 assert.equal(cells, 36);
65 // upper × {lower, upper} on either side, except lower/lower: 4 − 1 = 3
66 assert.equal(disagreed, 3);
67 } finally { rmSync(root, { recursive: true, force: true }); }
68});
Diagnostics4 git calls · 404 ms
CallStatusSizeTime0404 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 · 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=3 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.6 KiB399 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=399 git.response.bytes=1642 git.response.cache=MISS git.response.duration_ms=399 git.fetch.wants=dee54e06193988eecd73a07c2457801566b6fd26 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=1642 git.pkt.payload.max=1621 git.sideband.band1.bytes=1620 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
- a5e2d7a38d0414c2
- Request
- a3f8b169…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format