Fix MLB division leaders showing under wildcard #84

Merged
chrisp merged 1 commit from fix/mlb-division-rank into main 2026-06-11 00:25:19 +00:00
Owner

Summary

  • MlbStandingsAdapter never populated divisionRank, so buildDivisionSections evaluated every team as divisionRank ?? 99 > 1 and put them all in the wildcard section
  • Now computes divisionRank per team using ESPN's original division entry order (ESPN already applies MLB's official tiebreakers — run differential, head-to-head — so re-sorting by win/loss would discard them)
  • Passes divisionRank through to the upsert; next sync will fix the live display

Not affected

  • NHL — uses NHL official API which provides divisionSequence directly; never broken
  • NBA/WNBA/others — use flat display mode; divisionRank is not consulted

Known gaps (not in scope)

  • syncStandings change detection only checks gamesPlayed + leagueRank, so standingsLastChangedAt won't fire on the first sync after this fix (subsequent syncs are fine)
  • NBA adapter will need the same treatment when Phase 4 adds a division layout

Test plan

  • All 16 MLB adapter unit tests pass
  • New test: divisionRank 1 for division leader, 2 for second place, across both leagues
  • Trigger a manual sync on the MLB season and confirm division sections populate correctly
## Summary - `MlbStandingsAdapter` never populated `divisionRank`, so `buildDivisionSections` evaluated every team as `divisionRank ?? 99 > 1` and put them all in the wildcard section - Now computes `divisionRank` per team using ESPN's original division entry order (ESPN already applies MLB's official tiebreakers — run differential, head-to-head — so re-sorting by win/loss would discard them) - Passes `divisionRank` through to the upsert; next sync will fix the live display ## Not affected - **NHL** — uses NHL official API which provides `divisionSequence` directly; never broken - **NBA/WNBA/others** — use `flat` display mode; `divisionRank` is not consulted ## Known gaps (not in scope) - `syncStandings` change detection only checks `gamesPlayed` + `leagueRank`, so `standingsLastChangedAt` won't fire on the first sync after this fix (subsequent syncs are fine) - NBA adapter will need the same treatment when Phase 4 adds a division layout ## Test plan - [ ] All 16 MLB adapter unit tests pass - [ ] New test: `divisionRank` 1 for division leader, 2 for second place, across both leagues - [ ] Trigger a manual sync on the MLB season and confirm division sections populate correctly
chrisp added 1 commit 2026-06-10 19:48:11 +00:00
Fix MLB division leaders showing under wildcard instead of division sections
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m45s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Successful in 1m23s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
6ef4d39d14
The MlbStandingsAdapter never populated `divisionRank`, so every team
evaluated to `divisionRank ?? 99 > 1` in `buildDivisionSections` and
fell through to the wildcard section.

Computes `divisionRank` per team using ESPN's existing division entry
order (which already applies MLB's official tiebreakers) rather than
re-sorting, then passes it through to the upsert.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp merged commit ea84ffd915 into main 2026-06-11 00:25:19 +00:00
chrisp deleted branch fix/mlb-division-rank 2026-06-11 00:25:19 +00:00
Sign in to join this conversation.
No description provided.