Artifactspublic-v0

ply

main
ply4 git calls419 ms41 KiB2 cachedprotocol v2
113 lines8.0 KiBRaw
1// Author and committer stamps, decided by git (#103 item 4): each stamp carries its own name, email, time and zone, and
2// merge `from` / rebase `onto` take a 40-hex commit id as well as a branch. For every stamp pair and every operation, ply
3// writes the commit(s) against a bare repository and git writes them in a clone of the same repository with
4// GIT_AUTHOR_* / GIT_COMMITTER_* set to the same stamps; the raw objects (`git cat-file -p`) must be byte-equal.
5import { test, beforeAll as before, afterAll as after } from 'vitest';
6import assert from 'node:assert/strict';
7import { join } from 'node:path';
8import { mkdirSync, writeFileSync, rmSync, mkdtempSync } from 'node:fs';
9import { spawnSync } from 'node:child_process';
10import { tmpdir } from 'node:os';
11import { git, tmpRoot, makeBareRepo, startGitServer, initRepo } from './server.js';
12import { oracleRediff } from './gitversion.js';
13import { mergeBranch } from '../src/merge.js';
14import { rebaseBranch, cherryPick, revertCommit } from '../src/rebase.js';
15import { Tracer } from '../src/otel.js';
16import { unwrapAsync } from './unwrap.js';
18const rediff = oracleRediff();
19const BASE_ENV = { ...process.env, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'commit.gpgsign', GIT_CONFIG_VALUE_0: 'false' };
20const as = (a, c) => ({ ...BASE_ENV, GIT_AUTHOR_NAME: a.name, GIT_AUTHOR_EMAIL: a.email, GIT_AUTHOR_DATE: `@${a.time} ${a.tz ?? '+0000'}`, GIT_COMMITTER_NAME: c.name, GIT_COMMITTER_EMAIL: c.email, GIT_COMMITTER_DATE: `@${c.time} ${c.tz ?? '+0000'}` });
21const run = (cwd, args, env) => { const r = spawnSync('git', ['-C', cwd, ...args], { encoding: 'utf8', env }); assert.equal(r.status, 0, `git ${args.join(' ')}: ${r.stderr}${r.stdout}`); return r.stdout.trim(); };
23// the history's own commits, by someone else at another time
24const ORIG = { name: 'orig', email: 'orig@x', time: 1400000000, tz: '+0200' };
25// stamp pairs: author, committer — zones either side of UTC, the civil extremes, a half and a quarter hour, and an
26// omitted zone (+0000)
27export const PAIRS = [
28 [{ name: 'Ann', email: 'ann@x', time: 1700000000, tz: '+0530' }, { name: 'Cid', email: 'cid@x', time: 1700003600, tz: '-0800' }],
29 [{ name: 'Ann', email: 'ann@x', time: 1600000000, tz: '-1200' }, { name: 'Cid', email: 'cid@x', time: 1600000123, tz: '+1400' }],
30 [{ name: 'Ann', email: 'ann@x', time: 1500000000 }, { name: 'Cid', email: 'cid@x', time: 1500000001, tz: '+0545' }],
31];
32export const OPS = ['merge from a branch', 'merge from a commit id', 'rebase onto a branch', 'rebase onto a commit id', 'squash', 'cherry-pick', 'revert'];
34let root, cleanup, srv, n = 0;
35before(async () => { ({ root, cleanup } = tmpRoot()); srv = await startGitServer(root); });
36after(async () => { await srv?.close(); cleanup?.(); });
38// base ← main (m.txt); base ← feat (a.txt, then b.txt). Returns the bare repo and the oids.
39function build() {
40 const name = `st${n++}`; const bare = makeBareRepo(root, name); const w = join(root, `w${name}`); mkdirSync(w);
41 const env = as(ORIG, ORIG);
42 initRepo(w);
43 const commit = (file, msg) => { writeFileSync(join(w, file), `${file}\n`); run(w, ['add', '-A'], env); run(w, ['commit', '-q', '-m', msg], env); return run(w, ['rev-parse', 'HEAD'], env); };
44 const base = commit('f.txt', 'base');
45 const main = commit('m.txt', 'm');
46 run(w, ['checkout', '-q', '-b', 'feat', base], env);
47 commit('a.txt', 'a'); const feat = commit('b.txt', 'b');
48 run(w, ['push', '-q', bare, 'refs/heads/main', 'refs/heads/feat'], env);
49 rmSync(w, { recursive: true, force: true });
50 return { name, bare, url: `${srv.url}/${name}.git`, main, feat };
52const clone = (bare, branch) => { const d = mkdtempSync(join(tmpdir(), 'st-')); run(d, ['clone', '-q', '-b', branch, bare, '.'], BASE_ENV); return d; };
53const raw = (repo, oid) => run(repo, ['cat-file', '-p', oid], BASE_ENV);
54// the commits from..to, oldest first, as raw objects
55const range = (repo, from, to) => run(repo, ['rev-list', '--reverse', `${from}..${to}`], BASE_ENV).split('\n').filter(Boolean).map(o => raw(repo, o));
57// one cell: [ply's raw commits, git's raw commits]
58async function cell(op, a, c) {
59 const r = build(); const opts = { tracer: new Tracer(), rediff };
60 const d = clone(r.bare, op.startsWith('rebase') || op === 'squash' ? 'feat' : 'main');
61 try {
62 const env = as(a, c);
63 if (op.startsWith('merge')) {
64 const from = op === 'merge from a branch' ? 'refs/heads/feat' : r.feat;
65 const res = await unwrapAsync(mergeBranch(r.url, { ref: 'refs/heads/main', from, author: a, committer: c, message: 'merge msg', noFastForward: true }, opts));
66 run(d, ['merge', '--no-ff', '-q', '-m', 'merge msg', r.feat], env);
67 return [[raw(r.bare, res.oid)], [raw(d, 'HEAD')]];
68 }
69 if (op.startsWith('rebase')) {
70 const onto = op === 'rebase onto a branch' ? 'refs/heads/main' : r.main;
71 const res = await unwrapAsync(rebaseBranch(r.url, { ref: 'refs/heads/feat', onto, committer: c }, opts));
72 run(d, ['rebase', '-q', r.main], env);
73 return [range(r.bare, r.main, res.oid), range(d, r.main, 'HEAD')];
74 }
75 if (op === 'squash') {
76 const res = await unwrapAsync(rebaseBranch(r.url, { ref: 'refs/heads/feat', onto: 'refs/heads/main', committer: c, author: a, squash: true, message: 'squash msg\n' }, opts));
77 run(d, ['checkout', '-q', '-B', 'sq', r.main], env); run(d, ['merge', '--squash', '-q', r.feat], env); run(d, ['commit', '-q', '-m', 'squash msg'], env);
78 return [[raw(r.bare, res.oid)], [raw(d, 'HEAD')]];
79 }
80 if (op === 'cherry-pick') {
81 const res = await unwrapAsync(cherryPick(r.url, { ref: 'refs/heads/main', commit: r.feat, committer: c }, opts));
82 run(d, ['cherry-pick', r.feat], env);
83 return [[raw(r.bare, res.oid)], [raw(d, 'HEAD')]];
84 }
85 const res = await unwrapAsync(revertCommit(r.url, { ref: 'refs/heads/main', commit: r.main, committer: c, author: a }, opts));
86 run(d, ['revert', '--no-edit', r.main], env);
87 return [[raw(r.bare, res.oid)], [raw(d, 'HEAD')]];
88 } finally { rmSync(d, { recursive: true, force: true }); }
91test('author and committer stamps with zones, from/onto by commit id: every commit byte-equal to git\'s', { timeout: 10 * 60_000 }, async () => {
92 const bad = []; let cells = 0, commits = 0;
93 for (const [i, [a, c]] of PAIRS.entries()) for (const op of OPS) {
94 const [ours, theirs] = await cell(op, a, c); cells++; commits += theirs.length;
95 assert.ok(theirs.length > 0, `${op}: git wrote nothing`);
96 if (JSON.stringify(ours) !== JSON.stringify(theirs)) bad.push(`pair ${i} ${op}:\n ply: ${JSON.stringify(ours)}\n git: ${JSON.stringify(theirs)}`);
97 }
98 console.log(`# stamps: ${cells} cells (${PAIRS.length} stamp pairs × ${OPS.length} operations), ${commits} commits compared, ${bad.length} differ`);
99 assert.deepEqual(bad, []);
100});
102test('from / onto: the zero oid is refused before any request; an oid that is not a commit is not_found', async () => {
103 const r = build(); const opts = { tracer: new Tracer(), rediff };
104 const zero = '0'.repeat(40);
105 await assert.rejects(unwrapAsync(mergeBranch(r.url, { from: zero, author: PAIRS[0][0] }, opts)), e => e.code === 'bad_request' && e.what === 'from');
106 await assert.rejects(unwrapAsync(rebaseBranch(r.url, { ref: 'refs/heads/feat', onto: zero, committer: PAIRS[0][1] }, opts)), e => e.code === 'bad_request' && e.what === 'onto');
107 const tree = run(r.bare, ['rev-parse', 'main^{tree}'], BASE_ENV);
108 await assert.rejects(unwrapAsync(mergeBranch(r.url, { from: tree, author: PAIRS[0][0] }, opts)), e => e.code === 'not_found' && e.what === 'from' && e.miss?.kind === 'commit' && e.miss.miss.kind === 'not_commit' && e.miss.miss.type === 'tree' && e.miss.miss.oid === tree);
109 const onto = 'f'.repeat(40);
110 await assert.rejects(unwrapAsync(rebaseBranch(r.url, { ref: 'refs/heads/feat', onto, committer: PAIRS[0][1] }, opts)), e => e.code === 'not_found' && e.what === 'onto' && e.miss?.kind === 'commit' && e.miss.miss.kind === 'absent' && e.miss.miss.oid === onto);
111 assert.equal(run(r.bare, ['rev-parse', 'main'], BASE_ENV), r.main, 'nothing pushed');
112 assert.equal(run(r.bare, ['rev-parse', 'feat'], BASE_ENV), r.feat, 'nothing pushed');
113});
Diagnostics4 git calls · 419 ms
CallStatusSizeTime0419 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=414
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=55
Open pack map
fetch2002.9 KiB414 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2934
git.response.cache=MISS
git.response.duration_ms=414
git.fetch.wants=5bd1bdfcc55baf58a2869f0662251b0951d1a762
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=2934
git.pkt.payload.max=2913
git.sideband.band1.bytes=2912
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
a5e1b8511f2c5b65
Request
c523ce55…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format