Skip to content

Commit 9423fc8

Browse files
TMHSDigitalclaude
andcommitted
CI runs the checks on Windows (#267); npm run coverage lists untested functions (#268)
- ci.yml gains a windows-latest job running npm run check - site/coverage.mjs runs both suites under NODE_V8_COVERAGE and prints the functions no test calls, per file; zero dependencies, informational Closes #267 Closes #268 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXQPaUhxjgqdqnk6BrJ
1 parent 946eea7 commit 9423fc8

6 files changed

Lines changed: 131 additions & 3 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Validate catalog
44
# top-level Markdown files, and the whole run takes seconds.
55
#
66
# Runs on pull requests, and as the first job of pages.yml on every push to
7-
# main (so a push builds only here: once in this job and once in node-minimum). With `upload-dist` the
7+
# main (so a push builds only here: in this job, node-minimum and windows). With `upload-dist` the
88
# checkout has full history (the sitemap's lastmod dates come from git) and
99
# the built site is uploaded as the Pages artifact for pages.yml to deploy.
1010
on:
@@ -83,3 +83,24 @@ jobs:
8383

8484
- name: Lint, test, validate, check added dates, build
8585
run: npm run check
86+
87+
# Contributors run the scripts on Windows too (path separators, CRLF
88+
# checkouts, case-insensitive files), so the same checks run there (#267).
89+
windows:
90+
name: validate (Windows)
91+
runs-on: windows-latest
92+
timeout-minutes: 15
93+
steps:
94+
- name: Checkout
95+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
96+
with:
97+
persist-credentials: false
98+
fetch-depth: 0
99+
100+
- name: Setup Node
101+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
102+
with:
103+
node-version-file: .nvmrc
104+
105+
- name: Lint, test, validate, check added dates, build
106+
run: npm run check

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ To add a starter stack (one pick per need for a kind of game), follow [`stacks/R
7070

7171
## What CI runs
7272

73-
Every pull request, every push to `main` (before the site deploys) and every release run one sequence, `npm run check` in [`package.json`](package.json). Pull requests and pushes run it on Node 24 and again on Node 22; releases run it on Node 24:
73+
Every pull request, every push to `main` (before the site deploys) and every release run one sequence, `npm run check` in [`package.json`](package.json). Pull requests and pushes run it on Node 24, again on Node 22, and on Windows; releases run it on Node 24:
7474

7575
1. `npm run lint` (`site/lint.mjs`): every script parses, and none imports a name it does not use. It is syntax-only, not ESLint: a misspelled variable still passes and fails only when that line runs, so code the tests never reach needs a test or a careful read.
7676
2. `npm test`: the checks against known-bad fixtures (`site/checks.test.mjs`) and the site modules' tests (`site/lib/lib.test.mjs`).

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"links": "node site/check-links.mjs",
1919
"thumbs": "node site/thumbs.mjs",
2020
"reverify": "node site/reverify-batch.mjs",
21-
"serve": "node site/serve.mjs"
21+
"serve": "node site/serve.mjs",
22+
"coverage": "node site/coverage.mjs"
2223
}
2324
}

‎site/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Script options:
217217
| `node site/reverify-batch.mjs` | `--report <file.md>`; `--size <n>` overrides the computed batch size |
218218
| `node site/thumbs.mjs` | `--only <id,id>` limits the run to those entries; `--force` refetches records that are not due; `--limit <n>` caps fetches per run; `--dry-run` writes nothing; `--report <file.md>` |
219219
| `node site/serve.mjs` | `--port <n>`, or the `PORT` environment variable (3000) |
220+
| `node site/coverage.mjs` (`npm run coverage`) | Runs both test suites under Node's built-in V8 coverage and lists, per file, the functions no test calls; `--all` lists every file. Informational, not part of `npm run check` |
220221

221222
Deploy: `.github/workflows/pages.yml` (source = GitHub Actions), which first runs
222223
`ci.yml` as a reusable workflow.

‎site/coverage.mjs‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Which site/ functions the test suites never call. Runs both suites under
4+
* NODE_V8_COVERAGE (built into Node, no dependency), then prints, per file,
5+
* the share of functions that ran and the uncovered ones with their lines.
6+
* node site/coverage.mjs [--all]
7+
* By default only files with an uncovered function are listed; --all lists
8+
* every file. Informational: it never fails (exit 1 only if a suite fails).
9+
*/
10+
import { execFileSync } from "node:child_process";
11+
import fs from "node:fs";
12+
import os from "node:os";
13+
import path from "node:path";
14+
import { fileURLToPath, pathToFileURL } from "node:url";
15+
import { cliArgs } from "./lib/cli.mjs";
16+
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
18+
const ROOT = path.resolve(__dirname, "..");
19+
const SUITES = ["site/checks.test.mjs", "site/lib/lib.test.mjs"];
20+
21+
/**
22+
* V8 script coverage => `{ total, uncovered: [{ name, line }] }` per url.
23+
* A function counts as covered when its own range ran at least once in any
24+
* of the runs (a module loaded by both suites appears once per run); the
25+
* module's top-level pseudo-function (empty name at offset 0) is skipped.
26+
*/
27+
export function functionCoverage(scripts, sourceOf) {
28+
const byUrl = new Map(); // url => Map(startOffset => { name, ran })
29+
for (const script of scripts) {
30+
if (!byUrl.has(script.url)) byUrl.set(script.url, new Map());
31+
const fns = byUrl.get(script.url);
32+
for (const fn of script.functions) {
33+
const range = fn.ranges[0];
34+
if (!range || (range.startOffset === 0 && !fn.functionName)) continue;
35+
const seen = fns.get(range.startOffset) || { name: fn.functionName || "(anonymous)", ran: false };
36+
seen.ran ||= range.count > 0;
37+
fns.set(range.startOffset, seen);
38+
}
39+
}
40+
const out = new Map();
41+
for (const [url, fns] of byUrl) {
42+
const src = sourceOf(url);
43+
if (src === null) continue;
44+
const lineAt = (offset) => src.slice(0, offset).split("\n").length;
45+
const uncovered = [...fns]
46+
.filter(([, f]) => !f.ran)
47+
.sort(([a], [b]) => a - b)
48+
.map(([offset, f]) => ({ name: f.name, line: lineAt(offset) }));
49+
out.set(url, { total: fns.size, uncovered });
50+
}
51+
return out;
52+
}
53+
54+
function main() {
55+
const { values } = cliArgs({ all: { type: "boolean" } }, "node site/coverage.mjs [--all]");
56+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fgda-coverage-"));
57+
try {
58+
for (const suite of SUITES) {
59+
execFileSync(process.execPath, [suite], { cwd: ROOT, stdio: ["ignore", "ignore", "inherit"], env: { ...process.env, NODE_V8_COVERAGE: dir } });
60+
}
61+
const siteUrl = pathToFileURL(__dirname).href + "/";
62+
const scripts = [];
63+
for (const name of fs.readdirSync(dir)) {
64+
for (const s of JSON.parse(fs.readFileSync(path.join(dir, name), "utf8")).result) {
65+
if (s.url.startsWith(siteUrl) && !/\.test\.mjs$/.test(s.url) && !s.url.includes("/dist/")) scripts.push(s);
66+
}
67+
}
68+
const sourceOf = (url) => {
69+
try {
70+
return fs.readFileSync(fileURLToPath(url), "utf8");
71+
} catch {
72+
return null;
73+
}
74+
};
75+
let total = 0;
76+
let missed = 0;
77+
for (const [url, cov] of [...functionCoverage(scripts, sourceOf)].sort(([a], [b]) => a.localeCompare(b))) {
78+
total += cov.total;
79+
missed += cov.uncovered.length;
80+
if (!cov.uncovered.length && !values.all) continue;
81+
const rel = path.relative(ROOT, fileURLToPath(url)).split(path.sep).join("/");
82+
const pct = cov.total ? Math.round((100 * (cov.total - cov.uncovered.length)) / cov.total) : 100;
83+
console.log(`${rel} ${pct}% of ${cov.total} functions`);
84+
for (const u of cov.uncovered) console.log(` line ${u.line} ${u.name}`);
85+
}
86+
console.log(`coverage: ${total - missed} of ${total} functions in loaded site/ modules ran under the tests (scripts never imported by a test are not listed)`);
87+
} finally {
88+
fs.rmSync(dir, { recursive: true, force: true });
89+
}
90+
}
91+
92+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();

‎site/lib/lib.test.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,19 @@ eq("search: q from the URL is capped", readState(`?q=${"a".repeat(5000)}`, { q:
20552055
}
20562056
}
20572057

2058+
/* coverage summary (#268) ------------------------------------------------- */
2059+
{
2060+
const { functionCoverage } = await import("../coverage.mjs");
2061+
const run = (count) => ({ url: "file:///x.mjs", functions: [
2062+
{ functionName: "", ranges: [{ startOffset: 0, endOffset: 30, count: 1 }] },
2063+
{ functionName: "f", ranges: [{ startOffset: 4, endOffset: 10, count }] },
2064+
{ functionName: "g", ranges: [{ startOffset: 12, endOffset: 20, count: 0 }] },
2065+
] });
2066+
const cov = functionCoverage([run(0), run(2)], () => "a\nb\nc\n").get("file:///x.mjs");
2067+
eq("coverage: the module body is not a function", cov.total, 2);
2068+
eq("coverage: covered in either run counts", cov.uncovered.map((u) => u.name).join(), "g");
2069+
}
2070+
20582071
/* report (keep last) ------------------------------------------------------ */
20592072
if (failures.length) {
20602073
console.error(`lib.test failed (${failures.length}):`);

0 commit comments

Comments
 (0)