GitHubivarvong

ply

main
ply6 git calls40 ms25 KiB4 cachedprotocol v2
99 lines6.5 KiBRaw
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 }); }
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 }));
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}));
Diagnostics6 git calls · 40 ms
CallStatusSizeTime040 ms
discover200191 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=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB3 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=11990
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4347
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
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=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · 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=919
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:02005.6 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=5724
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=58fabb6768b3f737ee9cd8bac647bdc27405fb4d
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=5724
git.pkt.payload.max=5697
git.sideband.band1.bytes=5697
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=5697
git.pack.trailer=be7e0453974a5fe832f9065a33bb7e3434c10e9b
Open pack map
fetch2002.3 KiB · hit28 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=28
git.response.bytes=2316
git.response.cache=HIT
git.response.duration_ms=28
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2316
git.pkt.payload.max=2289
git.sideband.band1.bytes=2289
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://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e1a57c9b735e44
Request
5a8501b5…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format