Skip to content

Resource update #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Resource update #44

wants to merge 5 commits into from

Conversation

hahn-kev
Copy link
Collaborator

@hahn-kev hahn-kev commented Jul 15, 2025

  • Tweaks some APIs (pass resource Id when uploading a new resource)
  • fix some bugs (unable to deserialize changes)
  • and adds a couple new ones to delete resources

Summary by CodeRabbit

  • New Features

    • Added the ability to create and register a local resource from an existing remote resource.
    • Introduced functionality to delete resources, ensuring they are removed from both local and remote storage.
  • Bug Fixes

    • Improved reliability of resource deletion, ensuring resources are fully removed from all retrieval methods.
  • Tests

    • Added tests to verify that resource deletion removes resources from all access points.
  • Improvements

    • Enhanced resource upload and management by requiring explicit resource IDs for uploads.
    • Improved code clarity and safety with updated property annotations and constructor styles.

hahn-kev added 4 commits July 14, 2025 11:11
- Implemented tests to verify that local and remote resources are correctly deleted from the resource service.
- Ensured that deleted resources are no longer retrievable from all APIs.
Copy link

coderabbitai bot commented Jul 15, 2025

Walkthrough

The changes introduce new and updated methods for handling resource uploads and deletions, including the addition of resource identifiers to upload operations. New test cases verify resource deletion behavior. Several constructors and method signatures were updated for consistency, and nullable reference annotations were added to clarify property contracts.

Changes

File(s) Change Summary
src/SIL.Harmony.Core/IRemoteResourceService.cs
src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs
src/SIL.Harmony/ResourceService.cs
UploadResource method signature updated to require a Guid resourceId parameter in interface, mock, and all usages.
src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs Added two async test methods to verify deletion of local and remote resources.
src/SIL.Harmony/Db/CrdtRepository.cs Added DeleteLocalResource(Guid id) method to remove a local resource by ID from the database.
src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs
src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs
Changed constructor parameter names from resourceId to entityId and switched to primary constructor syntax.
src/SIL.Harmony/Resource/HarmonyResource.cs Added [MemberNotNullWhen] attributes to clarify non-null property contracts for Local and Remote.
src/SIL.Harmony/ResourceService.cs Added AddExistingRemoteResource and DeleteResource methods; updated all UploadResource calls to use new signature.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ResourceService
    participant RemoteResourceService
    participant CrdtRepository

    Client->>ResourceService: AddExistingRemoteResource(resourcePath, clientId, resourceId, remoteId)
    ResourceService->>RemoteResourceService: UploadResource(resourceId, resourcePath)
    RemoteResourceService-->>ResourceService: UploadResult
    ResourceService->>CrdtRepository: AddLocalResource(...)
    CrdtRepository-->>ResourceService: (confirmation)
    ResourceService-->>Client: (completion)

    Client->>ResourceService: DeleteResource(clientId, resourceId)
    ResourceService->>CrdtRepository: DeleteLocalResource(resourceId)
    CrdtRepository-->>ResourceService: (confirmation)
    ResourceService-->>Client: (completion)
Loading

Poem

A rabbit hops with code so bright,
Uploads now need an ID in sight.
Old resources can be removed with glee,
Tests ensure they're gone, as they should be!
With attributes clear and signatures neat,
This code update is quite a treat! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55e3785 and 90e923c.

📒 Files selected for processing (1)
  • src/SIL.Harmony/ResourceService.cs (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/SIL.Harmony/ResourceService.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: Analyze (csharp)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a660d1 and 55e3785.

📒 Files selected for processing (8)
  • src/SIL.Harmony.Core/IRemoteResourceService.cs (1 hunks)
  • src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs (1 hunks)
  • src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs (1 hunks)
  • src/SIL.Harmony/Db/CrdtRepository.cs (1 hunks)
  • src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs (1 hunks)
  • src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs (1 hunks)
  • src/SIL.Harmony/Resource/HarmonyResource.cs (1 hunks)
  • src/SIL.Harmony/ResourceService.cs (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/SIL.Harmony/Db/CrdtRepository.cs (1)
src/SIL.Harmony/Resource/LocalResource.cs (1)
  • LocalResource (6-16)
src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs (3)
src/SIL.Harmony.Core/IRemoteResourceService.cs (2)
  • Task (17-17)
  • Task (25-25)
src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs (2)
  • Task (18-25)
  • Task (29-43)
src/SIL.Harmony/ResourceService.cs (12)
  • Task (31-46)
  • Task (48-93)
  • Task (95-102)
  • Task (104-122)
  • Task (124-131)
  • Task (133-138)
  • Task (140-149)
  • Task (151-160)
  • Task (162-167)
  • Task (169-183)
  • Task (185-188)
  • Task (190-193)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: Analyze (csharp)
🔇 Additional comments (9)
src/SIL.Harmony/Db/CrdtRepository.cs (1)

393-396: LGTM! Clean implementation following established patterns.

The new DeleteLocalResource method correctly follows the same pattern as other delete operations in the repository, using ExecuteDeleteAsync() for efficient bulk deletion.

src/SIL.Harmony/Resource/CreateRemoteResourceChange.cs (1)

6-6: LGTM! Parameter naming standardized for consistency.

The rename from resourceId to entityId aligns with the base class constructor and improves naming consistency across the resource management codebase.

src/SIL.Harmony.Core/IRemoteResourceService.cs (1)

22-25: All implementations updated for the new UploadResource signature

Verified that the only concrete implementation (RemoteServiceMock in src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs) and all callers have been updated to include the resourceId parameter. No other classes implement IRemoteResourceService, so the interface change is fully reflected.

src/SIL.Harmony.Tests/ResourceTests/RemoteServiceMock.cs (1)

29-29: Mock implementation updated to match interface signature.

The resourceId parameter addition correctly aligns with the updated IRemoteResourceService interface. It's acceptable that the mock doesn't utilize this parameter since it focuses on simulating upload behavior rather than resource tracking.

src/SIL.Harmony/Resource/CreateRemoteResourcePendingUpload.cs (1)

6-7: Excellent refactor to primary constructor with consistent naming.

The change to primary constructor syntax with entityId parameter improves code conciseness and aligns with the naming standardization across resource management classes.

src/SIL.Harmony/Resource/HarmonyResource.cs (1)

1-14: LGTM! Good use of nullable reference type annotations.

The MemberNotNullWhen attributes correctly express the null-state contract between the boolean properties and their corresponding nullable fields, helping the compiler provide better null-safety warnings.

src/SIL.Harmony.Tests/ResourceTests/RemoteResourcesTests.cs (1)

211-243: LGTM! Comprehensive test coverage for resource deletion.

Both tests properly verify that deleted resources are removed from all retrieval APIs (GetResource, GetLocalResource, and AllResources). The tests cover both local and remote resource deletion scenarios with clear Arrange-Act-Assert structure.

src/SIL.Harmony/ResourceService.cs (2)

31-46: LGTM! Well-structured method for adding existing remote resources.

The method properly validates resources setup, checks file existence, and follows the established pattern of creating changes and storing local resources.


69-69: LGTM! Consistent updates to UploadResource calls.

All calls to UploadResource have been correctly updated to pass the resource ID as the first parameter, aligning with the new interface signature.

Also applies to: 113-113, 136-136

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

1 participant