ci: add unit test gate for scripts - #1226
Conversation
Hive-Task-Id: doc-942
Audit of the new gate found two defects that would keep it red: - actions/setup-node@5fda3b95... does not exist upstream (GitHub reports no commit for the SHA), so every run would fail at job setup. Pin the real v7.0.0 commit 82076278... that every other workflow in this repository already uses. - Add merge_group so the gate can run where merges actually land; this repository uses the merge queue and pages.yml already triggers on merge_group. - The suite was not hermetic in a clean checkout: PortalContributors imports static/data/portal-contributors.json (gitignored generated output) at module scope, and the test shims read it with an unguarded readFileSync, so 5 portal tests failed with ENOENT on a fresh actions/checkout. A missing @site JSON now resolves to { unavailable: true }, the data contract the components already implement, matching the fixture-data direction of 4a50351. Verified: node v24.18.1, node --test "scripts/**/*.test.js" passes 925/925 both with and without the gitignored static/data files; actionlint 1.7.7 clean; eslint and prettier clean on touched files. Refs #942 Assisted-by: Kimi K3 via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Final-review audit (K3) found two defects that would have kept this gate red; fixed in 49c3719 on this branch:
|
The require shim convention for module-scope @site/static/data/*.json
imports now has a stated rule: a missing generated file resolves to
{ unavailable: true } so the suite stays green in a clean CI checkout.
Same PR as the shim fix, per the skill-improvement mandate.
Refs #942
Assisted-by: Kimi K3 via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hanthor
left a comment
There was a problem hiding this comment.
The hermetic-shim fix is the valuable part here — I hit that exact failure independently. Three notes on the workflow.
The shim fix is real
Before touching any PR, I ran the suite on unmodified main at 0b052ae:
$ npm run test:coverage
ℹ tests 925
ℹ pass 920
ℹ fail 5
test at scripts/portal-static-render.test.js:204:1
✖ PortalContributors renders graceful unavailable fallback when data is unavailable or empty
Error: ENOENT: no such file or directory, open '.../static/data/portal-contributors.json'
All 5 failures were that one missing gitignored artifact, across portal-page-loading, portal-prototype-page and portal-static-render. Seeding echo '[]' > static/data/portal-contributors.json gives 925 / 925 / 0. So this is not hypothetical — a clean checkout fails the suite today, and the fs.existsSync(target) ? ... : { unavailable: true } change is exactly right. The docs/skills/component-testing.md note is a good capture of the rule.
1. npm ci --legacy-peer-deps is unnecessary and masks real conflicts
pages.yml uses plain npm ci, and plain npm ci works on this tree:
$ npm ci
(exit 0)
I also ran it cleanly on the #1215 merge, which adds a new dependency. Please drop --legacy-peer-deps so the two workflows agree and a genuine peer conflict fails loudly rather than being silently downgraded.
2. The gate is weaker than the one in pages.yml
This runs npm test, which is:
"test": "node --test \"scripts/**/*.test.js\""pages.yml already runs npm run test:coverage, which is the same suite plus --test-coverage-lines=60 --test-coverage-functions=60 --test-coverage-branches=60. So a PR can pass this new required-looking gate while regressing coverage below the threshold, and only find out in the Pages build. Using npm run test:coverage here makes the fast gate the authoritative one.
3. The paths: filter excludes the source the tests cover
paths:
- "scripts/**"
- "package.json"
- "package-lock.json"
- ".github/workflows/test.yml"But the portal tests this PR just repaired live in scripts/ and load components from src/:
// scripts/portal-static-render.test.js
const rel = id.slice("@site/".length); // resolves .ts/.tsx out of src/So a PR that only touches src/components/portal/*.tsx — #1211 and #1228 among the currently open ones — does not trigger this workflow, even though scripts/portal-*.test.js is precisely what would catch a break. Adding src/** to both paths: blocks closes that hole.
None of this is blocking; the workflow is correct as far as it goes and Run scripts unit tests is green on this PR.
Generated by Claude Code
Summary
Adds a CI test workflow running
npm teston PRs and pushes that touchscripts/,package.json, or package-lock files.Closes #942