fix: codebase audit fixes — safety, accessibility, and production hygiene
Address 16 issues from external audit: - Move StoreKit transaction listener ownership to StoreManager singleton with proper deinit - Remove noisy VoiceOver announcements, add missing accessibility on StatPill and BootstrapLoadingView - Replace String @retroactive Identifiable with IdentifiableShareCode wrapper - Add crash guard in AchievementEngine getContributingVisitIds + cache stadium lookups - Pre-compute GamesHistoryViewModel filtered properties to avoid redundant SwiftUI recomputation - Remove force-unwraps in ProgressMapView with safe guard-let fallback - Add diff-based update gating in ItineraryTableViewWrapper to prevent unnecessary reloads - Replace deprecated UIScreen.main with UIWindowScene lookup - Add deinit task cancellation in ScheduleViewModel and SuggestedTripsGenerator - Wrap ~234 unguarded print() calls across 27 files in #if DEBUG Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -246,7 +246,9 @@ enum GameDAGRouter {
|
||||
// Step 6: Final diversity selection
|
||||
let finalRoutes = selectDiverseRoutes(routesWithAnchors, stadiums: stadiums, maxCount: maxOptions)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 DAG: Input games=\(games.count), beam=\(beam.count), withAnchors=\(routesWithAnchors.count), final=\(finalRoutes.count)")
|
||||
#endif
|
||||
|
||||
return finalRoutes
|
||||
}
|
||||
@@ -586,10 +588,12 @@ enum GameDAGRouter {
|
||||
let feasible = drivingHours <= maxDrivingHoursAvailable && drivingHours <= availableHours
|
||||
|
||||
// Debug output for rejected transitions
|
||||
#if DEBUG
|
||||
if !feasible && drivingHours > 10 {
|
||||
print("🔍 DAG canTransition REJECTED: \(fromStadium.city) → \(toStadium.city)")
|
||||
print("🔍 drivingHours=\(String(format: "%.1f", drivingHours)), daysBetween=\(daysBetween), maxAvailable=\(String(format: "%.1f", maxDrivingHoursAvailable)), availableHours=\(String(format: "%.1f", availableHours))")
|
||||
}
|
||||
#endif
|
||||
|
||||
return feasible
|
||||
}
|
||||
|
||||
@@ -192,12 +192,14 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioA: filteredGames=\(filteredGames.count), validRoutes=\(validRoutes.count)")
|
||||
if let firstRoute = validRoutes.first {
|
||||
print("🔍 ScenarioA: First route has \(firstRoute.count) games")
|
||||
let cities = firstRoute.compactMap { request.stadiums[$0.stadiumId]?.city }
|
||||
print("🔍 ScenarioA: Route cities: \(cities)")
|
||||
}
|
||||
#endif
|
||||
|
||||
if validRoutes.isEmpty {
|
||||
let noMustStopSatisfyingRoutes = !requiredMustStops.isEmpty
|
||||
@@ -233,13 +235,17 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
// Build stops for this route
|
||||
let stops = buildStops(from: routeGames, stadiums: request.stadiums)
|
||||
|
||||
#if DEBUG
|
||||
// Debug: show stops created from games
|
||||
let stopCities = stops.map { "\($0.city)(\($0.games.count)g)" }
|
||||
print("🔍 ScenarioA: Route \(index) - \(routeGames.count) games → \(stops.count) stops: \(stopCities)")
|
||||
#endif
|
||||
|
||||
guard !stops.isEmpty else {
|
||||
routesFailed += 1
|
||||
#if DEBUG
|
||||
print("⚠️ ScenarioA: Route \(index) - buildStops returned empty")
|
||||
#endif
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -250,7 +256,9 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
) else {
|
||||
// This route fails driving constraints, skip it
|
||||
routesFailed += 1
|
||||
#if DEBUG
|
||||
print("⚠️ ScenarioA: Route \(index) - ItineraryBuilder.build failed")
|
||||
#endif
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -291,21 +299,25 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
// Sort and rank based on leisure level
|
||||
let leisureLevel = request.preferences.leisureLevel
|
||||
|
||||
#if DEBUG
|
||||
// Debug: show all options before sorting
|
||||
print("🔍 ScenarioA: \(itineraryOptions.count) itinerary options before sorting:")
|
||||
for (i, opt) in itineraryOptions.enumerated() {
|
||||
print(" Option \(i): \(opt.stops.count) stops, \(opt.totalGames) games, \(String(format: "%.1f", opt.totalDrivingHours))h driving")
|
||||
}
|
||||
#endif
|
||||
|
||||
let rankedOptions = ItineraryOption.sortByLeisure(
|
||||
itineraryOptions,
|
||||
leisureLevel: leisureLevel
|
||||
)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioA: Returning \(rankedOptions.count) options after sorting")
|
||||
if let first = rankedOptions.first {
|
||||
print("🔍 ScenarioA: First option has \(first.stops.count) stops")
|
||||
}
|
||||
#endif
|
||||
|
||||
return .success(rankedOptions)
|
||||
}
|
||||
@@ -479,10 +491,12 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioA Regional: Partitioned \(games.count) games into \(gamesByRegion.count) regions")
|
||||
for (region, regionGames) in gamesByRegion {
|
||||
print(" \(region.shortName): \(regionGames.count) games")
|
||||
}
|
||||
#endif
|
||||
|
||||
// Run beam search for each region
|
||||
var allRoutes: [[Game]] = []
|
||||
@@ -497,7 +511,9 @@ final class ScenarioAPlanner: ScenarioPlanner {
|
||||
stopBuilder: buildStops
|
||||
)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioA Regional: \(region.shortName) produced \(regionRoutes.count) routes")
|
||||
#endif
|
||||
allRoutes.append(contentsOf: regionRoutes)
|
||||
}
|
||||
|
||||
|
||||
@@ -468,7 +468,9 @@ final class ScenarioBPlanner: ScenarioPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioB Regional: Anchor games in regions: \(anchorRegions.map { $0.shortName })")
|
||||
#endif
|
||||
|
||||
// Run beam search for each region that has anchor games
|
||||
// (Other regions without anchor games would produce routes that don't satisfy anchors)
|
||||
@@ -490,7 +492,9 @@ final class ScenarioBPlanner: ScenarioPlanner {
|
||||
stopBuilder: buildStops
|
||||
)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioB Regional: \(region.shortName) produced \(regionRoutes.count) routes")
|
||||
#endif
|
||||
allRoutes.append(contentsOf: regionRoutes)
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,7 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
let teamGames = filterToTeam(request.allGames, teamId: teamId)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 3: allGames=\(request.allGames.count), teamGames=\(teamGames.count)")
|
||||
print("🔍 ScenarioD: Looking for teamId=\(teamId)")
|
||||
for game in teamGames.prefix(20) {
|
||||
@@ -104,6 +105,7 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
let isHome = game.homeTeamId == teamId
|
||||
print("🔍 Game: \(stadium?.city ?? "?") on \(game.gameDate) (\(isHome ? "HOME" : "AWAY"))")
|
||||
}
|
||||
#endif
|
||||
|
||||
if teamGames.isEmpty {
|
||||
return .failure(
|
||||
@@ -124,15 +126,19 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
// Step 4: Apply date range and region filters
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
let selectedRegions = request.preferences.selectedRegions
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 4: dateRange=\(dateRange.start) to \(dateRange.end), selectedRegions=\(selectedRegions)")
|
||||
#endif
|
||||
|
||||
let filteredGames = teamGames
|
||||
.filter { game in
|
||||
// Must be in date range
|
||||
let inDateRange = dateRange.contains(game.startTime)
|
||||
if !inDateRange {
|
||||
#if DEBUG
|
||||
let stadium = request.stadiums[game.stadiumId]
|
||||
print("🔍 FILTERED OUT (date): \(stadium?.city ?? "?") on \(game.gameDate) - startTime=\(game.startTime)")
|
||||
#endif
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -141,20 +147,24 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
guard let stadium = request.stadiums[game.stadiumId] else { return false }
|
||||
let gameRegion = Region.classify(longitude: stadium.coordinate.longitude)
|
||||
let inRegion = selectedRegions.contains(gameRegion)
|
||||
#if DEBUG
|
||||
if !inRegion {
|
||||
print("🔍 FILTERED OUT (region): \(stadium.city) on \(game.gameDate) - region=\(gameRegion)")
|
||||
}
|
||||
#endif
|
||||
return inRegion
|
||||
}
|
||||
return true
|
||||
}
|
||||
.sorted { $0.startTime < $1.startTime }
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 4 result: \(filteredGames.count) games after date/region filter")
|
||||
for game in filteredGames {
|
||||
let stadium = request.stadiums[game.stadiumId]
|
||||
print("🔍 Kept: \(stadium?.city ?? "?") on \(game.gameDate)")
|
||||
}
|
||||
#endif
|
||||
|
||||
if filteredGames.isEmpty {
|
||||
return .failure(
|
||||
@@ -185,15 +195,19 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
// July 27 if it makes the driving from Chicago feasible).
|
||||
let finalGames = filteredGames
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 5: Passing \(finalGames.count) games to router (allowRepeatCities=\(request.preferences.allowRepeatCities))")
|
||||
print("🔍 ScenarioD: teamGames=\(teamGames.count), filteredGames=\(filteredGames.count), finalGames=\(finalGames.count)")
|
||||
#endif
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
// Step 6: Find valid routes using DAG router
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
// Follow Team mode typically has fewer games than Scenario A,
|
||||
// so we can be more exhaustive in route finding.
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 6: Finding routes from \(finalGames.count) games")
|
||||
#endif
|
||||
|
||||
var validRoutes: [[Game]] = []
|
||||
|
||||
@@ -203,18 +217,22 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
allowRepeatCities: request.preferences.allowRepeatCities,
|
||||
stopBuilder: buildStops
|
||||
)
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 6: GameDAGRouter returned \(globalRoutes.count) routes")
|
||||
for (i, route) in globalRoutes.prefix(5).enumerated() {
|
||||
let cities = route.compactMap { request.stadiums[$0.stadiumId]?.city }.joined(separator: " → ")
|
||||
print("🔍 Route \(i+1): \(route.count) games - \(cities)")
|
||||
}
|
||||
#endif
|
||||
|
||||
validRoutes.append(contentsOf: globalRoutes)
|
||||
|
||||
// Deduplicate routes
|
||||
validRoutes = deduplicateRoutes(validRoutes)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD Step 6 after dedup: \(validRoutes.count) valid routes")
|
||||
#endif
|
||||
|
||||
if validRoutes.isEmpty {
|
||||
return .failure(
|
||||
@@ -292,7 +310,9 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
leisureLevel: leisureLevel
|
||||
)
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioD: Returning \(rankedOptions.count) options")
|
||||
#endif
|
||||
|
||||
return .success(rankedOptions)
|
||||
}
|
||||
@@ -315,22 +335,32 @@ final class ScenarioDPlanner: ScenarioPlanner {
|
||||
stadiums: [String: Stadium]
|
||||
) -> [Game] {
|
||||
guard !allowRepeat else {
|
||||
#if DEBUG
|
||||
print("🔍 applyRepeatCityFilter: allowRepeat=true, returning all \(games.count) games")
|
||||
#endif
|
||||
return games
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 applyRepeatCityFilter: allowRepeat=false, filtering duplicates")
|
||||
#endif
|
||||
var seenCities: Set<String> = []
|
||||
return games.filter { game in
|
||||
guard let stadium = stadiums[game.stadiumId] else {
|
||||
#if DEBUG
|
||||
print("🔍 Game \(game.id): NO STADIUM FOUND - filtered out")
|
||||
#endif
|
||||
return false
|
||||
}
|
||||
if seenCities.contains(stadium.city) {
|
||||
#if DEBUG
|
||||
print("🔍 Game in \(stadium.city) on \(game.gameDate): DUPLICATE CITY - filtered out")
|
||||
#endif
|
||||
return false
|
||||
}
|
||||
#if DEBUG
|
||||
print("🔍 Game in \(stadium.city) on \(game.gameDate): KEPT (first in this city)")
|
||||
#endif
|
||||
seenCities.insert(stadium.city)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -117,17 +117,21 @@ final class ScenarioEPlanner: ScenarioPlanner {
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE Step 2: Found \(allHomeGames.count) total home games across \(selectedTeamIds.count) teams")
|
||||
for (teamId, games) in homeGamesByTeam {
|
||||
let teamName = request.teams[teamId]?.fullName ?? teamId
|
||||
print("🔍 \(teamName): \(games.count) home games")
|
||||
}
|
||||
#endif
|
||||
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
// Step 3: Generate sliding windows across the season
|
||||
// ──────────────────────────────────────────────────────────────────
|
||||
let windowDuration = request.preferences.teamFirstMaxDays
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE Step 3: Window duration = \(windowDuration) days")
|
||||
#endif
|
||||
|
||||
let validWindows = generateValidWindows(
|
||||
homeGamesByTeam: homeGamesByTeam,
|
||||
@@ -150,13 +154,17 @@ final class ScenarioEPlanner: ScenarioPlanner {
|
||||
)
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE Step 3: Found \(validWindows.count) valid windows")
|
||||
#endif
|
||||
|
||||
// Sample windows if too many exist
|
||||
let windowsToEvaluate: [DateInterval]
|
||||
if validWindows.count > maxWindowsToEvaluate {
|
||||
windowsToEvaluate = sampleWindows(validWindows, count: maxWindowsToEvaluate)
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE Step 3: Sampled down to \(windowsToEvaluate.count) windows")
|
||||
#endif
|
||||
} else {
|
||||
windowsToEvaluate = validWindows
|
||||
}
|
||||
@@ -280,7 +288,9 @@ final class ScenarioEPlanner: ScenarioPlanner {
|
||||
|
||||
// Early exit if we have enough options
|
||||
if allItineraryOptions.count >= maxResultsToReturn * 5 {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE: Early exit at window \(windowIndex + 1) with \(allItineraryOptions.count) options")
|
||||
#endif
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -331,7 +341,9 @@ final class ScenarioEPlanner: ScenarioPlanner {
|
||||
)
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioE: Returning \(rankedOptions.count) options")
|
||||
#endif
|
||||
|
||||
return .success(rankedOptions)
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ enum ScenarioPlannerFactory {
|
||||
/// - Both start and end locations → ScenarioCPlanner
|
||||
/// - Otherwise → ScenarioAPlanner
|
||||
static func planner(for request: PlanningRequest) -> ScenarioPlanner {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: Selecting planner...")
|
||||
print(" - planningMode: \(request.preferences.planningMode)")
|
||||
print(" - selectedTeamIds.count: \(request.preferences.selectedTeamIds.count)")
|
||||
@@ -50,11 +51,14 @@ enum ScenarioPlannerFactory {
|
||||
print(" - selectedGames.count: \(request.selectedGames.count)")
|
||||
print(" - startLocation: \(request.startLocation?.name ?? "nil")")
|
||||
print(" - endLocation: \(request.endLocation?.name ?? "nil")")
|
||||
#endif
|
||||
|
||||
// Scenario E: Team-First mode - user selects teams, finds optimal trip windows
|
||||
if request.preferences.planningMode == .teamFirst &&
|
||||
request.preferences.selectedTeamIds.count >= 2 {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioEPlanner (team-first)")
|
||||
#endif
|
||||
return ScenarioEPlanner()
|
||||
}
|
||||
|
||||
@@ -62,30 +66,40 @@ enum ScenarioPlannerFactory {
|
||||
if request.preferences.planningMode == .teamFirst &&
|
||||
request.preferences.selectedTeamIds.count == 1 {
|
||||
// Single team in teamFirst mode → treat as follow-team
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioDPlanner (team-first single team)")
|
||||
#endif
|
||||
return ScenarioDPlanner()
|
||||
}
|
||||
|
||||
// Scenario D: User wants to follow a specific team
|
||||
if request.preferences.followTeamId != nil {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioDPlanner (follow team)")
|
||||
#endif
|
||||
return ScenarioDPlanner()
|
||||
}
|
||||
|
||||
// Scenario B: User selected specific games
|
||||
if !request.selectedGames.isEmpty {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioBPlanner (selected games)")
|
||||
#endif
|
||||
return ScenarioBPlanner()
|
||||
}
|
||||
|
||||
// Scenario C: User specified start and end locations
|
||||
if request.startLocation != nil && request.endLocation != nil {
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioCPlanner (start/end locations)")
|
||||
#endif
|
||||
return ScenarioCPlanner()
|
||||
}
|
||||
|
||||
// Scenario A: Date range only (default)
|
||||
#if DEBUG
|
||||
print("🔍 ScenarioPlannerFactory: → ScenarioAPlanner (default/date range)")
|
||||
#endif
|
||||
return ScenarioAPlanner()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user