fix: comprehensive codebase hardening — crashes, silent failures, performance, and security

Fixes ~95 issues from deep audit across 12 categories in 82 files:

- Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in
  DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test
  bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files
- Silent failure elimination: all 34 try? sites replaced with do/try/catch +
  logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService,
  CanonicalModels, CKModels, SportsTimeApp, and more)
- Performance: cached DateFormatters (7 files), O(1) team lookups via
  AppDataProvider, achievement definition dictionary, AnimatedBackground
  consolidated from 19 Tasks to 1, task cancellation in SharePreviewView
- Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard,
  @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix
- Planning engine: game end time in travel feasibility, state-aware city
  normalization, exact city matching, DrivingConstraints parameter propagation
- IAP: unknown subscription states → expired, unverified transaction logging,
  entitlements updated before paywall dismiss, restore visible to all users
- Security: API key to Info.plist lookup, filename sanitization in PDF export,
  honest User-Agent, removed stale "Feels" analytics super properties
- Navigation: consolidated competing navigationDestination, boolean → value-based
- Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat
- Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote
  fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel
  MKDirections, Sendable-safe POI struct

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-27 17:03:09 -06:00
parent e046cb6b34
commit c94e373e33
82 changed files with 1163 additions and 599 deletions

View File

@@ -11,6 +11,7 @@ struct PollCreationView: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@State private var viewModel = PollCreationViewModel()
@State private var showError = false
let trips: [Trip]
var onPollCreated: ((TripPoll) -> Void)?
@@ -74,7 +75,7 @@ struct PollCreationView: View {
.background(.ultraThinMaterial)
}
}
.alert("Error", isPresented: .constant(viewModel.error != nil)) {
.alert("Error", isPresented: $showError) {
Button("OK") {
viewModel.error = nil
}
@@ -83,6 +84,9 @@ struct PollCreationView: View {
Text(error.localizedDescription)
}
}
.onChange(of: viewModel.error != nil) { _, hasError in
showError = hasError
}
.onChange(of: viewModel.createdPoll) { _, newPoll in
if let poll = newPoll {
onPollCreated?(poll)

View File

@@ -277,15 +277,17 @@ struct PollDetailView: View {
VStack(spacing: Theme.Spacing.sm) {
ForEach(Array(results.tripScores.enumerated()), id: \.element.tripIndex) { index, item in
let trip = results.poll.tripSnapshots[item.tripIndex]
let rank = index + 1
ResultRow(
rank: rank,
tripName: trip.displayName,
score: item.score,
percentage: results.scorePercentage(for: item.tripIndex),
isLeader: rank == 1 && item.score > 0
)
if item.tripIndex < results.poll.tripSnapshots.count {
let trip = results.poll.tripSnapshots[item.tripIndex]
let rank = index + 1
ResultRow(
rank: rank,
tripName: trip.displayName,
score: item.score,
percentage: results.scorePercentage(for: item.tripIndex),
isLeader: rank == 1 && item.score > 0
)
}
}
}
}

View File

@@ -11,6 +11,7 @@ struct PollVotingView: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@State private var viewModel = PollVotingViewModel()
@State private var showError = false
let poll: TripPoll
let existingVote: PollVote?
@@ -23,24 +24,7 @@ struct PollVotingView: View {
instructionsHeader
// Reorderable list
List {
ForEach(Array(viewModel.rankings.enumerated()), id: \.element) { index, tripIndex in
RankingRow(
rank: index + 1,
trip: poll.tripSnapshots[tripIndex],
canMoveUp: index > 0,
canMoveDown: index < viewModel.rankings.count - 1,
onMoveUp: { viewModel.moveTripUp(at: index) },
onMoveDown: { viewModel.moveTripDown(at: index) }
)
.accessibilityHint("Drag to change ranking position, or use move up and move down buttons")
.listRowBackground(Theme.cardBackground(colorScheme))
.listRowSeparatorTint(Theme.surfaceGlow(colorScheme))
}
.onMove { source, destination in
viewModel.moveTrip(from: source, to: destination)
}
}
rankingList
.listStyle(.plain)
.scrollContentBackground(.hidden)
.environment(\.editMode, .constant(.active))
@@ -64,7 +48,7 @@ struct PollVotingView: View {
existingVote: existingVote
)
}
.alert("Error", isPresented: .constant(viewModel.error != nil)) {
.alert("Error", isPresented: $showError) {
Button("OK") {
viewModel.error = nil
}
@@ -73,6 +57,9 @@ struct PollVotingView: View {
Text(error.localizedDescription)
}
}
.onChange(of: viewModel.error != nil) { _, hasError in
showError = hasError
}
.onChange(of: viewModel.didSubmit) { _, didSubmit in
if didSubmit {
onVoteSubmitted?()
@@ -82,6 +69,29 @@ struct PollVotingView: View {
}
}
private var rankingList: some View {
List {
ForEach(Array(viewModel.rankings.enumerated()), id: \.element) { index, tripIndex in
if tripIndex < poll.tripSnapshots.count {
RankingRow(
rank: index + 1,
trip: poll.tripSnapshots[tripIndex],
canMoveUp: index > 0,
canMoveDown: index < viewModel.rankings.count - 1,
onMoveUp: { viewModel.moveTripUp(at: index) },
onMoveDown: { viewModel.moveTripDown(at: index) }
)
.accessibilityHint("Drag to change ranking position, or use move up and move down buttons")
.listRowBackground(Theme.cardBackground(colorScheme))
.listRowSeparatorTint(Theme.surfaceGlow(colorScheme))
}
}
.onMove { source, destination in
viewModel.moveTrip(from: source, to: destination)
}
}
}
@ViewBuilder
private var instructionsHeader: some View {
VStack(spacing: 8) {

View File

@@ -72,6 +72,9 @@ struct PollsListView: View {
.navigationDestination(item: $pendingJoinCode) { code in
PollDetailView(shareCode: code.value)
}
.navigationDestination(for: TripPoll.self) { poll in
PollDetailView(poll: poll)
}
.alert(
"Error",
isPresented: Binding(
@@ -107,9 +110,6 @@ struct PollsListView: View {
}
}
.listStyle(.plain)
.navigationDestination(for: TripPoll.self) { poll in
PollDetailView(poll: poll)
}
}
private func loadPolls() async {