main
ply4 git calls326 ms42 KiB2 cachedprotocol v2
70 lines4.0 KiBRaw
1// A stand-in for the Artifacts namespace binding, for the workbench tests: each create is `git init --bare` behind
2// git http-backend (test/server.js) with the policy ply's probe suite gives its reference (test/probes/runner.mjs
3// REFERENCE_POLICY), a write token that the upstream fetch honours until it is revoked (403 after, as Artifacts
4// answers), and a cf-ray on every answer. Nothing leaves 127.0.0.1.
5import { execFileSync } from 'node:child_process'
6import { mkdtempSync, rmSync } from 'node:fs'
7import { tmpdir } from 'node:os'
8import { join } from 'node:path'
9import { startGitServer } from './server.js'
10import type { ProbeRepos } from '../src/bench/run.ts'
12const POLICY: ReadonlyArray<readonly [string, string]> = [
13 ['http.receivepack', 'true'], ['receive.fsckObjects', 'true'], ['transfer.fsckObjects', 'true'],
14 ['uploadpack.allowFilter', 'true'], ['uploadpack.allowReachableSHA1InWant', 'true'], ['uploadpack.allowAnySHA1InWant', 'false'],
15 ['receive.maxInputSize', String(64 * 1024 * 1024)], ['receive.advertiseAtomic', 'true'], ['gc.auto', '0'], ['maintenance.auto', 'false'],
18export type Harness = {
19 readonly repos: ProbeRepos
20 readonly upstream: typeof fetch
21 readonly made: string[]
22 readonly deleted: string[]
23 readonly revoked: string[]
24 readonly close: () => Promise<void>
27export async function startHarness(config: (name: string) => ReadonlyArray<readonly [string, string]> = () => []): Promise<Harness> {
28 const root = mkdtempSync(join(tmpdir(), 'ply-bench-'))
29 const srv = await startGitServer(root)
30 const tokens = new Map<string, { readonly repo: string; active: boolean }>()
31 const made: string[] = []
32 const deleted: string[] = []
33 const revoked: string[] = []
34 let n = 0
35 const repos: ProbeRepos = {
36 async create(name) {
37 const dir = join(root, `${name}.git`)
38 execFileSync('git', ['init', '-q', '--bare', '-b', 'main', dir])
39 for (const [k, v] of [...POLICY, ...config(name)]) execFileSync('git', ['config', k, v], { cwd: dir })
40 const token = `art_v1_${String(n++).padStart(40, '0')}`
41 tokens.set(token, { repo: name, active: true })
42 made.push(name)
43 return { name, remote: `${srv.url}/${name}.git`, token }
44 },
45 async get(name) {
46 if (!made.includes(name) || deleted.includes(name)) throw Object.assign(new Error(`repository ${name}: NOT_FOUND`), { code: 'NOT_FOUND' })
47 return {
48 async listTokens() { return { tokens: [...tokens].filter(([, t]) => t.repo === name).map(([id, t]) => ({ id, state: t.active ? 'active' : 'revoked' })) } },
49 async revokeToken(id: string) { const t = tokens.get(id); if (typeof t !== 'object' || !t.active) return false; t.active = false; revoked.push(id); return true },
50 }
51 },
52 async delete(name) { if (!made.includes(name) || deleted.includes(name)) return false; rmSync(join(root, `${name}.git`), { recursive: true, force: true }); deleted.push(name); return true },
53 }
54 let ray = 0
55 const upstream: typeof fetch = async (input, init) => {
56 const req = new Request(input, init)
57 const auth = String(req.headers.get('authorization'))
58 const t = tokens.get(auth.replace(/^Bearer /, ''))
59 const id = `${(0xabc000 + ray++).toString(16).padStart(16, '0')}-SJC`
60 if (typeof t !== 'object' || !t.active) return new Response('forbidden\n', { status: 403, headers: { 'cf-ray': id } })
61 // A streamed body is read here first: git http-backend's CGI child would wait forever on a body cut halfway (the
62 // recorder's cut-request), keeping this process alive, so a cut body never reaches the stand-in server at all.
63 const body = req.body === null ? null : new Uint8Array(await req.arrayBuffer())
64 const res = await fetch(req.url, { method: req.method, headers: req.headers, body, redirect: 'manual' })
65 const headers = new Headers(res.headers)
66 headers.set('cf-ray', id)
67 return new Response(res.body, { status: res.status, statusText: res.statusText, headers })
68 }
69 return { repos, upstream, made, deleted, revoked, close: async () => { await srv.close(); rmSync(root, { recursive: true, force: true }) } }
Diagnostics4 git calls · 326 ms
CallStatusSizeTime0326 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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=2
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
fetch2001.8 KiB320 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=320
git.response.bytes=1819
git.response.cache=MISS
git.response.duration_ms=320
git.fetch.wants=57eb181de26f24851bb4b7729c368bf0f9d7ea4a
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=1819
git.pkt.payload.max=1798
git.sideband.band1.bytes=1797
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
a5e31a6d5d273e6e
Request
a2c9e39f…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format