Artifactspublic-v0

ply

main
ply4 git calls443 ms40 KiB2 cachedprotocol v2
124 lines7.7 KiBRaw
1// The exchange clock through the transport, on a fake clock (vitest's timers: setTimeout and Date.now; no real sleeps).
2// Every expectation is worked out by hand from the rules: time is charged only while ply waits on the network; headers
3// seen means the first byte is satisfied for good; upload progress is a piece (at most 64 KiB) taken by the fetch.
4import { test, vi, beforeEach, afterEach } from 'vitest';
5import assert from 'node:assert/strict';
6import { createTransport } from '../src/http.js';
7import { withLimits } from '../src/limits.js';
9const te = new TextEncoder();
10const RESULT = { 'content-type': 'application/x-git-upload-pack-result' };
11const spanOf = () => { const attrs = {}; return { attrs, set: a => Object.assign(attrs, a), event() {}, error() {} }; };
12const T = { firstByteTimeoutMs: 300, idleTimeoutMs: 300 };
13const advance = ms => vi.advanceTimersByTimeAsync(ms);
14// a stream the test feeds by hand
15const manual = () => { let ctl; const stream = new ReadableStream({ start(c) { ctl = c; } }); const quiet = f => { try { f(); } catch { /* the transport cancelled it: the outcome says so */ } };
16 return { stream, push: b => quiet(() => ctl.enqueue(b)), close: () => quiet(() => ctl.close()) }; };
17// the outcome of draining frames, never a rejection: { frames } or { frames, error }
18const drain = async (t, body = new Uint8Array(0), each = async () => {}) => {
19 let frames = 0;
20 try { for await (const _ of t.frames('git-upload-pack', body, spanOf(), { bypassCache: false })) { frames++; await each(frames); } } catch (error) { return { frames, error }; }
21 return { frames };
22};
24beforeEach(() => { vi.useFakeTimers(); });
25afterEach(() => { vi.useRealTimers(); });
27// a server that answers its headers at once (as git http-backend does) while it is still reading the request body
28const earlyHeaders = (response) => (_u, init) => {
29 (async () => { const rd = init.body.getReader(); for (;;) { const r = await rd.read(); if (r.done) break; } })().catch(() => {});
30 init.signal.addEventListener('abort', () => { /* the body read is cut by the transport */ }, { once: true });
31 return Promise.resolve(new Response(response.stream, { status: 200, headers: RESULT }));
32};
34test('an upload that ends after the response headers does not put the clock back into the first-byte wait', async () => {
35 const upload = manual(), response = manual();
36 const t = createTransport('https://h/r', { fetchImpl: earlyHeaders(response), limits: withLimits(T) }).value;
37 const run = drain(t, { stream: upload.stream, length: 2048 });
38 await advance(0);
39 upload.push(new Uint8Array(1024)); await advance(50);
40 upload.push(new Uint8Array(1024)); upload.close(); await advance(50);
41 // 20 frames 100 ms apart: 2000 ms after the upload's end, nearly seven first-byte timeouts, and no gap over 100 ms.
42 // By the rules (headers seen, bytes moving every 100 ms < idle 300) nothing may fire.
43 for (let i = 0; i < 20; i++) { response.push(te.encode('0008abcd')); await advance(100); }
44 response.push(te.encode('0000')); response.close();
45 await advance(0);
46 assert.deepEqual(await run, { frames: 21 });
47});
49test('after such an upload a body that then stalls ends at the idle timeout, named as idle', async () => {
50 const upload = manual(), response = manual();
51 const t = createTransport('https://h/r', { fetchImpl: earlyHeaders(response), limits: withLimits(T) }).value;
52 const run = drain(t, { stream: upload.stream, length: 1024 });
53 await advance(0);
54 upload.push(new Uint8Array(1024)); upload.close(); await advance(50);
55 for (let i = 0; i < 5; i++) { response.push(te.encode('0008abcd')); await advance(100); }
56 // the last frame arrived at 450 ms, taken at once; 100 ms have passed. Silence until 300 ms after it: 200 ms more.
57 await advance(199);
58 const still = await Promise.race([run, Promise.resolve('running')]);
59 assert.equal(still, 'running');
60 await advance(2);
61 const r = await run;
62 assert.deepEqual([r.frames, r.error?.code, r.error?.what], [5, 'timeout', 'idleTimeoutMs']);
63});
65test('a consumer that holds each frame for three idle timeouts gets a complete response and no timeout', async () => {
66 // the whole answer is there at once: three data frames and the flush, one chunk each
67 const whole = () => new ReadableStream({ start(c) { for (const f of ['0008abcd', '0008abcd', '0008abcd', '0000']) c.enqueue(te.encode(f)); c.close(); } });
68 const t = createTransport('https://h/r', { fetchImpl: () => Promise.resolve(new Response(whole(), { status: 200, headers: RESULT })), limits: withLimits(T) }).value;
69 // 900 ms per frame is the consumer's time, not the server's silence: 4 frames, no error
70 assert.deepEqual(await drain(t, new Uint8Array(0), () => advance(900)), { frames: 4 });
71});
73test('a server that stalls while a slow consumer is waiting for the next chunk is still cut, idle counted from the ask', async () => {
74 const response = manual();
75 const t = createTransport('https://h/r', { fetchImpl: () => Promise.resolve(new Response(response.stream, { status: 200, headers: RESULT })), limits: withLimits(T) }).value;
76 response.push(te.encode('0008abcd'));
77 // the consumer holds the one frame 900 ms (three idle timeouts, not charged) and asks again at 900; nothing comes:
78 // the cut is 300 ms after the ask, at 1200, and not a millisecond before
79 const run = drain(t, new Uint8Array(0), () => new Promise(res => setTimeout(res, 900)));
80 await advance(900);
81 await advance(299);
82 assert.equal(await Promise.race([run, Promise.resolve('running')]), 'running');
83 await advance(2);
84 const r = await run;
85 assert.deepEqual([r.frames, r.error?.code, r.error?.what], [1, 'timeout', 'idleTimeoutMs']);
86});
88test('a server that never answers is cut at the first-byte timeout', async () => {
89 const never = (_u, init) => new Promise((_res, reject) => { init.signal.addEventListener('abort', () => reject(init.signal.reason), { once: true }); });
90 const t = createTransport('https://h/r', { fetchImpl: never, limits: withLimits(T) }).value;
91 const run = drain(t);
92 await advance(299);
93 assert.equal(await Promise.race([run, Promise.resolve('running')]), 'running');
94 await advance(2);
95 const r = await run;
96 assert.deepEqual([r.frames, r.error?.code, r.error?.what], [0, 'timeout', 'firstByteTimeoutMs']);
97});
99test('one 4 MiB upload chunk is handed to the fetch in 64 KiB pieces, each a progress mark (a wire with no buffer)', async () => {
100 // A double that takes a piece only when the link has drained the last: it proves the split, not what undici and the
101 // kernel buffer on a real socket (test/upload-progress-socket.test.js).
102 // The link drains 64 KiB every 25 ms and never stops: 4 MiB takes 64 * 25 = 1600 ms, over five idle timeouts, with
103 // no gap in byte movement longer than 25 ms. It must be sent whole and answered.
104 const seen = { bytes: 0 };
105 const slowLink = (_u, init) => new Promise((resolve, reject) => {
106 init.signal.addEventListener('abort', () => reject(init.signal.reason), { once: true });
107 (async () => {
108 const rd = init.body.getReader();
109 for (;;) {
110 const r = await rd.read();
111 if (r.done) break;
112 seen.bytes += r.value.length;
113 await new Promise(res => setTimeout(res, 25 * Math.ceil(r.value.length / 65536)));
114 }
115 resolve(new Response(new ReadableStream({ start(c) { c.enqueue(te.encode('0000')); c.close(); } }), { status: 200, headers: RESULT }));
116 })().catch(reject);
117 });
118 const t = createTransport('https://h/r', { fetchImpl: slowLink, limits: withLimits(T) }).value;
119 const one = new ReadableStream({ start(c) { c.enqueue(new Uint8Array(4 << 20)); c.close(); } });
120 const run = drain(t, { stream: one, length: 4 << 20 });
121 await advance(1700);
122 const r = await run;
123 assert.deepEqual([r.frames, r.error?.what, seen.bytes], [1, undefined, 4 << 20]);
124});
Diagnostics4 git calls · 443 ms
CallStatusSizeTime0443 ms
discover200152 B17 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 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 1020038 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=423
git.response.bytes=38434
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=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=55
Open pack map
fetch2002.6 KiB423 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2619
git.response.cache=MISS
git.response.duration_ms=423
git.fetch.wants=7104b412d3ac628d671fb4bed359cf0b6092ce9f
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=2619
git.pkt.payload.max=2598
git.sideband.band1.bytes=2597
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
a5e35a421a34dfff
Request
691733d5…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format