Artifactspublic-v0

ply

main
ply4 git calls28 ms46 KiB3 cachedprotocol v2
381 lines25 KiBRaw
1// The commit, tag and ident decision space (issue #59), decided by git. Every rule fsck.c applies to a commit or a tag
2// (verify_headers, fsck_commit, fsck_tag_standalone, fsck_ident) is an axis below, as a tagged union of the shapes that
3// rule sees. The cells are the product of the axes: each is built byte for byte, written by `git hash-object -t <type>
4// --literally`, and judged by `git fsck --strict` (both streams, the exit code, `error in` and `warning in` lines,
5// never --connectivity-only). ply must refuse exactly the cells git reports an error for, with the same msgId, and
6// accept the rest, except the allowed typed refusals in ALLOWED_REFUSAL (PR #7). A cell git only warns about is decided per msgId in WARN_DECISION; a warning without a decision
7// fails the test, so a new git msgId cannot slip through as "accept" by default.
8//
9// FSCK_SPACE_LIST=1 npx vitest run test/fsck-space.test.js prints every disagreeing cell
10//
11// The space (git 2.50, fsck.h FOREACH_FSCK_MSG_ID, default severities under --strict):
12// FATAL nulInHeader unterminatedHeader error
13// ERROR missingTree badTreeSha1 badParentSha1 missingAuthor multipleAuthors missingCommitter
14// missingNameBeforeEmail badName missingEmail missingSpaceBeforeEmail badEmail
15// missingSpaceBeforeDate badDate zeroPaddedDate badDateOverflow badTimezone
16// missingObject badObjectSha1 missingTypeEntry missingType badType missingTagEntry missingTag error
17// WARN nulInCommit --strict makes it an error
18// INFO badTagName missingTaggerEntry a warning even under --strict (exit 0)
19// IGNORE extraHeaderEntry not reported at all
20// fsck_commit stops reading headers after committer: anything later (encoding, gpgsig, mergetag, unknown headers, a
21// second tree/parent/author/committer, a line with no space) is not checked. fsck_tag stops after tagger the same way,
22// and never looks at the tag body: a NUL there is accepted, unlike in a commit.
23import { test } from 'vitest';
24import assert from 'node:assert/strict';
25import { spawn } from 'node:child_process';
26import { mkdtempSync, rmSync, writeFileSync, mkdirSync, readFileSync } from 'node:fs';
27import { tmpdir, availableParallelism } from 'node:os';
28import { join } from 'node:path';
29import { deflateSync } from 'node:zlib';
30import { createHash } from 'node:crypto';
31import { assertFetched, parseCommit, parseTag, hashObject } from '../src/objects.js';
32import { commitView } from '../src/read.js';
33import { unwrap } from './unwrap.js';
35// ---- the fsck oracle (test/server.js `fsck` / `fsckProblemsOf` semantics, PR #53; one run per store) ----
36// git 2.50 prints an object problem as `error in <type> <oid>: <msgId>: <text>` or `warning in <type> <oid>: …` on
37// stderr; connectivity as `broken link from …`/`missing …` on stdout; a damaged store as `error:`/`fatal:`. Notices say
38// nothing about an object. A continuation line is folded into the line before it. Exit bits beyond 1 (object) and 2
39// (connectivity) are a store or git failure and throw. Every line must be pinned to a cell or the test throws: a
40// problem no cell owns would otherwise be dropped.
41function run(cmd, args, { cwd, input } = {}) {
42 return new Promise((resolve, reject) => {
43 const p = spawn(cmd, args, { cwd });
44 const out = [], err = [];
45 p.stdout.on('data', d => out.push(d));
46 p.stderr.on('data', d => err.push(d));
47 p.on('error', reject);
48 p.on('close', status => resolve({ status, stdout: Buffer.concat(out).toString('utf8'), stderr: Buffer.concat(err).toString('utf8') }));
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 });
55async function fsckLines(dir, { packed }) {
56 const r = await run('git', ['fsck', '--strict', '--no-dangling'], { cwd: dir });
57 const lines = [];
58 for (const l of `${r.stdout}\n${r.stderr}`.split('\n')) {
59 if (!l.trim() || l.startsWith('notice:')) continue;
60 if (/^\s/.test(l) && lines.length) lines[lines.length - 1] += ` ${l.trim()}`; else lines.push(l.trim());
61 }
62 // A packed object that does not parse is exit bit 4 (ERROR_PACK) where the same loose object is bit 1 (ERROR_OBJECT);
63 // the packed run allows that bit and nothing more, and the loose sample below holds the two runs to one verdict.
64 if (r.status === null || (r.status & ~(packed ? 7 : 3)) !== 0) throw new Error(`git fsck failed (exit ${r.status}): ${lines.join(' | ')}`);
65 if (r.status !== 0 && !lines.length) throw new Error(`git fsck exit ${r.status} with no output`);
66 return { status: r.status, lines };
69// ---- fixtures every store holds: the objects a cell points at ----
70const bin = s => Buffer.from(s, 'latin1');
71const CANON = 'A U Thor <a@b.c> 1700000000 +0000';
72const CANON2 = 'B Other <b@b.c> 1700000001 +0100';
73const EMPTY_TREE = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
74const BLOB = 'hello\n';
75const BLOB_OID = hashObject('blob', bin(BLOB));
76const P1_TEXT = `tree ${EMPTY_TREE}\nauthor ${CANON}\ncommitter ${CANON}\n\np1\n`;
77const P1 = hashObject('commit', bin(P1_TEXT));
78const P2_TEXT = `tree ${EMPTY_TREE}\nauthor ${CANON2}\ncommitter ${CANON2}\n\np2\n`;
79const P2 = hashObject('commit', bin(P2_TEXT));
80const OTHER_TREE = 'a'.repeat(40);
81const FIXTURES = [['tree', ''], ['blob', BLOB], ['commit', P1_TEXT], ['commit', P2_TEXT]];
83// ---- axes ----
84// ident shape: one fsck_ident rule each, applied to one role (author or committer of a commit, tagger of a tag).
85// Strings are latin1 byte strings: \xF6 is the byte 0xF6.
86const IDENT = {
87 ok: CANON,
88 'ok-empty-email': 'A <> 1700000000 +0000',
89 'ok-space-name': ' <a@b.c> 1700000000 +0000',
90 'ok-ws-before-date': 'A <a@b.c> \t 1700000000 +0000',
91 'ok-zero-date': 'A <a@b.c> 0 +0000',
92 'ok-max-date': 'A <a@b.c> 9223372036854775807 +0000',
93 'ok-tz-unranged': 'A <a@b.c> 1700000000 +9999',
94 'ok-tz-negative': 'A <a@b.c> 1700000000 -0730',
95 'ok-utf8-name': 'J\xC3\xB6rg <j@b.c> 1700000000 +0000',
96 'ok-latin1-name': 'J\xF6rg <j@b.c> 1700000000 +0000',
97 'ok-email-spaces': 'A <a b@c d> 1700000000 +0000',
98 'missing-name-before-email': '<a@b.c> 1700000000 +0000',
99 'bad-name': 'A > B <a@b.c> 1700000000 +0000',
100 'bad-name-gt-only': 'A a@b.c> 1700000000 +0000',
101 'missing-email': 'A U Thor 1700000000 +0000',
102 'missing-space-before-email': 'A<a@b.c> 1700000000 +0000',
103 'bad-email-unclosed': 'A <a@b.c 1700000000 +0000',
104 'bad-email-second-lt': 'A <a<b@c> 1700000000 +0000',
105 'missing-space-before-date': 'A <a@b.c>1700000000 +0000',
106 'missing-date': 'A <a@b.c>',
107 'bad-date-word': 'A <a@b.c> soon +0000',
108 'bad-date-trailing': 'A <a@b.c> 17x +0000',
109 'bad-date-empty': 'A <a@b.c> +0000',
110 'bad-date-tab-before-tz': 'A <a@b.c> 1700000000\t+0000',
111 'bad-date-no-tz': 'A <a@b.c> 1700000000',
112 'date-overflow': 'A <a@b.c> 9223372036854775808 +0000',
113 'date-overflow-huge': 'A <a@b.c> 99999999999999999999999 +0000',
114 'zero-padded-date': 'A <a@b.c> 01700000000 +0000',
115 'zero-padded-00': 'A <a@b.c> 00 +0000',
116 'bad-tz-short': 'A <a@b.c> 1700000000 +000',
117 'bad-tz-long': 'A <a@b.c> 1700000000 +00000',
118 'bad-tz-nosign': 'A <a@b.c> 1700000000 0000',
119 'bad-tz-nondigit': 'A <a@b.c> 1700000000 +00a0',
120 'bad-tz-trailing': 'A <a@b.c> 1700000000 +0000 ',
121 'bad-tz-double-space': 'A <a@b.c> 1700000000 +0000',
122 'nul-in-ident': 'A\0B <a@b.c> 1700000000 +0000',
123};
125// body: what follows the headers. `blank: false` appends the text as header lines (no blank line before it).
126const BODY = {
127 text: { blank: true, text: 'subject\n\nbody\n' },
128 none: { blank: false, text: '' },
129 empty: { blank: true, text: '' },
130 nul: { blank: true, text: 'sub\0ject\n' },
131 'non-utf8': { blank: true, text: 'caf\xE9 \xFF\xFE\n' },
132 'crlf-body': { blank: true, text: 'subject\r\n\r\nbody\r\n' },
133 'missing-blank-word': { blank: false, text: 'subject\n' },
134 'missing-blank-text': { blank: false, text: 'hello world\n' },
135 'missing-blank-unterminated': { blank: false, text: 'subject' },
136};
138// line ending: every LF in the object, or every LF turned into CRLF
139const EOL = { lf: s => s, crlf: s => s.replace(/\n/g, '\r\n') };
141// commit header: the lines fsck_commit reads (tree, parents, author, committer) and what follows them. `a` and `c` are
142// the author and committer idents for the cell; the ident axis replaces one of them.
143const COMMIT_HEADER = {
144 'parents-0': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`],
145 'parents-1': (a, c) => [`tree ${EMPTY_TREE}`, `parent ${P1}`, `author ${a}`, `committer ${c}`],
146 'parents-many': (a, c) => [`tree ${EMPTY_TREE}`, `parent ${P1}`, `parent ${P2}`, `author ${a}`, `committer ${c}`],
147 'tree-missing': (a, c) => [`author ${a}`, `committer ${c}`],
148 'tree-short': (a, c) => [`tree ${EMPTY_TREE.slice(1)}`, `author ${a}`, `committer ${c}`],
149 'tree-upper': (a, c) => [`tree ${EMPTY_TREE.toUpperCase()}`, `author ${a}`, `committer ${c}`],
150 'tree-junk': (a, c) => [`tree ${EMPTY_TREE} x`, `author ${a}`, `committer ${c}`],
151 'tree-twice': (a, c) => [`tree ${EMPTY_TREE}`, `tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`],
152 'tree-not-first': (a, c) => [`parent ${P1}`, `tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`],
153 'parent-bad': (a, c) => [`tree ${EMPTY_TREE}`, `parent ${'z'.repeat(40)}`, `author ${a}`, `committer ${c}`],
154 'parent-upper': (a, c) => [`tree ${EMPTY_TREE}`, `parent ${P1.toUpperCase()}`, `author ${a}`, `committer ${c}`],
155 'parent-after-author': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `parent ${P1}`, `committer ${c}`],
156 'author-missing': (a, c) => [`tree ${EMPTY_TREE}`, `committer ${c}`],
157 'author-twice': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `author ${CANON2}`, `committer ${c}`],
158 'committer-missing': (a) => [`tree ${EMPTY_TREE}`, `author ${a}`],
159 'committer-first': (a, c) => [`tree ${EMPTY_TREE}`, `committer ${c}`, `author ${a}`],
160 'encoding-before-committer': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, 'encoding UTF-8', `committer ${c}`],
161 'unknown-before-author': (a, c) => [`tree ${EMPTY_TREE}`, 'x-foo bar', `author ${a}`, `committer ${c}`],
162 encoding: (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'encoding ISO-8859-1'],
163 gpgsig: (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'gpgsig -----BEGIN PGP SIGNATURE-----', ' abc', ' -----END PGP SIGNATURE-----'],
164 mergetag: (a, c) => [`tree ${EMPTY_TREE}`, `parent ${P1}`, `author ${a}`, `committer ${c}`, `mergetag object ${P2}`, ' type commit', ' tag v1', ` tagger ${CANON}`, ' ', ' m'],
165 'unknown-after': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'x-foo bar'],
166 'unknown-nospace': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'foo'],
167 'orphan-continuation': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, ' orphan'],
168 'tree-after-committer': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, `tree ${OTHER_TREE}`],
169 'parent-after-committer': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, `parent ${P1}`],
170 'author-after-committer': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, `author ${CANON2}`],
171 'committer-twice': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, `committer ${CANON2}`],
172 'encoding-twice': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'encoding ISO-8859-1', 'encoding UTF-8'],
173 'encoding-after-gpgsig': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'gpgsig x', ' y', 'encoding ISO-8859-1'],
174 'garbage-after-committer': (a, c) => [`tree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`, 'committer garbage'],
175 bom: (a, c) => [`\xEF\xBB\xBFtree ${EMPTY_TREE}`, `author ${a}`, `committer ${c}`],
176 'empty-object': () => null,
177};
178const COMMIT_ROLE = ['author', 'committer'];
180// tag header: what fsck_tag_standalone reads (object, type, tag, tagger) and what follows
181const TAG_HEADER = {
182 ok: t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`],
183 'type-blob': t => [`object ${BLOB_OID}`, 'type blob', 'tag v1', `tagger ${t}`],
184 'type-tree': t => [`object ${EMPTY_TREE}`, 'type tree', 'tag v1', `tagger ${t}`],
185 'object-missing': t => ['type commit', 'tag v1', `tagger ${t}`],
186 'object-bad': t => [`object ${'z'.repeat(40)}`, 'type commit', 'tag v1', `tagger ${t}`],
187 'object-upper': t => [`object ${P1.toUpperCase()}`, 'type commit', 'tag v1', `tagger ${t}`],
188 'type-missing': t => [`object ${P1}`, 'tag v1', `tagger ${t}`],
189 'type-bad': t => [`object ${P1}`, 'type commi', 'tag v1', `tagger ${t}`],
190 'type-empty': t => [`object ${P1}`, 'type ', 'tag v1', `tagger ${t}`],
191 'tag-missing': t => [`object ${P1}`, 'type commit', `tagger ${t}`],
192 'tag-name-bad': t => [`object ${P1}`, 'type commit', 'tag v1..2', `tagger ${t}`],
193 'tag-name-empty': t => [`object ${P1}`, 'type commit', 'tag ', `tagger ${t}`],
194 'tagger-missing': () => [`object ${P1}`, 'type commit', 'tag v1'],
195 'tagger-missing-extra': () => [`object ${P1}`, 'type commit', 'tag v1', 'x-foo bar'],
196 'tagger-missing-extra-tagger': t => [`object ${P1}`, 'type commit', 'tag v1', 'tag v2', `tagger ${t}`],
197 'object-after-tagger': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, `object ${P2}`],
198 'type-after-tagger': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, 'type blob'],
199 'tag-after-tagger': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, 'tag v2'],
200 'tagger-twice': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, `tagger ${CANON2}`],
201 'unknown-after': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, 'x-foo bar'],
202 'unknown-nospace': t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, 'foo'],
203 gpgsig: t => [`object ${P1}`, 'type commit', 'tag v1', `tagger ${t}`, 'gpgsig -----BEGIN', ' abc'],
204 'type-before-object': t => ['type commit', `object ${P1}`, 'tag v1', `tagger ${t}`],
205 bom: t => [`\xEF\xBB\xBFobject ${P1}`, 'type commit', 'tag v1', `tagger ${t}`],
206 'empty-object': () => null,
207};
209function assemble(head, body, eol) {
210 if (head === null) return '';
211 const b = BODY[body];
212 const text = b.blank ? `${head.join('\n')}\n\n${b.text}` : `${head.join('\n')}\n${b.text}`;
213 return EOL[eol](text);
216function* cells() {
217 for (const [h, build] of Object.entries(COMMIT_HEADER)) for (const [i, shape] of Object.entries(IDENT))
218 for (const role of COMMIT_ROLE) for (const body of Object.keys(BODY)) for (const eol of Object.keys(EOL)) {
219 const head = build(role === 'author' ? shape : CANON, role === 'committer' ? shape : CANON);
220 yield { type: 'commit', axes: { header: h, ident: i, role, body, eol }, data: bin(assemble(head, body, eol)) };
221 }
222 for (const [h, build] of Object.entries(TAG_HEADER)) for (const [i, shape] of Object.entries(IDENT))
223 for (const body of Object.keys(BODY)) for (const eol of Object.keys(EOL))
224 yield { type: 'tag', axes: { header: h, ident: i, role: 'tagger', body, eol }, data: bin(assemble(build(shape), body, eol)) };
227// A warning git still accepts the object under: what ply does with it, and why.
228// badTagName accept: the tag header's name is not a ref ply creates; git checks it as a refname only to
229// warn. Refs ply writes are validated separately (validate.js, `git check-ref-format`).
230// missingTaggerEntry accept: tags older than git 0.99.1 have no tagger (git.git's own v0.99 is one); git reads them.
231const WARN_DECISION = { badTagName: 'accept', missingTaggerEntry: 'accept' };
233// An object git accepts that ply refuses on purpose, with the typed msgId it refuses with and why. Every other
234// accepted cell must be accepted.
235// duplicateHeader a second tree, parent, author, committer or encoding after the committer, or a second
236// object, type, tag or tagger after the tagger:
237// fsck-clean, but git's views of the object disagree (pretty.c's %an/%cn show the last
238// author/committer line, %T and the commit date the first; cat-file shows a late parent %P
239// ignores, and a late tag object/type/name the parsed tag ignores), so any value ply showed is contradicted by some git view: an author-spoofing
240// differential. Refused since PR #7 ("Reject duplicate commit/tag headers (git differential)").
241const ALLOWED_REFUSAL = { duplicateHeader: 'PR #7: git views of the object disagree' };
242// The header shapes those refusals may come from; a refusal anywhere else is a disagreement.
243const ALLOWED_REFUSAL_HEADERS = new Set([
244 'commit:tree-after-committer', 'commit:parent-after-committer', 'commit:author-after-committer', 'commit:committer-twice',
245 'commit:encoding-twice', 'commit:garbage-after-committer', 'tag:tagger-twice', 'tag:tagger-missing-extra-tagger',
246 'tag:object-after-tagger', 'tag:type-after-tagger', 'tag:tag-after-tagger',
247]);
249const msgIdOf = line => /^(?:error|warning) in \w+ [0-9a-f]{40}: (\w+):/.exec(line)?.[1] ?? null;
250const plyVerdict = (fn) => {
251 try { fn(); return { verdict: 'accept', msgId: null }; } catch (e) {
252 if (e?.code !== 'pack_corrupt') throw e;
253 return { verdict: 'reject', msgId: e.msgId ?? /^\w+: (\w+):/.exec(e.message)?.[1] ?? e.message };
254 }
255};
257// How the cells reach the store. The full space goes in one pack per shard, framed here with node:zlib (not ply's pack
258// writer) and indexed by `git index-pack` without --strict, which judges nothing: git hashes every object from its
259// bytes and type, and `git show-index` must list exactly the oids ply computed. Writing each object with `git hash-object
260// -t <type> --literally -w` costs about 0.5 ms an object on APFS (a minute for the space), so that literal path runs
261// on a fixed sample of every LOOSE_EVERY-th cell (all of them with FSCK_SPACE_LOOSE=1), and the sample's verdicts and
262// msgIds must equal the packed run's, object for object.
263const LOOSE_EVERY = process.env.FSCK_SPACE_LOOSE ? 1 : 25;
264const TYPE_CODE = { commit: 1, tree: 2, blob: 3, tag: 4 };
266async function writeLoose(dir, objs) {
267 mkdirSync(join(dir, 'in'), { recursive: true });
268 for (const type of ['tree', 'blob', 'commit', 'tag']) {
269 const mine = objs.filter(o => o.type === type);
270 if (!mine.length) continue;
271 const paths = mine.map((o, k) => { const p = join(dir, 'in', `${type}-${k}`); writeFileSync(p, o.data); return p; });
272 const r = await run('git', ['hash-object', '-t', type, '--literally', '-w', '--stdin-paths'], { cwd: dir, input: paths.join('\n') + '\n' });
273 assert.equal(r.status, 0, r.stderr);
274 assert.deepEqual(r.stdout.trim().split('\n'), mine.map(o => o.oid), `git and ply hash every ${type} alike`);
275 }
276 rmSync(join(dir, 'in'), { recursive: true, force: true });
279async function writePack(dir, objs) {
280 const parts = [Buffer.from('PACK'), Buffer.from([0, 0, 0, 2]), Buffer.alloc(4)];
281 parts[2].writeUInt32BE(objs.length);
282 for (const o of objs) {
283 let size = o.data.length;
284 const head = [(TYPE_CODE[o.type] << 4) | (size & 0x0f)];
285 size >>= 4;
286 while (size) { head[head.length - 1] |= 0x80; head.push(size & 0x7f); size >>= 7; }
287 parts.push(Buffer.from(head), deflateSync(o.data));
288 }
289 const body = Buffer.concat(parts);
290 const pack = Buffer.concat([body, createHash('sha1').update(body).digest()]);
291 const r = await run('git', ['index-pack', '--stdin'], { cwd: dir, input: pack });
292 assert.equal(r.status, 0, r.stderr);
293 const idx = join(dir, 'objects', 'pack', `pack-${r.stdout.trim().split(/\s+/).pop()}.idx`);
294 const listed = await run('git', ['show-index'], { cwd: dir, input: readFileSync(idx) });
295 assert.equal(listed.status, 0, listed.stderr);
296 assert.deepEqual(listed.stdout.trim().split('\n').map(l => l.split(' ')[1]).sort(), objs.map(o => o.oid).sort(), 'git hashes every object as ply does');
299// Judge `objs` with git fsck --strict, sharded over stores; returns oid → the fsck lines pinned to it.
300async function judge(objs, { loose }) {
301 const shards = Math.max(1, Math.min(8, availableParallelism()));
302 const root = mkdtempSync(join(tmpdir(), 'ply-fsck-space-'));
303 const out = new Map();
304 try {
305 await Promise.all(Array.from({ length: shards }, async (_, s) => {
306 const dir = join(root, `s${s}`);
307 const init = await run('git', ['init', '-q', '--bare', dir]);
308 assert.equal(init.status, 0, init.stderr);
309 const mine = [...FIXTURES.map(([type, text], k) => ({ type, data: bin(text), oid: hashObject(type, bin(text)), fixture: k })), ...objs.filter((_, k) => k % shards === s)];
310 if (loose) await writeLoose(dir, mine); else await writePack(dir, mine);
311 const { lines } = await fsckLines(dir, { packed: !loose });
312 const index = new Map(mine.map(o => [o.oid, o]));
313 const got = new Map(mine.map(o => [o.oid, []]));
314 for (const l of lines) {
315 const owner = [...l.matchAll(/[0-9a-f]{40}/g)].map(m => index.get(m[0])).find(o => o && o.fixture === undefined);
316 if (!owner) throw new Error(`fsck line pinned to no cell: ${l}`);
317 got.get(owner.oid).push(l);
318 }
319 for (const o of mine) if (o.fixture !== undefined) { if (got.get(o.oid).length) throw new Error(`fixture ${o.oid} is not fsck-clean: ${got.get(o.oid)}`); } else out.set(o.oid, got.get(o.oid));
320 }));
321 } finally {
322 rmSync(root, { recursive: true, force: true });
323 }
324 return out;
327// git's verdict on one object from its lines: any line that is not a `warning in` is an error.
328function classify(lines) {
329 const errors = lines.filter(l => !l.startsWith('warning in ')).map(l => msgIdOf(l) ?? '');
330 const warnings = lines.filter(l => l.startsWith('warning in ')).map(msgIdOf);
331 return { verdict: errors.length ? 'error' : warnings.length ? 'warn' : 'ok', errors: errors.filter(Boolean), warnings };
334test('commit, tag and ident space: ply refuses exactly what git fsck --strict reports an error for', { timeout: 600_000 }, async () => {
335 // one cell per distinct object: axes that do not reach the bytes (an ident on a role the header drops) collapse
336 const byOid = new Map();
337 let product = 0;
338 for (const c of cells()) {
339 product++;
340 const oid = hashObject(c.type, c.data);
341 if (!byOid.has(oid)) byOid.set(oid, { ...c, oid, labels: [] });
342 byOid.get(oid).labels.push(c.axes);
343 }
344 const all = [...byOid.values()];
345 const packed = await judge(all, { loose: false });
346 const sample = all.filter((_, k) => k % LOOSE_EVERY === 0);
347 const loose = await judge(sample, { loose: true });
348 for (const c of sample) assert.deepEqual(classify(loose.get(c.oid)), classify(packed.get(c.oid)), `loose and packed fsck agree on ${c.oid}`);
349 for (const c of all) c.git = packed.get(c.oid);
351 const tally = { error: 0, warn: 0, ok: 0 };
352 const wrong = [], wrongMsg = [], wrongView = [], designed = [];
353 for (const c of all) {
354 const { verdict: gitVerdict, errors, warnings } = classify(c.git);
355 tally[gitVerdict]++;
356 let expect = gitVerdict === 'error' ? 'reject' : 'accept';
357 if (gitVerdict === 'warn') {
358 for (const w of warnings) assert.ok(WARN_DECISION[w], `git warns ${w} (${c.git}); decide it in WARN_DECISION`);
359 expect = warnings.some(w => WARN_DECISION[w] === 'reject') ? 'reject' : 'accept';
360 }
361 const gitMsg = errors.find(Boolean) ?? null;
362 const ply = plyVerdict(() => unwrap(assertFetched(c.type, c.data)));
363 const parsed = plyVerdict(() => (c.type === 'commit' ? unwrap(parseCommit(c.data)) : unwrap(parseTag(c.data))));
364 const view = c.type === 'commit' ? plyVerdict(() => unwrap(commitView(c.data))) : parsed;
365 const row = { oid: c.oid, type: c.type, axes: c.labels[0], git: c.git, ply };
366 const allowed = expect === 'accept' && ply.verdict === 'reject' && ALLOWED_REFUSAL[ply.msgId] && c.labels.every(l => ALLOWED_REFUSAL_HEADERS.has(`${c.type}:${l.header}`));
367 if (allowed) designed.push(row);
368 else if (ply.verdict !== expect) wrong.push(row);
369 else if (ply.verdict === 'reject' && gitMsg && ply.msgId !== gitMsg) wrongMsg.push({ ...row, gitMsg });
370 if (parsed.verdict !== ply.verdict || view.verdict !== ply.verdict) wrongView.push({ ...row, parsed, view });
371 }
372 const summary = `${product} product cells, loose sample ${sample.length}, ${all.length} distinct objects (commit ${all.filter(c => c.type === 'commit').length}, tag ${all.filter(c => c.type === 'tag').length}); git: ${tally.error} error, ${tally.warn} warning-only, ${tally.ok} clean; ply agrees on ${all.length - wrong.length - designed.length}, refuses ${designed.length} as designed (${Object.keys(ALLOWED_REFUSAL).join(', ')}), disagrees on ${wrong.length} verdicts, ${wrongMsg.length} msgIds, ${wrongView.length} read paths`;
373 console.log(summary);
374 if (process.env.FSCK_SPACE_LIST) for (const w of [...wrong, ...wrongMsg, ...wrongView]) console.log(JSON.stringify(w));
375 const show = rows => rows.slice(0, 5).map(r => `${r.type} ${JSON.stringify(r.axes)} git=${r.git.join(' | ') || 'clean'} ply=${r.ply.verdict}${r.ply.msgId ? `:${r.ply.msgId}` : ''}${r.gitMsg ? ` want ${r.gitMsg}` : ''}`).join('\n');
376 assert.equal(wrong.length, 0, `verdicts:\n${show(wrong)}`);
377 // every header shape in the allowed class is refused in at least one cell (the class is not vacuous)
378 for (const h of ALLOWED_REFUSAL_HEADERS) assert.ok(designed.some(r => `${r.type}:${r.axes.header}` === h), `no designed refusal from ${h}`);
379 assert.equal(wrongMsg.length, 0, `msgIds:\n${show(wrongMsg)}`);
380 assert.equal(wrongView.length, 0, `parseCommit/parseTag/commitView disagree with assertFetched:\n${show(wrongView)}`);
381});
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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 · 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=22
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
fetch2008.1 KiB · hit22 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=8319
git.response.cache=HIT
git.response.duration_ms=22
git.fetch.wants=1531f047af53960766f3df198063e53d54c75007
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=8319
git.pkt.payload.max=8298
git.sideband.band1.bytes=8297
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
a5e1a75179095e44
Request
1422adc7…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format