Skip to content

🌱 [scanner] test: add unit tests for scripts/ CI automation scripts - #7012

Merged
kubestellar-hive[bot] merged 1 commit into
mainfrom
scanner/fix-6842
Sep 19, 2026
Merged

kubestellar-hive[bot] merged 1 commit into
mainfrom
scanner/fix-6842

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

Refs #6842 — remaining scripts: migrate-version.sh, netlify-ignore.sh (already have test files; not touched here), and the network-only glue in generate-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 large generate-*.mjs generators:

  • scripts/generate-leaderboard.mjs (658 loc → now 314 loc; pure logic already lives in scripts/lib/*.mjs from 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 into scripts/lib/*.mjs as 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.mjsstartOfDayUTC, addDays
  • scripts/lib/scoring.test.mjs — point values, contributor levels, weekKeyForDate, getRecentWeekKeys, computeRecentScore
  • scripts/lib/snapshot.test.mjsscoreItemsIntoMap, addItemsToWeeklyActivity, loadSnapshot/saveSnapshot round-trip

These fully cover generate-leaderboard.mjs's testable surface (its main() is now pure orchestration over these lib functions plus network fetches).

New extraction + tests:

  • scripts/lib/contributor-metrics.mjs (new) — extracts computeCadence, computeTimeline, findDeepenSuggestions, findStretchAreas, and the CONSOLE_CODEBASE_AREAS data out of generate-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 of generate-acmm-history.mjs's main(). 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.sh and netlify-ignore.sh already have test files (scripts/test_migrate-version.sh, scripts/netlify-ignore.test.ts) from prior PRs, so they're out of scope here.
  • The remaining un-extracted logic in the three generate-*.mjs scripts is network I/O (GitHub API pagination, the ACMM scan-API fetch-with-retry loop) and fs writes at the very top level of main(). Testing that would need either a subprocess harness with a mocked HTTP server (the pattern used by scripts/verify-site-health.test.ts) or vi.mock('fetch'), which is a larger follow-up than fits cleanly alongside this extraction pass.

Testing

$ npx vitest run scripts/
 Test Files  17 passed (17)
      Tests  234 passed (234)

234 tests pass (169 pre-existing + 65 new), no regressions. Ran node --check on all three modified/refactored .mjs production scripts to confirm they still parse correctly after the extraction.

Per repo instructions, npm run build/npm run lint were 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

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>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Sep 19, 2026
@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Sep 19, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellar-docs ready!

Name Link
🔨 Latest commit c3ccfa9
🔍 Latest deploy log https://app.netlify.com/projects/kubestellar-docs/deploys/6aadf99ebd8bb80009c3699e
😎 Deploy Preview https://deploy-preview-7012--kubestellar-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubestellar-prow kubestellar-prow Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 19, 2026
@kubestellar-prow kubestellar-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 19, 2026
@kubestellar-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubestellar-hive
kubestellar-hive Bot merged commit aa456ee into main Sep 19, 2026
13 of 14 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-6842 branch September 19, 2026 02:56
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributing copilot dco-signoff: yes Indicates the PR's author has signed the DCO. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant