f8b120c0aa
The on-demand "Read" grade model is RETIRED. A scheduled pipeline pre-grades the
slate, locks grades to the line, tracks movement; the dashboard shows them already
there. Orchestrates existing services — nothing rebuilt.
- snapshotService.runSnapshot(sport): getOdds → gradeAndCacheSlate → classify
archetype per player → lock gradedAt → line deltas vs previous snapshot → write
snapshot:{sport}:latest/previous + grades:{sport} → ticker events. Fully
injectable, zero-network unit tests. runAllSnapshots = cron entrypoint.
- Internal trigger POST /api/internal/snapshot/:sport + /all (requireInternalAuth).
In-process cron (SNAPSHOT_CRON=1, UTC 14,19,22,1,3) in server.js, no new dep.
- Public reads: GET /api/snapshot/:sport (cache-only) + GET /api/ticker (merges
TICKER_MANUAL pins) + Next proxies.
- GameCard swap: live Slate renders vyndr/GameCard (legacy kept for types only),
overlays locked grades onto game props → player name once + archetype badge +
"Graded Xh ago at -115 · Current 2.5 · ▲ TOWARD +1.0". Ungraded → "Awaiting next
scan", NO Read button. On-demand onGrade flow deleted.
- Ticker polls /api/ticker every 30s, graceful fallback to hardcoded items.
- NBA/WNBA: espnStatsAdapter free fallback (defensive parse → found:false on shape
mismatch) wired into resolvePlayerStats after the offline Python service.
Env: PROPLINE_API_KEY_1/2/3, VYNDR_INTERNAL_KEY, SNAPSHOT_CRON=1, TICKER_MANUAL.
Backend 2061 -> 2100 tests (+39), 173 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['aaronjudge|total_bases'].grade).toBe('A+');
|
|
const di = a.indexDeltas(deltas);
|
|
expect(di['aaronjudge|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 ');
|
|
});
|
|
});
|