Artifactspublic-v0

ply

main
ply4 git calls585 ms41 KiB2 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});
Diagnostics4 git calls · 585 ms
CallStatusSizeTime0585 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
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 · 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=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
fetch2003.2 KiB580 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=580
git.response.bytes=3239
git.response.cache=MISS
git.response.duration_ms=580
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3239
git.pkt.payload.max=3218
git.sideband.band1.bytes=3217
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
a5e1e4515d5cd96e
Request
019a3008…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format