← Back to Pull requests

Serve NFL game-details starters from live ESPN depth charts #118

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 29, 2026 04:46 UTC
Author

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->

What changed

The NFL Starting Lineups block on game details (NFLRosterSection → GET /api/nfl/roster?action=game-starters) was reading NFLRosterEntry via getGameStarters / getTeamStarters. That table is a one-time ESPN snapshot from Nov 7, 2025 (season hardcoded 2025, every Active player stored as depthOrder 1), so a 2026 game like NYG_at_IND_2026-11-29 showed the 2025 Giants with Russell Wilson, Jaxson Dart, and Jameis Winston all as starting QBs.

This PR makes that path fetch live ESPN depth-chart starters at request time. It does not fall back to NFLRosterEntry. No Prisma schema changes, migrations, DB writes, new npm dependencies, or env vars.

  • New lib/nfl-live-starters.js maps NFL_19 / abbrs through existing resolveEspnTeamId, fetches roster + depth chart for each team, and returns QB1, RB1, WR1–3, TE1, K, plus first-string defense.

  • Jersey and experience come from the roster payload; injury status (IR / Out / Questionable / …) comes from ESPN injuries[] and is flagged on the card.

  • NFLRosterSection shows Lineups unavailable right now when ESPN fails or times out.

  • Populate scripts are unchanged except a warning that they still write season 2025 / depthOrder: 1 and must not be run as-is.
  • Prop eligibility, published picks, and MLB/NHL game details are untouched.

    ESPN endpoints

    Used site.api.espn.com (current season, no hardcoded year):

  • Roster: https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams/{espnTeamId}/roster

  • Depth chart: https://site.api.espn.com/apis/site/v2/sports/football/nfl/teams/{espnTeamId}/depthcharts
  • sports.core.api.espn.com/v2/sports/football/leagues/nfl/seasons/{year}/teams/{id}/depthcharts also works but only returns athlete $refs (no names or injuries), so this path uses the site.api depthcharts payload.

    Team ids (NFL_19 → ESPN 19) reuse resolveEspnTeamId from lib/event-roster-eligibility.js / ESPN_TEAM_IDS.

    Caching

  • In-memory TTL 45 minutes per ESPN team id for successful lineups.

  • ESPN fetch uses cache: 'no-store' (not Next revalidate). A 45-minute Data Cache would pin an empty 200 and keep the UI on "unavailable" after the 60s failure TTL expired. Next 14.2 also caches unoptioned fetches for a year, so the cache mode is set explicitly.

  • 8s timeout per request; ESPN failures cache in memory for 60 seconds, then retry.

  • Two teams × roster+depth chart in parallel on a cache miss.
  • Fallback

    If ESPN fails, times out, or the depth chart has no QB starter, the API returns { starters: null | { unavailable: true, … }, unavailable: true, error: 'Lineups unavailable right now' }. The UI shows that copy. NFLRosterEntry is never queried on this path.

    How to test locally

    npx jest --no-coverage
    # focused:
    npx jest __tests__/lib/nfl-live-starters.test.js __tests__/lib/nfl-roster-game-starters.test.js __tests__/components/nfl-roster-section.test.js __tests__/app/nfl-roster-game-starters-route.test.js --no-coverage
    

    Manual: open game details for NYG at IND 2026-11-29 (/game/NYG_at_IND_2026-11-29). Starting Lineups should list J.J. McCarthy as NYG QB1 (jersey 18 on live ESPN today) and Anthony Richardson Sr. as IND QB1 — not Wilson/Dart/Winston as co-starters. If ESPN is down, the block should say Lineups unavailable right now.

    Follow-ups (not in this PR)

    Optional scheduled NFLRosterEntry refresh for the current season with real depth order (not every Active player as 1). That needs a dry run and owner approval; do not run scripts/populate-nfl-rosters*.js as-is.

    Test results

    npx jest --no-coverage: 132 suites, 1978 tests passed.

    Live site.api payloads (2026-11-29) parsed with the production selector: NYG QB1 J.J. McCarthy #18; IND QB1 Anthony Richardson Sr. #5; Wilson / Winston / Dart excluded.
    <!-- CURSOR_AGENT_PR_BODY_END -->

    <div><a href="https://cursor.com/agents/bc-3d9d92d1-ab62-58ca-9e3f-b17d14b7a77a?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/background-agent?bcId=bc-3d9d92d1-ab62-58ca-9e3f-b17d14b7a77a&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes a user-facing data path from local DB to external ESPN with new failure modes, but scope is limited to NFL starting lineups and avoids serving stale roster snapshots.

    > <sup>Reviewed by Cursor Bugbot for commit f9ff307e489f106ce1f3663422a6ecf405f44af6. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: cursor[bot] Review duration: 16m
    All Vouch review confidence checks passed
    Residual risk 0.33 = Change Risk (0.57) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #118"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 32.5% · Safe to merge
    32.5%