GitHubivarvong
ply
main
1// Generates the machine-checked parts of SPACE.md: the "Fsck tree entries" section from test/space/fsck-tree.space.js
2// (checked by test/space/fsck-tree.test.js), and the "Push outcome" section from test/space/push-outcome.space.js:
3// the axes (tagged unions) and their variants, the product size, the impossible and collapsed cells, the cell count,
4// the expected outcomes, and the cells observed from git. test/space/push-outcome.test.js fails if SPACE.md drifts.
5// node scripts/space-md.mjs print the block
6// node scripts/space-md.mjs --write rewrite it in SPACE.md
7import { readFileSync, writeFileSync } from 'node:fs';
8import { fileURLToPath } from 'node:url';
9import * as space from '../test/space/push-outcome.space.js';
10import { SCENARIOS, cellOf } from '../test/space/push-outcome.observed.js';
11import * as fsckTree from '../test/space/fsck-tree.space.js';
12import * as adv from '../test/space/advertisement.space.js';
14export const START = '<!-- push-outcome: generated by scripts/space-md.mjs; do not edit by hand -->';
15export const END = '<!-- push-outcome: end generated -->';
16const SPACE_MD = fileURLToPath(new URL('../SPACE.md', import.meta.url));
18const payload = v => Object.entries(v).filter(([k]) => !['tag', 'why', 'n'].includes(k)).map(([k, x]) => `${k}=${typeof x === 'object' ? x.tag : JSON.stringify(x)}`).join(', ');
19const label = o => (o.tag === 'rejected' || o.tag === 'preSend' ? `${o.tag}(${o.code})` : o.tag);
21export function observedCells() {
22 const by = new Map();
23 for (const [name, spec] of SCENARIOS) { const id = space.cellId(cellOf(spec)); by.set(id, [...(by.get(id) ?? []), name]); }
24 return by;
25}
27export function census() {
28 const outcomes = {};
29 const c = space.walk(cell => { const k = label(space.expected(cell)); outcomes[k] = (outcomes[k] ?? 0) + 1; });
30 return { census: c, outcomes };
31}
33export function block({ census: c, outcomes }) {
34 const L = [START, ''];
35 L.push('### Axes (tagged unions)', '');
36 for (const a of space.AXES) {
37 if (a.name === 'spread') {
38 L.push(`**${a.name}** — ${a.doc} (${a.variants.length} variants)`, '');
39 L.push('- `uniform` — every ref has `status`');
40 L.push(`- \`mixed\` — at ∈ {0, 1, 2} × odd ∈ the ${space.STATUS_TAGS.length} \`status\` tags: ${a.variants.length - 1} variants (the odd ref's status overrides \`status\` for ref \`at\`)`, '');
41 continue;
42 }
43 L.push(`**${a.name}** — ${a.doc} (${a.variants.length} variants)`, '');
44 for (const v of a.variants) L.push(`- \`${v.tag}\`${payload(v) ? ` (${payload(v)})` : ''} — ${v.why}`);
45 L.push('');
46 }
47 L.push('### Product', '');
48 L.push(`Raw product: ${space.AXES.map(a => `${a.variants.length}`).join(' × ')} = **${c.raw.toLocaleString('en-US')}** (${space.AXES.map(a => a.name).join(' × ')}).`, '');
49 L.push('| removed | why | raw cells |', '|---|---|---:|');
50 space.IMPOSSIBLE.forEach((r, i) => L.push(`| impossible | ${r.why} | ${(c[`impossible:${i}`] ?? 0).toLocaleString('en-US')} |`));
51 space.COLLAPSE.forEach((r, i) => L.push(`| collapsed | ${r.why} (${r.axes.join(', ')} keep their first variant) | ${(c[`collapsed:${i}`] ?? 0).toLocaleString('en-US')} |`));
52 L.push('');
53 L.push(`**Cells: ${c.cells.toLocaleString('en-US')}.** Expected outcomes: ${Object.entries(outcomes).sort((a, b) => b[1] - a[1]).map(([k, n]) => `${k} ${n.toLocaleString('en-US')}`).join(', ')}.`, '');
54 const obs = observedCells();
55 L.push(`### Observed from git (${obs.size} cells; the other ${(c.cells - obs.size).toLocaleString('en-US')} are derived)`, '');
56 for (const [id, names] of obs) L.push(`- \`${id}\` — ${names.join('; ')}`);
57 L.push('', END);
58 return L.join('\n');
59}
61export function splice(md, generated) {
62 const a = md.indexOf(START), b = md.indexOf(END);
63 if (a < 0 || b < 0) throw new Error('SPACE.md has no generated push-outcome block');
64 return md.slice(0, a) + generated + md.slice(b + END.length);
65}
66// ---- the fsck tree-entry section ----
67export const FT_START = '<!-- fsck-tree: generated by scripts/space-md.mjs; do not edit by hand -->';
68export const FT_END = '<!-- fsck-tree: end generated -->';
69const show = b => `"${b.toString('latin1').replace(/[^\x20-\x7e]/g, ch => `\\x${ch.charCodeAt(0).toString(16).padStart(2, '0')}`).replace(/([lm])\1{4095,}/, (m, ch) => `${ch}×${m.length}`)}"`;
70export function fsckTreeBlock() {
71 const L = [FT_START, ''];
72 L.push('### Axes (tagged unions)', '');
73 for (const a of fsckTree.AXES) {
74 L.push(`**${a.name}** — ${a.doc} (${a.variants.length} variants)`, '');
75 for (const v of a.variants) {
76 const what = v.raw !== undefined ? ` \`${v.raw}\`` : v.bytes ? ` ${show(v.bytes)}` : v.entry && v.entry !== 'same' ? ` \`${v.entry.mode} ${show(v.entry.name).slice(1, -1)}\`` : '';
77 L.push(`- \`${v.tag}\`${what} — ${v.why}`);
78 }
79 L.push('');
80 }
81 const cells = fsckTree.product();
82 const raw = fsckTree.AXES.reduce((n, a) => n * a.variants.length, 1);
83 const by = {}, ids = {};
84 for (const c of cells) {
85 const w = fsckTree.expected(c);
86 by[w.ply] = (by[w.ply] ?? 0) + 1;
87 for (const m of w.errors) ids[m] = (ids[m] ?? 0) + 1;
88 for (const m of w.warnings) ids[`${m} (warning)`] = (ids[`${m} (warning)`] ?? 0) + 1;
89 }
90 L.push('### Product', '');
91 L.push(`Raw product: ${fsckTree.AXES.map(a => a.variants.length).join(' × ')} = **${raw.toLocaleString('en-US')}** (${fsckTree.AXES.map(a => a.name).join(' × ')}); ${fsckTree.COLLAPSE.map(r => r.why).join('; ')}: **${cells.length.toLocaleString('en-US')} cells**.`, '');
92 L.push(`Expected: ply accepts ${(by.accept ?? 0).toLocaleString('en-US')}, refuses ${(by.refuse ?? 0).toLocaleString('en-US')}. Cells per msgId git reports (a cell can have several):`, '');
93 L.push('| msgId | cells |', '|---|---:|');
94 for (const [m, n] of Object.entries(ids).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))) L.push(`| \`${m}\` | ${n.toLocaleString('en-US')} |`);
95 L.push('', '### Decisions for the warnings git exits 0 on', '');
96 for (const [m, d] of Object.entries(fsckTree.WARN_DECISION)) L.push(`- \`${m}\` → ${d.ply}: ${d.why}`);
97 L.push('', FT_END);
98 return L.join('\n');
99}
100export function spliceFsckTree(md, generated) {
101 const a = md.indexOf(FT_START), b = md.indexOf(FT_END);
102 if (a < 0 || b < 0) throw new Error('SPACE.md has no generated fsck-tree block');
103 return md.slice(0, a) + generated + md.slice(b + FT_END.length);
104}
105export const currentFsckTree = () => { const md = readFileSync(SPACE_MD, 'utf8'); return md.slice(md.indexOf(FT_START), md.indexOf(FT_END) + FT_END.length); };
107export const current = () => { const md = readFileSync(SPACE_MD, 'utf8'); return md.slice(md.indexOf(START), md.indexOf(END) + END.length); };
108// the advertisement section's block (test/space/advertisement.space.js mdBlock)
109export const currentAdvertisement = () => { const md = readFileSync(SPACE_MD, 'utf8'); return md.slice(md.indexOf(adv.MD_START), md.indexOf(adv.MD_END) + adv.MD_END.length); };
110const spliceAdvertisement = (md, generated) => {
111 const a = md.indexOf(adv.MD_START), b = md.indexOf(adv.MD_END);
112 if (a < 0 || b < 0) throw new Error('SPACE.md has no generated advertisement block');
113 return md.slice(0, a) + generated + md.slice(b + adv.MD_END.length);
114};
116if (process.argv[1] === fileURLToPath(import.meta.url)) {
117 const g = block(census()), ft = fsckTreeBlock();
118 const ga = adv.mdBlock(adv.observedCounts());
119 if (process.argv.includes('--write')) writeFileSync(SPACE_MD, spliceAdvertisement(spliceFsckTree(splice(readFileSync(SPACE_MD, 'utf8'), g), ft), ga));
120 else console.log(`${g}\n\n${ft}\n\n${ga}`);
121}
Diagnostics6 git calls · 34 ms
CallStatusSizeTime034 ms
discover200191 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=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=10Open 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=5323b9266eea5ded637285d1c5320699f12be76eOpen pack map
fetchtree:0200831 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=831 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=b9290e370bd091fd3272931655a175dd1a7af82d 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=831 git.pkt.payload.max=804 git.sideband.band1.bytes=804 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=804 git.pack.trailer=81ddc1f73214935b4ee953ad84f959db955ce0d1Open pack map
fetch2002.6 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=2647 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=7ecc120e99f131e9c9af287be0547208c4c9c3e8 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=2647 git.pkt.payload.max=2620 git.sideband.band1.bytes=2620 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
- a5e2882259854af4
- Request
- 5e5fa906…
- 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