Artifactspublic-v0

ply

main
ply4 git calls223 ms41 KiB2 cachedprotocol v2
150 lines7.5 KiBRaw
1// ply#274: the fetch filter-refusal predicate and readConfig's key/value line, both rewritten to run in linear time.
2//
3// The oracle for WHAT each one classifies is the pattern main (8e3939d) applied, run here by the regex engine on short
4// inputs where its cost does not matter, plus the real refusal texts (Cloudflare Artifacts, observed 2026-10-23; git's
5// upload-pack, upload-pack.c "filter '%s' not supported") and `git config --file … --list` for the config forms ply reads.
6// The oracle for the COST is a ratio of two times measured the same way (the issue's generator), never a time.
7import { spawnSync } from 'node:child_process';
8import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
9import { tmpdir } from 'node:os';
10import { join } from 'node:path';
11import { test } from 'vitest';
12import assert from 'node:assert/strict';
13import { isFilterRefusal, isFilterRejection } from '../src/fetch.js';
14import { readConfig } from '../src/repo-node.js';
16const OLD_FILTER = /only blob:none is supported|unsupported (git )?fetch filter|filter .* not (supported|allowed)/i;
17const OLD_KV = /^([A-Za-z][\w-]*)\s*(=\s*(.*))?$/u;
19test('the refusal texts servers really send are refusals at 400 and nothing else', () => {
20 const real = [
21 'Unsupported Git fetch filter; only blob:none is supported.',
22 'HTTP 400 git-upload-pack: Unsupported Git fetch filter; only blob:none is supported.',
23 "filter 'tree' not supported",
24 "filter 'sparse:oid' not supported",
25 "git upload-pack: filter 'blob:limit' not supported",
26 'filter blob:limit=1 not allowed',
27 'filter tree:0 not supported',
28 'unsupported fetch filter',
29 'unsupported git fetch filter',
30 ];
31 for (const t of real) {
32 assert.equal(isFilterRefusal(400, t), true, t);
33 assert.equal(isFilterRefusal(500, t), false, t);
34 assert.equal(isFilterRejection({ code: 'remote_error', message: t }), true, t);
35 }
36 for (const t of ['filter not allowed', 'filter\nnot supported', 'filter x\r not supported', 'not supported filter ', 'fetch filter=blob:none', '']) {
37 assert.equal(isFilterRefusal(400, t), false, JSON.stringify(t));
38 }
39});
41test('isFilterRefusal classifies every message of up to 4 tokens exactly as main\'s regex did', () => {
42 const tokens = ['filter ', 'FiLtEr ', ' not supported', ' NOT Allowed', ' not', ' ', 'x', '\n', '\r', '
', '
', '\0',
43 'unsupported git fetch filter', 'Unsupported Git fetch filter', 'only blob:none is supported', 'ONLY blob:None is supported', 'İ', 'K', 'filte'];
44 let checked = 0;
45 const walk = (text, left) => {
46 assert.equal(isFilterRefusal(400, text), OLD_FILTER.test(text), JSON.stringify(text));
47 checked += 1;
48 if (left > 0) for (const t of tokens) walk(text + t, left - 1);
49 };
50 walk('', 4);
51 assert.ok(checked > 137000); // 1 + 19 + 19^2 + 19^3 + 19^4 = 137,561
52});
54// readConfig as main had it, the config-line regex the only change.
55const oldReadConfig = text => {
56 const out = new Map();
57 let section = '';
58 for (const raw of text.split('\n')) {
59 const line = raw.trim();
60 const head = /^\[([^\]\s"]+)(\s+"([^"]*)")?\]$/u.exec(line);
61 if (head !== null) { section = head[3] !== undefined ? `${head[1].toLowerCase()}.${head[3]}` : head[1].toLowerCase(); continue; }
62 const kv = OLD_KV.exec(line);
63 if (kv !== null && section !== '') out.set(`${section}.${kv[1].toLowerCase()}`, (kv[3] ?? 'true').trim());
64 }
65 return out;
66};
68test('readConfig reads every key/value line of up to 6 characters exactly as main\'s regex did', () => {
69 const alphabet = ['a', '=', ' ', '\t', '\r', '
', '
', ' ', 'x', '-'];
70 let checked = 0;
71 const walk = (line, left) => {
72 if (!line.includes('#') && !line.includes(';')) {
73 assert.deepEqual([...readConfig(`[s]\n${line}`)], [...oldReadConfig(`[s]\n${line}`)], JSON.stringify(line));
74 checked += 1;
75 }
76 if (left > 0) for (const c of alphabet) walk(line + c, left - 1);
77 };
78 walk('', 6);
79 assert.ok(checked > 1000000);
80});
82test('readConfig agrees with git config --list on the forms ply reads', () => {
83 const dir = mkdtempSync(join(tmpdir(), 'ply-274-'));
84 try {
85 const file = join(dir, 'config');
86 const git = (...a) => spawnSync('git', ['config', '--file', file, ...a], { encoding: 'utf8' });
87 git('core.bare', 'false');
88 git('extensions.objectFormat', 'sha1');
89 git('extensions.refStorage', 'files');
90 git('remote.origin.url', 'https://example.com/a b.git');
91 git('remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*');
92 git('branch.main.remote', 'origin');
93 const text = `${readFileSync(file, 'utf8')}\tbare2 = spaced value \n\tflag\n`;
94 const listed = spawnSync('git', ['config', '-f', '-', '--list'], { input: text, encoding: 'utf8' }).stdout.trim().split('\n')
95 .map(l => { const i = l.indexOf('='); return i < 0 ? [l, 'true'] : [l.slice(0, i), l.slice(i + 1)]; });
96 const ours = readConfig(text);
97 for (const [k, v] of listed) {
98 const dot = k.lastIndexOf('.');
99 assert.equal(ours.get(`${k.slice(0, dot)}.${k.slice(dot + 1).toLowerCase()}`), v, k);
100 }
101 } finally {
102 rmSync(dir, { recursive: true, force: true });
103 }
104});
106const ratio = (f, gen, n) => {
107 const time = m => { const s = gen(m); let best = Infinity; for (let i = 0; i < 7; i++) { const t0 = performance.now(); f(s); best = Math.min(best, performance.now() - t0); } return best; };
108 return time(4 * n) / time(n);
109};
111test('both stay linear on the issue\'s generators (4x the input costs well under 16x the time)', () => {
112 for (const [name, f, gen] of [
113 ['filter', s => isFilterRefusal(400, s), n => 'filter '.repeat(n)],
114 ['config', s => readConfig(`[s]\n${s}`), n => `a=${' '.repeat(n)}x\ry`],
115 ]) {
116 let best = Infinity;
117 for (let a = 0; a < 3 && best >= 9; a++) best = Math.min(best, ratio(f, gen, 20000));
118 assert.ok(best < 9, `${name}: ${best.toFixed(1)}x`);
119 }
120});
122// Every BMP code unit put into each slot of a refusal and of a near-miss, against main's regex: a hand case fold or a
123// line-end test that is off for one code unit (a control character that ORs to a space, a line separator) shows here.
124test('isFilterRefusal agrees with main\'s regex on every single-code-unit edit of a refusal', () => {
125 const bases = ['filter x not supported', 'filter a\nfilter x not allowed'];
126 let n = 0;
127 for (let c = 0; c < 0x10000; c++) {
128 const ch = String.fromCharCode(c);
129 for (const base of bases) for (let i = 0; i <= base.length; i++) for (const t of [base.slice(0, i) + ch + base.slice(i), base.slice(0, i) + ch + base.slice(i + 1)]) {
130 if (isFilterRefusal(400, t) !== OLD_FILTER.test(t)) assert.fail(JSON.stringify(t));
131 n += 1;
132 }
133 }
134 assert.ok(n > 6000000);
135});
137// The common case is a non-refusal: an HTTP 400 page. Its cost is compared with main's regex on the same body, measured
138// the same way (interleaved, best of rounds), so the bound is a ratio, never a time.
139test('a typical 4 KiB non-refusal 400 body costs about what main\'s regex did (under 10x)', () => {
140 const html = `${'<html><body>Bad Request: the request could not be processed by this server. ' + 'x'.repeat(60)}\n`.repeat(30).slice(0, 4096);
141 const each = (f, k) => { const t0 = performance.now(); for (let i = 0; i < k; i++) f(); return performance.now() - t0; };
142 let ours = Infinity;
143 let main = Infinity;
144 for (let r = 0; r < 15; r++) {
145 ours = Math.min(ours, each(() => isFilterRefusal(400, html), 500));
146 main = Math.min(main, each(() => OLD_FILTER.test(html), 500));
147 }
148 assert.equal(isFilterRefusal(400, html), false);
149 assert.ok(ours / main < 10, `${(ours / main).toFixed(1)}x main`);
150});
Diagnostics4 git calls · 223 ms
CallStatusSizeTime0223 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · hit2 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=HIT
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 · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=213
git.response.bytes=38434
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=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
fetch2003.0 KiB213 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3080
git.response.cache=MISS
git.response.duration_ms=213
git.fetch.wants=19e19624f31505bbe073ada4bb65338f033e13f1
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=3080
git.pkt.payload.max=3059
git.sideband.band1.bytes=3058
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
a5e343b0dbf86e2a
Request
8eefabe6…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format