Grading binds opponent features to the REAL game, not ESPN's "today"
Order 1.6 Phase 1. This is a MODEL-OUTPUT fix, not bookkeeping. computeFeatures.lookupTodayGame called the ESPN scoreboard with NO date param and took whatever ESPN calls "today". Renamed to lookupGameOnDate and now sends ?dates=YYYYMMDD from the prop's BOUND game — the same game the ledger, retention and settlement use, so all four finally agree. PROVEN against live ESPN (before/after, same instant): dateless "today" CLE->PIT NYY->LAD LAD->NYY (Jul 19 card) bound to 2026-07-20 CLE->MIN NYY->PIT LAD->PHI (the real games) bound to 2026-07-19 CLE->PIT NYY->LAD LAD->NYY (reproduces OLD) Every opponent was wrong. opponentAbbr feeds opp_rank_stat (a +/-1.0 factor) and isHome feeds home_away (+0.5), so late-slot grades were scored against the wrong matchup. Note the window is WIDER than the 01:00/03:00 UTC slots: this ran at 07:5x UTC = 03:5x ET and ESPN's dateless scoreboard was STILL returning the previous day's card. HONEST DEGRADATION: with no bound game date the grader does NOT fall back to a dateless lookup — it records 'no_bound_game_date' and leaves opponentAbbr/isHome/gameId null, so engine1 simply omits the opponent and home/away factors rather than scoring a wrong matchup. Tests assert both directions. Same class of bug fixed alongside: the Tank01 augmentation used TODAY's UTC date for its cache key; it now uses the bound game date. gradeSlateService threads game_date/game_time/home_team/away_team into the grader so the binding reaches computeFeatures at all. Audited the rest of the feature path for dateless/"today" lookups — none remain (weather is current-conditions by venue, park/pace are static). Suite 282/3383 green, build exit 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SmNjJAwEnqHPtXbvSZR8kA
This commit is contained in:
@@ -99,6 +99,9 @@ describe('computeFeaturesForProp — happy path', () => {
|
||||
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Jalen Brunson', stat_type: 'points', line: 25.5, direction: 'over', sport: 'nba',
|
||||
// Session 64 — grading binds opponent features to the prop's REAL game.
|
||||
// Without a bound date it no longer guesses ESPN's "today".
|
||||
game_date: '2026-07-20',
|
||||
});
|
||||
|
||||
expect(out.features.l5_avg).toBe(28.4);
|
||||
@@ -132,7 +135,7 @@ describe('computeFeaturesForProp — graceful degradation', () => {
|
||||
mockSupabaseState.rosterRow = { team_abbr: 'NYK', espn_id: '1', sport: 'nba' };
|
||||
mockAxiosGet.mockResolvedValue(nbaScoreboard([])); // empty slate
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Some Player', stat_type: 'points', line: 22, direction: 'over', sport: 'nba',
|
||||
player: 'Some Player', stat_type: 'points', line: 22, direction: 'over', sport: 'nba', game_date: '2026-07-20',
|
||||
});
|
||||
expect(out.meta.errors).toContain('no_game_scheduled_today');
|
||||
expect(out.meta.teamAbbr).toBe('NYK');
|
||||
@@ -144,7 +147,7 @@ describe('computeFeaturesForProp — graceful degradation', () => {
|
||||
mockAxiosGet.mockResolvedValue(nbaScoreboard([game('e2', 'NYK', 'BOS')]));
|
||||
mockFeatures.throws = true;
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba',
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba', game_date: '2026-07-20',
|
||||
});
|
||||
expect(out.meta.errors).toContain('no_features_computed');
|
||||
// Session 15 — static lookups (pace factor, park factor) populate
|
||||
@@ -166,7 +169,7 @@ describe('computeFeaturesForProp — graceful degradation', () => {
|
||||
mockFeatures.current = { l5_avg: 25 };
|
||||
mockTrap.throws = true;
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba',
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba', game_date: '2026-07-20',
|
||||
});
|
||||
expect(out.trap).toMatchObject({ composite: 0, recommendation: 'proceed' });
|
||||
});
|
||||
@@ -198,3 +201,31 @@ describe('computeFeaturesForProp — graceful degradation', () => {
|
||||
expect(src).not.toMatch(/UnifiedOddsProvider/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Session 64 — grading binds to the BOUND game, never "today"', () => {
|
||||
test('no bound game date → opponent features are NOT bound to a guessed game', async () => {
|
||||
mockSupabaseState.rosterRow = { team_abbr: 'NYK', espn_id: '1', sport: 'nba' };
|
||||
// A full scoreboard is available — the old code would have happily bound
|
||||
// this (possibly yesterday's) game. Without a bound date we must not.
|
||||
mockAxiosGet.mockResolvedValue(nbaScoreboard([game('ev-9', 'NYK', 'BOS')]));
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba',
|
||||
// no game_date / game_time
|
||||
});
|
||||
expect(out.meta.errors).toContain('no_bound_game_date');
|
||||
expect(out.meta.gameId).toBeNull();
|
||||
expect(out.meta.opponentAbbr).toBeNull();
|
||||
expect(out.meta.isHome).toBeNull();
|
||||
});
|
||||
|
||||
test('a bound date resolves the opponent for THAT date', async () => {
|
||||
mockSupabaseState.rosterRow = { team_abbr: 'NYK', espn_id: '1', sport: 'nba' };
|
||||
mockAxiosGet.mockResolvedValue(nbaScoreboard([game('ev-10', 'NYK', 'MIA')]));
|
||||
const out = await computeFeaturesForProp({
|
||||
player: 'Brunson', stat_type: 'points', line: 25, direction: 'over', sport: 'nba',
|
||||
game_date: '2026-07-20',
|
||||
});
|
||||
expect(out.meta.opponentAbbr).toBe('MIA');
|
||||
expect(out.meta.errors).not.toContain('no_bound_game_date');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user