feat: use high level macros in most tests#46
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR migrates test aggregates and read-model definitions across the sourced-rust test suite from ChangesEvent-Sourcing and Read-Model Attribute Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
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 docstrings
🧪 Generate unit tests (beta)
Comment |
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 `@tests/sagas/order/inventory.rs`:
- Around line 49-53: The reserve method is unsafe for duplicate order_ids:
reserve(&mut self, order_id: String, quantity: u32) currently always subtracts
quantity from available and adds to reserved then inserts/overwrites
reservations, corrupting state on repeats; fix by checking reservations for an
existing entry first and either (a) early-return/block duplicates (if
reservations.contains_key(&order_id) return) or (b) make update idempotent by
computing let prev = self.reservations.get(&order_id).cloned().unwrap_or(0); let
delta = quantity.saturating_sub(prev); apply self.available -= delta;
self.reserved += delta; then insert the new quantity — choose one approach and
update the guard on the #[event("StockReserved", when =
self.can_reserve(quantity))] path accordingly.
🪄 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 Plus
Run ID: def2ad9a-0022-4a26-bbda-db26ec19c657
📒 Files selected for processing (29)
src/commit_builder/mod.rssrc/outbox/commit.rssrc/snapshot/repository.rstests/async_repository/main.rstests/blob_game/aggregate.rstests/bomberman/views.rstests/distributed_read_model/main.rstests/distributed_read_model/read_models/checkout_step_view.rstests/distributed_read_model/read_models/checkout_view.rstests/distributed_read_model/read_models/seat_view.rstests/distributed_read_model_board/read_models/board_view.rstests/distributed_read_model_board/read_models/card_view.rstests/persistent_repository_conformance/read_models.rstests/postgres_repository/main.rstests/read_model_commit_bridge/main.rstests/read_model_metadata/main.rstests/read_model_relationship_includes/main.rstests/read_model_schema_bootstrap/main.rstests/read_model_session/main.rstests/read_models/aggregate.rstests/sagas/order/inventory.rstests/sagas/order/order_aggregate.rstests/sagas/order/payment.rstests/sagas/order/saga.rstests/snapshots/aggregate.rstests/snapshots/main.rstests/sourced_snapshot/aggregates.rstests/sqlite_repository/main.rstests/todos/aggregate.rs
| #[event("StockReserved", when = self.can_reserve(quantity))] | ||
| pub fn reserve(&mut self, order_id: String, quantity: u32) { | ||
| self.available -= quantity; | ||
| self.reserved += quantity; | ||
| self.reservations.insert(order_id, quantity); |
There was a problem hiding this comment.
Reject duplicate reservations for the same order.
Line 53 overwrites any existing entry for order_id, but Lines 51-52 still apply the full delta, so a second StockReserved for the same order corrupts available and reserved. Either block duplicate order IDs in the guard or make the map update additive/idempotent.
Suggested fix
- #[event("StockReserved", when = self.can_reserve(quantity))]
+ #[event(
+ "StockReserved",
+ when = self.can_reserve(quantity) && !self.reservations.contains_key(&order_id)
+ )]
pub fn reserve(&mut self, order_id: String, quantity: u32) {
self.available -= quantity;
self.reserved += quantity;
self.reservations.insert(order_id, quantity);
}🤖 Prompt for 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.
In `@tests/sagas/order/inventory.rs` around lines 49 - 53, The reserve method is
unsafe for duplicate order_ids: reserve(&mut self, order_id: String, quantity:
u32) currently always subtracts quantity from available and adds to reserved
then inserts/overwrites reservations, corrupting state on repeats; fix by
checking reservations for an existing entry first and either (a)
early-return/block duplicates (if reservations.contains_key(&order_id) return)
or (b) make update idempotent by computing let prev =
self.reservations.get(&order_id).cloned().unwrap_or(0); let delta =
quantity.saturating_sub(prev); apply self.available -= delta; self.reserved +=
delta; then insert the new quantity — choose one approach and update the guard
on the #[event("StockReserved", when = self.can_reserve(quantity))] path
accordingly.
|
Actionable comments posted: 0 |
Summary by CodeRabbit