🌱 [scanner] test: add unit tests for scripts/ CI automation scripts - #7012
Conversation
Adds vitest coverage for the pure logic in the three remaining untested generate-*.mjs scripts named in #6842 (generate-leaderboard.mjs, generate-acmm-history.mjs, generate-contributor-profiles.mjs), following the repo's established extract-pure-helpers-into-lib-then-test pattern already used for github-fetch.mjs and text-clustering.mjs: - scripts/lib/dates.test.mjs, scoring.test.mjs, snapshot.test.mjs — cover the lib/*.mjs helpers already backing generate-leaderboard.mjs (no behavior change; the pure logic was already extracted, just untested). - scripts/lib/contributor-metrics.mjs (new) — extracts computeCadence, computeTimeline, findDeepenSuggestions, findStretchAreas, and the CONSOLE_CODEBASE_AREAS data from generate-contributor-profiles.mjs as a test-hook-only, behavior-neutral refactor, plus its test file. - scripts/lib/acmm-history.mjs (new) — extracts the legacy-migration, cold-start-seed, idempotency, and 26-week rolling-window trim/backfill logic from generate-acmm-history.mjs's main(), plus its test file. 65 new tests added; full scripts/ suite (234 tests) passes with no regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: kubestellar-hive[bot] <223556219+Copilot@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellar-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @kubestellar-hive[bot]. Thanks for your PR. I'm waiting for a kubestellar member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
Refs #6842 — remaining scripts:
migrate-version.sh,netlify-ignore.sh(already have test files; not touched here), and the network-only glue ingenerate-leaderboard.mjs/generate-acmm-history.mjs/generate-contributor-profiles.mjs(fetch loops, retries, file writes) left for follow-up because they require either a subprocess/mock-fetch harness or live network access, which is out of scope for a pure-unit-test pass.Context
Re-verified the issue's original claim against current
main: 5 of the original 8 "zero test coverage" scripts already have tests from earlier PRs (update-version.js,create-version-branches.sh,migrate-version.sh,netlify-ignore.sh,verify-site-health.sh,add-repo-breakdown.mjs). The issue's own status-update comments (see issue thread) confirm this and re-scope the remaining work to the 3 largegenerate-*.mjsgenerators:scripts/generate-leaderboard.mjs(658 loc → now 314 loc; pure logic already lives inscripts/lib/*.mjsfrom a prior refactor, but 4 of those lib files had no tests)scripts/generate-acmm-history.mjs(520 loc)scripts/generate-contributor-profiles.mjs(897 loc → now 357 loc)What this PR does
Following the pattern already established in this repo (
scripts/lib/github-fetch.mjs+.test.mjs,scripts/lib/text-clustering.mjs+.test.mjs): extract pure, network-free logic intoscripts/lib/*.mjsas test-hook-only refactors (no behavior change), then add co-located Vitest unit tests.New test files for already-extracted helpers (no script changes needed — these were extracted in an earlier PR but left untested):
scripts/lib/dates.test.mjs—startOfDayUTC,addDaysscripts/lib/scoring.test.mjs— point values, contributor levels,weekKeyForDate,getRecentWeekKeys,computeRecentScorescripts/lib/snapshot.test.mjs—scoreItemsIntoMap,addItemsToWeeklyActivity,loadSnapshot/saveSnapshotround-tripThese fully cover
generate-leaderboard.mjs's testable surface (itsmain()is now pure orchestration over these lib functions plus network fetches).New extraction + tests:
scripts/lib/contributor-metrics.mjs(new) — extractscomputeCadence,computeTimeline,findDeepenSuggestions,findStretchAreas, and theCONSOLE_CODEBASE_AREASdata out ofgenerate-contributor-profiles.mjs(897 → 357 loc). Behavior-neutral: same functions, same logic, just imported instead of defined inline.scripts/lib/contributor-metrics.test.mjs— 13 tests covering cadence trend classification, day-of-week/hour bucketing, monthly timeline, and both suggestion algorithms.scripts/lib/acmm-history.mjs(new) — extracts the legacy"weeks"→"dates"migration, cold-start seeding, idempotency check (no-op vs. backfill vs. fresh append), and the 26-week rolling-window trim/stale-repo-pruning logic out ofgenerate-acmm-history.mjs'smain(). Behavior-neutral.scripts/lib/acmm-history.test.mjs— 17 tests covering migration, cold start, idempotency states, append/backfill/trim/prune.Not covered (left as follow-up):
migrate-version.shandnetlify-ignore.shalready have test files (scripts/test_migrate-version.sh,scripts/netlify-ignore.test.ts) from prior PRs, so they're out of scope here.generate-*.mjsscripts is network I/O (GitHub API pagination, the ACMM scan-API fetch-with-retry loop) andfswrites at the very top level ofmain(). Testing that would need either a subprocess harness with a mocked HTTP server (the pattern used byscripts/verify-site-health.test.ts) orvi.mock('fetch'), which is a larger follow-up than fits cleanly alongside this extraction pass.Testing
234 tests pass (169 pre-existing + 65 new), no regressions. Ran
node --checkon all three modified/refactored.mjsproduction scripts to confirm they still parse correctly after the extraction.Per repo instructions,
npm run build/npm run lintwere intentionally not run locally (CI validates); only the test suite was run to verify the new tests pass.— hive: agent=scanner backend=copilot model=claude-fable-5 copilot=1.0.78