Skip to content

test(scripts): unit test and measure the pure scripts/lib helpers#2194

Merged
JSONbored merged 3 commits into
JSONbored:mainfrom
fansilas:test/script-lib-coverage
Jun 28, 2026
Merged

test(scripts): unit test and measure the pure scripts/lib helpers#2194
JSONbored merged 3 commits into
JSONbored:mainfrom
fansilas:test/script-lib-coverage

Conversation

@fansilas

Copy link
Copy Markdown
Contributor

Summary

Adds focused unit tests for the pure helper modules under scripts/lib, and lists them in the vitest coverage.include so their lines finally show up in the coverage report. These modules hold the deterministic transforms the build relies on: text formatting and sanitization, the economics, endpoint, and enrichment artifact derivations, and README link selection. Until now they ran only through scripts/build-artifacts.mjs, which the suite drives as a child process via execFileSync, so their lines never reached the in process coverage collector.

No script behavior changes. npm run build produces the same artifacts, and the working tree stays clean under public/ after a fresh build.

Closes #2065

What Changed

New test files, each covering every export of its module plus the reachable edge and fallback paths (empty input, missing fields, malformed rows, boundary values), modeled on the existing tests/build-readiness.test.mjs:

  • tests/formatting.test.mjs for scripts/lib/formatting.mjs
  • tests/economics-artifacts.test.mjs for scripts/lib/economics-artifacts.mjs
  • tests/readme-links.test.mjs for scripts/lib/readme-links.mjs
  • tests/endpoint-artifacts.test.mjs for scripts/lib/endpoint-artifacts.mjs
  • tests/enrichment-queue-artifacts.test.mjs for scripts/lib/enrichment-queue-artifacts.mjs

vitest.config.mjs gains the six scripts/lib/*.mjs modules in coverage.include. They are listed by name rather than with a scripts/lib/** glob, so a future module dropped into the directory without its own test cannot quietly pull the backstop floors down. build-readiness.mjs already had a suite but was never measured, so it joins the list too.

Two of the covered modules (enrichment-queue-artifacts.mjs and build-readiness.mjs) were lifted out of build-artifacts.mjs, and the others came out of scripts/lib.mjs, so this measures real build pipeline logic. The remaining uncovered branches in the four sub 100 modules are defensive try/catch fallbacks and impossible state guards that the exported API cannot reach; all modules clear the backstop floors with margin.

Follow up extraction targets

Captured here so the rest can land as separate PRs:

  • scripts/build-artifacts.mjs pure helpers not yet split out, such as gapRowSeverity, mergeSubnet, buildGaps, subnetProfileCompleteness, resolveAgentServiceSchema, fixtureCoverageEntry, and profileSuggestedNextAction.
  • Validator predicates in scripts/validate.mjs (validateProvider, validateCuration, validateLinks, validatePublicSafeJson, validateVerification) and scripts/validate-api.mjs (validateWorkerResponse, validateErrorEnvelope).

Registry Safety

  • No secrets, PATs, wallet data, private dashboards, private URLs, or validator local state.
  • Generated artifacts were produced by repo scripts, not hand edited. (None touched.)
  • R2 only and high churn detail artifacts are not committed.
  • Public API, OpenAPI, and schema changes are intentional and documented. (None; this covers tests and coverage config only.)

Validation

  • npm run validate
  • npm run validate:schemas
  • npm run validate:api
  • npm run validate:openapi
  • npm run validate:types
  • npm run validate:contract-drift
  • npm run validate:artifact-budgets
  • npm run validate:docs
  • npm run validate:intake
  • npm run validate:workflows
  • npm run worker:test
  • npm run lint and npm run format:check
  • npm run test:ci and npm run test:ci:artifacts
  • npm run scan:public-safety
  • git diff --check
  • npm run build, then git status clean under public/

@fansilas fansilas requested a review from JSONbored as a code owner June 27, 2026 18:11
@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.40%. Comparing base (4d1df4d) to head (909ee3b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2194      +/-   ##
==========================================
+ Coverage   93.35%   93.40%   +0.04%     
==========================================
  Files          54       60       +6     
  Lines        8639     9487     +848     
  Branches     3138     3502     +364     
==========================================
+ Hits         8065     8861     +796     
- Misses        100      106       +6     
- Partials      474      520      +46     

see 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gittensory-orb

gittensory-orb Bot commented Jun 27, 2026

Copy link
Copy Markdown

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review — held for maintainer review

7 files · 1 AI reviewers · no blockers · readiness 55/100 · CI green · clean

⏸️ Held for maintainer review — Large change — held for manual review

Review summary
Pure coverage PR: adds five dedicated unit-test files for `scripts/lib/` helpers and wires them into `vitest.config.mjs` coverage inclusion. Every exported symbol is exercised with edge and fallback paths, the tests correctly import from the per-module paths, and the removal of `tests/miner-readiness.test.mjs` is clean — `economics-artifacts.test.mjs` is a strict superset of its assertions. The file-by-file listing in `coverage.include` rather than a glob is the right defensive choice and the explanatory comment justifies it well.

Signal Result Evidence
Code review ✅ No blockers 1 reviewers, synthesized
Linked issue ✅ Linked #2065
Related work ⚠️ 2 scoped overlaps Top overlaps are listed below; lower-confidence bulk is hidden.
Review load ❌ 8/20 Readiness component derived from cached public PR metadata and labels.
Validation evidence ❌ 5/25 Cached preflight status is hold.
Open PR queue ❌ 3/10 15 open PR(s), 13 likely reviewable, 2 unlinked.
Contributor context ✅ Confirmed Gittensor contributor fansilas; Gittensor profile; 15 PR(s), 9 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Nits — 6 non-blocking
  • tests/endpoint-artifacts.test.mjs (r1.score === 104, r2.score === 85): the inline arithmetic breakdowns (`// ok 50 + archive 15 + …`) make these pinned-integer assertions readable, but if a point weight changes the failure message will show only the expected vs. actual numbers with no pointer to which component shifted; extracting local weight constants would make regressions self-diagnosing.
  • tests/enrichment-queue-artifacts.test.mjs ('buckets candidate classifications'): the comment `unverified_count: 4 // schema-valid + maintainer-review + verified + unknown` is confusing because the classification value `'verified'` lands in the *unverified* bucket — a parenthetical like `// 'verified' here = awaiting-maintainer state, not live-confirmed` would prevent the double-take.
  • tests/economics-artifacts.test.mjs: the removed `miner-readiness.test.mjs` contained a combination assertion (registration_allowed + cost=5 TAO → 10 pts + active-via-stake → expected 60) that has no direct equivalent in the new suite; individual-component tests cover it inferentially, but an explicit combined-path case would close the gap.
  • vitest.config.mjs: `scripts/lib.mjs` (the barrel re-exporter) is covered by the existing `{artifact-budgets,lib,…}.mjs` brace expansion, and the new `scripts/lib/{…}.mjs` line covers the per-module implementations — these are distinct paths and there is no v8 collision, but a one-line comment distinguishing 'lib.mjs = barrel' from 'lib/*.mjs = implementations' would prevent future maintainers from wondering why both patterns coexist.
  • tests/endpoint-artifacts.test.mjs: consider a small local `SCORES` object (`{ OK: 50, ARCHIVE: 15, BLOCK: 10, METHODS_OBJ: 10, METHODS_ARR: 15, LATENCY_50: 19, LATENCY_10: 20 }`) so `assert.equal(r1.score, SCORES.OK + SCORES.ARCHIVE + SCORES.BLOCK + SCORES.METHODS_OBJ + SCORES.LATENCY_50)` turns each assertion into a self-documenting formula that survives weight refactors and immediately explains any failure.
  • Large change — held for manual review — Split this into smaller, focused PRs, or a maintainer reviews and merges it manually.
Review context
Contributor next steps
  • Review top overlaps.
  • Add scope summary.
  • Fix blocker.
  • Expect slower review.
  • Refresh registry data or choose a registered active repo.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Review load = cached public PR metadata such as size labels, changed paths, and preflight status.
  • Open PR queue = repo-wide review pressure; it is not a PR quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
Review details

Generated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative.

Pure coverage PR: adds five dedicated unit-test files for `scripts/lib/` helpers and wires them into `vitest.config.mjs` coverage inclusion. Every exported symbol is exercised with edge and fallback paths, the tests correctly import from the per-module paths, and the removal of `tests/miner-readiness.test.mjs` is clean — `economics-artifacts.test.mjs` is a strict superset of its assertions. The file-by-file listing in `coverage.include` rather than a glob is the right defensive choice and the explanatory comment justifies it well.

Nits (5)

  • tests/endpoint-artifacts.test.mjs (r1.score === 104, r2.score === 85): the inline arithmetic breakdowns (`// ok 50 + archive 15 + …`) make these pinned-integer assertions readable, but if a point weight changes the failure message will show only the expected vs. actual numbers with no pointer to which component shifted; extracting local weight constants would make regressions self-diagnosing.
  • tests/enrichment-queue-artifacts.test.mjs ('buckets candidate classifications'): the comment `unverified_count: 4 // schema-valid + maintainer-review + verified + unknown` is confusing because the classification value `'verified'` lands in the *unverified* bucket — a parenthetical like `// 'verified' here = awaiting-maintainer state, not live-confirmed` would prevent the double-take.
  • tests/economics-artifacts.test.mjs: the removed `miner-readiness.test.mjs` contained a combination assertion (registration_allowed + cost=5 TAO → 10 pts + active-via-stake → expected 60) that has no direct equivalent in the new suite; individual-component tests cover it inferentially, but an explicit combined-path case would close the gap.
  • vitest.config.mjs: `scripts/lib.mjs` (the barrel re-exporter) is covered by the existing `{artifact-budgets,lib,…}.mjs` brace expansion, and the new `scripts/lib/{…}.mjs` line covers the per-module implementations — these are distinct paths and there is no v8 collision, but a one-line comment distinguishing 'lib.mjs = barrel' from 'lib/*.mjs = implementations' would prevent future maintainers from wondering why both patterns coexist.
  • tests/endpoint-artifacts.test.mjs: consider a small local `SCORES` object (`{ OK: 50, ARCHIVE: 15, BLOCK: 10, METHODS_OBJ: 10, METHODS_ARR: 15, LATENCY_50: 19, LATENCY_10: 20 }`) so `assert.equal(r1.score, SCORES.OK + SCORES.ARCHIVE + SCORES.BLOCK + SCORES.METHODS_OBJ + SCORES.LATENCY_50)` turns each assertion into a self-documenting formula that survives weight refactors and immediately explains any failure.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@gittensory-orb gittensory-orb Bot added gittensor Gittensor contributor context gittensor:bug Bug labels Jun 27, 2026
@JSONbored JSONbored merged commit bfde7fa into JSONbored:main Jun 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Bug gittensor Gittensor contributor context

Development

Successfully merging this pull request may close these issues.

test(scripts): unit-test the build/validator pipeline (only 4 of 85 scripts measured)

2 participants