strat-gameplay-webapp/backend/app/core
Cal Corum 05fc037f2b CLAUDE: Fix game recovery and add required field validation for plays
Fixed critical bugs in game recovery and play persistence:

1. Terminal REPL Auto-Recovery:
   - Added _ensure_game_loaded() helper to auto-recover games from database
   - Calls state_manager.recover_game() when game not in memory
   - Calls _prepare_next_play() after recovery to populate snapshot fields
   - Enables seamless continuation of games across REPL sessions

2. Play Validation:
   - Added verification in _save_play_to_db() for required fields
   - Ensures batter_id, pitcher_id, catcher_id are never NULL
   - Raises ValueError with clear error message if fields missing
   - Prevents database constraint violations

3. Updated Commands:
   - All REPL commands now call _ensure_game_loaded()
   - Commands: defensive, offensive, resolve, status, quick_play, box_score
   - Fixes "Game state not found" errors on recovered games

Root Cause:
- state_manager.recover_game() rebuilds GameState from database
- But didn't populate snapshot fields (current_batter_lineup_id, etc.)
- _save_play_to_db() requires these fields to save plays
- Solution: Call _prepare_next_play() after recovery

Files Modified:
- app/core/game_engine.py - Added verification in _save_play_to_db()
- terminal_client/repl.py - Added _ensure_game_loaded() and integrated

Testing: Successfully recovered game, submitted decisions, and resolved plays

🚀 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 13:14:12 -05:00
..
__init__.py CLAUDE: Complete Week 4 - State Management & Persistence 2025-10-22 12:01:03 -05:00
dice.py CLAUDE: Implement comprehensive dice roll system with persistence 2025-10-24 08:29:02 -05:00
game_engine.py CLAUDE: Fix game recovery and add required field validation for plays 2025-10-26 13:14:12 -05:00
play_resolver.py CLAUDE: Implement GameEngine, PlayResolver, and GameValidator 2025-10-24 10:00:21 -05:00
roll_types.py CLAUDE: Fix GameEngine lineup integration and add test script 2025-10-24 15:04:41 -05:00
state_manager.py CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
validators.py CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00