strat-gameplay-webapp/backend/terminal_client
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: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
__main__.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
CLAUDE.md CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
config.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
display.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
main.py CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
repl.py CLAUDE: Fix game recovery and add required field validation for plays 2025-10-26 13:14:12 -05:00