test(ci): add unit-test seam for ci-duration-report.mjs percentile/summarize - #7479
Conversation
…mmarize percentile() (nearest-rank with a floor clamp) and summarize() (excludes cancelled runs from both the duration set and the failure-rate denominator; treats skipped as success) carried real, non-obvious behavior but only ran inside the script's un-guarded top-level body, which also makes a live GitHub API call -- untestable in isolation. Export percentile/summarize/durationSeconds and move the env-reading, live-fetch, and report-assembly driver behind an entrypoint guard (import.meta.url === argv[1]) so importing the module for tests never fetches. Add test/unit/ci-duration-report-script.test.ts covering percentile at p50/p95 (incl. single-element and empty->null), summarize excluding cancelled from count + failure denominator (counting them as excludedCancelled), and summarize treating skipped as a success. Behavior of the script when run directly is unchanged. Closes JSONbored#7456
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7479 +/- ##
=======================================
Coverage 91.36% 91.36%
=======================================
Files 717 717
Lines 73022 73022
Branches 21629 21632 +3
=======================================
Hits 66719 66719
Misses 5265 5265
Partials 1038 1038
Flags with carried forward coverage won't be shown. Click here to find out more. |
|
Caution 🛑 LoopOver review result - fixes requiredReview updated: 2026-07-20 12:08:30 UTC
Review summary Nits — 5 non-blocking
CI checks failing
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
LoopOver is closing this pull request on the maintainer's behalf (CI is failing (validate, validate-code)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed. |
Closes #7456
What
scripts/ci-duration-report.mjs'spercentile()andsummarize()carry real, non-obvious behavior —percentile()is a nearest-rank formula with a floor clamp, andsummarize()deliberately excludescancelledruns from both the duration set and the failure-rate denominator (acancel-in-progressre-push artifact, not a CI failure) while treatingskippedas a success. Neither was exported or tested; both only ran inside the un-guarded top-level body, which also makes a live GitHub API call — so nothing was testable in isolation.This PR:
percentile,summarize, anddurationSecondsas named exports.main()behind an entrypoint guard (import.meta.url === pathToFileURL(process.argv[1]).href), so importing the module for tests never triggers afetch. Running the script directly is unchanged.test/unit/ci-duration-report-script.test.ts.Tests (all pass locally under
vitest run test/unit)percentileat p50/p95 against a known sorted array, plus a single-element array and an empty array (null).summarizeexcludescancelledfromcountand the failure-rate denominator while reporting them asexcludedCancelled; treatsskippedas a success (not a failure); returnsnullpercentiles/failureRate for an empty set.durationSeconds=(updated_at − created_at)in seconds.Verified importing the module with empty env neither throws nor fetches (exports resolve to just the pure functions).
scripts/**isn't incoverage.include, so no numeric patch gate — the new test is real and green.