--- phase: 08-dag-system-tdd type: execute --- TDD for GameDAGRouter performance with large datasets and diversity coverage. Purpose: Ensure the DAG algorithm performs well with production-scale data (10K+ games) and produces diverse route options. Output: Performance test suite validating scalability and diversity guarantees, with code fixes if tests fail. ~/.claude/get-shit-done/workflows/execute-phase.md ./summary.md ~/.claude/get-shit-done/references/tdd.md @.planning/PROJECT.md @.planning/ROADMAP.md @SportsTime/Planning/Engine/GameDAGRouter.swift @SportsTimeTests/GameDAGRouterTests.swift Task 1: Add performance tests with large datasets SportsTimeTests/GameDAGRouterTests.swift Add performance tests to existing GameDAGRouterTests file. Create helper to generate large test data: ```swift private func generateLargeDataset( gameCount: Int, stadiumCount: Int, daysSpan: Int ) -> (games: [Game], stadiums: [UUID: Stadium]) ``` Write RED tests: 1. 1000 games, 50 stadiums, 30 days → completes in <2 seconds 2. 5000 games, 100 stadiums, 60 days → completes in <10 seconds 3. 10000 games, 150 stadiums, 90 days → completes in <30 seconds 4. Memory: 10K games doesn't cause memory spike (verify routes returned, not OOM) Use Swift Testing's `Clock` or `ContinuousClock` for timing: ```swift @Test("10K games completes in reasonable time") func performance_10KGames_CompletesInTime() async { let (games, stadiums) = generateLargeDataset(gameCount: 10000, stadiumCount: 150, daysSpan: 90) let start = ContinuousClock.now let routes = GameDAGRouter.findRoutes(games: games, stadiums: stadiums, constraints: .default) let elapsed = start.duration(to: .now) #expect(routes.count > 0, "Should return routes") #expect(elapsed < .seconds(30), "Should complete within 30 seconds") } ``` Run tests and note any performance failures. Performance tests exist and execute 4 performance tests written with timing assertions Task 2: Fix any performance issues SportsTime/Planning/Engine/GameDAGRouter.swift If performance tests fail (timeouts), optimize GameDAGRouter: Potential optimizations (apply only if tests fail): 1. Reduce beam width for very large inputs (dynamic scaling based on game count) 2. Early termination when enough diverse routes found 3. More aggressive diversity pruning during expansion 4. Pre-compute stadium distances instead of recalculating Do NOT weaken test expectations. If the test says 30 seconds, the code must meet that. Re-run tests until performance requirements met. ```bash xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test ``` All performance tests pass within time limits All 4 performance tests pass within specified time limits Task 3: Add diversity coverage tests SportsTimeTests/GameDAGRouterTests.swift Add tests verifying the diversity selection produces varied results: 1. Game count diversity: With 50 games over 10 days, routes include 2-game, 3-game, 4-game, and 5+ game options 2. City count diversity: Routes span different numbers of cities (2, 3, 4, 5+) 3. Mileage diversity: Routes include short (<500mi), medium (500-1000mi), and long (1000+mi) options 4. Duration diversity: Routes include 2-day, 3-day, 5-day, and 7+ day options 5. Bucket coverage: At least 3 of 5 game count buckets represented in output 6. No duplicates: All returned routes have unique game combinations Test diversity by analyzing the returned routes: ```swift @Test("diversity includes varied game counts") func diversity_VariedGameCounts() { let (games, stadiums) = generateDiverseDataset() // 50 games, 20 stadiums, 14 days let routes = GameDAGRouter.findRoutes(games: games, stadiums: stadiums, constraints: .default) let gameCounts = Set(routes.map { $0.count }) #expect(gameCounts.count >= 3, "Should have at least 3 different route lengths") #expect(gameCounts.contains { $0 <= 3 }, "Should include short routes") #expect(gameCounts.contains { $0 >= 5 }, "Should include long routes") } ``` ```bash xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test ``` All diversity tests pass 6 diversity tests pass, verifying multi-dimensional variety Task 4: Fix any diversity issues SportsTime/Planning/Engine/GameDAGRouter.swift If diversity tests fail, fix selectDiverseRoutes() logic: Common issues: 1. Not all buckets being sampled (check pass 1-4 in selectDiverseRoutes) 2. Short routes getting pruned too early (check diversityPrune) 3. Bucket calculations wrong (check RouteProfile bucket properties) Fix the diversity algorithm to ensure varied output. Do NOT modify test expectations. ```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 All diversity tests pass, proving multi-dimensional route variety Before declaring phase complete: - [ ] Performance tests pass for 1K, 5K, 10K game datasets - [ ] Diversity tests verify varied route lengths, cities, miles, durations - [ ] No test assertions weakened to pass - [ ] All existing GameDAGRouter edge case tests still pass - [ ] Full test suite runs successfully - All tasks completed - All verification checks pass - 10+ new tests (4 performance + 6 diversity) - GameDAGRouter handles 10K+ games efficiently - Diversity selection produces varied results After completion, create `.planning/phases/08-dag-system-tdd/08-02-SUMMARY.md`