test(core): add tests for untested core modules — artifacts, review, api_key_service (#654)#694
Conversation
…expand prd_stress_test (#654) Adds direct unit tests for three untested core modules and expands coverage of a fourth, all marked @pytest.mark.v2: - test_api_key_service.py: create/list/revoke/rotate/get against a real tmp Database — main paths + error cases (invalid scopes, wrong owner, not-found, rotate-keeps-old-key-on-creation-failure). - test_artifacts.py: export_patch/create_commit/get_status/list_patches with a real git repo + workspace (events persisted); git-missing / not-a-repo / no-changes error paths; pure parse-helper tests. - test_review.py: status/severity thresholds, review_files findings/empty/skip/ analyzer-error paths, review_task delegation, get_review_summary. - test_prd_stress_test.py: resolve_ambiguities_into_prd, JSON-failure fallbacks, malformed-children filtering, sync exception propagation. Also fixes a real bug surfaced by the new tests: artifacts.get_status() used result.stdout.strip(), which stripped the leading status column from the first porcelain line — misclassifying a worktree-only change as staged and dropping its first filename character. Switched to splitlines(). Closes #654
|
Warning Review limit reached
More reviews will be available in 32 minutes and 11 seconds. Learn how PR review limits work. Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Code Review -- PR 694 Overall: Approve with minor notes. A well-scoped coverage hardening PR that also surfaces a real bug. No previous Claude review to reconcile against. BUG FIX in artifacts.py: The strip().split() to splitlines() change is correct. The comment explaining why is warranted -- this is the kind of silent column-shift nearly impossible to catch without a test. The 5-line comment is verbose per CLAUDE.md style but the subtlety justifies it. test_api_key_service.py (238 lines, 21 tests):
test_artifacts.py (279 lines, 23 tests):
test_review.py (231 lines, 26 tests):
test_prd_stress_test.py (13 new tests):
Summary of actionable items (all minor):
None of these block merge. |
…, get_api_key contract - review.py: leave the in-process ComplexityAnalyzer real in the autouse fixture and add a non-mocked smoke test that locks the finding attribute contract review.py depends on. - artifacts.py: add the MM (staged-then-modified) porcelain case so the two-column status parser is exercised in both columns at once. - api_key_service.py: pin get_api_key's intentional owner-agnostic behavior.
…ests Addresses review note #3: consolidate the three Workspace.__new__ bypass sites behind a documented factory helper that sets every attribute artifacts.py reads.
|
Thanks for the review. Triage of the four minor notes:
Also addressed earlier-round feedback: added a real (non-mocked) |
Code Review — PR #694: test(core) coverage hardening (#654)Overall: This is a well-executed test coverage PR. The structure is consistent across all four new/expanded test files, the real-infrastructure approach (real SQLite + real git) is the right call for these modules, and the Bug Fix —
|
| Area | Status |
|---|---|
Bug fix (artifacts.py) |
✅ Correct, well-tested |
test_api_key_service.py |
|
test_artifacts.py |
✅ Minor: duplicate-count assertion in MM test |
test_prd_stress_test.py |
✅ Minor: document truncation threshold |
test_review.py |
✅ Clean |
Marker compliance (@pytest.mark.v2) |
✅ All new tests carry it |
| No live API calls | ✅ |
The prefix-length assertion on line 93 is worth fixing before merge (it's the easiest kind of latent breakage to introduce). Everything else is low-priority suggestions. No blocking issues.
|
Code Review - PR 694: test coverage hardening. Overall: solid coverage PR. Bug fix is correct, all four test files carry pytestmark v2, no live API calls, tests cover main paths plus realistic error/edge cases. artifacts.py fix: correct and necessary - splitlines() properly preserves the leading space of porcelain status lines that strip().split was eating, fixing misclassification of worktree-only changes as staged. Style note: the 5-line comment added conflicts with CLAUDE.md one-line-max rule; condense to a single line naming the porcelain two-column format. test_api_key_service.py: pass - real SQLite DB, per-user isolation, rotate-on-failure safety invariant. Minor: USER_A=1 couples to bootstrap admin seed ID detail. test_artifacts.py: pass with concern - Workspace.new(Workspace) without init in three stubs bypasses constructor invariants; safer to use a real constructor fixture. The MM porcelain regression test is exactly the right coverage. test_prd_stress_test.py: nit - local imports inside test methods should move to file/class top for consistency. _provider_returning helper is clean. test_review.py: pass - quiet_heavy_analyzers autouse fixture is a good pattern, score arithmetic constants lock the threshold contract, integration test pins the attribute contract against the real analyzer. Summary: comment condensation in artifacts.py is the only CLAUDE.md conflict; everything else is advisory. |
Summary
Closes #654 (P6.8.1 — test coverage hardening).
Adds direct unit tests for three previously-untested core modules and expands coverage of a fourth. All new tests carry
@pytest.mark.v2. No live API calls (MockProvider / real tmp git+SQLite only).core/api_key_service.pytests/core/test_api_key_service.py(NEW)core/artifacts.pytests/core/test_artifacts.py(NEW)core/review.pytests/core/test_review.py(NEW)core/prd_stress_test.pytests/core/test_prd_stress_test.py(EXPAND, +13 tests)resolve_ambiguities_into_prd, JSON-failure fallbacks, malformed-children filtering, sync exception propagationBug fixed (surfaced by the new tests)
artifacts.get_status()parsedgit status --porcelainviaresult.stdout.strip(). The porcelain status field is two columns wide (" M file"for a worktree-only change), sostrip()removed the leading space of the first line and shifted column parsing — misclassifying that file as staged and dropping its first filename character (hello.py→ello.py). Switched tosplitlines(). This path feedscf statusand the git_v2/proof scope surfaces.Acceptance criteria
api_key_service.py,artifacts.py,review.pyhave direct tests covering main paths + error cases@pytest.mark.v2markerprd_stress_test.pycoverage expandedVerification
test_api_key_service21,test_artifacts23,test_review26,test_prd_stress_test45 [32 existing + 13 new],test_git_review9)tests/core/suite: 2303 passed, 0 failures (no regression from the bug fix)ruff checkclean on all changed filesKnown limitations
test_artifacts.pyrequiresgiton PATH (guarded by the existingskip_if_no_gitfixture).review.pytests patch the three analyzers (complexity/security/OWASP) so they don't shell out tobandit/radon; the analyzers themselves are out of scope for [P6.8.1] Add tests for untested core modules: artifacts.py, review.py, api_key_service.py #654.