Artifactspublic-v0

ply

main
ply4 git calls173 ms39 KiB2 cachedprotocol v2
74 lines4.1 KiBRaw
1// The Option constructors a public signature takes (encodeSavedIndex's `resolved`, loadTransferPack's `saved`) are
2// importable from the package root (#301 item 3). `none` is one shared plain object: README says never assign to it; nothing here freezes or checks that.
3// Expected values come from the README contract: `some(value)` is `{ tag: 'some', value }`, `none` is `{ tag: 'none' }`.
4import { test } from 'vitest';
5import assert from 'node:assert/strict';
6import { execFileSync } from 'node:child_process';
7import { mkdirSync, writeFileSync } from 'node:fs';
8import { join } from 'node:path';
9import * as ply from '../src/index.js';
10import { tmpRoot, git } from './server.js';
12const { some, none, isSome, isNone, matchOption, encodeSavedIndex, decodeSavedIndex, scanPackIndex } = ply;
14test('Option constructors and helpers are root exports and behave as README says', () => {
15 for (const name of ['some', 'none', 'isSome', 'isNone', 'matchOption']) assert.ok(name in ply, `root exports ${name}`);
16 const bytes = new Uint8Array([1, 2, 3]);
17 const s = some(bytes);
18 assert.deepEqual(s, { tag: 'some', value: bytes });
19 assert.deepEqual(none, { tag: 'none' });
20 assert.equal(isSome(s), true);
21 assert.equal(isNone(s), false);
22 assert.equal(isSome(none), false);
23 assert.equal(isNone(none), true);
24 const h = { some: v => `some:${v.length}`, none: () => 'none' };
25 assert.deepEqual(matchOption(s, h), { ok: true, value: 'some:3' });
26 assert.deepEqual(matchOption(none, h), { ok: true, value: 'none' });
27});
29// #296 at the root: an argument that is not an Option is no Option. Expected from README "Saved pack index": isSome and
30// isNone answer false, matchOption answers bad_request naming the argument, and a branch that throws is bad_request
31// naming 'matchOption handler' with the thrown value as cause. None of them throws.
32test('the root Option helpers answer a wrong shape as a value, never a throw (#296)', () => {
33 const h = { some: () => 1, none: () => 2 };
34 for (const bad of [null, undefined, 5, 'some', [], {}, { tag: 'other' }]) {
35 assert.equal(isSome(bad), false, String(bad));
36 assert.equal(isNone(bad), false, String(bad));
37 const r = matchOption(bad, h);
38 assert.deepEqual([r.ok, r.error.code, r.error.what], [false, 'bad_request', 'option'], String(bad));
39 }
40 assert.equal(isSome({ tag: 'some', value: 0 }), true);
41 assert.equal(isNone({ tag: 'none' }), true);
42 for (const bad of [null, undefined, 5, [], {}, { some: () => 1 }, { none: () => 2 }, { some: 1, none: () => 2 }, { some: () => 1, none: 'x' }]) {
43 for (const o of [some(1), none]) {
44 const r = matchOption(o, bad);
45 assert.deepEqual([r.ok, r.error.code, r.error.what], [false, 'bad_request', 'handlers'], JSON.stringify(bad));
46 }
47 }
48 const boom = new Error('boom');
49 for (const o of [some(1), none]) {
50 const r = matchOption(o, { some: () => { throw boom; }, none: () => { throw boom; } });
51 assert.deepEqual([r.ok, r.error.code, r.error.what, r.error.cause], [false, 'bad_request', 'matchOption handler', boom]);
52 }
53});
55test('encodeSavedIndex takes the root none, and decodeSavedIndex gives none back for an unresolved index', async () => {
56 const { root, cleanup } = tmpRoot();
57 const repo = join(root, 'r');
58 mkdirSync(repo, { recursive: true });
59 git(repo, ['init', '-q']);
60 writeFileSync(join(repo, 'a.txt'), 'hello\n');
61 git(repo, ['add', '.']);
62 git(repo, ['-c', 'user.name=A', '-c', 'user.email=a@x', 'commit', '-qm', 'one']);
63 const pack = new Uint8Array(execFileSync('git', ['-C', repo, 'pack-objects', '--stdout', '--revs'], { input: 'HEAD\n' }));
64 const scanned = await scanPackIndex(new ReadableStream({ start(c) { c.enqueue(pack); c.close(); } }));
65 assert.ok(scanned.ok);
66 const enc = encodeSavedIndex(scanned.value, none);
67 assert.ok(enc.ok);
68 const trailer = Buffer.from(pack.subarray(pack.length - 20)).toString('hex');
69 const dec = decodeSavedIndex(enc.value, { trailer, bytes: pack.length });
70 assert.ok(dec.ok);
71 assert.equal(isNone(dec.value.resolved), true);
72 assert.equal(dec.value.pack.count, 3); // git's pack: one commit, one tree, one blob
73 cleanup();
74});
Diagnostics4 git calls · 173 ms
CallStatusSizeTime0173 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 · 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 · 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=38434
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=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
fetch2001.6 KiB168 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=168
git.response.bytes=1622
git.response.cache=MISS
git.response.duration_ms=168
git.fetch.wants=22d6766f25cc5a8f9923a6a901c2118ee1c20cb6
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=1622
git.pkt.payload.max=1601
git.sideband.band1.bytes=1600
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
a5e2c768b81d4afc
Request
b11a5d70…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format