- Remove unused imports (findMatchSubGamesByMatchId, isNull, or, MatchRecord, STAGE_NAMES)
- Replace all != / == with !== / === throughout match-sync and components
- Remove all no-non-null-assertion violations: use Map get-or-initialize
pattern, remove guarded assertions (playoffMatch.round), use 'as' cast
for filter-then-map pattern
- Replace .sort() with .toSorted() in 5 locations
- Merge duplicate react-router import in tournament.tsx
- Remove unused LoaderData type alias in tournament.tsx
- Rename unused 'stage' param to '_stage' in Cs2TournamentBracket
- Use ?? [] in pandascore.test.ts to eliminate non-null assertions on subGames
https://claude.ai/code/session_01WUUM7uWzFoSkGcZRhnEKG6
- Fix 1 (CRITICAL): CS2 "Sync from API" button was always 401 because it
POSTed to /admin/jobs/sync-matches which requires a cron secret header
that browsers can't send. Added sync-matches intent to cs2-setup action.
- Fix 2 (CRITICAL): loserAdvances was hardcoded false in match-sync/index.ts,
breaking NBA Play-In scoring. Now calls doesLoserAdvance().
- Fix 3: ESPN score "0" was falsy → stored as null. Non-numeric strings
like "F/OT" produced NaN. Added parseScore() helper.
- Fix 4: ESPN limit=1000 silently truncated MLB/NBA playoff games. Added
seasonType param to EspnScheduleAdapter; all *_bracket types pass 3
(postseason only).
- Fix 5: Cron job was syncing completed seasons unnecessarily. Added
active status filter.
- Fix 6: hasLiveMatches triggered perpetual 30s polling for unseeded
brackets. Added participant presence check.
- Fix 7: autoCompleteRoundIfDone was duplicated between bracket.server.ts
and scoring-calculator.ts. Removed inline copy, imported shared version.
- Fix 8: MatchSchedule date grouping never ran for ESPN sports (no matchday
field). Removed hasMatchdays gate, always call groupByMatchday with
stable UTC date key.
- Fix 9: Silent failure when bracket matches exist but no scoring events.
Added warning log.
- Fix 10: Added 3 tests — zero score preservation, NaN from non-numeric
score, seasonType in URL.
https://claude.ai/code/session_01WUUM7uWzFoSkGcZRhnEKG6
Phase 2 — Match Sync Adapters + Cron Job:
- PandaScoreMatchSyncAdapter (CS2): fetches matches with map-level sub-games, stage detection
- EspnScheduleAdapter (MLB/NBA/MLS/WNBA/NHL): fetches scoreboard with live scores
- syncMatches() orchestrator: resolves participants by externalId+name, bulk-upserts season_matches, syncs playoff bracket results through existing setMatchWinner/processMatchResult pipeline
- POST /admin/jobs/sync-matches cron endpoint (mirrors sync-and-simulate pattern)
- External Season ID field added to sports season create/edit admin forms
- Sync from API button wired in CS2 setup page (enabled when externalSeasonId set)
Phase 3 — Public Tournament & Schedule Display:
- MatchSchedule component: generic match list with live/scheduled/complete status badges, matchday grouping
- Cs2TournamentBracket component: tab layout (Opening/Challengers/Legends/Champions Stage), map scores per match
- /sports-seasons/:sportsSeasonId/tournament public route with 30-second live polling
Phase 4 — Playoff Bracket Auto-Sync:
- externalMatchId column added to playoff_matches table (migration 0121)
- Bracket matches (matchStage=null) auto-synced: matches existing playoff_match rows by externalMatchId then participant IDs, calls full scoring pipeline
- autoCompleteRoundIfDone extracted to scoring-calculator.ts for shared use
All 2365 tests pass; typecheck clean.
https://claude.ai/code/session_01WUUM7uWzFoSkGcZRhnEKG6