main
1// Shared wire helpers for the framing and pack spaces: a real http transport (src/http.js createTransport) over a fake
2// fetch that answers with exactly the bytes a cell renders, so every cell goes through ply's own pkt-line reader
3// (pktStep/pktFinish in the transport), its own consumers and its own error typing. No network, no server process.
4import { createTransport as createTransportR } from '../../src/http.js';
5import { Tracer } from '../../src/otel.js';
6import { withLimits } from '../../src/limits.js';
7import { isPlyCode } from '../../src/errors.js';
9import { unwrap } from '../unwrap.js';
10// Throwing adapters over the Result API (0.2.0): the assertions below are about the throw.
11const createTransport = (...a) => unwrap(createTransportR(...a));
12const te = new TextEncoder();
13export const enc = s => (typeof s === 'string' ? te.encode(s) : s);
14export const cat = parts => { let n = 0; for (const p of parts) n += p.length; const o = new Uint8Array(n); let i = 0; for (const p of parts) { o.set(p, i); i += p.length; } return o; };
15// A pkt-line exactly as git's writer frames it (4 lower-case hex digits, inclusive length). No bound: cells build
16// over-long frames on purpose.
17export const frame = payload => { const p = enc(payload); return cat([te.encode((p.length + 4).toString(16).padStart(4, '0')), p]); };
18export const FLUSH = te.encode('0000'), DELIM = te.encode('0001'), END = te.encode('0002');
19export const band = (b, body) => frame(cat([Uint8Array.of(b), enc(body)]));
21// responder(kind, service, body) -> { status?, contentType?, bytes } | undefined (404)
22export function fakeFetch(responder) {
23 return async (url, init = {}) => {
24 const u = new URL(url);
25 const adv = u.pathname.endsWith('/info/refs');
26 const service = adv ? u.searchParams.get('service') : u.pathname.split('/').pop();
27 const r = await responder(adv ? 'advertise' : 'post', service, init.body ?? null);
28 if (!r) return new Response('not found', { status: 404 });
29 const ct = r.contentType ?? `application/x-${service}-${adv ? 'advertisement' : 'result'}`;
30 return new Response(r.bytes, { status: r.status ?? 200, headers: { 'content-type': ct } });
31 };
32}
34// Each fake is its own server at one URL: its own quirks record, not the remote's remembered one (#136), so a test that
35// sets treeFilter on one transport does not change the next.
36export function transport(responder, limits = {}, extra = {}) {
37 return createTransport('https://git.example/repo.git', { tracer: new Tracer(), fetchImpl: fakeFetch(responder), limits: withLimits(limits), quirks: {}, ...extra });
38}
40// The outcome of an operation as a tagged union. `typed` holds only an error ply built with fail() (a code from its
41// table, the plain Error class): a TypeError or RangeError that `coded()` stamped with a code is `untyped`, a bug.
42export async function outcome(fn) {
43 try { return { tag: 'ok', value: await fn() }; } catch (e) {
44 if (!(e instanceof Error) || e.constructor !== Error || !isPlyCode(e.code)) return { tag: 'untyped', code: e?.code, name: e?.constructor?.name, message: String(e?.message ?? e) };
45 return { tag: 'typed', code: e.code, message: e.message };
46 }
47}
48export function outcomeSync(fn) {
49 try { return { tag: 'ok', value: fn() }; } catch (e) {
50 if (!(e instanceof Error) || e.constructor !== Error || !isPlyCode(e.code)) return { tag: 'untyped', code: e?.code, name: e?.constructor?.name, message: String(e?.message ?? e) };
51 return { tag: 'typed', code: e.code, message: e.message };
52 }
53}
55// A v2 fetch response: the given section lines, then `packfile` with the pack in band-1 frames of `chunk` bytes, a flush.
56export function v2PackResponse(pack, { chunk = 8192, before = [] } = {}) {
57 const frames = [...before.map(l => frame(l)), frame('packfile\n')];
58 for (let i = 0; i < pack.length; i += chunk) frames.push(band(1, pack.subarray(i, i + chunk)));
59 if (pack.length === 0) frames.push(band(1, new Uint8Array(0)));
60 frames.push(FLUSH);
61 return cat(frames);
62}
Diagnostics4 git calls · 31 ms
CallStatusSizeTime031 ms
discover200152 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=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 B2 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=UPDATING 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 · hit4 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=38434 git.response.cache=HIT git.response.duration_ms=4 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=55Open pack map
fetch2001.8 KiB · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=1794 git.response.cache=HIT git.response.duration_ms=25 git.fetch.wants=f2d77a92deadcff689cfa8c51180a22107f03e19 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=1794 git.pkt.payload.max=1773 git.sideband.band1.bytes=1772 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
- a5e2ccbdb8407929
- Request
- aa586e1f…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format