paper-dynasty-gameplay-webapp/app
Cal Corum 7fd9079425 CLAUDE: Improve AI Service test coverage from 60% to 72% with comprehensive integration tests
Added targeted integration tests to cover previously uncovered conditional branches
and edge cases in AI decision-making logic:

- test_ai_service_focused_coverage.py: 11 tests for key missing branches
  * Steal opportunity conditions (lines 91, 93, 98-99, 108)
  * Steal to third/home scenarios (lines 129, 157, 161)
  * Defensive alignment logic (lines 438, 480)
  * Tag decision branches (lines 204, 253)

- test_ai_service_final_coverage.py: 10 tests for remaining gaps
  * Complex steal conditions (lines 95, 118-119, 132, 136-137, 141)
  * Late inning steal logic (lines 159, 163)
  * Uncapped advance bounds checking (lines 382-388)
  * Complex defensive scenarios (lines 440-449)

- test_ai_service_coverage.py: Comprehensive coverage tests (unused due to complexity)

Fixed:
- Player model relationship syntax (removed unsupported cascade_delete parameter)
- Existing test assertion in test_ai_service_simple.py for steal to home scenario

Coverage improvement: 369 statements, 147→105 missed lines (60%→72% coverage)
All 49 AI Service tests now pass with comprehensive integration testing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 21:28:43 -05:00
..
config CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
engine CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
models CLAUDE: Improve AI Service test coverage from 60% to 72% with comprehensive integration tests 2025-09-29 21:28:43 -05:00
repositories CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
routers CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
services CLAUDE: Complete Player model migration with service layer and integration test infrastructure 2025-09-29 16:20:29 -05:00
templates CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
__init__.py CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
main.py CLAUDE: Initialize Paper Dynasty web app with Model/Service Architecture 2025-09-27 21:44:12 -05:00
README.md CLAUDE: Achieve 100% test pass rate with comprehensive AI service testing 2025-09-28 17:55:34 -05:00

App Directory

This directory contains the main application code for the Paper Dynasty web app, following the Model/Service Architecture pattern.

Architecture Overview

The app follows a clean separation of concerns:

  • Models (models/) - Pure data models using SQLModel
  • Services (services/) - Business logic layer with dependency injection
  • Controllers (routers/) - Thin FastAPI route handlers
  • Engine (engine/) - Stateless game simulation functions
  • Configuration (config/) - Application settings and constants

Key Files

  • main.py - FastAPI application setup and configuration
  • Entry point for the web application

Directory Structure

app/
├── main.py                 # FastAPI application setup
├── config/                 # Configuration and constants
├── models/                 # SQLModel data models
├── services/               # Business logic layer (⭐ Core of architecture)
├── repositories/           # Optional data access layer
├── routers/                # FastAPI route handlers
├── engine/                 # Stateless game simulation
├── static/                 # Static web assets
└── templates/              # Jinja2 HTML templates

Service-First Development

When adding new features:

  1. Start with services - implement business logic in the service layer
  2. Test services independently - unit test with mocked dependencies
  3. Create thin routes - delegate to services via dependency injection
  4. Keep engine stateless - pure functions for game calculations

Migration Context

This application is migrated from a Discord bot (../discord-app/) with the goal of extracting Discord-specific business logic into clean, testable services that can support multiple interfaces (web, API, mobile, etc.).

Current Migration Status

Phase 1: Foundation Data Models - COMPLETE

  • ManagerAi - AI configuration (→ AIService with 9 methods)
  • Cardset - Card set metadata (pure data, no extraction needed)

Phase 2: Player and Card Data - 🚧 NEXT

  • 📋 Team - Team identity data (→ UIService for embed property)
  • 📋 Player - Player metadata (→ UIService for Discord markdown)

Testing Infrastructure - COMPLETE

  • Transaction rollback pattern for test isolation
  • Factory pattern for unique test data generation
  • Comprehensive test coverage (23 tests passing)

See .claude/model-migration-plan.md for detailed migration tracking.