Add implementation code for all 4 improvement plan phases

Production changes:
- TravelEstimator: remove 300mi fallback, return nil on missing coords
- TripPlanningEngine: add warnings array, empty sports warning, inverted
  date range rejection, must-stop filter, segment validation gate
- GameDAGRouter: add routePreference parameter with preference-aware
  bucket ordering and sorting in selectDiverseRoutes()
- ScenarioA-E: pass routePreference through to GameDAGRouter
- ScenarioA: track games with missing stadium data
- ScenarioE: add region filtering for home games
- TravelSegment: add requiresOvernightStop and travelDays() helpers

Test changes:
- GameDAGRouterTests: +252 lines for route preference verification
- TripPlanningEngineTests: +153 lines for segment validation, date range,
  empty sports
- ScenarioEPlannerTests: +119 lines for region filter tests
- TravelEstimatorTests: remove obsolete fallback distance tests
- ItineraryBuilderTests: update nil-coords test expectation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey T
2026-03-21 09:40:32 -05:00
parent db6ab2f923
commit 6cbcef47ae
14 changed files with 807 additions and 88 deletions

View File

@@ -1058,6 +1058,125 @@ struct ScenarioEPlannerTests {
}
}
// MARK: - Region Filter Tests
@Test("teamFirst: east region only excludes west games")
func teamFirst_eastRegionOnly_excludesWestGames() {
// Create two teams: one east (NYC), one also east (Boston)
let teamNYC = TestFixtures.team(id: "team_nyc", city: "New York")
let teamBOS = TestFixtures.team(id: "team_bos", city: "Boston")
let stadiumNYC = TestFixtures.stadium(id: "stadium_nyc", city: "New York")
let stadiumBOS = TestFixtures.stadium(id: "stadium_bos", city: "Boston")
let stadiumLA = TestFixtures.stadium(id: "stadium_la", city: "Los Angeles")
let baseDate = TestFixtures.date(year: 2026, month: 6, day: 1, hour: 19, minute: 0)
let day2 = TestClock.calendar.date(byAdding: .day, value: 1, to: baseDate)!
let day3 = TestClock.calendar.date(byAdding: .day, value: 2, to: baseDate)!
let gameNYC = TestFixtures.game(id: "game_nyc", city: "New York", dateTime: baseDate, homeTeamId: "team_nyc", stadiumId: "stadium_nyc")
let gameBOS = TestFixtures.game(id: "game_bos", city: "Boston", dateTime: day2, homeTeamId: "team_bos", stadiumId: "stadium_bos")
// LA game should be excluded by east-only filter
let gameLA = TestFixtures.game(id: "game_la", city: "Los Angeles", dateTime: day3, homeTeamId: "team_nyc", stadiumId: "stadium_la")
let prefs = TripPreferences(
planningMode: .teamFirst,
sports: [.mlb],
selectedRegions: [.east], // East only
selectedTeamIds: ["team_nyc", "team_bos"]
)
let request = PlanningRequest(
preferences: prefs,
availableGames: [gameNYC, gameBOS, gameLA],
teams: ["team_nyc": teamNYC, "team_bos": teamBOS],
stadiums: ["stadium_nyc": stadiumNYC, "stadium_bos": stadiumBOS, "stadium_la": stadiumLA]
)
let planner = ScenarioEPlanner()
let result = planner.plan(request: request)
// Should succeed both teams have east coast games
if case .success(let options) = result {
for option in options {
let cities = option.stops.map { $0.city }
#expect(!cities.contains("Los Angeles"), "East-only filter should exclude LA")
}
}
// If it fails, that's also acceptable since routing may not work out
}
@Test("teamFirst: all regions includes everything")
func teamFirst_allRegions_includesEverything() {
let teamNYC = TestFixtures.team(id: "team_nyc", city: "New York")
let teamLA = TestFixtures.team(id: "team_la", city: "Los Angeles")
let stadiumNYC = TestFixtures.stadium(id: "stadium_nyc", city: "New York")
let stadiumLA = TestFixtures.stadium(id: "stadium_la", city: "Los Angeles")
let baseDate = TestFixtures.date(year: 2026, month: 6, day: 1, hour: 19, minute: 0)
let day5 = TestClock.calendar.date(byAdding: .day, value: 4, to: baseDate)!
let gameNYC = TestFixtures.game(id: "game_nyc", city: "New York", dateTime: baseDate, homeTeamId: "team_nyc", stadiumId: "stadium_nyc")
let gameLA = TestFixtures.game(id: "game_la", city: "Los Angeles", dateTime: day5, homeTeamId: "team_la", stadiumId: "stadium_la")
let prefs = TripPreferences(
planningMode: .teamFirst,
sports: [.mlb],
selectedRegions: [.east, .central, .west], // All regions
selectedTeamIds: ["team_nyc", "team_la"]
)
let request = PlanningRequest(
preferences: prefs,
availableGames: [gameNYC, gameLA],
teams: ["team_nyc": teamNYC, "team_la": teamLA],
stadiums: ["stadium_nyc": stadiumNYC, "stadium_la": stadiumLA]
)
let planner = ScenarioEPlanner()
let result = planner.plan(request: request)
// With all regions, both games should be available
// (may still fail due to driving constraints, but games won't be region-filtered)
#expect(result.isSuccess || result.failure?.reason == .constraintsUnsatisfiable || result.failure?.reason == .noValidRoutes)
}
@Test("teamFirst: empty regions includes everything")
func teamFirst_emptyRegions_includesEverything() {
let teamNYC = TestFixtures.team(id: "team_nyc", city: "New York")
let teamBOS = TestFixtures.team(id: "team_bos", city: "Boston")
let stadiumNYC = TestFixtures.stadium(id: "stadium_nyc", city: "New York")
let stadiumBOS = TestFixtures.stadium(id: "stadium_bos", city: "Boston")
let baseDate = TestFixtures.date(year: 2026, month: 6, day: 1, hour: 19, minute: 0)
let day2 = TestClock.calendar.date(byAdding: .day, value: 1, to: baseDate)!
let gameNYC = TestFixtures.game(id: "game_nyc", city: "New York", dateTime: baseDate, homeTeamId: "team_nyc", stadiumId: "stadium_nyc")
let gameBOS = TestFixtures.game(id: "game_bos", city: "Boston", dateTime: day2, homeTeamId: "team_bos", stadiumId: "stadium_bos")
let prefs = TripPreferences(
planningMode: .teamFirst,
sports: [.mlb],
selectedRegions: [], // Empty = no filtering
selectedTeamIds: ["team_nyc", "team_bos"]
)
let request = PlanningRequest(
preferences: prefs,
availableGames: [gameNYC, gameBOS],
teams: ["team_nyc": teamNYC, "team_bos": teamBOS],
stadiums: ["stadium_nyc": stadiumNYC, "stadium_bos": stadiumBOS]
)
let planner = ScenarioEPlanner()
let result = planner.plan(request: request)
// Empty regions = no filtering, so both games should be available
#expect(result.isSuccess || result.failure?.reason != .noGamesInRange)
}
// MARK: - Helper Methods
private func makeStadium(