main
1// The fsck oracle's own mutation test: every suite's "git fsck --strict is clean" goes through fsckProblems /
2// fsckProblemsOf in test/server.js, so each must report each way git 2.50 says an object is bad. Feed it known-bad
3// objects (duplicate entry, zero-padded mode, bad mode, bad ident, missing tagger, missing object, damaged object
4// file, dangling) and it must say so; a clean store must say nothing. The old `l.startsWith('error:')` filter returned
5// [] for every one of these object problems, so its `assert.deepEqual(..., [])` could not fail.
6import { test } from 'vitest';
7import assert from 'node:assert/strict';
8import { mkdtempSync, rmSync, writeFileSync, chmodSync } from 'node:fs';
9import { tmpdir } from 'node:os';
10import { join } from 'node:path';
11import { gitBuf, fsck, fsckProblems, fsckProblemsOf } from './server.js';
13const run = (dir, args, input) => gitBuf(dir, args, input).toString().trim();
14const lit = (dir, type, data) => run(dir, ['hash-object', '-t', type, '-w', '--stdin', '--literally'], Buffer.from(data));
15const entry = (mode, name, oid) => Buffer.concat([Buffer.from(`${mode} ${name}\0`), Buffer.from(oid, 'hex')]);
16const ident = 'A <a@b.c> 1700000000 +0000';
18function withRepo(fn) {
19 const dir = mkdtempSync(join(tmpdir(), 'ply-fsck-oracle-'));
20 try {
21 run(dir, ['init', '-q', '-b', 'main']);
22 const blob = run(dir, ['hash-object', '-w', '--stdin'], Buffer.from('x\n'));
23 return fn(dir, blob);
24 } finally { rmSync(dir, { recursive: true, force: true }); }
25}
26// a commit over `tree`, on main, so the object is reachable and connectivity is checked too
27const onMain = (dir, tree, who = ident) => { const c = lit(dir, 'commit', `tree ${tree}\nauthor ${who}\ncommitter ${who}\n\nm\n`); run(dir, ['update-ref', 'refs/heads/main', c]); return c; };
29test('a clean store: [] from both, exit 0', () => withRepo((dir, blob) => {
30 const tree = lit(dir, 'tree', entry('100644', 'a', blob));
31 const c = onMain(dir, tree);
32 assert.equal(fsck(dir, ['--no-dangling']).status, 0);
33 assert.deepEqual(fsckProblems(dir), []);
34 assert.deepEqual(fsckProblemsOf(dir, tree), []);
35 assert.deepEqual(fsckProblemsOf(dir, c), []);
36}));
38// [label, build(dir, blob) → oid of the bad object, the msgId git reports, the exit fsck --strict gives]
39const BAD = [
40 ['duplicate tree entry', (d, b) => lit(d, 'tree', Buffer.concat([entry('100644', 'a', b), entry('100644', 'a', b)])), /^error in tree [0-9a-f]{40}: duplicateEntries: /, 1],
41 ['zero-padded mode', (d, b) => lit(d, 'tree', entry('0100644', 'a', b)), /^error in tree [0-9a-f]{40}: zeroPaddedFilemode: /, 1],
42 ['tree entries out of order', (d, b) => lit(d, 'tree', Buffer.concat([entry('100644', 'b', b), entry('100644', 'a', b)])), /^error in tree [0-9a-f]{40}: treeNotSorted: /, 1],
43 ['.git in a tree', (d, b) => lit(d, 'tree', entry('100644', '.git', b)), /^error in tree [0-9a-f]{40}: hasDotgit: /, 1],
44 // an INFO id: still a warning under --strict, and fsck exits 0 — an exit-code-only oracle misses it
45 ['bad file mode 100664', (d, b) => lit(d, 'tree', entry('100664', 'a', b)), /^warning in tree [0-9a-f]{40}: badFilemode: /, 0],
46 ['bad ident (no "<")', (d, b) => { const t = lit(d, 'tree', entry('100644', 'a', b)); return onMain(d, t, 'A a@b.c> 1700000000 +0000'); }, /^error in commit [0-9a-f]{40}: badName: /, 1],
47 ['bad timezone', (d, b) => { const t = lit(d, 'tree', entry('100644', 'a', b)); return onMain(d, t, 'A <a@b.c> 1700000000 +00'); }, /^error in commit [0-9a-f]{40}: badTimezone: /, 1],
48 ['tag without a tagger', (d, b) => { const t = lit(d, 'tree', entry('100644', 'a', b)); const c = onMain(d, t); const tag = lit(d, 'tag', `object ${c}\ntype commit\ntag v1\n\nm\n`); run(d, ['update-ref', 'refs/tags/v1', tag]); return tag; }, /^warning in tag [0-9a-f]{40}: missingTaggerEntry: /, 0],
49 // stdout, not stderr; exit 2
50 ['missing tree', d => onMain(d, 'a'.repeat(40)), /^broken link from +commit [0-9a-f]{40} to +tree a{40}$/, 2],
51];
53for (const [label, build, report, exit] of BAD) {
54 test(`the oracle can fail: ${label}`, () => withRepo((dir, blob) => {
55 const oid = build(dir, blob);
56 const { status, lines } = fsck(dir, ['--no-dangling']);
57 assert.equal(status, exit, lines.join('\n'));
58 assert.ok(lines.some(l => report.test(l)), `git's report: ${lines.join(' | ')}`);
59 assert.ok(!lines.some(l => l.startsWith('error:')), 'git 2.50 never prefixes an object problem with "error:" (what the old filter required)');
60 const all = fsckProblems(dir);
61 assert.notDeepEqual(all, [], 'fsckProblems reports it');
62 assert.ok(all.some(l => report.test(l)), all.join(' | '));
63 assert.ok(fsckProblemsOf(dir, oid).some(l => report.test(l)), 'fsckProblemsOf pins it to the object');
64 }));
65}
67test('the oracle can fail: a damaged loose object file (the `error:` shape)', () => withRepo((dir, blob) => {
68 const tree = lit(dir, 'tree', entry('100644', 'a', blob));
69 onMain(dir, tree);
70 const path = join(dir, '.git', 'objects', blob.slice(0, 2), blob.slice(2));
71 chmodSync(path, 0o644); writeFileSync(path, Buffer.from('not zlib'));
72 const p = fsckProblems(dir);
73 assert.ok(p.some(l => l.startsWith('error:')), p.join(' | '));
74 assert.ok(p.some(l => /exit [1-9]/.test(l)), p.join(' | '));
75}));
77test('dangling objects: silenced by default, reported with dangling: true', () => withRepo((dir, blob) => {
78 onMain(dir, lit(dir, 'tree', entry('100644', 'a', blob)));
79 const stray = run(dir, ['hash-object', '-w', '--stdin'], Buffer.from('stray\n'));
80 assert.deepEqual(fsckProblems(dir), []);
81 assert.deepEqual(fsckProblems(dir, { dangling: true }), [`dangling blob ${stray}`]);
82}));
84test('fsckProblemsOf: one bad object does not taint a good one in the same store', () => withRepo((dir, blob) => {
85 const bad = lit(dir, 'tree', Buffer.concat([entry('100644', 'a', blob), entry('100644', 'a', blob)]));
86 const good = lit(dir, 'tree', entry('100644', 'b', blob));
87 assert.notDeepEqual(fsckProblems(dir), []);
88 assert.deepEqual(fsckProblemsOf(dir, good), []);
89 assert.equal(fsckProblemsOf(dir, bad).length, 1);
90}));
92test('refusals: --connectivity-only (skips every format check) and an abbreviated oid', () => withRepo((dir, blob) => {
93 const bad = lit(dir, 'tree', Buffer.concat([entry('100644', 'a', blob), entry('100644', 'a', blob)]));
94 onMain(dir, bad);
95 // the fact behind the refusal: git itself passes a reachable duplicate-entry tree under --connectivity-only
96 assert.equal(run(dir, ['fsck', '--strict', '--connectivity-only', '--no-dangling']), '');
97 assert.throws(() => fsck(dir, ['--connectivity-only']), /not an oracle/);
98 assert.throws(() => fsckProblemsOf(dir, bad.slice(0, 7)), /full oid/);
99}));
Diagnostics4 git calls · 41 ms
CallStatusSizeTime041 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 · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 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=55Open pack map
fetch2002.3 KiB · hit35 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=35 git.response.bytes=2309 git.response.cache=HIT git.response.duration_ms=35 git.fetch.wants=462c5e0ba30b31c5c85a7186b26333c4d6fb4478 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=2309 git.pkt.payload.max=2288 git.sideband.band1.bytes=2287 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
- a5e1e4ce6830d96e
- Request
- 5fd2f690…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format