main
1import assert from "node:assert/strict";
2import { execFileSync } from "node:child_process";
3import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
4import { tmpdir } from "node:os";
5import { join } from "node:path";
6import { test } from "node:test";
7import { drift, riseReasons, scanRepo, scanSource, type AbsenceCounts } from "../scripts/absence-gate.ts";
9const word = ["un", "defined"].join("");
11function counts(part: Pick<AbsenceCounts, "word" | "optional" | "chain" | "nullish">): AbsenceCounts {
12 return { ...part, total: part.word + part.optional + part.chain + part.nullish };
13}
15test("the scanner counts each absence spelling, including comments", () => {
16 const optional = `a${"?"}: string`;
17 const chain = `a${"?"}.b`;
18 const nullish = `a${"?"}${"?"} b`;
19 const text = `// ${word}\ntype T = { ${optional} }\nconst x = ${chain}\nconst y = ${nullish}\n`;
20 assert.deepEqual(scanSource(text), counts({ word: 1, optional: 1, chain: 1, nullish: 1 }));
21 assert.equal(scanSource(`not${word}`).word, 0);
22 assert.equal(scanSource(`${"?"}a`).optional, 0);
23 assert.equal(scanSource(["a", "?", "?", " b ", "?", "?", " c"].join("")).nullish, 2);
24});
26test("only the boundary module is exempt, and skipped directories are not scanned", () => {
27 const root = mkdtempSync(join(tmpdir(), "absence-"));
28 try {
29 mkdirSync(join(root, "src", "node_modules"), { recursive: true });
30 writeFileSync(join(root, "src", "absent.ts"), `export const hole = ${word}\n`);
31 writeFileSync(join(root, "src", "use.ts"), `export const hole = ${word}\n`);
32 writeFileSync(join(root, "src", "node_modules", "leak.ts"), `export const hole = ${word}\n`);
33 const scan = scanRepo(root);
34 assert.equal(scan.counts.word, 1);
35 assert.equal(scan.counts.total, 1);
36 assert.equal(Object.hasOwn(scan.files, "src/absent.ts"), false);
37 const use = scan.files["src/use.ts"];
38 assert.ok(use);
39 assert.equal(use.word, 1);
40 } finally {
41 rmSync(root, { recursive: true, force: true });
42 }
43});
45test("the baseline may stay or fall, and a rise is refused", () => {
46 const previous = counts({ word: 2, optional: 1, chain: 0, nullish: 0 });
47 const lower = counts({ word: 1, optional: 1, chain: 0, nullish: 0 });
48 const higher = counts({ word: 3, optional: 1, chain: 0, nullish: 0 });
49 assert.deepEqual(riseReasons(lower, previous), []);
50 assert.deepEqual(riseReasons(previous, previous), []);
51 assert.equal(riseReasons(higher, previous).length, 2);
52});
54test("drift names a file the baseline does not list", () => {
55 const clean = counts({ word: 0, optional: 0, chain: 0, nullish: 0 });
56 const one = counts({ word: 1, optional: 0, chain: 0, nullish: 0 });
57 const lines = drift(
58 { boundary: "src/absent.ts", counts: one, files: { "src/use.ts": one } },
59 { boundary: "src/absent.ts", counts: clean, files: {} },
60 );
61 assert.ok(lines.some((line) => line.includes("src/use.ts")));
62 assert.ok(lines.some((line) => line.includes("absence-word")));
63});
65test("the checked-in tree matches its baseline", () => {
66 const result = execFileSync(process.execPath, ["--experimental-strip-types", "scripts/absence-gate.ts"], {
67 cwd: new URL("..", import.meta.url),
68 encoding: "utf8",
69 });
70 assert.match(result, /absence gate: ok/);
71});
Diagnostics4 git calls · 24 ms
CallStatusSizeTime024 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 · hit3 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=145 git.response.cache=HIT git.response.duration_ms=3 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 1020040 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=41349 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=526b305930b8ef382f2d7a1f9c0238730a585921 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=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.2 KiB · hit18 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=18 git.response.bytes=1203 git.response.cache=HIT git.response.duration_ms=18 git.fetch.wants=40d23dfd7eb3f3108f1b4d53048bedacd2bf8de8 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=1203 git.pkt.payload.max=1182 git.sideband.band1.bytes=1181 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-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e30f113c578a31
- Request
- 89e2675f…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format