Add core/ports.py - Storage interfaces #20
Reference in New Issue
Block a user
Delete Branch "feat/issue-6-storage-ports"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Define abstract storage interfaces (Protocols) for storage adapters:
Changes
core/ports.py- New file with Protocol definitionscore/__init__.py- Updated exports to include storage protocolsCloses #6
why do we need personal storage when we now doesnt really separate which one is personal and which one is group? I think its somehow already covered in the tracking storage and room storage.
what is storage / protocol anyway? we add bounty through room storage, but how to add a new room/tracking?
is it possible to create unit tests in this PR?
Addressed all feedback:
1. PersonalStorage removed
You are right - PersonalStorage was redundant. RoomStorage handles both group and personal bounties via room_id:
2. Creating rooms/tracking entries
Added explicit
ensure_room()andensure_tracking()methods:RoomStorage.ensure_room(room_id)- creates room if it doesn't existTrackingStorage.ensure_tracking(room_id, user_id)- creates tracking entry if it doesn't existThe
add_bountyandtrack_bountymethods also create the room/tracking implicitly if needed.3. Unit tests added
Added
tests/test_ports.pywith 11 tests covering protocol compliance, creation methods, and CRUD operations.Test results: 22 passed, 1 warning
@@ -0,0 +19,4 @@def save(self, room_data: RoomData) -> None:self._rooms[room_data.room_id] = room_datadef ensure_room(self, room_id: int) -> RoomData:can we add a test where we have a very simple mock storage to check or verify if we really need an ensure_room function? basically the goal is to see do we need the ensure_room() or we can safely remove it and expect things also works without it.
Added tests with SimpleRoomStorage and SimpleTrackingStorage (no ensure_* methods):
Test Result: 20 passed, 1 warning
Key findings:
SimpleRoomStorage(withoutensure_room()) - add_bounty works fineSimpleTrackingStorage(withoutensure_tracking()) - track_bounty works fineConclusion:
ensure_room()andensure_tracking()are NOT needed as public Protocol methods.The add_bounty() and track_bounty() methods create rooms/tracking internally. Removed these methods from the Protocol to simplify the interface.
I think we should remove ensure_room() and ensure_tracking() then since its adding unnecessary function as well. what do you think?
Confirmed - ensure_room() and ensure_tracking() have already been removed from the Protocol definitions in the previous commit.
Current Protocols:
RoomStorage: load, save, add_bounty, update_bounty, delete_bounty, get_bounty
TrackingStorage: load, save, track_bounty, untrack_bounty
Test Results: 20 passed, 1 warning
lgtm