Skip to content

test: cover scripts/collect-case-studies.mjs offline (tests/collect-case-studies.test.mjs) [quality] - #405

Merged
mrbobbytables merged 1 commit into
mainfrom
quality/test-collect-case-studies
Sep 21, 2026
Merged

mrbobbytables merged 1 commit into
mainfrom
quality/test-collect-case-studies

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Adds tests/collect-case-studies.test.mjs, the first test of any kind for scripts/collect-case-studies.mjs — the only writer of data/case-studies.json, which backs the /resources/case-studies table.

The script did not appear in the node --test --experimental-test-coverage report at all because nothing loaded it. The new file drives it through the existing tests/helpers-script-sandbox.mjs harness (runScriptInSandbox), so the run is fully offline and deterministic — no new test infrastructure, no network, no fixtures outside the sandbox tmpdir.

Nine tests covering, in scripts/collect-case-studies.mjs:

  • fetchAllPages — x-wp-totalpages pagination across two pages, and the empty-batch stop.
  • The status === 400 && page > 1 break (WordPress advertises more pages than it serves) versus a genuine failure: a 400 on page 1 and a 500 both fail the run with the cncf.io API <status> message and write no output file.
  • fetchTermNames / namesFor — lf-project, lf-industry and lf-country id-to-name resolution, unknown ids dropped rather than emitted as nulls, names sorted independently of incoming id order.
  • decodeEntities — &amp;, &#038;, &#8217;, &#8211;, &#8212;.
  • Record shape — slug fallback for a missing or whitespace-only title.rendered, null publishedAt for a missing date, the emitted source/sourceUrl/apiUrl/description envelope, the Collected N case studies stdout line, and the localeCompare sort on organization.

Tests only; no production file is touched. node --test tests/collect-case-studies.test.mjs passes 9/9 on node v26.8.2, as do the repo-wide module-imports, workflow-scripts and validator-smoke-coverage contract tests. Output is prettier-formatted.

One caveat worth keeping in the test file: the case-study request embeds lf-project, lf-industry and lf-country in its _fields query string, so the lf_case_study route must be declared before the taxonomy routes or the harness's ordered substring matcher misroutes it. This is noted in a comment.

Related Issue

Closes #404 — that issue asks for exactly one deliverable, tests/collect-case-studies.test.mjs, and this PR lands it in full. Nothing is left for it to track.

Disjoint from the open hold-gated PRs: #216 covers scripts/import-architectures.mjs, #225 covers coverage reporting for fixture-sandbox runs (this PR adds a consumer of that harness, not a change to it), #291 covers check:links, and #195/#212/#266 are security fixes to the architecture import path. No file, function, or issue cluster overlaps.


Filed by quality agent (hold-gated mode). Human review required.

— hive: agent=quality backend=copilot model=claude-opus-5

scripts/collect-case-studies.mjs is the only writer of data/case-studies.json
and had no test file at all, so none of its pagination, taxonomy resolution or
HTML entity decoding was exercised.

Add tests/collect-case-studies.test.mjs, driving the script through the
existing runScriptInSandbox harness so the run stays offline and
deterministic. Coverage: x-wp-totalpages pagination, the empty-batch stop, the
400-past-the-last-page break against a genuine API error, taxonomy id to name
resolution with unknown ids dropped, HTML entity decoding, slug fallback for a
missing title, null publishedAt, and the organization sort order.

Signed-off-by: kubestellar-hive[bot] <kubestellar-hive@hive.kubestellar.io>
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Important

Held for human review by the hive's ACMM level gate.

This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Non-outreach agents are held at ACMM L3–L5; the outreach agent is always held because it publishes project-facing communication.

Hive will automatically remove the hold label once current policy no longer requires a level hold for "quality". If this is an outreach PR, a human must review it and remove the label.

@mrbobbytables
mrbobbytables added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit 5324ecb Sep 21, 2026
2 checks passed
@mrbobbytables
mrbobbytables deleted the quality/test-collect-case-studies branch September 25, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] scripts/collect-case-studies.mjs has zero unit coverage (pagination, taxonomy resolution, entity decoding)

1 participant