Files
Sportstime/.planning/phases/08-dag-system-tdd/08-01-PLAN.md
Trey t a786d7e2aa plan: Phase 8 DAG System TDD with 2 plans
- 08-01: GameDAGRouter edge cases and anchor validation TDD (17+ tests)
- 08-02: Performance with large datasets (10K+ games) and diversity coverage TDD

TDD discipline: tests define correctness, code must match.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 11:36:29 -06:00

132 lines
4.8 KiB
Markdown

---
phase: 08-dag-system-tdd
type: execute
---
<objective>
TDD for GameDAGRouter edge cases and anchor game validation.
Purpose: Ensure the DAG routing algorithm handles boundary conditions correctly before testing at scale.
Output: Comprehensive edge case test suite for GameDAGRouter, with code fixes if tests fail.
</objective>
<execution_context>
~/.claude/get-shit-done/workflows/execute-phase.md
./summary.md
~/.claude/get-shit-done/references/tdd.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@SportsTime/Planning/Engine/GameDAGRouter.swift
@SportsTimeTests/ScenarioBPlannerTests.swift
</context>
<tasks>
<task type="auto">
<name>Task 1: Create GameDAGRouterTests with edge case tests</name>
<files>SportsTimeTests/GameDAGRouterTests.swift</files>
<action>
Create a new test file using Swift Testing framework (@Test attributes, #expect assertions).
Include test helpers:
- makeStadium(id:city:lat:lon:) with default coordinates spread across US
- makeGame(id:stadiumId:startTime:) with default sport/teams
- date(_:) helper for "yyyy-MM-dd HH:mm" parsing
Write RED tests for these edge cases:
1. Empty games array → returns empty routes
2. Single game → returns [[game]] (unless anchor mismatch)
3. Single game with non-matching anchor → returns []
4. Two games, chronological and feasible → returns route containing both
5. Two games, chronological but infeasible (too far) → returns two separate single-game routes
6. Two games, reverse chronological (second before first) → returns two separate single-game routes
7. Three games where only pairs are feasible → returns all valid pairs/singles
8. Anchor game filtering: routes missing anchors are excluded
9. Repeat cities OFF: routes with same city twice are excluded
10. Repeat cities ON: routes with same city twice are included
Run tests expecting failures for any code gaps:
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
</action>
<verify>All edge case tests exist and execute (RED or GREEN)</verify>
<done>GameDAGRouterTests.swift contains 10+ edge case tests using Swift Testing framework</done>
</task>
<task type="auto">
<name>Task 2: Fix any failing edge case tests</name>
<files>SportsTime/Planning/Engine/GameDAGRouter.swift</files>
<action>
Run the edge case tests. For any failures:
1. Identify the exact assertion that fails
2. Trace the code path in GameDAGRouter.swift
3. Fix the logic bug (do NOT modify the test - tests define correctness)
4. Re-run until GREEN
Common fix areas:
- Edge case handling in findRoutes() lines 101-120
- canTransition() feasibility logic lines 463-507
- Anchor filtering logic lines 181-184
Do NOT change test expectations. If a test fails, the code is wrong.
</action>
<verify>
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
All tests pass
</verify>
<done>All 10+ edge case tests pass (GREEN)</done>
</task>
<task type="auto">
<name>Task 3: Add canTransition boundary tests</name>
<files>SportsTimeTests/GameDAGRouterTests.swift</files>
<action>
Add tests for canTransition edge cases via findRoutes() behavior:
1. Same stadium, same day, 4 hours apart → transition feasible
2. Different stadium, 1000 miles apart, same day → infeasible (not enough driving time)
3. Different stadium, 1000 miles apart, 2 days apart → feasible (enough driving days)
4. Different stadium, 100 miles apart, 4 hours available → feasible
5. Different stadium, 100 miles apart, 1 hour available → infeasible (need 3hr buffer after game)
6. Game end buffer: 3hr buffer after game end before departure
7. Arrival buffer: 1hr buffer before next game start
These test the canTransition() logic indirectly through findRoutes() results.
</action>
<verify>
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
All tests pass
</verify>
<done>7 additional boundary tests pass (17+ total tests)</done>
</task>
</tasks>
<verification>
Before declaring phase complete:
- [ ] `xcodebuild test` for GameDAGRouterTests passes with 17+ tests
- [ ] All edge cases documented in test names
- [ ] No tests were modified to pass (code was fixed instead)
- [ ] Existing tests in other test files still pass
</verification>
<success_criteria>
- All tasks completed
- All verification checks pass
- 17+ edge case tests for GameDAGRouter
- TDD discipline maintained (tests define correctness)
</success_criteria>
<output>
After completion, create `.planning/phases/08-dag-system-tdd/08-01-SUMMARY.md`
</output>