refactor: extract evaluate-game business logic from router to service layer #202
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-working
autonomous
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
size:M
size:S
tech-debt
todo
type:feature
type:stability
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#202
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
Problem
The
evaluate_gamefunction inapp/routers_v2/refractor.pylines 318–452 is 134 lines of orchestration logic: pair extraction, auto-init, dry_run evaluation, multi-tier boost loop with partial failure handling, and notification assembly.All in the router layer, which makes testing require HTTP round-trips through the test client.
Fix
Extract into a service function (
evaluate_and_boostin a refractor service module). The spec indocs/plans/refractor-service-layer.mdalready documents this as the target architecture.Impact
Working fine as-is. Refactor when next touching this code — don't rush. The main benefit is testability of edge cases without HTTP overhead.
PR #207 opens the refactor: #207
Approach: Created
app/services/refractor_service.pywith two functions:ensure_variant_cards— idempotent variant-card creation up to a target tier; handles partial failures, REFRACTOR_BOOST_ENABLED kill switch, and skips tiers where variants already existevaluate_and_boost— composesevaluate_card(dry_run=True)+ensure_variant_cardsinto a single callBoth router endpoints (
POST /cards/{card_id}/evaluateandPOST /evaluate-game/{game_id}) now delegate toevaluate_and_boost. The evaluate-game router loses ~55 lines of inline boost orchestration. Response shapes are unchanged.