GitHubivarvong

ply

main
ply6 git calls191 ms26 KiB3 cachedprotocol v2
124 lines8.7 KiBRaw
1// The harness's repositories start no background maintenance: observed, not read from config.
2//
3// Why it matters: a test reads the object store right after a push returns (fsckProblems, ls-tree). git 2.56 on CI
4// failed that fsck with "packfile … index not opened" while a repack started by receive-pack was renaming packs (ci
5// runs 43067401434 and 43070027886). makeBareRepo sets gc.auto=0, maintenance.auto=false, receive.autoGc=false.
6//
7// The observation: two pushes over git http-backend into a repository with receive.unpackLimit=1 (each push stays a
8// pack) under GIT_TRACE2_EVENT, which every git process the server starts inherits and appends to. trace2's
9// `child_start` event carries the argv of each child a git process spawns; none may be `maintenance`, `gc` or `repack`.
10//
11// The forcing: the environment (GIT_CONFIG_COUNT/KEY_n/VALUE_n) sets gc.auto=1 and gc.autoPackLimit=1, so that any
12// `maintenance run --auto` that does start has work on the first pack and goes on to `gc --auto` and `repack`.
13// Environment config outranks the repository's file, so this DEFEATS the repository's gc.auto=0 on purpose: what is
14// left standing is receive.autoGc=false and maintenance.auto=false, which the environment does not name and which
15// stop the process before any task condition is asked. gc.auto=0 by itself is therefore not what this test proves
16// (it is the third line of defence, for a maintenance run somebody starts by hand); the test proves that the settings
17// that stop the spawn are present and are enough even when the gc task is willing.
18//
19// The control (same file, same forcing, same pushes): a repository made the same way with the three keys unset again
20// must show the `maintenance` child. Without it, an empty list could mean "trace2 did not record" or "this git never
21// starts maintenance from receive-pack" (git before 2.29 ran `gc --auto` there instead; the control accepts either
22// name). If the control shows no child on some git, the test fails rather than passing vacuously.
23import { test, beforeAll as before, afterAll as after } from 'vitest';
24import assert from 'node:assert/strict';
25import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
26import { join } from 'node:path';
27import { git, gitAsync, tmpRoot, makeBareRepo, startGitServer, NO_MAINTENANCE, initRepo } from './server.js';
29// PLY_TEST_AUTO_MAINTENANCE=1: test/git-shim/git (below) stands aside for the server's git processes, so the first two
30// tests observe the repository's own settings and nothing else.
31const SHIM_OFF = { PLY_TEST_AUTO_MAINTENANCE: '1' };
32const FORCED = { GIT_CONFIG_COUNT: '2', GIT_CONFIG_KEY_0: 'gc.auto', GIT_CONFIG_VALUE_0: '1', GIT_CONFIG_KEY_1: 'gc.autoPackLimit', GIT_CONFIG_VALUE_1: '1' };
33const MAINTENANCE = new Set(['maintenance', 'gc', 'repack']);
35let root, cleanup, n = 0;
36before(() => { ({ root, cleanup } = tmpRoot()); });
37after(() => cleanup());
39// Two pushes into `bare` through a server whose git processes trace to one file. Returns the trace's events.
40async function pushTwice(bare, name) {
41 const trace = join(root, `trace-${name}.jsonl`);
42 const srv = await startGitServer(root, { ...FORCED, ...SHIM_OFF, GIT_TRACE2_EVENT: trace });
43 try {
44 const work = join(root, `work${n++}`); mkdirSync(work);
45 initRepo(work);
46 for (const k of [1, 2]) {
47 writeFileSync(join(work, 'f.txt'), `${k}\n`);
48 git(work, ['add', 'f.txt']);
49 git(work, ['-c', 'user.name=t', '-c', 'user.email=t@x', '-c', 'commit.gpgsign=false', 'commit', '-q', '-m', `c${k}`]);
50 const pushed = await gitAsync(work, ['push', '-q', `${srv.url}/${name}.git`, 'HEAD:refs/heads/main']); // async: the server is this process
51 assert.equal(pushed.status, 0, pushed.stderr);
52 }
53 } finally { await srv.close(); }
54 assert.ok(existsSync(trace), 'the server-side git processes wrote a trace2 event file');
55 const events = readFileSync(trace, 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l));
56 // Each push stayed a pack (receive.unpackLimit=1): the state gc.autoPackLimit=1 calls "too many packs".
57 const packs = git(bare, ['count-objects', '-v']).match(/^packs: (\d+)$/m);
58 assert.equal(packs && packs[1], '2', 'two pushes left two packs: nothing repacked them, and the forcing had packs to see');
59 return events;
61// argv[1] of each child a traced git process started that is a git maintenance command ("git maintenance run --auto",
62// "git gc --auto", "git repack -d -l"), and the commands that ran, to show receive-pack is in the trace at all.
63const children = events => events.filter(e => e.event === 'child_start' && Array.isArray(e.argv)).map(e => e.argv.filter(a => !a.startsWith('-')).slice(0, 3)).filter(argv => argv.some(a => MAINTENANCE.has(a))).map(argv => argv.join(' '));
64const ranReceivePack = events => events.some(e => e.event === 'cmd_name' && e.name === 'receive-pack');
66test('harness: a makeBareRepo repository starts no maintenance, gc or repack child after a push, with the gc task forced willing', async () => {
67 const bare = makeBareRepo(root, 'quiet');
68 git(bare, ['config', 'receive.unpackLimit', '1']);
69 const events = await pushTwice(bare, 'quiet');
70 assert.ok(ranReceivePack(events), 'receive-pack is in the trace');
71 assert.deepEqual(children(events), []);
72});
74test('harness control: the same repository with the three keys unset does start maintenance (the observation can see it)', async () => {
75 const bare = makeBareRepo(root, 'loud');
76 git(bare, ['config', 'receive.unpackLimit', '1']);
77 for (const [k] of NO_MAINTENANCE) git(bare, ['config', '--unset', k]);
78 // One push is enough: receive-pack starts the child whatever the pack count. The two-pack check of pushTwice is
79 // not asked here, because this repository may be repacked in the background (the defect itself).
80 const trace = join(root, 'trace-loud.jsonl');
81 const srv = await startGitServer(root, { ...FORCED, ...SHIM_OFF, GIT_TRACE2_EVENT: trace });
82 try {
83 const work = join(root, `work${n++}`); mkdirSync(work);
84 initRepo(work);
85 writeFileSync(join(work, 'f.txt'), '1\n');
86 git(work, ['add', 'f.txt']);
87 git(work, ['-c', 'user.name=t', '-c', 'user.email=t@x', '-c', 'commit.gpgsign=false', 'commit', '-q', '-m', 'c1']);
88 const pushed = await gitAsync(work, ['push', '-q', `${srv.url}/loud.git`, 'HEAD:refs/heads/main']);
89 assert.equal(pushed.status, 0, pushed.stderr);
90 } finally { await srv.close(); }
91 const events = readFileSync(trace, 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l));
92 assert.ok(ranReceivePack(events), 'receive-pack is in the trace');
93 const seen = children(events);
94 assert.ok(seen.some(c => /\b(maintenance|gc)\b/.test(c)), `receive-pack started maintenance without the three keys; saw ${JSON.stringify(seen)}`);
95});
97// ---- every git process the suite starts (test/git-shim/git, first on PATH from vitest.config.ts) ----
98// The files that make their own repositories hand git an environment of their own: GIT_* scrubbed and
99// GIT_CONFIG_GLOBAL=/dev/null (test/space/refname.test.js, push-oid.test.js), or their own GIT_CONFIG_COUNT
100// (test/stamps.test.js, merge.test.js, rebase.test.js). This is that environment, with the gc task forced willing the
101// same way, in a repository made by a bare `git init` that nothing configured: `git commit` starts
102// `git maintenance run --auto` there by git's default (builtin/commit.c: run_auto_maintenance), which the control
103// (the same steps with the shim told to stand aside) must show.
104function commitTraced(name, extraEnv = {}) {
105 const dir = join(root, name), trace = join(root, `trace-${name}.jsonl`);
106 const env = { PATH: process.env.PATH, HOME: root, GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null', ...FORCED, PLY_TEST_AUTO_MAINTENANCE: '', GIT_TRACE2_EVENT: trace, ...extraEnv };
107 mkdirSync(dir);
108 git(dir, ['init', '-q', '-b', 'main'], { env });
109 writeFileSync(join(dir, 'f.txt'), '1\n');
110 git(dir, ['add', 'f.txt'], { env });
111 git(dir, ['-c', 'user.name=t', '-c', 'user.email=t@x', '-c', 'commit.gpgsign=false', 'commit', '-q', '-m', 'c1'], { env });
112 const events = readFileSync(trace, 'utf8').split('\n').filter(Boolean).map(l => JSON.parse(l));
113 assert.ok(events.some(e => e.event === 'cmd_name' && e.name === 'commit'), 'commit is in the trace');
114 return children(events);
117test('harness: git commit in an unconfigured repository, under a scrubbed environment with its own GIT_CONFIG_COUNT, starts no maintenance child', () => {
118 assert.deepEqual(commitTraced('bare-init'), []);
119});
121test('harness control: the same commit with PLY_TEST_AUTO_MAINTENANCE=1 does start maintenance', () => {
122 const seen = commitTraced('bare-init-loud', { PLY_TEST_AUTO_MAINTENANCE: '1' });
123 assert.ok(seen.some(c => /\b(maintenance|gc)\b/.test(c)), `git commit started maintenance by default; saw ${JSON.stringify(seen)}`);
124});
Diagnostics6 git calls · 191 ms
CallStatusSizeTime0191 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 KiB93 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=93
git.response.bytes=11990
git.response.cache=EXPIRED
git.response.duration_ms=93
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
fetch2003.2 KiB89 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=89
git.response.bytes=3251
git.response.cache=MISS
git.response.duration_ms=89
git.fetch.wants=345bf2b27f7d5ea3ce412a9d4ec4d611dec9335d
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=3251
git.pkt.payload.max=3224
git.sideband.band1.bytes=3224
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
a5e19286aef4ddf0
Request
89a4cb35…
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