Add comprehensive backend test plan for iterative sub-agent testing

This commit is contained in:
2026-08-08 23:17:21 +00:00
parent 2d10523efc
commit 2d52e2dc89
+387
View File
@@ -0,0 +1,387 @@
# Backend Test Plan
## Overview
This test plan is designed for iterative execution using sub-agents, with each sub-agent handling a specific phase to avoid exceeding the 300,000 token context limit. Each phase focuses on a distinct subsystem and includes specific test cases and verification steps.
## Test Phases
### Phase 1: Database & Migration Tests
**Scope:** Alembic migrations, database schema, model relationships
**Sub-agent Task:** Verify all migrations run correctly and database schema is consistent
#### Test Cases:
1. **Migration 000 (Empty)**
- Verify migration exists and is empty
- Check downgrade/upgrade functions exist
2. **Migration 001 (Initial User Schema)**
- Run migration upgrade
- Verify all 16 tables created:
- `mtgonline_users` (base table)
- `mtgonline_decklist_files` (base table)
- `mtgonline_rooms` (base table)
- `user_sessions`
- `deck_versions`
- `game_replays`
- `replay_players`
- `game_outcomes`
- `user_statistics`
- `user_card_collection`
- `card_wishlist`
- `user_groups`
- `group_members`
- `group_chat_messages`
- `user_networks`
- `network_members`
- `user_preferences`
- `user_activity_log`
- Verify foreign key constraints
- Verify indexes created
- Verify unique constraints
- Run migration downgrade
- Verify all tables dropped
3. **Migration 002 (User Deck Building Tables)**
- Run migration upgrade
- Verify tables created:
- `mtgonline_decklist_cards`
- `mtgonline_decklist_precedents`
- `mtgonline_decklist_suggestions`
- Verify foreign keys to `mtgonline_decklist_files`
- Run migration downgrade
- Verify tables dropped
4. **Migration 003 (MTG Cards Table)**
- Run migration upgrade
- Verify `mtgonline_cards` table created
- Verify columns and indexes
- Run migration downgrade
- Verify table dropped
5. **Migration 004 (Card Import Table)**
- Run migration upgrade
- Verify `mtgonline_card_imports` table created
- Verify foreign key to `mtgonline_users`
- Run migration downgrade
- Verify table dropped
6. **Schema Consistency Checks**
- Verify all foreign keys reference existing tables
- Verify no circular dependencies
- Verify all tables have proper indexes
- Verify unique constraints are valid
**Verification:** All migrations run successfully in order, schema is consistent, no orphaned foreign keys.
---
### Phase 2: Model Layer Tests
**Scope:** SQLAlchemy models, relationships, validation
**Sub-agent Task:** Verify all model definitions are correct and consistent
#### Test Cases:
1. **User Data Models (`app/models/user_data.py`)**
- Verify `User` model matches `mtgonline_users` table
- Verify all columns defined
- Verify relationships defined
- Check for missing fields
2. **User Deck Models (`app/models/user_deck.py`)**
- Verify `DecklistFile`, `DecklistCard`, `DecklistPrecedent`, `DecklistSuggestion` models
- Verify foreign key relationships
- Verify cascade delete behavior
- Check for missing fields
3. **Card Import Models (`app/models/user_card_import.py`)**
- Verify `CardImport` model
- Verify foreign key to `mtgonline_users`
- Check for missing fields
4. **Game Models (`app/models/game.py`)**
- Verify `Game`, `GamePlayer`, `GameCard`, `GameAction`, `GameLog` models
- Verify relationships
- Check for missing fields
5. **MTG Card Models (`app/models/mtg_card.py`)**
- Verify `MtgonlineCard`, `CardPriceHistory` models
- Verify relationships
- Check for missing fields
6. **Model Consistency**
- Verify all models have proper `__tablename__`
- Verify all foreign keys reference correct tables
- Verify all relationships are bidirectional where needed
- Check for missing imports
- Verify model imports in `app/models/__init__.py`
**Verification:** All models compile without errors, relationships are correct, no missing fields.
---
### Phase 3: Schema Layer Tests
**Scope:** Pydantic schemas, request/response validation
**Sub-agent Task:** Verify all schema definitions are correct
#### Test Cases:
1. **User Data Schemas (`app/schemas/user_data_schemas.py`)**
- Verify `UserCreate`, `UserUpdate`, `UserResponse` schemas
- Verify all required fields
- Check for missing validation
2. **User Deck Schemas (`app/schemas/user_deck_schemas.py`)**
- Verify `DecklistFileCreate`, `DecklistFileUpdate`, `DecklistFileResponse`
- Verify `DecklistCardCreate`, `DecklistCardUpdate`, `DecklistCardResponse`
- Verify `DecklistPrecedentCreate`, `DecklistPrecedentUpdate`, `DecklistPrecedentResponse`
- Verify `DecklistSuggestionCreate`, `DecklistSuggestionUpdate`, `DecklistSuggestionResponse`
- Check for missing fields
3. **Card Import Schemas (`app/schemas/card_import_schemas.py`)**
- Verify `CardImportCreate`, `CardImportResponse`
- Verify `CardImportStatusResponse`, `CardImportSummaryResponse`
- Check for missing fields
4. **Game Schemas (`app/schemas/game_schemas.py`)**
- Verify `GameCreate`, `GameUpdate`, `GameResponse`
- Verify `GamePlayerCreate`, `GamePlayerResponse`
- Verify `GameCardCreate`, `GameCardResponse`
- Verify `GameActionCreate`, `GameActionResponse`
- Verify `GameLogCreate`, `GameLogResponse`
- Check for missing fields
5. **MTG Card Schemas (`app/schemas/mtg_card_schemas.py`)**
- Verify `MtgonlineCardCreate`, `MtgonlineCardUpdate`, `MtgonlineCardResponse`
- Verify `CardPriceHistoryCreate`, `CardPriceHistoryResponse`
- Check for missing fields
6. **Schema Consistency**
- Verify all schemas have proper `model_config`
- Verify required vs optional fields
- Check for missing imports
- Verify schema imports in `app/schemas/__init__.py`
**Verification:** All schemas compile without errors, validation rules are correct, no missing fields.
---
### Phase 4: Router Layer Tests
**Scope:** FastAPI routers, endpoint definitions, dependencies
**Sub-agent Task:** Verify all router definitions are correct
#### Test Cases:
1. **User Data Router (`app/routers/user_data.py`)**
- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies (auth, etc.)
- Check for missing endpoints
2. **Deck Router (`app/routers/decks.py`)**
- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
3. **Card Import Router (`app/routers/card_import.py`)**
- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
4. **Game Router (`app/routers/game.py`)**
- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
5. **MTG Card Router (`app/routers/mtg_card.py`)**
- Verify all endpoints defined
- Verify request/response schemas
- Verify dependencies
- Check for missing endpoints
6. **Router Consistency**
- Verify all routers imported in `app/main.py`
- Verify prefix paths are correct
- Verify tag assignments
- Check for missing imports
**Verification:** All routers compile without errors, endpoints are properly defined, no missing imports.
---
### Phase 5: Service Layer Tests
**Scope:** Business logic, service functions
**Sub-agent Task:** Verify all service implementations are correct
#### Test Cases:
1. **User Service (`app/services/user_service.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
2. **Deck Service (`app/services/deck_service.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
3. **Card Import Service (`app/services/card_import_service.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
4. **Game Service (`app/services/game_service.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
5. **MTG Card Service (`app/services/mtg_card_service.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
6. **Service Consistency**
- Verify all services imported where needed
- Verify function calls match implementations
- Check for missing imports
**Verification:** All services compile without errors, functions are properly implemented, no missing imports.
---
### Phase 6: Utility & Helper Tests
**Scope:** Utility functions, helpers, constants
**Sub-agent Task:** Verify all utility implementations are correct
#### Test Cases:
1. **Auth Utilities (`app/utils/auth.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
2. **Database Utilities (`app/utils/database.py`)**
- Verify all functions defined
- Verify function signatures
- Check for missing implementations
3. **Error Handlers (`app/utils/errors.py`)**
- Verify all exception classes defined
- Verify error codes
- Check for missing exceptions
4. **Constants (`app/utils/constants.py`)**
- Verify all constants defined
- Verify constant values
- Check for missing constants
5. **Utility Consistency**
- Verify all utilities imported where needed
- Verify function calls match implementations
- Check for missing imports
**Verification:** All utilities compile without errors, functions are properly implemented, no missing imports.
---
### Phase 7: Configuration & Environment Tests
**Scope:** Settings, environment variables, configuration
**Sub-agent Task:** Verify all configuration is correct
#### Test Cases:
1. **Settings (`app/core/settings.py`)**
- Verify all settings defined
- Verify default values
- Check for missing settings
2. **Database Configuration (`app/core/database.py`)**
- Verify database URL configuration
- Verify async/sync engine setup
- Check for missing configuration
3. **App Configuration (`app/main.py`)**
- Verify FastAPI app initialization
- Verify middleware setup
- Verify CORS configuration
- Check for missing configuration
4. **Environment Consistency**
- Verify all settings used in code
- Verify environment variables match settings
- Check for missing configuration
**Verification:** All configuration compiles without errors, settings are properly defined, no missing configuration.
---
### Phase 8: Integration Tests
**Scope:** Cross-component integration, API consistency
**Sub-agent Task:** Verify all components work together correctly
#### Test Cases:
1. **Router-Service Integration**
- Verify routers call correct service functions
- Verify service functions return correct types
- Check for integration issues
2. **Service-Model Integration**
- Verify services use correct models
- Verify model operations are correct
- Check for integration issues
3. **Schema-Router Integration**
- Verify routers use correct schemas
- Verify schemas match request/response
- Check for integration issues
4. **Database-Model Integration**
- Verify models match database schema
- Verify migrations create correct tables
- Check for integration issues
5. **Overall Consistency**
- Verify all imports are correct
- Verify all function calls are valid
- Check for circular dependencies
- Verify no orphaned code
**Verification:** All components integrate correctly, no circular dependencies, all imports valid.
---
## Execution Strategy
### Sub-Agent Execution Order:
1. **Phase 1:** Database & Migration Tests
2. **Phase 2:** Model Layer Tests
3. **Phase 3:** Schema Layer Tests
4. **Phase 4:** Router Layer Tests
5. **Phase 5:** Service Layer Tests
6. **Phase 6:** Utility & Helper Tests
7. **Phase 7:** Configuration & Environment Tests
8. **Phase 8:** Integration Tests
### Context Management:
- Each sub-agent handles one phase at a time
- Sub-agents return only findings and issues
- Main agent aggregates results and coordinates fixes
- Maximum context usage per sub-agent: ~50,000 tokens
### Verification Criteria:
- All files compile without syntax errors
- All imports resolve correctly
- All function signatures match across components
- All foreign keys reference existing tables
- All schemas have proper validation
- All routers have proper dependencies
- No circular dependencies
- No orphaned code
### Issue Reporting:
Each sub-agent should report:
1. **Critical Issues:** Missing files, broken imports, syntax errors
2. **Consistency Issues:** Mismatched types, missing fields, incorrect references
3. **Recommendations:** Improvements, missing features, best practices
---
## Summary
This test plan provides a systematic approach to verifying the entire backend system by breaking it down into 8 manageable phases. Each phase can be executed by a sub-agent independently, ensuring comprehensive coverage while staying within context limits. The plan focuses on consistency, correctness, and completeness of the codebase.