c8fc9f577e
Three focused P1 fixes on the Session-45 snapshot model.
- Grade card intel ROOT CAUSE: gameLogService is NBA/WNBA-only (offline Python),
so MLB props never got l5_avg/l20_avg and buildIntelFields returned {}. Wired
MLB game logs into featureCache.gameLogFeatures via mlbStatsAdapter.getPlayerStats
(pure mlbGameLogFeatures + MLB stat_type->field map). buildIntelFields gained
playerStats/projection fallbacks for partial intel.
- Player name normalization: src/utils/playerName.js (+ web/src/lib copy):
normalizeName -> {display,key}. Strips periods, de-dots suffix, accent-folds
the key. Applied in snapshotService grouping, slateAdapter grade index +
player-strip merge (variants collapse, longest name shown), and
playerIntelService. "A.J. Ewing"/"AJ Ewing" + "Jazz Chisholm"/"Jr." now merge.
- MLB starting pitchers: new GET /api/schedule/:sport/pitchers (probablePitchers
service wrapping mlbStatsAdapter.getScheduleWithPitchers + best-effort ERA).
Slate fetches it, builds a team->pitcher map (full name + mascot match),
attaches pitchers to MLB GameCardData. + Next proxy.
Backend 2100 -> 2122 tests (+22), 176 suites. Web build clean (exit 0).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
82 lines
3.7 KiB
JavaScript
82 lines
3.7 KiB
JavaScript
// Session 45 — Phase 3: pre-graded snapshot overlay + the GameCard swap.
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
|
|
const read = (rel) => fs.readFileSync(path.join(WEB, rel), 'utf8');
|
|
const a = require('../../web/src/lib/slateAdapter');
|
|
|
|
describe('snapshot overlay adapter', () => {
|
|
const grades = [
|
|
{ player: 'Aaron Judge', stat_type: 'total_bases', line: 1.5, direction: 'over', grade: 'A+', archetype: 'BOMBER', gradedAt: { line: 1.5, odds: -115, timestamp: '2026-06-18T18:00:00Z' } },
|
|
{ player: 'Aaron Judge', stat_type: 'home_runs', line: 0.5, direction: 'over', grade: 'C', archetype: 'BOMBER', gradedAt: { line: 0.5, odds: 120, timestamp: '2026-06-18T18:00:00Z' } },
|
|
];
|
|
const deltas = [{ player: 'Aaron Judge', stat: 'total_bases', side: 'O', delta: 1.0, direction: 'toward', currentLine: 2.5 }];
|
|
|
|
it('indexes grades + deltas for lookup', () => {
|
|
const gi = a.indexGrades(grades);
|
|
expect(gi['aaron judge|total_bases'].grade).toBe('A+');
|
|
const di = a.indexDeltas(deltas);
|
|
expect(di['aaron judge|total_bases|O'].direction).toBe('toward');
|
|
});
|
|
|
|
it('overlays grades onto game props → playerStrips (name once, archetype, gradedAt, delta)', () => {
|
|
const gameProps = [
|
|
{ player: 'Aaron Judge', stat_type: 'total_bases', line: 1.5 },
|
|
{ player: 'Aaron Judge', stat_type: 'home_runs', line: 0.5 },
|
|
];
|
|
const strips = a.buildPlayerStripsFromProps(gameProps, a.indexGrades(grades), a.indexDeltas(deltas), new Date('2026-06-18T20:00:00Z').getTime());
|
|
expect(strips).toHaveLength(1); // name once
|
|
expect(strips[0].archetype).toEqual({ primary: 'BOMBER' });
|
|
const tb = strips[0].props.find((p) => p.stat === 'TB');
|
|
expect(tb.grade).toBe('A+');
|
|
expect(tb.gradedAt.ago).toBe('2h ago');
|
|
expect(tb.gradedAt.odds).toBe(-115);
|
|
expect(tb.delta).toEqual({ delta: 1.0, direction: 'toward', currentLine: 2.5 });
|
|
});
|
|
|
|
it('marks ungraded props as awaiting (no Read button)', () => {
|
|
const strips = a.buildPlayerStripsFromProps(
|
|
[{ player: 'New Guy', stat_type: 'hits', line: 1.5 }],
|
|
a.indexGrades(grades), a.indexDeltas(deltas),
|
|
);
|
|
expect(strips[0].props[0].awaiting).toBe(true);
|
|
expect(strips[0].props[0].grade).toBeNull();
|
|
});
|
|
|
|
it('gradedAgo formats relative time', () => {
|
|
const now = new Date('2026-06-18T20:00:00Z').getTime();
|
|
expect(a.gradedAgo('2026-06-18T19:30:00Z', now)).toBe('30m ago');
|
|
expect(a.gradedAgo('2026-06-18T18:00:00Z', now)).toBe('2h ago');
|
|
expect(a.gradedAgo(undefined, now)).toBe('');
|
|
});
|
|
});
|
|
|
|
describe('Slate uses the VYNDR card + pre-graded snapshot (swap is real)', () => {
|
|
const src = read('components/Slate.tsx');
|
|
it('imports the VYNDR GameCard component (legacy only for types)', () => {
|
|
expect(src).toContain("import VyndrGameCard");
|
|
expect(src).toContain("'@/components/vyndr/GameCard'");
|
|
expect(src).toContain('<VyndrGameCard');
|
|
// legacy component default-import is gone (only `import type` remains)
|
|
expect(src).not.toMatch(/^import GameCard /m);
|
|
});
|
|
it('fetches the pre-graded snapshot and builds playerStrips', () => {
|
|
expect(src).toContain('/api/snapshot/');
|
|
expect(src).toContain('buildPlayerStripsFromProps');
|
|
expect(src).toContain('slateGameToCardData');
|
|
});
|
|
it('retired the on-demand Read grade flow', () => {
|
|
expect(src).not.toContain('const onGrade = useCallback');
|
|
});
|
|
});
|
|
|
|
describe('StatStrip renders snapshot states', () => {
|
|
const src = read('components/vyndr/StatStrip.tsx');
|
|
it('renders Awaiting next scan + line-delta sub-line', () => {
|
|
expect(src).toContain('Awaiting next scan');
|
|
expect(src).toContain('TOWARD');
|
|
expect(src).toContain('Graded ');
|
|
});
|
|
});
|