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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user