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:
Trey t
2026-02-22 00:07:53 -06:00
parent 826eadbc0f
commit 91c5eac22d
32 changed files with 434 additions and 67 deletions

View File

@@ -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)
}