// The push-ng space (push-ng.space.js): every rejection reason git v2.50.0's receive-pack writes × the failing command's // shape × atomic × refs. Every cell's report goes through push() over the fake transport and must give the class // table's outcome; every cell git can be made to write is observed from real git (push-ng.observed.js): git's bytes must // be the derived report, ply's outcome on them the table's, and the repository's refs must agree. SPACE.md's "Push ng // reasons" block is generated here (PUSH_NG_WRITE=1 rewrites it). PUSH_NG_ONLY= observes one reason. import { test } from 'vitest'; import assert from 'node:assert/strict'; import { readFileSync, writeFileSync } from 'node:fs'; import * as space from './push-ng.space.js'; import { runPush, sameOutcome, label } from './harness.js'; const SPACE_MD = new URL('../../SPACE.md', import.meta.url); const START = ''; const END = ''; test('the reason axis is git\'s list: every "reject" entry of git-manifest.json, each with a class and its reason', () => { assert.equal(space.GIT_SOURCE.tag, 'v2.50.0'); assert.deepEqual(space.REASONS.map(r => r.id).sort(), space.MANIFEST_REJECTS.map(e => e.id).sort(), 'REASONS covers exactly the manifest\'s reject ids'); for (const r of space.REASONS) { assert.ok(space.CLASSES.includes(r.cls), `${r.id}: class ${r.cls}`); assert.ok(space.STAGES.includes(r.stage), `${r.id}: stage ${r.stage}`); assert.ok(r.next?.length > 40, `${r.id}: says what a caller can safely do next`); assert.ok(r.derived === undefined || r.derived.length > 30, `${r.id}: a derived reason says why it is not observed`); assert.ok(Array.isArray(r.commands), `${r.id}: commands`); } // the consequences have no cell of their own; every other reason has cells const census = {}; space.walk(c => { census[c.reason.tag] = (census[c.reason.tag] ?? 0) + 1; }); for (const v of space.axis('reason').variants) assert.ok(census[v.tag] > 0, `${v.tag} has cells`); }); test('src/push.js and the space agree on git\'s unpack failure strings', async () => { const { GIT_UNPACK_ERRORS } = await import('../../src/push.js'); assert.deepEqual([...GIT_UNPACK_ERRORS].sort(), space.REASONS.filter(r => r.stage === 'unpack').map(r => r.text).sort()); }); const outcomes = {}; test('push ng: every cell through push(), against the class table', async () => { Error.stackTraceLimit = 0; const census = space.walk(); const wrong = []; let n = 0; for (const c of space.cells()) { const want = space.expected(c), got = await runPush(space.render(c)); n++; outcomes[label(want)] = (outcomes[label(want)] ?? 0) + 1; if (!sameOutcome(want, got)) wrong.push(`${space.cellId(c)}: table ${label(want)}, ply ${label(got)}`); } Error.stackTraceLimit = 10; console.log(` push-ng: cells ${n} (raw product ${census.raw}; impossible ${census.impossible.join(' + ')}); expected ${JSON.stringify(outcomes)}; disagree ${wrong.length}`); for (const w of wrong.slice(0, 20)) console.log(` ${w}`); assert.equal(n, census.cells); assert.deepEqual(wrong, [], 'cells whose outcome differs from the table'); }); test('push ng: cells observed from git — git\'s report is the derived one, ply\'s outcome the table\'s, the refs agree', { timeout: 600_000 }, async () => { const { observeAll } = await import('./push-ng.observed.js'); const only = process.env.PUSH_NG_ONLY; const t0 = performance.now(); const { results, derived, rootUser, era, version } = await observeAll({ only }); const ms = performance.now() - t0; const problems = [], truth = {}; for (const o of results) { const want = space.expected(o.cell); const derivedBytes = Buffer.from(space.reportBytes(space.gitReport(o.cell))).toString(); const gitBytes = Buffer.from(o.bytes).toString(); if (gitBytes !== derivedBytes) { problems.push(`${o.id}: git wrote ${JSON.stringify(gitBytes)}, derived ${JSON.stringify(derivedBytes)}`); continue; } const got = await runPush({ commands: o.commands, opts: { sideband: false, reportV2: false, atomic: o.cell.atomic.tag === 'on', pushOptions: [] }, limits: { maxRefs: 8, maxReportLines: 16, maxPackBytes: 1 << 20 } }, { bytes: o.bytes, end: 'eof' }); if (!sameOutcome(want, got)) problems.push(`${o.id}: table ${label(want)}, ply ${label(got)}`); const moved = new Set(o.moved), refs = o.commands.map(x => x.ref); const wantMoved = want.tag === 'landed' ? refs : want.tag === 'partial' ? want.landed : want.tag === 'rejected' ? [] : null; if (wantMoved && (wantMoved.length !== moved.size || !wantMoved.every(r => moved.has(r)))) problems.push(`${o.id}: ${label(want)} but git moved [${o.moved}]`); if (want.tag === 'ambiguous') { const k = `${o.cell.reason.tag}: moved ${o.moved.length}/${refs.length}`; truth[k] = (truth[k] ?? 0) + 1; } } console.log(` push-ng: observed from git ${version} (era ${era}) ${results.length} cells in ${(ms / 1000).toFixed(1)} s, derived ${derived.length}${rootUser ? ' (root: permission recipes derived)' : ''}; ambiguous cells' truth: ${Object.entries(truth).map(([k, v]) => `${k} ×${v}`).join('; ')}`); for (const p of problems.slice(0, 20)) console.log(` ${p}`); assert.deepEqual(problems, []); if (!only) assert.equal(results.length + derived.length, space.walk().cells); }); test('SPACE.md\'s push-ng block is current', async t => { if (process.env.PUSH_NG_ONLY) return t.skip('PUSH_NG_ONLY'); const { observableAnywhere: observable } = await import('./push-ng.observed.js'); const per = new Map(); space.walk(c => { const p = per.get(c.reason.tag) ?? { cells: 0, observed: 0, codes: new Set() }; p.cells++; if (observable(c)) p.observed++; p.codes.add(label(space.expected(c))); per.set(c.reason.tag, p); }); const census = space.walk(); const totalObserved = [...per.values()].reduce((a, p) => a + p.observed, 0); const L = [START, '']; L.push(`Axes: ${space.AXES.map(a => `${a.name}(${a.variants.length})`).join(' × ')} = ${census.raw} raw; ${census.cells} cells after the impossible ones (${space.IMPOSSIBLE.map((r, i) => `${census.impossible[i]}: ${r.why}`).join('; ')}).`, ''); L.push(`Observable from real git: **${totalObserved}** cells (git's report byte for byte = the derived one, ply's outcome = the table's, refs agree), each on the git of its era: v2.50 cells on git 2.50 (a laptop), v2.51+ cells on git >= 2.51 (CI: 2.56); a run observes its own era's cells and derives the rest. Derived from receive-pack.c only: **${census.cells - totalObserved}** (on a run as root, the two permission recipes are derived too).`, ''); L.push('| reason (receive-pack.c line) | class | ply outcomes over its cells | cells (observed) | what a caller can safely do next |', '|---|---|---|---|---|'); for (const r of space.REASONS) { const tag = r.id.replace('receive-pack.c:reject:', ''); const p = per.get(tag); const cells = p ? `${p.cells} (${p.observed})` : `— (${r.stage === 'none' ? 'a consequence: rides on other cells' : 'none'})`; L.push(`| \`${r.text}\` (${r.line}${tag.endsWith('#2') ? ', 2nd site' : ''}) | ${r.cls} | ${p ? [...p.codes].sort().join(', ') : '—'} | ${cells} | ${r.next}${r.derived ? ` *Derived:* ${r.derived}.` : ''} |`); } L.push('', 'git >= 2.51 batched texts (era v2.51+, the non-atomic commit failure):', '', '| text | class | what a caller can safely do next |', '|---|---|---|'); for (const b of space.BATCHED) L.push(`| \`${b.text}\` | ${b.cls} | ${b.next} |`); L.push('', END); const block = L.join('\n'); const md = readFileSync(SPACE_MD, 'utf8'); const i = md.indexOf(START), j = md.indexOf(END); if (process.env.PUSH_NG_WRITE) { const next = i >= 0 ? md.slice(0, i) + block + md.slice(j + END.length) : `${md.trimEnd()}\n\n## Push ng reasons\n\nThe space of git's receive-pack rejection reasons (test/space/push-ng.space.js): every reason git v2.50.0 can write × the failing command's shape × atomic × refs. Each reason's class is data, justified by what a caller can safely do next; the report git writes for each cell is derived from receive-pack.c and checked byte for byte against real git where git can be made to write it (test/space/push-ng.observed.js).\n\n${block}\n`; writeFileSync(SPACE_MD, next); return; } assert.ok(i >= 0 && j > i, 'SPACE.md has no push-ng block: run PUSH_NG_WRITE=1 npx vitest run test/space/push-ng.test.js'); assert.equal(md.slice(i, j + END.length), block, 'SPACE.md push-ng block is stale: run PUSH_NG_WRITE=1 npx vitest run test/space/push-ng.test.js'); });