Skip to content

Cover resource service guard and error paths - #94

Merged
hahn-kev merged 1 commit into
mainfrom
tests/resource-guard-paths
Aug 7, 2026
Merged

Cover resource service guard and error paths#94
hahn-kev merged 1 commit into
mainfrom
tests/resource-guard-paths

Conversation

@hahn-kev-bot

@hahn-kev-bot hahn-kev-bot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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 — the RemoteResourceNotEnabledException guard protects 11 methods and was never triggered because the sample kernel always enables resources. Builds a ResourceService directly with a disabled HarmonyConfig (the ctor is internal, visible to tests) and asserts every guarded entry point throws.
  • File guardsFileNotFoundException for AddLocalResource and AddExistingRemoteResource with a missing path.
  • Lookup guardsEntityNotFoundException for DownloadResource with an unknown id; ArgumentException for uploading a missing resource by id and for uploading an already-uploaded resource.
  • UploadPendingResources — no-op (no commit) when nothing is pending, and the finally-block durability guarantee: a resource uploaded before a later upload throws is still persisted.
  • DeleteResource_SetsDeletedAtToCommitTime — asserts the actual DeletedAt field, not just that the resource disappears from queries.
  • HarmonyResource_ThrowsWhenBothResourcesNull.

To make the partial-failure test deterministic regardless of iteration order, RemoteServiceMock gained a ThrowOnUploadCall(n) hook that fails the Nth upload call.

Test-only; no production code changed.

Test plan

  • dotnet test --filter FullyQualifiedName~RemoteResourcesTests passes (32/32 locally, 10 new).

Summary by CodeRabbit

  • Tests
    • Added coverage for resource-service behavior when resources are disabled.
    • Added tests for missing resources and files, duplicate uploads, no-op uploads, upload failures, deletion timestamps, and invalid resource construction.
    • Added simulated remote upload failures to verify partial-upload handling and persistence.

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>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Resource service tests

Layer / File(s) Summary
Resource guards and validation
src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs
Adds disabled-service guards, missing-resource and missing-file checks, deletion timestamp validation, and invalid HarmonyResource construction coverage.
Upload persistence scenarios
src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs, src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs
Adds no-op upload coverage and verifies that earlier successful uploads persist when a later upload fails. The mock can fail on a configured upload call.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • sillsdev/harmony#44: The changes extend its resource upload tests and remote service mock behavior.

Suggested reviewers: hahn-kev, rmunn

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the added tests for resource service guards and error paths.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tests/resource-guard-paths

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hahn-kev

hahn-kev commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 03f609f and 3c7b1a5.

📒 Files selected for processing (2)
  • src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs
  • src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs

Comment thread src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs
@hahn-kev
hahn-kev merged commit 365f4d5 into main Aug 7, 2026
7 checks passed
@hahn-kev
hahn-kev deleted the tests/resource-guard-paths branch August 7, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants