GitHubivarvong
ply
main
1// The coverage matrix is checked, not remembered: every op is an export of its module, every test anchor is text in its
2// file, reference-git evidence cites a file that runs real git, run evidence names a recorded run and check, and
3// COVERAGE.md is the matrix rendered. The types (test/behaviours/types.ts, types.typetest.ts) refuse the rest.
4import { test } from 'vitest';
5import assert from 'node:assert/strict';
6import { readFileSync, existsSync } from 'node:fs';
7import { join, dirname } from 'node:path';
8import { fileURLToPath } from 'node:url';
9import { BEHAVIOURS } from './matrix.ts';
10import { RUNS } from './runs.ts';
11import { AREAS, EVIDENCE_KINDS } from './types.ts';
12import { renderMd, evidenceOf } from '../../scripts/coverage-matrix.mjs';
14const ROOT = join(fileURLToPath(import.meta.url), '..', '..', '..');
15const read = p => readFileSync(join(ROOT, p), 'utf8');
16const escapeRe = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
17// Test sources write an apostrophe inside a quoted name as \' : an anchor matches either spelling.
18const contains = (src, anchor) => src.includes(anchor) || src.includes(anchor.replace(/'/g, "\\'"));
20test('COVERAGE.md is `npm run coverage-matrix -- --md` of the matrix', () => {
21 assert.equal(read('COVERAGE.md'), renderMd(), 'COVERAGE.md is stale: run `npm run coverage-matrix -- --md`');
22});
24test('ids are unique, each id is `<area>.<slug>`, and every area has behaviours', () => {
25 const ids = BEHAVIOURS.map(b => b.id);
26 assert.deepEqual(ids.filter((id, i) => ids.indexOf(id) !== i), [], 'duplicate ids');
27 for (const b of BEHAVIOURS) {
28 assert.ok(AREAS.includes(b.area), `${b.id}: unknown area ${b.area}`);
29 assert.match(b.id, new RegExp(`^${escapeRe(b.area)}\\.[a-z0-9]+(-[a-z0-9]+)*$`), `${b.id}: id must be ${b.area}.<kebab-slug>`);
30 }
31 for (const a of AREAS) assert.ok(BEHAVIOURS.some(b => b.area === a), `area ${a} has no behaviours`);
32});
34test('the status rules hold at run time too: verified has evidence, unsupported names no op and says why', () => {
35 for (const b of BEHAVIOURS) {
36 if (b.status.tag === 'verified') assert.ok(b.status.evidence.length > 0, `${b.id}: verified with no evidence`);
37 if (b.status.tag === 'unsupported') {
38 assert.equal(b.ops.length, 0, `${b.id}: unsupported but names ops`);
39 assert.ok(b.status.why.trim().length > 0, `${b.id}: unsupported with no reason`);
40 } else assert.ok(b.ops.length > 0, `${b.id}: ${b.status.tag} names no ply op`);
41 for (const e of evidenceOf(b)) assert.ok(EVIDENCE_KINDS.includes(e.kind), `${b.id}: unknown evidence kind ${e.kind}`);
42 }
43});
45test('every ply op is an export of its src module (grep, not memory)', () => {
46 const bad = [];
47 for (const b of BEHAVIOURS) for (const o of b.ops) {
48 if (!existsSync(join(ROOT, o.module))) { bad.push(`${b.id}: ${o.module} does not exist`); continue; }
49 const re = new RegExp(`export\\s+(async\\s+)?(function\\*?|const|let|class)\\s+${escapeRe(o.symbol)}\\b`);
50 if (!re.test(read(o.module))) bad.push(`${b.id}: ${o.module} does not export ${o.symbol}`);
51 }
52 assert.deepEqual(bad, []);
53});
55test('every cited test exists and contains its anchor', () => {
56 const bad = [];
57 for (const b of BEHAVIOURS) {
58 const refs = [...b.tests, ...evidenceOf(b).filter(e => e.ref.tag === 'test').map(e => e.ref)];
59 for (const r of refs) {
60 if (!existsSync(join(ROOT, r.path))) { bad.push(`${b.id}: ${r.path} does not exist`); continue; }
61 if (!contains(read(r.path), r.anchor)) bad.push(`${b.id}: ${r.path} does not contain ${JSON.stringify(r.anchor)}`);
62 }
63 }
64 assert.deepEqual(bad, []);
65});
67// A file runs real git if it, or a test helper it imports directly (a module under test/, never src/), starts the git
68// http-backend server or spawns git.
69const RUNS_GIT = /\bstartGitServer\(|(spawnSync|execFileSync|spawn|execFile)\(\s*['"]git['"]/;
70const runsGit = path => {
71 const src = read(path);
72 if (RUNS_GIT.test(src)) return true;
73 const local = [...src.matchAll(/from\s+['"](\.{1,2}\/[^'"]+)['"]/g)].map(m => join(dirname(path), m[1]));
74 return local.filter(p => p.startsWith('test/')).some(p => {
75 const candidates = [p, p.replace(/\.js$/, '.ts')];
76 return candidates.some(c => existsSync(join(ROOT, c)) && RUNS_GIT.test(read(c)));
77 });
78};
80test('ply_vs_reference_git evidence cites a file that runs real git', () => {
81 const bad = [];
82 for (const b of BEHAVIOURS) for (const e of evidenceOf(b)) {
83 if (e.kind === 'ply_vs_reference_git' && !runsGit(e.ref.path)) bad.push(`${b.id}: ${e.ref.path} runs no git`);
84 }
85 assert.deepEqual(bad, []);
86});
88test('run evidence names a recorded run, a check that run recorded, and a kind the run can back', () => {
89 const bad = [];
90 for (const b of BEHAVIOURS) for (const e of evidenceOf(b)) {
91 if (e.ref.tag !== 'run') continue;
92 const run = RUNS[e.ref.run];
93 if (run === undefined) { bad.push(`${b.id}: no run ${e.ref.run}`); continue; }
94 if (!run.checks.includes(e.ref.check)) bad.push(`${b.id}: ${e.ref.run} recorded no check ${JSON.stringify(e.ref.check)}`);
95 if (!run.kinds.includes(e.kind)) bad.push(`${b.id}: ${e.ref.run} cannot back ${e.kind}`);
96 }
97 assert.deepEqual(bad, []);
98});
Diagnostics7 git calls · 299 ms
CallStatusSizeTime0299 ms
discover200191 B5 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 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 KiB104 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=99 git.response.bytes=11990 git.response.cache=EXPIRED git.response.duration_ms=99 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 · 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=4347 git.response.cache=HIT git.response.duration_ms=3 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 · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=5 git.response.bytes=919 git.response.cache=HIT git.response.duration_ms=5 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:02005.6 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=5724 git.response.cache=HIT git.response.duration_ms=3 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=be7e0453974a5fe832f9065a33bb7e3434c10e9bOpen pack map
fetchtree:0200228 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=228 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=e8c7c6703b9e38b182804a4efd23e971d1be4edd 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=228 git.pkt.payload.max=201 git.sideband.band1.bytes=201 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=201 git.pack.trailer=9d1e959816e16d9a506dd8756f47f08604e39a86Open pack map
fetch2002.0 KiB181 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=181 git.response.bytes=2017 git.response.cache=MISS git.response.duration_ms=181 git.fetch.wants=3aaf40956371f5352fae56a60cc35e020990e49e 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=2017 git.pkt.payload.max=1990 git.sideband.band1.bytes=1990 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
- a5e15feaee61b1a9
- Request
- 042773bc…
- 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