refactor: complete phase-5 handler DI migration to AppContext (#639) - #657
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR refactors the action handler dispatcher by removing the direct database pool parameter from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/app.rs (1)
250-285: Please extend the routing smoke test for these new branches.
handle_message_action_tests::test_action_routing_logicstill omitsAction::LastTradeIndex,Action::RestoreSession, andAction::Orders, so the routes added here can regress without a failing test.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/app.rs` around lines 250 - 285, The routing test handle_message_action_tests::test_action_routing_logic is missing coverage for Action::LastTradeIndex, Action::RestoreSession, and Action::Orders; update that test to include cases for these three variants and assert they route to the corresponding handlers (last_trade_index_with_ctx, restore_session_action_with_ctx, orders_action_with_ctx) by constructing messages/events that select those Actions and verifying the dispatched path/handler is invoked or returned as expected so future changes to Action routing will fail the test if regressions occur.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app.rs`:
- Around line 246-250: The match arm for Action::PayInvoice currently panics via
todo!(); replace it with returning a typed Mostro error instead (e.g., construct
and return MostroError::MostroCantDo with an appropriate CantDoReason) so the
message loop handles unsupported actions gracefully; ensure the arm mirrors the
other arms' error handling by returning the error converted into the function's
Result/Error type (similar to how
add_invoice_action_with_ctx(...).await.map_err(|e| e.into()) is handled), and
reference the Action::PayInvoice match arm to implement this change.
---
Nitpick comments:
In `@src/app.rs`:
- Around line 250-285: The routing test
handle_message_action_tests::test_action_routing_logic is missing coverage for
Action::LastTradeIndex, Action::RestoreSession, and Action::Orders; update that
test to include cases for these three variants and assert they route to the
corresponding handlers (last_trade_index_with_ctx,
restore_session_action_with_ctx, orders_action_with_ctx) by constructing
messages/events that select those Actions and verifying the dispatched
path/handler is invoked or returned as expected so future changes to Action
routing will fail the test if regressions occur.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4b7907f7-ab54-41e0-b87b-05d3039a4c1b
📒 Files selected for processing (17)
src/app.rssrc/app/add_invoice.rssrc/app/admin_add_solver.rssrc/app/admin_cancel.rssrc/app/admin_settle.rssrc/app/admin_take_dispute.rssrc/app/dispute.rssrc/app/fiat_sent.rssrc/app/last_trade_index.rssrc/app/order.rssrc/app/orders.rssrc/app/rate_user.rssrc/app/release.rssrc/app/restore_session.rssrc/app/take_buy.rssrc/app/take_sell.rssrc/app/trade_pubkey.rs
|
Follow-up hardening done in
Validation:
|
|
I agree with this review assessment.
Validation after changes:
|
Phase 5 of #639 — Migrate remaining handlers to AppContext entrypoints
This PR completes Phase 5 by moving all remaining action routes in
app.rsto&AppContext-based handler entrypoints.What changed
1) New
*_with_ctxentrypoints for all remaining action handlersAdded thin DI wrappers in each module to preserve current behavior while routing through
AppContext:add_invoice_action_with_ctxadmin_add_solver_action_with_ctxadmin_cancel_action_with_ctxadmin_settle_action_with_ctxadmin_take_dispute_action_with_ctxdispute_action_with_ctxfiat_sent_action_with_ctxlast_trade_index_with_ctxorder_action_with_ctxorders_action_with_ctxupdate_user_reputation_action_with_ctxrelease_action_with_ctxrestore_session_action_with_ctxtake_buy_action_with_ctxtake_sell_action_with_ctxtrade_pubkey_action_with_ctxcancel_action_with_ctxalready existed from Phase 2.2) Dispatcher (
src/app.rs) now routes all handled actions through DI entrypointshandle_message_actionnow calls only*_with_ctxaction functions for handled action variants.3) Removed legacy migration parameter from dispatcher signature
handle_message_actionno longer takes apoolargument.ctxis now the dependency source for routed handlers.Notes
*_action(..., pool, ...)) as compatibility wrappers inside modules.Validation
cargo fmt✅cargo clippy --all-targets --all-features -- -D warnings✅cargo test✅ (190 passing)Part of #639
Related cleanup tracker: #656
Summary by CodeRabbit