test: add unit tests for DuplicateService (Fixes #442)#895
test: add unit tests for DuplicateService (Fixes #442)#895zeroknowledge0x wants to merge 2 commits into
Conversation
- 25 tests covering initialization, availability, load behavior, add_ticket, check_duplicate, save_to_disk, and degraded mode - All ML dependencies mocked (sentence-transformers) - Tests verify: memory persistence, disk persistence, threshold override, best-match selection, corrupt JSON handling, and graceful degradation when model is unavailable
|
@zeroknowledge0x is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 5 minutes and 48 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA complete pytest test suite for ChangesDuplicateService Unit Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/tests/test_duplicate_service.py`:
- Around line 61-62: The test_storage_dir_created test is tautological because
the service fixture already sets service.storage_file under tmp_path (which
exists); change the test to configure DuplicateService to use a nested,
non-existent path before constructing it so __init__ must create the parent dir,
then assert that target.parent (the directory) exists; locate the
test_storage_dir_created and the service fixture setup (and
DuplicateService.__init__ / storage_file usage) and modify the test to provide a
nested path (e.g. tmp_path / "nested" / "case_history_cache.json") and
instantiate the service so the assertion verifies directory creation rather than
relying on tmp_path.
- Around line 128-132: Remove the leftover variable assignment (drop
loaded_service_result) and make the test actually exercise the degraded path by
adding a stored ticket before calling service.check_duplicate; specifically, in
test_degraded_returns_no_duplicate set service._loaded = False and
service._load_failed = True, store a ticket via the same API used in other tests
(e.g., the service method that adds tickets or the fixture helper) so
check_duplicate would normally detect a duplicate, then call
service.check_duplicate("text") and assert result["is_duplicate"] is False; keep
references to test_degraded_returns_no_duplicate, service._loaded,
service._load_failed, and service.check_duplicate to locate the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a49fdabd-d843-4408-b886-e0acf4aa9faa
📒 Files selected for processing (1)
backend/tests/test_duplicate_service.py
|
Hi @zeroknowledge0x! 🙌 Thank you so much for your excellent contribution: "test: add unit tests for DuplicateService (Fixes #442)"! We really appreciate the high-quality code and effort you have put into the platform. Just a quick, friendly heads-up as we prepare our manual merging and verification queues—please make sure to complete all the mandatory community steps listed below. Once those manual steps are verified, we'll get your PR officially merged into the Let's build something amazing together! 🚀🔥 🌟 Community Support & Network Steps (Take 10 Seconds!)As we prepare our manual verification and merging queues, please make sure you have taken a moment to complete these required steps to finalize your points:
Note: Having these steps completed manually is required before your PR points are officially cleared. |
|
Hi @zeroknowledge0x! 🙌 Thank you so much for your excellent contribution: "test: add unit tests for DuplicateService (Fixes #442)"! We really appreciate the high-quality code and effort you have put into the platform. Just a quick, friendly heads-up as we prepare our manual merging and verification queues—please make sure to complete all the mandatory community steps listed below. Once those manual steps are verified, we'll get your PR officially merged into the Let's build something amazing together! 🚀🔥 🌟 Community Support & Network Steps (Take 10 Seconds!)As we prepare our manual verification and merging queues, please make sure you have taken a moment to complete these required steps to finalize your points:
Note: Having these steps completed manually is required before your PR points are officially cleared. |
- test_storage_dir_created: test actual directory creation by DuplicateService instead of checking tmp_path (which pytest always creates) - test_degraded_returns_no_duplicate: remove dead loaded_service_result variable, add stored ticket to properly exercise degraded code path
Fixes #442
Summary
Adds comprehensive unit tests for
DuplicateServiceinbackend/services/duplicate_service.py. All 25 tests pass with ML dependencies mocked.Changes
backend/tests/test_duplicate_service.pywith 25 test casesis_available(),load(),add_ticket(),check_duplicate(),save_to_disk()Testing
Result: 25 passed in 8.35s
Test Coverage
All ML dependencies (
sentence_transformers) are mocked — no model download required.Summary by CodeRabbit