Cover resource service guard and error paths - #94
Conversation
The resource suite covered happy paths but almost none of the guard/error branches. Adds coverage for: - RemoteResourceNotEnabledException across every guarded entry point (built a disabled-config ResourceService directly). - FileNotFoundException for AddLocalResource / AddExistingRemoteResource. - EntityNotFoundException for DownloadResource with an unknown id. - ArgumentException for uploading a missing / already-uploaded resource. - UploadPendingResources no-op when nothing is pending, and the finally-block durability guarantee: successful uploads persist even when a later upload throws (new ThrowOnUploadCall hook on the mock makes the failure point deterministic regardless of iteration order). - DeleteResource sets DeletedAt to the commit time. - HarmonyResource throws when both local and remote resources are null. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe pull request expands resource-service test coverage for disabled operations, invalid inputs, upload persistence, deletion timestamps, and invalid resource construction. The remote service mock now supports deterministic failures on a selected upload call. ChangesResource service tests
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs`:
- Line 40: Update ThrowOnUploadCall to reject callNumber values less than 1
immediately, while preserving valid 1-based call numbers and the existing
assignment behavior.
🪄 Autofix
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 Plus
Run ID: 6df26d67-eab4-4f2e-9e14-054bb6dd6ab1
📒 Files selected for processing (2)
src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cssrc/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs
AI-generated summary
Third batch from the test-suite review. The resource subsystem had solid happy-path coverage but nearly every guard/error branch was untested — roughly one of the service's throw sites had an assertion.
New tests in
RemoteResourcesTests:GuardedMethods_ThrowWhenResourcesNotEnabled— theRemoteResourceNotEnabledExceptionguard protects 11 methods and was never triggered because the sample kernel always enables resources. Builds aResourceServicedirectly with a disabledHarmonyConfig(the ctor isinternal, visible to tests) and asserts every guarded entry point throws.FileNotFoundExceptionforAddLocalResourceandAddExistingRemoteResourcewith a missing path.EntityNotFoundExceptionforDownloadResourcewith an unknown id;ArgumentExceptionfor uploading a missing resource by id and for uploading an already-uploaded resource.UploadPendingResources— no-op (no commit) when nothing is pending, and thefinally-block durability guarantee: a resource uploaded before a later upload throws is still persisted.DeleteResource_SetsDeletedAtToCommitTime— asserts the actualDeletedAtfield, not just that the resource disappears from queries.HarmonyResource_ThrowsWhenBothResourcesNull.To make the partial-failure test deterministic regardless of iteration order,
RemoteServiceMockgained aThrowOnUploadCall(n)hook that fails the Nth upload call.Test-only; no production code changed.
Test plan
dotnet test --filter FullyQualifiedName~RemoteResourcesTestspasses (32/32 locally, 10 new).Summary by CodeRabbit