strat-gameplay-webapp/backend
Cal Corum bcbf6036c7 CLAUDE: Fix state recovery batter advancement and flyball descriptions
This commit fixes two critical bugs in the game engine and updates tests
to match current webhook behavior:

1. State Recovery - Batter Advancement (operations.py:545-546)
   - Added missing batting_order and outs_recorded fields to plays dictionary
   - These fields exist in database but weren't loaded by load_game_state()
   - Root cause: Batter index was correctly recovered but current_batter remained
     at placeholder (batting_order=1) because recovery logic couldn't find the
     actual batting_order from last play
   - Fix enables proper batter advancement after backend restarts

2. Flyball Descriptions - 2 Outs Logic (runner_advancement.py)
   - Made flyball descriptions dynamic based on outs and actual base runners
   - FLYOUT_A (Deep): Lines 1352-1363
   - FLYOUT_B (Medium): Lines 1438-1449
   - FLYOUT_BQ (Medium-shallow): Lines 1521-1530
   - With 2 outs: "3rd out, inning over" (no advancement possible)
   - With 0-1 outs: Dynamic based on runners ("R3 scores" only if R3 exists)
   - Game logic was already correct (runs_scored=0), only descriptions were wrong
   - Fixed method signatures to include hit_location parameter for all flyball methods
   - Updated X-check function calls to pass hit_location parameter

3. Test Updates
   - Fixed test expectation in test_flyball_advancement.py to match corrected behavior
   - Descriptions now only show runners that actually exist (no phantom "R2 DECIDE")
   - Auto-fixed import ordering with Ruff
   - Updated websocket tests to match current webhook behavior:
     * test_submit_manual_outcome_success now expects 2 broadcasts (play_resolved + game_state_update)
     * test_submit_manual_outcome_missing_required_location updated to reflect hit_location now optional

Testing:
- All 739 unit tests passing (100%)
- Verified batter advances correctly after state recovery
- Verified flyball with 2 outs shows correct description
- Verified dynamic descriptions only mention actual runners on base
- Verified websocket handler broadcasts work correctly

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 15:38:29 -06:00
..
.claude CLAUDE: Add configurable regulation_innings and outs_per_inning 2025-11-19 20:06:57 -06:00
.git-hooks CLAUDE: Fix all unit test failures and implement 100% test requirement 2025-11-04 19:35:21 -06:00
alembic/versions CLAUDE: Phases 3.5, F1-F5 Complete - Statistics & Frontend Components 2025-11-14 09:52:30 -06:00
app CLAUDE: Fix state recovery batter advancement and flyball descriptions 2025-11-21 15:38:29 -06:00
scripts CLAUDE: Add test game creation utilities 2025-11-19 16:30:29 -06:00
terminal_client CLAUDE: Refactor offensive decisions - replace approach with action field 2025-11-14 15:07:54 -06:00
tests CLAUDE: Fix state recovery batter advancement and flyball descriptions 2025-11-21 15:38:29 -06:00
.dockerignore CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
.env.example CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
.gitignore CLAUDE: Add pages/ to backend gitignore 2025-11-20 23:57:25 -06:00
.python-version CLAUDE: Migrate backend to UV package management 2025-11-04 08:52:11 -06:00
CLAUDE.md CLAUDE: Replace black and flake8 with ruff for formatting and linting 2025-11-20 15:33:21 -06:00
clean_test_data.py CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
docker-compose.yml CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
Dockerfile CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
mypy.ini CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
pyproject.toml CLAUDE: Replace black and flake8 with ruff for formatting and linting 2025-11-20 15:33:21 -06:00
pyrightconfig.json Clean up false positive Pylance errors 2025-10-23 09:10:41 -05:00
pytest.ini CLAUDE: Complete Week 4 - State Management & Persistence 2025-10-22 12:01:03 -05:00
README.md CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
requirements-dev.txt CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
requirements.txt CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
TEST_COVERAGE_SUMMARY.md CLAUDE: Phase 2 test infrastructure + comprehensive documentation 2025-11-05 12:39:32 -06:00
test_db_playground.py Add scripts to test models in dev database 2025-10-23 09:10:55 -05:00
test_pd_api_live.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_pd_api_mock.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_redis_cache.py CLAUDE: Phase 3E-Final - Redis Caching & X-Check WebSocket Integration 2025-11-03 22:46:59 -06:00
uv.lock CLAUDE: Replace black and flake8 with ruff for formatting and linting 2025-11-20 15:33:21 -06:00

Paper Dynasty Backend

FastAPI-based real-time baseball game engine with WebSocket support.

Quick Start

# Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install dependencies
uv sync

# Run server
uv run python -m app.main

Documentation

See CLAUDE.md for full documentation.