Artifactspublic-v0

ply

main
ply4 git calls539 ms40 KiB2 cachedprotocol v2
123 lines6.0 KiBRaw
1// Sha1 (src/sha1.ts) against node:crypto: every length 0..300 (every padding case: the 55/56/63/64-byte edges and the
2// two-block tail), lengths around each power of two to 1 MiB, inputs fed in random chunks (the buffered path at every
3// offset), bytes chosen to set the high bit of each schedule word and state word, and digest/hex/toOid agreement.
4import { test } from 'vitest';
5import assert from 'node:assert/strict';
6import { createHash } from 'node:crypto';
7import { Sha1, toHex, streamingSha1 } from '../src/sha1.js';
9const want = b => createHash('sha1').update(b).digest('hex');
10function bytes(n, seed) {
11 let s = seed >>> 0 || 1;
12 const out = new Uint8Array(n);
13 for (let i = 0; i < n; i++) { s ^= s << 13; s >>>= 0; s ^= s >>> 17; s ^= s << 5; s >>>= 0; out[i] = s; }
14 return out;
17test('every length 0..300, random and all-0xff bytes, whole', () => {
18 for (let n = 0; n <= 300; n++) {
19 for (const b of [bytes(n, n + 1), new Uint8Array(n).fill(0xff), new Uint8Array(n)]) {
20 assert.equal(new Sha1().update(b).hex(), want(b), `length ${n}`);
21 assert.equal(toHex(new Sha1().update(b).digest()), want(b), `digest, length ${n}`);
22 }
23 }
24});
26test('lengths around powers of two to 1 MiB, fed in random chunks', () => {
27 let seed = 7;
28 for (let p = 6; p <= 20; p++) {
29 for (const n of [(1 << p) - 1, 1 << p, (1 << p) + 1]) {
30 const b = bytes(n, seed++);
31 const h = new Sha1();
32 let o = 0, r = seed;
33 while (o < n) { r = (r * 1103515245 + 12345) >>> 0; const k = Math.min(n - o, r % 200); h.update(b.subarray(o, o + k)); o += k; }
34 assert.equal(h.hex(), want(b), `length ${n}`);
35 }
36 }
37});
39test('the streaming hasher (pure-JS path under node) agrees', async () => {
40 const b = bytes(100_000, 3);
41 const s = streamingSha1();
42 for (let o = 0; o < b.length; o += 777) await s.update(b.subarray(o, o + 777));
43 assert.equal(await s.hex(), want(b));
44});
46// digest() and hex() are snapshots (a running pack checksum reads the hash so far and keeps hashing): called any number
47// of times they give the SHA-1 of the bytes fed so far, and update() continues from there. The expected value is
48// node:crypto's over the same prefix, never the hasher's own earlier answer. Before this held, digest() padded the live
49// state, so a second call hashed the message plus its padding: for 'abc', ec7a3886... where SHA-1 is a9993e36....
50test('digest/hex are non-destructive snapshots: twice in a row, at random points of a stream, updates continuing', () => {
51 // FIPS 180-1 appendix A's vector, so the first cell needs no oracle at all
52 const abc = new Sha1().update(new TextEncoder().encode('abc'));
53 assert.equal(abc.hex(), 'a9993e364706816aba3e25717850c26c9cd0d89d');
54 assert.equal(abc.hex(), 'a9993e364706816aba3e25717850c26c9cd0d89d', 'the second hex() of the same input');
55 assert.equal(toHex(abc.digest()), 'a9993e364706816aba3e25717850c26c9cd0d89d', 'digest() after two hex()');
56 // every buffered length 0..130 (both padding shapes, the block edges): digest twice, then keep hashing
57 for (let n = 0; n <= 130; n++) {
58 const b = bytes(n + 70, n + 11);
59 const h = new Sha1().update(b.subarray(0, n));
60 assert.equal(h.hex(), want(b.subarray(0, n)), `first, length ${n}`);
61 assert.equal(toHex(h.digest()), want(b.subarray(0, n)), `second, length ${n}`);
62 assert.equal(h.update(b.subarray(n)).hex(), want(b), `update after digest, length ${n}`);
63 }
64 // random streams: random chunk sizes, a snapshot (sometimes two) at random points, against node:crypto of the prefix
65 let r = 0x9e3779b9;
66 const next = () => { r ^= r << 13; r >>>= 0; r ^= r >>> 17; r ^= r << 5; r >>>= 0; return r; };
67 for (let round = 0; round < 200; round++) {
68 const n = next() % 5000;
69 const b = bytes(n, round + 1);
70 const h = new Sha1();
71 let o = 0, snaps = 0;
72 while (o < n) {
73 const k = Math.min(n - o, next() % 300);
74 h.update(b.subarray(o, o + k));
75 o += k;
76 if (next() % 3 === 0) {
77 snaps++;
78 assert.equal(h.hex(), want(b.subarray(0, o)), `round ${round}: snapshot at ${o} of ${n}`);
79 if (next() % 2 === 0) assert.equal(toHex(h.digest()), want(b.subarray(0, o)), `round ${round}: again at ${o}`);
80 }
81 }
82 assert.equal(h.hex(), want(b), `round ${round}: the whole input after ${snaps} snapshots`);
83 assert.equal(h.hex(), want(b), `round ${round}: and once more`);
84 }
85});
87test('the streaming hasher\'s hex() can be awaited twice (pure-JS path)', async () => {
88 const b = bytes(1000, 5);
89 const s = streamingSha1();
90 await s.update(b);
91 assert.equal(await s.hex(), want(b));
92 assert.equal(await s.hex(), want(b));
93});
95// The native path (Workers' crypto.DigestStream), which node does not have: a stand-in with DigestStream's shape (a
96// WritableStream whose `digest` promise settles on close) backed by node:crypto, so the expected value is still
97// node:crypto's. Closing a closed writer rejects, which is what a second hex() used to do.
98test('the streaming hasher\'s hex() can be awaited twice (native DigestStream path)', async () => {
99 class FakeDigestStream extends WritableStream {
100 constructor(algorithm) {
101 const h = createHash(algorithm.replace('-', '').toLowerCase());
102 let settle;
103 const digest = new Promise(res => { settle = res; });
104 super({ write(chunk) { h.update(chunk); }, close() { const d = h.digest(); settle(d.buffer.slice(d.byteOffset, d.byteOffset + d.length)); } });
105 this.digest = digest;
106 }
107 }
108 Object.defineProperty(globalThis.crypto, 'DigestStream', { value: FakeDigestStream, configurable: true });
109 try {
110 const b = bytes(5000, 9);
111 const s = streamingSha1();
112 assert.equal(s.kind, 'digeststream');
113 await s.update(b.subarray(0, 1234));
114 await s.update(b.subarray(1234));
115 const first = s.hex(), second = s.hex();
116 assert.equal(await first, want(b));
117 assert.equal(await second, want(b));
118 assert.equal(await s.hex(), want(b), 'and after both settled');
119 } finally {
120 delete globalThis.crypto.DigestStream;
121 }
122 assert.equal(streamingSha1().kind, 'js', 'the stand-in is gone');
123});
Diagnostics4 git calls · 539 ms
CallStatusSizeTime0539 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 · hit3 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=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.3 KiB533 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=533
git.response.bytes=2318
git.response.cache=MISS
git.response.duration_ms=533
git.fetch.wants=614a496ac8e0a35f7e9adfc6f8bccbd44dc1aa76
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=2318
git.pkt.payload.max=2297
git.sideband.band1.bytes=2296
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
a5e2c1974ba889da
Request
18340479…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format