main
1// The workbench builds a scenario's seed in memory (src/bench/seed.ts). Its object ids must be the ones git plumbing
2// makes from the same plan (ply's test/probes/runner.mjs buildSeed), or a run from the Worker would not be the run ply's
3// suite makes. Every scenario the workbench can hold is built both ways here and compared id by id.
4import { test } from 'node:test';
5import assert from 'node:assert/strict';
6import { execFileSync } from 'node:child_process';
7import { createHash } from 'node:crypto';
8import { mkdtempSync, rmSync } from 'node:fs';
9import { tmpdir } from 'node:os';
10import { join } from 'node:path';
11import { SCENARIOS, type Seed } from 'ply/probes';
12import { buildSeed, contentBytes, objectsFor, seedBytes } from '../src/bench/seed.ts';
13import { WORKBENCH_SEED_BYTES } from '../src/bench/catalogue.ts';
15const IDENT = { GIT_AUTHOR_NAME: 'ply probe', GIT_AUTHOR_EMAIL: 'probe@ply.invalid', GIT_COMMITTER_NAME: 'ply probe', GIT_COMMITTER_EMAIL: 'probe@ply.invalid', GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000' };
17async function gitSeed(seed: Seed): Promise<Map<string, string>> {
18 const root = mkdtempSync(join(tmpdir(), 'bench-seed-'));
19 const dir = join(root, 'objects.git');
20 const env = { PATH: String(process.env['PATH']), HOME: root, GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', ...IDENT };
21 const git = (args: string[], input: Uint8Array | string | null = null, extra: Record<string, string> = {}): string => execFileSync('git', args, { cwd: dir, env: { ...env, ...extra }, input: input === null ? '' : input, encoding: 'utf8' }).trim();
22 execFileSync('git', ['init', '-q', '--bare', '-b', 'main', dir], { env });
23 const names = new Map<string, string>();
24 const trees = new Map<string, string>();
25 try {
26 for (const o of seed.objects) {
27 switch (o.tag) {
28 case 'commit': {
29 const idx = { GIT_INDEX_FILE: join(root, `index-${o.name}`) };
30 const first = o.parents[0];
31 git(typeof first === 'string' ? ['read-tree', String(trees.get(first))] : ['read-tree', '--empty'], null, idx);
32 for (const f of o.files) {
33 const blob = git(['hash-object', '-w', '--stdin'], await contentBytes(f.content));
34 git(['update-index', '--add', '--cacheinfo', `100644,${blob},${f.path}`], null, idx);
35 }
36 trees.set(o.name, git(['write-tree'], null, idx));
37 names.set(o.name, git(['commit-tree', String(trees.get(o.name)), ...o.parents.flatMap(p => ['-p', String(names.get(p))]), '-m', o.message]));
38 break;
39 }
40 case 'annotated-tag':
41 names.set(o.name, git(['mktag'], `object ${names.get(o.target)}\ntype commit\ntag ${o.tagName}\ntagger ply probe <probe@ply.invalid> 1700000000 +0000\n\n${o.message}\n`));
42 break;
43 case 'raw-tree': {
44 // git plumbing resolves each entry's blob, then writes the bytes as given (hash-object --literally)
45 const body = Buffer.concat(o.entries.map(e => {
46 const blob = e.blob.tag === 'commit' ? String(names.get(e.blob.name)) : git(['rev-parse', `${trees.get(e.blob.of)}:${e.blob.path}`]);
47 return Buffer.concat([Buffer.from(`${e.mode} ${e.name}\0`), Buffer.from(blob, 'hex')]);
48 }));
49 names.set(o.name, git(['hash-object', '--literally', '-t', 'tree', '-w', '--stdin'], body));
50 break;
51 }
52 case 'raw-commit': {
53 const tree = trees.has(o.tree) ? trees.get(o.tree) : names.get(o.tree);
54 const body = [`tree ${tree}`, ...o.parents.map(p => `parent ${names.get(p)}`), `author ${o.author}`, 'committer ply probe <probe@ply.invalid> 1700000000 +0000', '', o.message, ''].join('\n');
55 names.set(o.name, git(['hash-object', '--literally', '-t', 'commit', '-w', '--stdin'], body));
56 break;
57 }
58 case 'raw-tag':
59 // the type line as written (it may disagree with the target, or name an object nothing holds)
60 names.set(o.name, git(['hash-object', '--literally', '-t', 'tag', '-w', '--stdin'], `object ${names.get(o.object)}\ntype ${o.type}\ntag ${o.tagName}\ntagger ply probe <probe@ply.invalid> 1700000000 +0000\n\n${o.message}\n`));
61 break;
62 case 'phantom':
63 names.set(o.name, createHash('sha1').update(`probe phantom ${o.seed}`).digest('hex'));
64 break;
65 }
66 }
67 return names;
68 } finally {
69 rmSync(root, { recursive: true, force: true });
70 }
71}
73const HELD = SCENARIOS.filter(s => seedBytes(s.seed) <= WORKBENCH_SEED_BYTES);
75test('the workbench holds most of the catalogue in memory', () => {
76 assert.ok(HELD.length >= SCENARIOS.length - 2, `${HELD.length} of ${SCENARIOS.length}`);
77});
79// Seeds repeat across scenarios; each distinct seed is built once.
80const distinct = [...new Map(HELD.map(s => [JSON.stringify(s.seed), s])).values()];
81for (const s of distinct) {
82 test(`seed object ids match git plumbing: ${s.id}`, async () => {
83 const built = await buildSeed(s.seed);
84 assert.ok(built.ok, built.ok ? '' : built.error);
85 const want = await gitSeed(s.seed);
86 assert.deepEqual(Object.fromEntries(built.value.names), Object.fromEntries(want));
87 });
88}
90test('objectsFor: a push carries what the target lacks, minus the plan omit', async () => {
91 const s = SCENARIOS.find(x => x.id === 'pack.push-malformed-object-refused#missing-blob');
92 assert.ok(s);
93 const built = await buildSeed(s.seed);
94 assert.ok(built.ok);
95 const base = String(built.value.names.get('base'));
96 const step = s.steps[0];
97 assert.equal(step.tag, 'push');
98 if (step.tag !== 'push') return;
99 const objs = objectsFor(built.value, step.push, [base as never]);
100 assert.ok(objs.ok);
101 // ff: its commit and its root tree; f.txt's new blob is omitted, dir/ is unchanged and held
102 assert.deepEqual(objs.value.map(o => o.type).sort(), ['commit', 'tree']);
103});
105test('objectsFor: a listed pack carries exactly the named objects, with no walk', async () => {
106 const s = SCENARIOS.find(x => x.id === 'pack.push-malformed-object-refused#tag-type-mismatch');
107 assert.ok(s);
108 const built = await buildSeed(s.seed);
109 assert.ok(built.ok);
110 const step = s.steps[0];
111 assert.equal(step.tag, 'push');
112 if (step.tag !== 'push') return;
113 assert.equal(step.push.pack.tag, 'listed');
114 const objs = objectsFor(built.value, step.push, []);
115 assert.ok(objs.ok);
116 assert.deepEqual(objs.value.map(o => o.type), ['tag']);
117});
Diagnostics4 git calls · 286 ms
CallStatusSizeTime0286 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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 · 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 1020040 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=41349 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=526b305930b8ef382f2d7a1f9c0238730a585921 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=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2002.4 KiB280 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=280 git.response.bytes=2424 git.response.cache=MISS git.response.duration_ms=280 git.fetch.wants=2bf6214ae0dab3fdaf43eeff7198422c4cede8ae 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=2424 git.pkt.payload.max=2403 git.sideband.band1.bytes=2402 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-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e30f26c8d78a31
- Request
- 94a45ed9…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format