strat-gameplay-webapp/backend
Cal Corum dd1b087af1 CLAUDE: Fix double play bug after state recovery
Critical bug fix for issue where Groundball A with runner on first would
fail to execute a double play after game recovery from database.

Root cause: current_on_base_code field was not recalculated during state
recovery, defaulting to 0 (empty bases) even when runners were on base.
This caused runner advancement logic to select Result 1 (batter out,
runners hold) instead of Result 2 (double play).

Changes:
- Added calculate_on_base_code() helper method to GameState model
- Updated _prepare_next_play() to use helper (eliminates duplication)
- Fixed state recovery to calculate current_on_base_code from runners
- Fixed X-Check G1 mapping (was GROUNDBALL_B, should be GROUNDBALL_A)
- Added 5 regression tests to prevent recurrence

Testing:
- All 359 unit tests passing
- New regression tests verify fix and demonstrate bug scenario
- Tested in network dev environment - double plays now work correctly

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-07 13:55:10 -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 CLAUDE: RosterLink refactor for bench players with cached player data 2026-01-17 22:15:12 -06:00
app CLAUDE: Fix double play bug after state recovery 2026-02-07 13:55:10 -06:00
scripts CLAUDE: Add test game creation utilities 2025-11-19 16:30:29 -06:00
terminal_client CLAUDE: Fix RunnerAdvancementData tuple unpacking regression 2025-11-28 23:11:26 -06:00
tests CLAUDE: Fix double play bug after state recovery 2026-02-07 13:55:10 -06:00
.dockerignore CLAUDE: Fix Docker build for UV migration 2025-11-04 09:19:30 -06:00
.env.dev CLAUDE: Improve UX with single-click OAuth, enhanced games list, and layout fix 2025-12-05 16:14:00 -06:00
.env.example CLAUDE: Implement server-side OAuth flow with HttpOnly cookies 2025-11-26 22:16:30 -06:00
.env.network CLAUDE: Add --network flag to dev-native.sh for cross-device testing 2026-02-06 18:09:01 -06:00
.env.prod CLAUDE: Improve UX with single-click OAuth, enhanced games list, and layout fix 2025-12-05 16:14:00 -06:00
.gitignore CLAUDE: Add pages/ to backend gitignore 2025-11-20 23:57:25 -06:00
.python-version CLAUDE: Add native development workflow for instant startup and hot-reload 2026-02-06 17:56:56 -06:00
alembic.ini CLAUDE: Add Alembic migrations and database session injection 2025-11-28 12:09:09 -06:00
CLAUDE.md CLAUDE: Add multi-domain environment configuration support 2025-12-03 13:58:42 -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: Add SBA schedule integration with weekly matchup display 2026-01-14 23:39:31 -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: Update documentation across codebase 2025-11-28 12:10:10 -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

# Apply database migrations
uv run alembic upgrade head

# Run server
uv run python -m app.main

Database Migrations

This project uses Alembic for database schema migrations.

Initial Setup (New Database)

# Apply all migrations to create schema
uv run alembic upgrade head

Creating New Migrations

# Auto-generate from model changes
uv run alembic revision --autogenerate -m "Description of changes"

# IMPORTANT: Always review the generated migration before applying!
# Then apply:
uv run alembic upgrade head

Viewing Migration Status

# Show migration history
uv run alembic history

# Show current revision
uv run alembic current

Rolling Back

# Rollback one migration
uv run alembic downgrade -1

# Rollback to specific revision
uv run alembic downgrade 001

# Rollback all (dangerous!)
uv run alembic downgrade base

Migration Best Practices

  1. Always review auto-generated migrations before applying - autogenerate is helpful but not perfect
  2. Test migrations on dev/staging before production
  3. Keep migrations small and focused - easier to rollback
  4. Never edit migrations that have been applied to shared databases
  5. Include both upgrade and downgrade for reversibility

Existing Migrations

Revision Description
001 Initial schema (games, plays, lineups, rolls, etc.)
004 Materialized views for statistics

Documentation

See CLAUDE.md for full documentation.