perf(test): memoize the shared GitHub App test keypair and cap rag-index's fixture size#8550
Conversation
…dex's fixture size 19 test files each generated a fresh RSA-2048 GitHub App keypair per call (~774 sites) for JWTs no fetch stub ever verifies -- any single valid key works for every fixture. test/helpers/github-app-key.ts memoizes one keypair per worker process on globalThis (not module scope -- vitest's per-file module isolation would rebuild it once per file otherwise, the same lesson test/helpers/d1.ts's template memo already learned). github-app.test.ts's key-rotation tests genuinely need distinct keys and keep their own local generator. rag-index.test.ts's cap tests built up to 4000 real chunk rows to prove MAX_CHUNKS_PER_REPO-capping BEHAVIOR, not to validate the number itself. rag.ts gains maxChunksPerRepo()/setMaxChunksPerRepoForTest() (the same ...ForTest override convention as clearInstallationTokenCacheForTest); the test file runs under a 24-row cap. rag-index.test.ts: 46s -> 1.6s (28x).
|
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 #8550 +/- ##
==========================================
+ Coverage 89.58% 92.50% +2.92%
==========================================
Files 97 793 +696
Lines 22706 79549 +56843
Branches 3872 24036 +20164
==========================================
+ Hits 20341 73587 +53246
- Misses 2187 4800 +2613
- Partials 178 1162 +984
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Warning ⏸️ LoopOver review result - manual review recommendedReview updated: 2026-07-24 20:14:04 UTC
Review summary Nits — 5 non-blocking
Concerns raised — review before merging
📋 Copy for AI agents — paste into your coding agentDecision drivers
Context & advisory signals — never blocks the verdict
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.
|
Summary
Second follow-up in the CI-speed sequence (after the TestD1Database template-clone fix and the github/client↔db/repositories import-cycle cut). Profiling the suite's remaining per-test outliers found two concentrated, fixable hotspots — neither requires sharding, and neither touches test semantics:
generatePrivateKeyPem()and called it per test — a real WebCrypto keygen (prime search) whose signature no fetch stub ever verifies; any single valid key works for every fixture. Newtest/helpers/github-app-key.tsmemoizes one keypair per worker process onglobalThis(not module scope — vitest's per-file module isolation would otherwise rebuild it once per file, the same lessontest/helpers/d1.ts's template memo already learned).github-app.test.ts's key-rotation tests genuinely need distinct keys per call and keep their own local, non-memoized generator — left untouched.rag-index.test.ts's cap tests built up to 4,000 real chunk rows to proveMAX_CHUNKS_PER_REPO-capping behavior, not to validate the number 4000 itself.src/review/rag.tsgainsmaxChunksPerRepo()/setMaxChunksPerRepoForTest()— the same...ForTestoverride convention asclearInstallationTokenCacheForTest/clearGitHubResponseCacheForTest— andrag-index.ts's three cap-read sites switch from the raw constant to the getter. Production is unaffected (the override is null unless a test arms it). The test file runs under a 24-row cap; no other fixture in it indexes anywhere near that many files, so unrelated test semantics are unchanged. Added one direct test asserting the getter falls back to the real 4000 when unarmed.Measured:
rag-index.test.ts46s → 1.6s (28×). The keygen fix's effect is spread thin across ~19 files rather than concentrated in one, but removes real, pointless CPU work (prime search) at ~774 call sites.Validation
npm run typecheckclean.npm run test:coverage(full, unsharded): 21,483 passed / 0 failed.npx vitest run test/unit/rag-index.test.ts— 52 passed, including the new default-cap assertion.