main
ply4 git calls373 ms45 KiB2 cachedprotocol v2
181 lines12 KiBRaw
1// The probe workbench (src/bench): its parsers and pages, and whole runs of ply's scenarios through the Worker's run
2// path against git http-backend standing in for Artifacts (test/bench-harness.ts). Every runnable scenario but the
3// 10-20 s stalls runs here and must meet its stated expectation with its cleanup proven; a server that lies about a
4// push is classified server_bug with the exchange and cf-ray that show it; an export carries no credential.
5import { test, before, after } from 'node:test'
6import assert from 'node:assert/strict'
7import { Tracer } from 'ply'
8import { SCENARIOS } from 'ply/probes'
9import { presentedSecret } from '../src/bench/auth.ts'
10import { mintRunId, parseRunSeed, repoNameFor, type RunSeed } from '../src/bench/brand.ts'
11import { CATALOGUE } from '../src/bench/catalogue.ts'
12import { replayJson, replayTest } from '../src/bench/export.ts'
13import { handPack } from '../src/bench/handpack.ts'
14import { benchRoute, replayOf, sameOrigin } from '../src/bench/http.ts'
15import { createRecorder } from '../src/bench/recorder.ts'
16import { runPage, indexPage } from '../src/bench/render.ts'
17import { runLive, type RunResult } from '../src/bench/run.ts'
18import { buildSeed } from '../src/bench/seed.ts'
19import type { StoredRun } from '../src/bench/store.ts'
20import { verdictOf } from '../src/bench/verdict.ts'
21import { waterfall } from '../src/bench/waterfall.ts'
22import { readReceiveRequest } from '../src/bench/wire.ts'
23import { startHarness, type Harness } from './bench-harness.ts'
25const seedOf = (s: string): RunSeed => { const r = parseRunSeed(s); if (!r.ok) throw new Error(r.error); return r.value }
26const SEED = seedOf('t1')
27const SLOW = new Set(['interrupted.stall-timeouts#push-request-stall', 'interrupted.stall-timeouts#push-request-stall-10s', 'interrupted.stall-timeouts#fetch-request-stall'])
29let h: Harness
30before(async () => { h = await startHarness() })
31after(async () => { await h.close() })
33async function runOne(id: string, upstream: typeof fetch = h.upstream): Promise<{ readonly result: RunResult; readonly stored: StoredRun }> {
34 const entry = CATALOGUE.find(e => e.scenario.id === id)
35 assert.ok(typeof entry === 'object', id)
36 const run = mintRunId()
37 const repo = repoNameFor(SEED, run)
38 const t0 = Date.now()
39 const result = await runLive({ repos: h.repos, upstream, tracer: new Tracer(), parent: null, keepBodies: () => {}, created: async () => {} }, entry.scenario, SEED, repo)
40 return { result, stored: { id: run, scenario: id, seed: SEED, repo, startedAt: t0, finishedAt: Date.now(), ply: 'test', result, spans: [] } }
43test('auth: Bearer, or Basic with the token as the password; nothing else', () => {
44 assert.deepEqual(presentedSecret('Bearer abc'), { tag: 'secret', value: 'abc' })
45 assert.deepEqual(presentedSecret(`Basic ${btoa('ivar:s3cret')}`), { tag: 'secret', value: 's3cret' })
46 assert.deepEqual(presentedSecret(`Basic ${btoa('ivar:')}`), { tag: 'none' })
47 assert.deepEqual(presentedSecret('Basic !!'), { tag: 'none' })
48 assert.deepEqual(presentedSecret(null), { tag: 'none' })
49})
51test('routes: only the listed paths, run ids are 16 hex', () => {
52 assert.deepEqual(benchRoute('GET', '/bench'), { tag: 'index' })
53 assert.deepEqual(benchRoute('POST', '/bench/runs'), { tag: 'start' })
54 assert.deepEqual(benchRoute('GET', '/bench/runs/0123456789abcdef'), { tag: 'run', id: '0123456789abcdef' })
55 assert.deepEqual(benchRoute('GET', '/bench/runs/0123456789abcdef/exchanges/3/response'), { tag: 'body', id: '0123456789abcdef', i: 3, which: 'response' })
56 assert.deepEqual(benchRoute('GET', '/bench/runs/0123456789abcdef/push-x-01234567.test.js'), { tag: 'export', id: '0123456789abcdef', file: 'test' })
57 assert.equal(benchRoute('GET', '/bench/runs/../etc'), null)
58 assert.equal(benchRoute('DELETE', '/bench/runs/0123456789abcdef'), null)
59 const post = (h2: Record<string, string>): Request => new Request('https://ply.example/bench/runs', { method: 'POST', headers: h2 })
60 assert.equal(sameOrigin(post({ 'sec-fetch-site': 'same-origin' })), true)
61 assert.equal(sameOrigin(post({ 'sec-fetch-site': 'cross-site' })), false)
62 assert.equal(sameOrigin(post({ origin: 'https://evil.example' })), false)
63 assert.equal(sameOrigin(post({})), false)
64})
66test('recorder: cf-ray, status, timings and bytes per exchange; the credential never kept', async () => {
67 const token = 'art_v1_secretsecret'
68 const rec = createRecorder({
69 upstream: async () => new Response('001e# service=git-upload-pack\n0000', { status: 200, headers: { 'cf-ray': '0123456789abcdef-SJC', 'x-echo': `Bearer ${token}` } }),
70 now: () => 0, scrub: s => s.split(token).join('[token]'), tracer: new Tracer(), keepBodies: () => {},
71 })
72 const res = await rec.fetchFor('main')(`https://h.example/git/ns/r.git/info/refs?service=git-upload-pack`, { headers: { authorization: `Bearer ${token}`, 'git-protocol': 'version=2' } })
73 assert.equal(res.status, 200)
74 const [x] = rec.exchanges
75 assert.ok(typeof x === 'object')
76 assert.equal(x.kind, 'advertise-upload')
77 assert.deepEqual(x.cfRay, { kind: 'id', id: '0123456789abcdef-SJC' })
78 assert.ok(!JSON.stringify(rec.exchanges).includes(token), 'no token in the record')
79 assert.ok(!x.requestHeaders.some(([k]) => k === 'authorization'))
80})
82test('hand packs: the damage each plan names', async () => {
83 const s = SCENARIOS.find(x => x.id === 'pack.push-corrupt-pack-refused#bad-trailer')
84 assert.ok(typeof s === 'object')
85 const built = await buildSeed(s.seed)
86 assert.ok(built.ok)
87 const st = s.steps[0]
88 assert.ok(st.tag === 'push' && st.push.pack.tag === 'hand')
89 const p = await handPack(built.value, [...built.value.objects.values()].slice(0, 2), st.push.pack)
90 assert.ok(p.ok)
91 assert.deepEqual([...p.value.subarray(0, 4)], [0x50, 0x41, 0x43, 0x4b])
92})
94for (const e of CATALOGUE.filter(x => x.support.tag === 'runnable' && !SLOW.has(x.scenario.id))) {
95 test(`run ${e.scenario.id} against the stand-in: meets the expectation, every exchange has a ray, cleanup proven`, async () => {
96 const { result } = await runOne(e.scenario.id)
97 assert.equal(result.verdict.tag, 'pass', JSON.stringify(result.verdict).slice(0, 600))
98 assert.ok(result.exchanges.length > 0)
99 for (const x of result.exchanges) assert.ok(x.answer.tag === 'no-response' || x.cfRay.kind === 'id', `#${x.i} has a cf-ray`)
100 const c = result.cleanup
101 assert.ok(c.tokensListed >= 1 && c.tokensRevoked === c.tokensListed, 'every token revoked')
102 assert.equal(c.revokedStatus, 403)
103 assert.ok(c.refused && c.deleted && c.gone, JSON.stringify(c))
104 })
107test('a server that reports ok and does not apply the push is a server_bug, with the exchange and its ray', async () => {
108 const pkt = (s: string | Uint8Array): Uint8Array<ArrayBuffer> => { const b = typeof s === 'string' ? new TextEncoder().encode(s) : s; const out = new Uint8Array(b.length + 4); out.set(new TextEncoder().encode((b.length + 4).toString(16).padStart(4, '0'))); out.set(b, 4); return out }
109 const cat = (...p: Uint8Array[]): Uint8Array<ArrayBuffer> => { const o = new Uint8Array(p.reduce((n, x) => n + x.length, 0)); let a = 0; for (const x of p) { o.set(x, a); a += x.length } return o }
110 let lied = 0
111 const liar: typeof fetch = async (input, init) => {
112 const req = new Request(input, init)
113 if (req.method === 'POST' && req.url.endsWith('/git-receive-pack') && lied === 0) {
114 const body = new Uint8Array(await req.arrayBuffer())
115 const cmds = readReceiveRequest(body).commands
116 if (cmds.length > 0 && cmds.every(c => c.ref === 'refs/heads/new')) {
117 lied++
118 const report = cat(pkt('unpack ok\n'), ...cmds.map(c => pkt(`ok ${c.ref}\n`)), new TextEncoder().encode('0000'))
119 const banded = cat(pkt(cat(Uint8Array.of(1), report)), new TextEncoder().encode('0000'))
120 return new Response(banded, { status: 200, headers: { 'content-type': 'application/x-git-receive-pack-result', 'cf-ray': 'feedfacefeedface-SJC' } })
121 }
122 return h.upstream(req.url, { method: 'POST', headers: req.headers, body })
123 }
124 return h.upstream(req)
125 }
126 const { result, stored } = await runOne('push.create-ref#plain', liar)
127 assert.equal(lied, 1)
128 assert.equal(result.verdict.tag, 'fail')
129 const v = result.verdict
130 assert.ok(v.tag === 'fail')
131 const bug = v.failures.find(f => f.tag === 'server_bug')
132 assert.ok(typeof bug === 'object', JSON.stringify(v.failures.map(f => [f.tag, f.difference.field])))
133 assert.ok(bug.evidence.some(x => x.cfRay === 'feedfacefeedface-SJC'))
134 assert.ok(result.cleanup.gone)
135 // the export: the plan verbatim, the observation, the differences; no credential, no URL of the server
136 const replay = replayOf(stored)
137 assert.ok(replay !== null)
138 const json = replayJson(replay)
139 const file = replayTest(replay)
140 const leak = /art_v1_|Bearer|127\.0\.0\.1:|server_bug|client_bug/.exec(json + file)
141 assert.equal(leak, null, String(leak && (json + file).slice(Math.max(0, leak.index - 80), leak.index + 40)))
142 assert.equal(JSON.parse(json).differences.length, v.failures.length)
143 // the run page and the waterfall render, escaped, with a row per exchange
144 const page = runPage(stored, replay.scenario).text
145 assert.ok(page.includes('server_bug') && page.includes('feedfacefeedface-SJC'))
146 assert.equal((waterfall(result.exchanges).text.match(/class="wf-row/g) || []).length, result.exchanges.length)
147 assert.ok(!page.includes('<script'))
148})
150test('client_bug: ply concluding landed when the report on the same exchange says ng', () => {
151 const s = SCENARIOS.find(x => x.id === 'push.create-ref#plain')
152 assert.ok(typeof s === 'object')
153 const obs = { steps: [{ outcomes: [{ outcome: 'landed' as const, error: null, detail: '' }] as const }], end: { head: 'refs/heads/main', refs: {}, objects: [], trees: {}, ancestry: [], mergeBases: {}, fsck: [] } }
154 const x = {
155 i: 4, phase: { tag: 'step' as const, index: 0 }, channel: 'main' as const, method: 'POST', path: '/r.git/git-receive-pack', kind: 'receive-pack' as const, answer: { tag: 'http' as const, status: 200 },
156 startMs: 0, headersMs: 1, endMs: 2, requestBytes: 1, responseBytes: 1, cfRay: { kind: 'missing' as const }, requestHeaders: [], responseHeaders: [], applied: null,
157 wire: { tag: 'receive-pack' as const, request: { commands: [], capabilities: [], shallow: [], packBytes: 0 }, report: { tag: 'report' as const, unpack: { tag: 'ok' as const }, refs: [{ tag: 'ng' as const, ref: 'refs/heads/topic', reason: 'denied' }], sideband: null } },
158 }
159 const v = verdictOf(s, obs, {}, [x])
160 assert.ok(v.tag === 'fail')
161 assert.ok(v.failures.some(f => f.tag === 'client_bug' && f.evidence.some(e => e.exchange === 4)), JSON.stringify(v.failures.map(f => f.tag)))
162})
164test('index page: every catalogue scenario listed, the runnable ones offered', () => {
165 const text = indexPage(CATALOGUE, [], { created: 0, cleaned: 0, lastHour: 0 }, 'test', null).text
166 for (const e of CATALOGUE) assert.ok(text.includes(e.scenario.id), e.scenario.id)
167 assert.equal((text.match(/<option /g) || []).length, CATALOGUE.filter(e => e.support.tag === 'runnable').length)
168})
170test('either: a git-version-dependent step is met by any listed pair, and a landed step is named without a single expected pair', () => {
171 const s = SCENARIOS.find(x => x.id === 'refs.directory-file-conflict#file-then-dir')
172 assert.ok(typeof s === 'object')
173 const end = { head: 'refs/heads/main', refs: {}, objects: [], trees: {}, ancestry: [], mergeBases: {}, fsck: [] }
174 const at = (outcome: 'conflict' | 'rejected' | 'landed', error: 'cas_conflict' | 'push_rejected' | null) => ({ steps: [{ outcomes: [{ outcome, error, detail: '' }] as const }], end })
175 const stepFailures = (v: ReturnType<typeof verdictOf>) => v.tag === 'fail' ? v.failures.filter(f => f.difference.field === 'outcome' || f.difference.field === 'error') : []
176 assert.deepEqual(stepFailures(verdictOf(s, at('conflict', 'cas_conflict'), {}, [])), [])
177 assert.deepEqual(stepFailures(verdictOf(s, at('rejected', 'push_rejected'), {}, [])), [])
178 const landed = stepFailures(verdictOf(s, at('landed', null), {}, []))
179 assert.ok(landed.length > 0)
180 assert.ok(landed.every(f => f.step !== null && f.step.index === 0 && f.step.outcome === 'landed' && f.step.expected === null), JSON.stringify(landed.map(f => f.step)))
181})
Diagnostics4 git calls · 373 ms
CallStatusSizeTime0373 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 · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=4
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 · hit7 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=7
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=61
Open pack map
fetch2004.3 KiB362 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=362
git.response.bytes=4376
git.response.cache=MISS
git.response.duration_ms=362
git.fetch.wants=3ab98523e77a6475bf352b17dd854e38b450c8f9
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=4376
git.pkt.payload.max=4355
git.sideband.band1.bytes=4354
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
a5e2d2ae9bcfcf3a
Request
696a30a8…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format