GitHubivarvong
ply
main
1// HTTP-level probes (test/probes/wire-plans.ts): every plan against the reference (git http-backend with Artifacts'
2// known policy, asked directly) and, with --artifacts, against a fresh Artifacts repository per plan, by every sender
3// that can send it (raw socket, curl, stock git, ply). Same rules as scripts/probes.mjs: --artifacts is opt-in and
4// private, ply-loadgen only, one repository at a time, results to <private dir>/wire-<run-id>.json outside this
5// repository, every token revoked and proven dead, every repository deleted and checked by listing.
6//
7// node --import ./test/ts-resolve.mjs scripts/wire-probes.mjs [--only <substring>[,...]]
8// PLY_PROBES_CF=<cf binary> PLY_PROBES_CF_CWD=<dir> \
9// node --import ./test/ts-resolve.mjs scripts/wire-probes.mjs --artifacts --out <private dir> [--only ...]
10import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
11import { createHash } from 'node:crypto';
12import { join, resolve, relative } from 'node:path';
13import { execFileSync } from 'node:child_process';
14import { fileURLToPath } from 'node:url';
15import { WIRE, WIRE_ALLOW, cornersOf, onReference } from '../test/probes/wire-plans.ts';
16import { REFERENCE_POLICY, gitEnv, newTracer, run } from '../test/probes/runner.mjs';
17import { startGitServer } from '../test/server.js';
18import { WIRE_REFERENCE_CONFIG, referenceAuth, runWirePlan, seedOf, tempRoot, v2Caps, wireDiffs, wireSeed } from '../test/probes/wire.mjs';
20const ROOT = fileURLToPath(new URL('..', import.meta.url));
21const arg = name => { const i = process.argv.indexOf(name); return i < 0 ? null : process.argv[i + 1] ?? null; };
22const artifacts = process.argv.includes('--artifacts');
23const only = arg('--only');
24const outDir = arg('--out');
25if (artifacts && (outDir === null || !relative(ROOT, resolve(outDir)).startsWith('..'))) { console.error('--artifacts needs --out <dir> outside this repository (results are private)'); process.exit(2); }
26const stamp = new Date().toISOString().replace(/[-:]/g, '').toLowerCase().slice(0, 13);
27const runId = arg('--run-id') ?? `${stamp}-${Math.random().toString(36).slice(2, 6)}`;
28const plyCommit = (() => { try { return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, encoding: 'utf8' }).trim(); } catch { return null; } })();
29const SOURCES = ['test/probes/wire-plans.ts', 'test/probes/wire.mjs', 'test/probes/artifacts.mjs', 'test/probes/runner.mjs', 'scripts/wire-probes.mjs'];
30const sourceHash = createHash('sha256').update(Buffer.concat(SOURCES.map(f => readFileSync(join(ROOT, f))))).digest('hex').slice(0, 16);
31const versions = { git: execFileSync('git', ['--version'], { encoding: 'utf8' }).trim(), curl: execFileSync('curl', ['--version'], { encoding: 'utf8' }).split('\n')[0], node: process.version };
33const audit = [];
34let art = null, scrub = s => String(s);
35if (artifacts) {
36 const bin = process.env.PLY_PROBES_CF, cwd = process.env.PLY_PROBES_CF_CWD;
37 if (!bin || !cwd) { console.error('--artifacts needs PLY_PROBES_CF (the cf CLI) and PLY_PROBES_CF_CWD'); process.exit(2); }
38 const env = { ...process.env }; delete env.CLOUDFLARE_API_TOKEN;
39 const mod = await import('../test/probes/artifacts.mjs');
40 scrub = mod.scrub;
41 art = mod.artifactsTarget({ cli: { bin, cwd, env }, runId: `w${runId}`, log: r => audit.push(r) });
42}
44const plans = WIRE.filter(p => only === null || only.split(',').some(o => p.id.includes(o)));
45const root = tempRoot();
46mkdirSync(join(root, 'repos'));
47const srv = await startGitServer(join(root, 'repos'));
48const ws = await wireSeed(root);
49let n = 0;
50async function referenceRepo(plan) {
51 const name = `w${n++}`;
52 const dir = join(root, 'repos', `${name}.git`);
53 const env = gitEnv(root);
54 await run('git', ['init', '-q', '--bare', '-b', 'main', dir], { env });
55 for (const [k, v] of [...REFERENCE_POLICY, ...WIRE_REFERENCE_CONFIG]) await run('git', ['config', k, v], { cwd: dir, env });
56 const url = `${srv.url}/${name}.git`;
57 const p = await run('git', ['push', '-q', url, ...(await seedOf(plan, ws)).specs], { cwd: ws.dir, env: ws.env });
58 if (p.status !== 0) throw new Error(`reference seed: ${p.stderr.trim().slice(0, 200)}`);
59 return url;
60}
62let open = null, closing = null;
63for (const sig of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.once(sig, async () => {
64 console.error(`${sig}: closing the open repository`);
65 if (open !== null) { const h = await open.catch(() => null); if (h !== null) await h.close(); }
66 if (closing !== null) await closing.catch(() => {});
67 process.exit(130);
68});
70const records = [], diffs = [], errors = [], used = new Set();
71const t0 = Date.now();
72for (const plan of plans) {
73 const byTarget = {};
74 const record = { id: plan.id, expect: plan.expect, targets: {} };
75 for (const t of artifacts ? ['ref', 'art'] : ['ref']) {
76 if (t === 'ref' && !onReference(plan)) continue;
77 const { tracer } = newTracer();
78 let handle = null;
79 const started = Date.now();
80 try {
81 let target;
82 if (t === 'art') {
83 open = art.open(`wire ${plan.id}`); handle = await open;
84 const side = `${handle.proxy.url}/side${handle.repoPath}`;
85 const p = await run('git', ['push', '-q', side, ...(await seedOf(plan, ws)).specs], { cwd: ws.dir, env: ws.env });
86 if (p.status !== 0) throw new Error(`artifacts seed: ${p.stderr.trim().slice(0, 200)}`);
87 target = { name: 'art', url: handle.wireAuth.url('write'), judgeUrl: `${handle.proxy.url}/judge${handle.repoPath}`, auth: handle.wireAuth };
88 } else { const url = await referenceRepo(plan); target = { name: 'ref', url, judgeUrl: url, auth: referenceAuth(url) }; }
89 const unrunnable = plan.request.tag === 'credential' && plan.request.credential === 'revoked' && !target.auth.hasRevoked();
90 const corners = unrunnable ? [] : cornersOf(plan);
91 const capsR = await v2Caps(target.url, target.auth);
92 const r = await runWirePlan(plan, corners, target, ws, { root, tracer, caps: capsR.caps });
93 for (const x of r.results) {
94 const a = WIRE_ALLOW.find(e => e.plan === plan.id && e.target === t && e.corner === x.corner);
95 if (a !== undefined && !x.meets && x.cls === a.cls) { used.add(a); x.allowed = a.reason; }
96 }
97 byTarget[t] = r;
98 record.targets[t] = { ms: Date.now() - started, repo: handle?.name ?? target.url, caps: capsR.caps, capsRay: capsR.ray, ...r, judgeExchanges: handle === null ? [] : handle.proxy.exchanges };
99 } catch (e) {
100 errors.push({ plan: plan.id, target: t, error: scrub(e?.message ?? e) });
101 record.targets[t] = { ms: Date.now() - started, error: scrub(e?.message ?? e) };
102 } finally {
103 open = null;
104 if (handle !== null) { closing = handle.close(); await closing; closing = null; }
105 }
106 const st = record.targets[t];
107 console.log(`${plan.id.padEnd(60)} ${t} ${String(st.ms).padStart(6)} ms ${st.error ? `ERROR ${st.error}` : st.results.map(x => `${x.corner}:${x.meets ? 'ok' : x.allowed ? 'allowed' : 'MISS'}(${x.cls.slice(0, 40)})`).join(' ')}`);
108 }
109 diffs.push(...wireDiffs(plan.id, byTarget).filter(d => !(d.field === 'meets' && Object.values(byTarget).flatMap(b => b.results).some(x => x.allowed))));
110 records.push(record);
111}
112await srv.close();
113rmSync(root, { recursive: true, force: true });
115const misses = records.flatMap(r => Object.entries(r.targets).flatMap(([t, v]) => (v.results ?? []).filter(x => !x.meets && !x.allowed).map(x => ({ plan: r.id, target: t, corner: x.corner, cls: x.cls, rays: x.rays }))));
116const ran = new Set(records.flatMap(r => Object.entries(r.targets).flatMap(([t, v]) => (v.results ?? []).map(x => `${r.id}|${t}|${x.corner}`))));
117const unused = WIRE_ALLOW.filter(a => ran.has(`${a.plan}|${a.target}|${a.corner}`) && !used.has(a));
118const tokensOk = art === null || art.tokens.every(t => t.revoked && (t.label === 'leftover' || t.probe === 403));
119const reposOk = art === null || art.repos.every(r => r.deleted && r.listedAfter === false);
120console.log(`\n${plans.length} plans in ${((Date.now() - t0) / 1000).toFixed(0)} s; ${misses.length} results off their answer; ${diffs.length} differences; ${unused.length} unused allow entries; ${errors.length} run errors`);
121for (const m of misses) console.log(` MISS ${m.plan} ${m.target}-${m.corner}: ${m.cls.slice(0, 140)}`);
122for (const d of diffs) console.log(` DIFF ${d.plan} ${d.pair} ${d.field}${d.minor ? ' (minor)' : ''}: ${String(d.left).slice(0, 120)} vs ${String(d.right).slice(0, 120)}`);
123for (const a of unused) console.log(` UNUSED allow entry ${a.plan} ${a.target} ${a.corner}`);
124for (const e of errors) console.log(` ERROR ${e.plan} ${e.target}: ${e.error}`);
125if (art !== null) console.log(`tokens: ${art.tokens.length} minted (auto ${art.tokens.filter(t => t.label.startsWith('auto')).length}), revoked ${art.tokens.filter(t => t.revoked).length}, proven 403 ${art.tokens.filter(t => t.probe === 403).length}; repos: ${art.repos.length} created, ${art.repos.filter(r => r.deleted).length} deleted, ${art.repos.filter(r => r.listedAfter === false).length} confirmed gone`);
126if (outDir !== null) {
127 mkdirSync(outDir, { recursive: true });
128 const checks = artifacts ? plans.flatMap(p => cornersOf(p).map(c => `${p.id}/art-${c}`)) : [];
129 const out = { runId: `wire-${runId}`, startedAt: new Date(t0).toISOString(), plyCommit, sourceHash, versions, checks, misses, differences: diffs, unused, errors, tokens: art?.tokens ?? [], repos: art?.repos ?? [], controlPlane: audit, plans: records };
130 const file = join(outDir, `wire-${runId}.json`);
131 writeFileSync(file, scrub(JSON.stringify(out, null, 1)), { mode: 0o600 });
132 console.log(`results: ${file}`);
133}
134process.exit(unused.length || errors.length || !tokensOk || !reposOk ? 1 : 0);
Diagnostics6 git calls · 109 ms
CallStatusSizeTime0109 ms
discover200191 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=191 git.server.agent=git/github-9922ec520325-Linux git.server.object_format=sha1 git.server.caps=agent ls-refs fetch server-option object-format git.server.fetch=shallow wait-for-done filter git.protocol.version=2 git.pkt.frames=9 git.pkt.data=7 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=191 git.pkt.payload.max=36
ls-refs20012 KiB · 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=11990 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=152 git.pkt.data=151 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=11990 git.pkt.payload.max=122 git.ls_refs.count=151 git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 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=4347 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 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=7 git.pkt.data=5 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=4347 git.pkt.payload.max=4247 git.sideband.band1.bytes=4247 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=10 git.pack.bytes=4247 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400 git.pack.full=10Open pack map
fetchtree:0200919 B · 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=919 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=919 git.pkt.payload.max=892 git.sideband.band1.bytes=892 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=892 git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:0200831 B · 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=831 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=b9290e370bd091fd3272931655a175dd1a7af82d 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=831 git.pkt.payload.max=804 git.sideband.band1.bytes=804 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=804 git.pack.trailer=81ddc1f73214935b4ee953ad84f959db955ce0d1Open pack map
fetch2003.7 KiB98 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=98 git.response.bytes=3772 git.response.cache=MISS git.response.duration_ms=98 git.fetch.wants=a02cc283d5a468482a5a15a228a511b8f78c2ef5 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=4 git.pkt.data=3 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3772 git.pkt.payload.max=3745 git.sideband.band1.bytes=3745 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://github.com/ivarvong/ply
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e2adfc193fe6b0
- Request
- 17c79de8…
- Protocol
- v2 · sha1
- Agent
- git/github-9922ec520325-Linux
- Filter
- advertised
- Fetch
- shallow wait-for-done filter
- Capabilities
- agent ls-refs fetch server-option object-format