main
1// The fsck tree-entry enumerator (test/space/fsck-tree.space.js). Every cell of trigger × mode × name × position is a
2// tree built byte for byte, judged by `git fsck --strict` (both streams, the exit code, every `error in` / `warning in`
3// line and its msgId, never --connectivity-only) and by ply's parseTree, through which every read path goes. Holds:
4// 1. the model (git's fsck_tree ported in the space file) to git, cell by cell: the same error and warning msgIds;
5// 2. ply to the expected outcome: it refuses exactly the trees git errors on, naming one of git's msgIds, and accepts
6// the rest with the canonical modes `git ls-tree` prints;
7// 3. the checkout: every entry ply accepts is a path `git read-tree` accepts with core.protectHFS and core.protectNTFS
8// both on (so verify_path refuses nothing parseTree lets through, on Linux or macOS), and checkoutPathRefusal agrees;
9// on Windows, checkoutPathRefusal against the rules of compat/mingw.c;
10// 4. .gitattributes contents at git's line and size caps: ply reads them as `git check-attr --source` does.
11// FSCK_TREE_SRC=<dir> runs ply's side against another copy of src/ (`git archive <rev> src | tar -x -C <dir>`), to count
12// what that revision got wrong. FSCK_TREE_LIST=1 prints every disagreeing cell. FSCK_TREE_LARGE=1 adds the three
13// 100 MiB .gitattributes cells (about 300 MB of blobs).
14import { test } from 'vitest';
15import assert from 'node:assert/strict';
16import { spawn } from 'node:child_process';
17import { mkdtempSync, rmSync, writeFileSync, mkdirSync, readFileSync, existsSync } from 'node:fs';
18import { tmpdir, availableParallelism } from 'node:os';
19import { join } from 'node:path';
20import { deflateSync } from 'node:zlib';
21import { createHash } from 'node:crypto';
22import * as space from './fsck-tree.space.js';
23import { checkoutPathRefusal } from '../../src/validate.js';
24import { attributesFor, bytesToStr } from '../../src/attributes.js';
25import { encodeBytes, decodeBytes } from '../../src/bytes.js';
26import { unwrap } from '../unwrap.js';
28// The reason git refuses the checkout of a path, or null when it accepts it.
29const refusalOf = (path, mode, platform) => { const why = unwrap(checkoutPathRefusal(path, mode, platform)); return why.tag === 'some' ? why.value : null; };
31const SRC = process.env.FSCK_TREE_SRC ?? new URL('../../src', import.meta.url).pathname;
32// an absolute specifier: the .js -> .ts resolve hook maps relative ones only (objects is TypeScript since T2; an older src copy is .js)
33const { parseTree } = await import(existsSync(`${SRC}/objects.ts`) ? `${SRC}/objects.ts` : `${SRC}/objects.js`);
34const LIST = !!process.env.FSCK_TREE_LIST;
36const sha1 = (type, data) => createHash('sha1').update(`${type} ${data.length}\0`).update(data).digest('hex');
37const EMPTY_BLOB = sha1('blob', Buffer.alloc(0));
38const NULL = '0'.repeat(40);
40function run(cmd, args, { cwd, input, env } = {}) {
41 return new Promise((resolve, reject) => {
42 const p = spawn(cmd, args, { cwd, env: env ? { ...process.env, ...env } : process.env });
43 const out = [], err = [];
44 p.stdout.on('data', d => out.push(d));
45 p.stderr.on('data', d => err.push(d));
46 p.on('error', reject);
47 p.on('close', status => resolve({ status, stdout: Buffer.concat(out).toString('latin1'), stderr: Buffer.concat(err).toString('latin1') }));
48 p.stdin.on('error', e => { if (e.code !== 'EPIPE') reject(e); }); // a git that exits without reading stdin
49 // git may exit before it reads stdin (a command that takes none): EPIPE then means nothing, its status says it all
50 p.stdin.on('error', e => { if (e.code !== 'EPIPE') reject(e); });
51 p.stdin.end(input ?? '');
52 });
53}
55// ---- the cells and the objects each one needs ----
56// objects: [{ type, data, oid, owner: cell index | null (a fixture) }]
57function build() {
58 const cells = space.product().map((c, i) => ({ c, i, id: space.cellId(c) }));
59 const objects = new Map([[EMPTY_BLOB, { type: 'blob', data: Buffer.alloc(0), oid: EMPTY_BLOB, owners: null }]]);
60 const own = (type, data, i) => {
61 const oid = sha1(type, data);
62 const o = objects.get(oid);
63 if (o) { if (o.owners) o.owners.add(i); else return oid; } else objects.set(oid, { type, data, oid, owners: new Set([i]) });
64 return oid;
65 };
66 for (const x of cells) {
67 x.entries = space.entriesOf(x.c);
68 x.extra = new Set();
69 const oidOf = e => {
70 if (e.oid === 'null') return NULL;
71 if (e.oid === 'blob') return EMPTY_BLOB;
72 if (e.oid === 'gitlink') { const g = space.gitlinkOid(x.id, e.role); x.extra.add(g); return g; }
73 const t = own('tree', space.subtreeBytes(x.id, e.role, EMPTY_BLOB), x.i); x.extra.add(t); return t;
74 };
75 x.bytes = space.treeBytes(x.entries, oidOf);
76 x.oid = own('tree', x.bytes, x.i);
77 x.want = space.expected(x.c);
78 }
79 return { cells, objects: [...objects.values()] };
80}
82// ---- the oracle: git fsck --strict over a store, every line pinned to the cell that owns an oid in it ----
83const UNPINNED = /^error: (empty filename in tree entry|malformed mode in tree entry)$/;
84const CONNECTIVITY = /^(broken link from|missing (blob|tree|commit) |error in tree [0-9a-f]{40}: broken links$)/;
85const msgIdOf = l => /^(?:error|warning) in \w+ [0-9a-f]{40}: (\w+): /.exec(l)?.[1] ?? null;
87async function writeLoose(dir, objs) {
88 mkdirSync(join(dir, 'in'), { recursive: true });
89 for (const type of ['blob', 'tree']) {
90 const mine = objs.filter(o => o.type === type);
91 if (!mine.length) continue;
92 const paths = mine.map((o, k) => { const p = join(dir, 'in', `${type}-${k}`); writeFileSync(p, o.data); return p; });
93 const r = await run('git', ['hash-object', '-t', type, '--literally', '-w', '--stdin-paths'], { cwd: dir, input: paths.join('\n') + '\n' });
94 assert.equal(r.status, 0, r.stderr);
95 assert.deepEqual(r.stdout.trim().split('\n'), mine.map(o => o.oid), `git hash-object --literally and this test hash every ${type} alike`);
96 }
97 rmSync(join(dir, 'in'), { recursive: true, force: true });
98}
100// The full space goes in one pack per shard, framed with node:zlib and indexed by `git index-pack` without --strict
101// (which judges nothing; git hashes each object from its bytes, and show-index must list exactly our oids), as #62 does:
102// a loose object per cell costs about half a millisecond on APFS. A fixed sample is also written loose with `git
103// hash-object --literally` and must get the same lines.
104async function writePack(dir, objs) {
105 const parts = [Buffer.from('PACK'), Buffer.from([0, 0, 0, 2]), Buffer.alloc(4)];
106 parts[2].writeUInt32BE(objs.length);
107 for (const o of objs) {
108 let size = o.data.length;
109 const head = [({ tree: 2, blob: 3 }[o.type] << 4) | (size & 0x0f)];
110 size >>= 4;
111 while (size) { head[head.length - 1] |= 0x80; head.push(size & 0x7f); size >>= 7; }
112 parts.push(Buffer.from(head), deflateSync(o.data));
113 }
114 const body = Buffer.concat(parts);
115 const r = await run('git', ['index-pack', '--stdin'], { cwd: dir, input: Buffer.concat([body, createHash('sha1').update(body).digest()]) });
116 assert.equal(r.status, 0, r.stderr);
117 const idx = join(dir, 'objects', 'pack', `pack-${r.stdout.trim().split(/\s+/).pop()}.idx`);
118 const listed = await run('git', ['show-index'], { cwd: dir, input: readFileSync(idx) });
119 assert.deepEqual(listed.stdout.trim().split('\n').map(l => l.split(' ')[1]).sort(), objs.map(o => o.oid).sort(), 'git hashes every object as this test does');
120}
122// → Map(cell index → lines), and the unpinned lines (git's own `error:` from decode_tree_entry, before a badTree)
123async function judge(cells, objects, { loose }) {
124 const shards = loose ? 1 : Math.max(1, Math.min(8, availableParallelism()));
125 const root = mkdtempSync(join(tmpdir(), 'ply-fsck-tree-'));
126 const lines = new Map(cells.map(x => [x.i, []]));
127 const unpinned = [];
128 const exits = [];
129 try {
130 await Promise.all(Array.from({ length: shards }, async (_, s) => {
131 const dir = join(root, `s${s}`);
132 assert.equal((await run('git', ['init', '-q', '--bare', dir])).status, 0);
133 const mineCells = cells.filter((_, k) => k % shards === s);
134 const want = new Set(mineCells.map(x => x.i));
135 const mine = objects.filter(o => !o.owners || [...o.owners].some(i => want.has(i)));
136 if (loose) await writeLoose(dir, mine); else await writePack(dir, mine);
137 const r = await run('git', ['fsck', '--strict', '--no-dangling'], { cwd: dir });
138 const got = [];
139 for (const l of `${r.stdout}\n${r.stderr}`.split('\n')) {
140 if (!l.trim() || l.startsWith('notice:')) continue;
141 if (/^\s/.test(l) && got.length) got[got.length - 1] += ` ${l.trim()}`; else got.push(l.trim());
142 }
143 // exit bits: 1 an object error, 2 connectivity, 4 (packed only) an object in a pack that does not parse
144 assert.ok(r.status !== null && (r.status & ~(loose ? 3 : 7)) === 0, `git fsck exit ${r.status}: ${got.slice(0, 5).join(' | ')}`);
145 exits.push({ status: r.status, errors: got.some(l => !l.startsWith('warning in ') && !UNPINNED.test(l) && !/^(broken link from|missing )/.test(l)) });
146 const byOid = new Map();
147 for (const x of mineCells) for (const oid of [x.oid, ...x.extra]) { if (!byOid.has(oid)) byOid.set(oid, []); byOid.get(oid).push(x.i); }
148 for (const l of got) {
149 if (UNPINNED.test(l)) { unpinned.push(l); continue; }
150 const owners = [...l.matchAll(/[0-9a-f]{40}/g)].map(m => byOid.get(m[0])).find(Boolean);
151 if (!owners) throw new Error(`fsck line pinned to no cell: ${l}`);
152 for (const i of owners) lines.get(i).push(l);
153 }
154 }));
155 } finally {
156 rmSync(root, { recursive: true, force: true });
157 }
158 return { lines, unpinned, exits };
159}
161const classify = ls => ({
162 errors: [...new Set(ls.filter(l => l.startsWith('error in ') && msgIdOf(l)).map(msgIdOf))].sort(),
163 warnings: [...new Set(ls.filter(l => l.startsWith('warning in ')).map(msgIdOf))].sort(),
164 connectivity: ls.filter(l => CONNECTIVITY.test(l)).length,
165 other: ls.filter(l => !msgIdOf(l) && !CONNECTIVITY.test(l)),
166});
168function plyOutcome(bytes) {
169 try { return { ply: 'accept', entries: unwrap(parseTree(new Uint8Array(bytes))) }; } catch (e) {
170 if (e?.code !== 'pack_corrupt') return { ply: 'other', message: `${e?.code}: ${e?.message}` };
171 return { ply: 'refuse', message: e.message, msgIds: space.msgIdsOfPly(e.message) };
172 }
173}
175// a name's bytes as ply's string for them (bytes.js decodeBytes, as parseTree returns it)
176const bytesName = b => decodeBytes(new Uint8Array(b));
178const LOOSE_EVERY = process.env.FSCK_TREE_LOOSE ? 1 : 40;
179let built, verdicts;
181test('fsck tree space: every axis variant cites git, the product is exhaustive, every cell has an expected outcome', () => {
182 for (const a of space.AXES) for (const v of a.variants) assert.ok(v.why && v.why.length > 2, `${a.name}.${v.tag} cites why`);
183 built = build();
184 const raw = space.AXES.reduce((n, a) => n * a.variants.length, 1);
185 const collapsed = raw - built.cells.length;
186 assert.equal(collapsed, space.AXES.filter(a => a.name !== 'trigger' && a.name !== 'position').reduce((n, a) => n * a.variants.length, 1) * (space.AXES.find(a => a.name === 'position').variants.length - 1), 'only the one-entry trees collapse');
187 for (const x of built.cells) assert.ok(x.want.ply === 'accept' || x.want.ply === 'refuse', x.id);
188 console.log(` fsck-tree: ${raw} raw cells, ${built.cells.length} after collapsing one-entry trees, ${built.objects.length} objects`);
189});
191test('fsck tree space: git fsck --strict agrees with the model on every cell (packed), and a loose sample agrees with the packed run', { timeout: 600_000 }, async () => {
192 const { cells, objects } = built;
193 const packed = await judge(cells, objects, { loose: false });
194 const sample = cells.filter((_, k) => k % LOOSE_EVERY === 0);
195 const loose = await judge(sample, objects, { loose: true });
196 for (const x of sample) {
197 const a = classify(loose.lines.get(x.i)), b = classify(packed.lines.get(x.i));
198 assert.deepEqual([a.errors, a.warnings], [b.errors, b.warnings], `loose and packed fsck agree on ${x.id}`);
199 }
200 // the loose store's exit code says what its lines say: bit 1 iff some error line
201 for (const ex of loose.exits) assert.equal(!!(ex.status & 1), ex.errors, `loose fsck exit ${ex.status} matches its lines`);
202 const wrong = [];
203 for (const x of cells) {
204 const g = classify(packed.lines.get(x.i));
205 x.git = g;
206 if (g.other.length) wrong.push(`${x.id}: unclassified fsck lines ${JSON.stringify(g.other)}`);
207 const hasNull = x.entries.some(e => e.oid === 'null'), badTree = g.errors.includes('badTree');
208 if (g.connectivity && !hasNull && !badTree) wrong.push(`${x.id}: connectivity lines without a null oid or a bad tree`);
209 if (JSON.stringify([g.errors, g.warnings]) !== JSON.stringify([x.want.errors, x.want.warnings])) wrong.push(`${x.id}: model errors ${x.want.errors} warnings ${x.want.warnings}; git errors ${g.errors} warnings ${g.warnings}`);
210 }
211 if (packed.unpinned.length) assert.ok(cells.some(x => x.git.errors.includes('badTree')), 'git\'s own error: lines come only with a badTree');
212 verdicts = packed;
213 if (wrong.length) console.log(wrong.slice(0, LIST ? wrong.length : 20).join('\n'));
214 assert.deepEqual(wrong.length, 0, `${wrong.length} cells where the model and git disagree`);
215 const tally = {};
216 for (const x of cells) { const k = x.git.errors.length ? 'error' : x.git.warnings.length ? 'warning-only' : 'clean'; tally[k] = (tally[k] ?? 0) + 1; }
217 console.log(` fsck-tree git: ${Object.entries(tally).map(([k, n]) => `${k} ${n}`).join(', ')}; loose sample ${sample.length}`);
218});
220test('fsck tree space: ply refuses exactly what git errors on (naming one of its msgIds) and reads the rest with git\'s canonical modes', () => {
221 assert.ok(verdicts, 'the fsck run');
222 const wrong = {}, samples = {};
223 let n = 0;
224 for (const x of built.cells) {
225 const got = plyOutcome(x.bytes);
226 let why = null;
227 if (got.ply !== x.want.ply) why = `${x.want.ply} -> ${got.ply}${got.message ? ` (${got.message.replace(/".*"/, '"…"')})` : ''}`;
228 else if (got.ply === 'refuse' && !(got.msgIds ?? []).some(m => x.git.errors.includes(m))) why = `refused as ${got.message.replace(/".*"/, '"…"')}, git said ${x.git.errors}`;
229 else if (got.ply === 'accept') {
230 const modes = got.entries.map(e => e.mode), names = got.entries.map(e => Buffer.from(unwrap(encodeBytes(e.name))).toString('hex'));
231 const wantModes = x.entries.map(e => space.canon(space.parseMode(e.mode))), wantNames = x.entries.map(e => e.name.toString('hex'));
232 if (JSON.stringify(modes) !== JSON.stringify(wantModes)) why = `modes ${modes} != canon_mode ${wantModes}`;
233 else if (JSON.stringify(names) !== JSON.stringify(wantNames)) why = 'names do not round-trip to their bytes';
234 }
235 if (why) {
236 n++;
237 const k = `${why} | git: ${[...x.git.errors, ...x.git.warnings.map(w => `${w}(warning)`)].join('+') || 'clean'}`;
238 wrong[k] = (wrong[k] ?? 0) + 1;
239 (samples[k] ??= []).push(x.id);
240 }
241 }
242 for (const [k, c] of Object.entries(wrong).sort((a, b) => b[1] - a[1])) console.log(` fsck-tree wrong: ${c} × ${k}${LIST ? `\n ${samples[k].join('\n ')}` : ` (e.g. ${samples[k][0]})`}`);
243 const accepted = built.cells.filter(x => x.want.ply === 'accept').length;
244 console.log(` fsck-tree ply (${SRC}): ${built.cells.length} cells, ${accepted} accept, ${built.cells.length - accepted} refuse expected; ${n} wrong`);
245 assert.equal(n, 0, `${n} cells where ply disagrees with the expected outcome`);
246});
248test('fsck tree space: the modes git ls-tree prints are canon_mode of the mode bytes (the model\'s canon is git\'s)', async () => {
249 const dir = mkdtempSync(join(tmpdir(), 'ply-fsck-tree-ls-'));
250 try {
251 assert.equal((await run('git', ['init', '-q', '--bare', dir])).status, 0);
252 const objs = [{ type: 'blob', data: Buffer.alloc(0), oid: EMPTY_BLOB }];
253 const sub = Buffer.concat([Buffer.from('100644 f\0'), Buffer.from(EMPTY_BLOB, 'hex')]);
254 objs.push({ type: 'tree', data: sub, oid: sha1('tree', sub) });
255 const trees = [];
256 for (const v of space.AXES.find(a => a.name === 'mode').variants) {
257 const c = space.canon(space.parseMode(v.raw));
258 const target = c === '40000' ? sha1('tree', sub) : c === '160000' ? 'c0ffee'.padEnd(40, '0') : EMPTY_BLOB;
259 const data = Buffer.concat([Buffer.from(`${v.raw} a\0`), Buffer.from(target, 'hex')]);
260 objs.push({ type: 'tree', data, oid: sha1('tree', data) });
261 trees.push({ v, c, oid: sha1('tree', data) });
262 }
263 await writeLoose(dir, objs);
264 for (const t of trees) {
265 const r = await run('git', ['ls-tree', t.oid], { cwd: dir });
266 assert.equal(r.status, 0, r.stderr);
267 assert.equal(Number.parseInt(r.stdout.split(' ')[0], 8), Number.parseInt(t.c, 8), `${t.v.raw}: git ls-tree ${r.stdout.trim()}, model ${t.c}`);
268 }
269 } finally { rmSync(dir, { recursive: true, force: true }); }
270});
272test('fsck tree space: every entry ply accepts is a path git read-tree checks out with protectHFS and protectNTFS on; checkoutPathRefusal agrees', { timeout: 300_000 }, async () => {
273 assert.ok(built, 'the cells');
274 // the distinct (name, mode) entries of cells ply accepts, each alone in a tree; plus names git must refuse (the oracle can fail)
275 const pairs = new Map();
276 for (const x of built.cells) if (x.want.ply === 'accept') for (const e of x.entries) pairs.set(`${e.mode} ${e.name.toString('hex')}`, { mode: e.mode, name: e.name, refuse: false });
277 for (const [mode, name] of [['100644', '.git'], ['100644', 'GIT~1'], ['100644', '.git. .'], ['120000', '.gitmodules'], ['120000', '.GITMODULES'], ['100644', '.git']]) pairs.set(`${mode} ${Buffer.from(name).toString('hex')}`, { mode, name: Buffer.from(name), refuse: true });
278 const dir = mkdtempSync(join(tmpdir(), 'ply-fsck-tree-co-'));
279 try {
280 assert.equal((await run('git', ['init', '-q', '--bare', dir])).status, 0);
281 const sub = Buffer.concat([Buffer.from('100644 f\0'), Buffer.from(EMPTY_BLOB, 'hex')]);
282 const objs = [{ type: 'blob', data: Buffer.alloc(0), oid: EMPTY_BLOB }, { type: 'tree', data: sub, oid: sha1('tree', sub) }];
283 const list = [...pairs.values()];
284 for (const p of list) {
285 const c = space.canon(space.parseMode(p.mode));
286 const target = c === '40000' ? sha1('tree', sub) : c === '160000' ? 'c0ffee'.padEnd(40, '0') : EMPTY_BLOB;
287 p.data = Buffer.concat([Buffer.from(`${p.mode} `), p.name, Buffer.from([0]), Buffer.from(target, 'hex')]);
288 p.oid = sha1('tree', p.data); p.canon = c;
289 objs.push({ type: 'tree', data: p.data, oid: p.oid });
290 }
291 await writeLoose(dir, [...new Map(objs.map(o => [o.oid, o])).values()]);
292 const wrong = [];
293 await Promise.all(Array.from({ length: 8 }, async (_, s) => {
294 for (const p of list.filter((_, k) => k % 8 === s)) {
295 const r = await run('git', ['-c', 'core.protectHFS=true', '-c', 'core.protectNTFS=true', 'read-tree', p.oid], { cwd: dir, env: { GIT_INDEX_FILE: join(dir, `index-${s}`) } });
296 const gitRefuses = r.status !== 0;
297 if (gitRefuses && !/invalid path/.test(r.stderr)) wrong.push(`${p.mode} ${JSON.stringify(p.name.toString('latin1'))}: read-tree failed for another reason: ${r.stderr.trim()}`);
298 if (gitRefuses !== p.refuse) wrong.push(`${p.mode} ${JSON.stringify(p.name.toString('latin1'))}: git read-tree ${gitRefuses ? 'refuses' : 'accepts'}`);
299 const name = bytesName(p.name);
300 for (const platform of ['linux', 'darwin']) {
301 const why = refusalOf(`d/${name}`, p.canon, platform);
302 if (!!why !== p.refuse) wrong.push(`${p.mode} ${JSON.stringify(p.name.toString('latin1'))} on ${platform}: checkoutPathRefusal ${why}`);
303 }
304 }
305 }));
306 assert.deepEqual(wrong, []);
307 console.log(` fsck-tree checkout: ${list.length} accepted (name, mode) entries, git read-tree with protectHFS+protectNTFS refuses none of them`);
308 } finally { rmSync(dir, { recursive: true, force: true }); }
309});
312test('fsck tree space: on Windows, checkoutPathRefusal refuses what git for Windows refuses (compat/mingw.c, derived)', () => {
313 const wrong = [];
314 for (const [name, refused] of space.WIN32) {
315 const why = refusalOf(`d/${name}`, '100644', 'win32');
316 if (!!why !== refused) wrong.push(`${JSON.stringify(name)}: ${why ?? 'allowed'}, mingw.c ${refused ? 'refuses' : 'allows'}`);
317 if (!/[\\:]/.test(name) && !/^(con|aux|prn|nul|com|lpt)/i.test(name) && !/[ .]$/.test(name) && !/[<>"|?*\x01]/.test(name)) assert.equal(refusalOf(`d/${name}`, '100644', 'linux'), null, name);
318 }
319 assert.deepEqual(wrong, []);
320});
322// ---- .gitattributes contents at git's caps (fsck_blob gitattributesLineLength / gitattributesLarge; attr.c) ----
323// fsck errors in the blob at a line of 2048 bytes or more, or a blob over 100 MiB; attr.c ignores such a line, and a blob
324// of 100 MiB or more, with a warning. ply's decision: a blob's content is not an object check (parseTree never sees it,
325// and git checks such a repository out); where ply reads .gitattributes (merge), it reads them as attr.c does.
326const CONTENT = [
327 ...[2047, 2048, 2049].flatMap(len => ['100644', '120000'].map(mode => ({ id: `line${len}/${mode}`, len, mode }))),
328 ...(process.env.FSCK_TREE_LARGE ? [100 * 1024 * 1024 - 1, 100 * 1024 * 1024, 100 * 1024 * 1024 + 1].map(size => ({ id: `size${size}`, size, mode: '100644' })) : []),
329];
330const contentOf = c => {
331 const head = '*.txt merge=union\n';
332 if (c.len) return Buffer.from(`${head}*.c foo=${'v'.repeat(c.len - '*.c foo='.length)}\n`);
333 const first = `${head}*.c foo=bar\n`;
334 const pad = c.size - first.length;
335 const line = `#${'p'.repeat(98)}\n`;
336 return Buffer.concat([Buffer.from(first), Buffer.from(line.repeat(Math.floor(pad / line.length))), Buffer.from('#'.repeat(pad % line.length))]);
337};
339test('fsck tree space: .gitattributes at git\'s line and size caps reads as git check-attr --source reads it; fsck\'s verdict is the model\'s', { timeout: 300_000 }, async () => {
340 const dir = mkdtempSync(join(tmpdir(), 'ply-fsck-tree-attr-'));
341 try {
342 assert.equal((await run('git', ['init', '-q', '--bare', dir])).status, 0);
343 const wrong = [];
344 for (const c of CONTENT) {
345 const data = contentOf(c);
346 if (c.len) assert.equal(data.toString().split('\n')[1].length, c.len);
347 if (c.size) assert.equal(data.length, c.size);
348 const blob = sha1('blob', data);
349 const tdata = Buffer.concat([Buffer.from(`${c.mode} .gitattributes\0`), Buffer.from(blob, 'hex'), Buffer.from('100644 x.c\0'), Buffer.from(EMPTY_BLOB, 'hex')]);
350 const tree = sha1('tree', tdata);
351 await writeLoose(dir, [{ type: 'blob', data, oid: blob }, { type: 'blob', data: Buffer.alloc(0), oid: EMPTY_BLOB }, { type: 'tree', data: tdata, oid: tree }]);
352 const ga = await run('git', ['check-attr', `--source=${tree}`, '-a', 'x.c', 'x.txt'], { cwd: dir });
353 assert.equal(ga.status, 0, ga.stderr);
354 const gitAttrs = ga.stdout.trim().split('\n').filter(Boolean).map(l => l.replace(/^x\.(c|txt): /, '$1 ')).sort();
355 const files = new Map([['', bytesToStr(data)]]);
356 const ours = ['c', 'txt'].flatMap(ext => [...attributesFor(`x.${ext}`, files)].filter(([, v]) => v !== null).map(([k, v]) => `${ext} ${k}: ${v === true ? 'set' : v === false ? 'unset' : v}`)).sort();
357 if (JSON.stringify(ours) !== JSON.stringify(gitAttrs)) wrong.push(`${c.id}: ply ${JSON.stringify(ours).slice(0, 200)}, git ${JSON.stringify(gitAttrs).slice(0, 200)}`);
358 // fsck: a blob over a cap is an error in the blob; a symlink is a warning in the tree and its content is not read
359 const f = await run('git', ['fsck', '--strict', '--no-dangling'], { cwd: dir });
360 const ids = [...`${f.stdout}\n${f.stderr}`.matchAll(/(?:error|warning) in \w+ ([0-9a-f]{40}): (\w+):/g)].filter(m => m[1] === blob || m[1] === tree).map(m => m[2]).sort();
361 const model = c.mode === '120000' ? ['gitattributesSymlink'] : (c.len >= 2048 || c.size > 100 * 1024 * 1024) ? [c.len ? 'gitattributesLineLength' : 'gitattributesLarge'] : [];
362 if (JSON.stringify(ids) !== JSON.stringify(model)) wrong.push(`${c.id}: fsck ${ids}, model ${model}`);
363 assert.ok(plyOutcome(tdata).ply === 'accept', `${c.id}: the tree itself is one ply accepts`);
364 await run('git', ['prune', '--expire=now'], { cwd: dir });
365 rmSync(join(dir, 'objects'), { recursive: true, force: true }); mkdirSync(join(dir, 'objects', 'pack'), { recursive: true }); mkdirSync(join(dir, 'objects', 'info'), { recursive: true });
366 }
367 assert.deepEqual(wrong, []);
368 console.log(` fsck-tree .gitattributes: ${CONTENT.length} cells agree with check-attr and fsck${process.env.FSCK_TREE_LARGE ? '' : ' (FSCK_TREE_LARGE=1 adds the 100 MiB cells)'}`);
369 } finally { rmSync(dir, { recursive: true, force: true }); }
370});
372test('fsck tree space: SPACE.md\'s generated block is current', async () => {
373 const doc = await import('../../scripts/space-md.mjs');
374 assert.equal(doc.currentFsckTree(), doc.fsckTreeBlock(), 'SPACE.md is stale: run node scripts/space-md.mjs --write');
375});
Diagnostics4 git calls · 22 ms
CallStatusSizeTime022 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=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 · 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=17 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=55Open pack map
fetch2008.3 KiB · hit17 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=8536 git.response.cache=HIT git.response.duration_ms=17 git.fetch.wants=7c8ef5da40f485e1b2cc16d0474ef7c8b740de5c 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=8536 git.pkt.payload.max=8515 git.sideband.band1.bytes=8514 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
- a5e2f5c27fe93a24
- Request
- 20cde465…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format