main
ply4 git calls348 ms42 KiB2 cachedprotocol v2
54 lines3.9 KiBRaw
1// Whole-response caching of commit-pinned reads (src/pinned.ts): which URLs get a key, that the key is canonical, and
2// that Pinned only accepts keys it would issue.
3import { test } from 'node:test';
4import assert from 'node:assert/strict';
5import { CACHE_VERSION } from '../src/cache-version.ts';
6import { IMMUTABLE, asPinned, isInternal, pinnedViewKey, requestForKey } from '../src/pinned.ts';
7import { PUBLIC_GIT_HOST, PUBLIC_GIT_ORIGIN } from '../src/public.ts';
9const OID = 'c2ccba2c554e8a18ac438cfbc53725d4b593811b';
10const REMOTE = `${PUBLIC_GIT_ORIGIN}/git/public-v0/ply.git`;
11const u = (s: string) => new URL(s, 'https://ply.ivar.workers.dev');
12const q = (o: Record<string, string>) => new URLSearchParams(o).toString();
13const anyPublic = () => true;
15/** Null and a missing value take the fallback. An empty string and 0 stay. */
16function fill<T>(value: unknown, fallback: T): T {
17 return value === null || value === void 0 ? fallback : value as T;
20test('pinnedViewKey: raw files at a pinned commit on a public repo only', () => {
21 const view = `/view/${PUBLIC_GIT_HOST}/git/public-v0/ply.git`;
22 assert.match(fill(pinnedViewKey(u(`${view}?raw=1&ref=${OID}&path=README.md`), 'GET', anyPublic), ''), new RegExp(`^/v${CACHE_VERSION}/pinned/view/`));
23 assert.ok(pinnedViewKey(u(`${view}?raw=1&at=${OID}&path=README.md`), 'HEAD', anyPublic));
24 assert.match(fill(pinnedViewKey(u(`/r/ply?raw=1&ref=${OID}&path=README.md`), 'GET', anyPublic), ''), new RegExp(`^/v${CACHE_VERSION}/pinned/r/ply\\?`));
25 assert.equal(pinnedViewKey(u(`/r/ply?ref=${OID}&path=README.md`), 'GET', anyPublic), null, 'html is not pinned');
26 assert.equal(pinnedViewKey(u(`/r/not a name?raw=1&ref=${OID}&path=README.md`), 'GET', anyPublic), null);
27 for (const s of [`${view}?ref=${OID}&path=README.md`, `${view}?raw=1&ref=main&path=README.md`, `${view}?raw=1&ref=${OID}`, `${view}?raw=1&ref=${OID}&path=a&x=1`, `${view}?raw=1&ref=${OID}&at=${'b'.repeat(40)}&path=a`]) {
28 assert.equal(pinnedViewKey(u(s), 'GET', anyPublic), null, s);
29 }
30 assert.equal(pinnedViewKey(u(`${view}?raw=1&ref=${OID}&path=README.md`), 'GET', () => false), null, 'not a public location');
31});
33test('requestForKey: Pinned accepts only canonical keys it would issue, and marks the request internal', () => {
34 const k = pinnedViewKey(u(`/r/ply?${q({ raw: '1', ref: OID, path: 'src/a.js' })}`), 'GET', anyPublic) as string;
35 const r = requestForKey(k, anyPublic);
36 assert.ok(r);
37 assert.equal(isInternal(r as Request), true);
38 assert.equal(new URL((r as Request).url).pathname, '/r/ply');
39 assert.equal([...(r as Request).headers].length, 0, 'no header, so no credential, reaches the handler');
40 assert.equal(isInternal(new Request((r as Request).url)), false, 'a copy is not internal');
41 // /v1 is never cached whole (every /v1 response is no-store): a /v1 key, even a canonical full-oid public one, is refused
42 const v1 = (path: string) => `/v${CACHE_VERSION}/pinned${path}?${q({ remote: REMOTE, ref: OID, path: 'src' })}`;
43 for (const bad of [k.replace(`/v${CACHE_VERSION}/`, `/v${CACHE_VERSION + 1}/`), k + '&x=1', `/v${CACHE_VERSION}/pinned/r/ply?path=src/a.js&raw=1&ref=${OID}`, v1('/v1/tree'), v1('/v1/read'), v1('/v1/commit'), `/v${CACHE_VERSION}/pinned/v1/refs?${q({ remote: REMOTE })}`, '/v1/tree']) {
44 assert.equal(requestForKey(bad, anyPublic), null, bad);
45 }
46});
48test('asPinned: a 200 is immutable without the fill\'s per-request headers; anything else is no-store', () => {
49 const ok = asPinned(new Response('x', { status: 200, headers: { 'x-ply-request-id': 'r', 'x-ply-trace': 't', 'server-timing': 's', 'x-artifacts-ray': 'ls-refs=-;dur=1', 'content-type': 'text/plain' } }));
50 assert.equal(ok.headers.get('cache-control'), IMMUTABLE);
51 for (const h of ['x-ply-request-id', 'x-ply-trace', 'server-timing', 'x-artifacts-ray']) assert.equal(ok.headers.get(h), null);
52 assert.equal(ok.headers.get('content-type'), 'text/plain');
53 assert.equal(asPinned(new Response('no', { status: 404 })).headers.get('cache-control'), 'no-store');
54});
Diagnostics4 git calls · 348 ms
CallStatusSizeTime0348 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=2
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
fetch2001.5 KiB337 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=337
git.response.bytes=1574
git.response.cache=MISS
git.response.duration_ms=337
git.fetch.wants=7245fcb225e2fa07c42c0db76dacfacbdfa6c78a
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=1574
git.pkt.payload.max=1553
git.sideband.band1.bytes=1552
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
a5e2fbc26dcacf81
Request
2271b7ce…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format