Session 45: Snapshot pipeline + GameCard swap + live ticker (2100 tests)

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>
This commit is contained in:
Kev
2026-06-18 21:34:29 -04:00
parent 7969a4971a
commit f8b120c0aa
24 changed files with 1425 additions and 129 deletions
+38
View File
@@ -0,0 +1,38 @@
// Session 45 — in-process snapshot scheduler (gated, fires once per slot).
const { startSnapshotScheduler, HOURS_UTC } = require('../../src/snapshotScheduler');
afterEach(() => { delete process.env.SNAPSHOT_CRON; });
describe('startSnapshotScheduler', () => {
it('no-ops unless SNAPSHOT_CRON=1', () => {
delete process.env.SNAPSHOT_CRON;
expect(startSnapshotScheduler()).toBeNull();
});
it('defaults to the sports-cycle UTC hours', () => {
expect(HOURS_UTC).toEqual([14, 19, 22, 1, 3]);
});
it('fires runAllSnapshots at a scheduled hour, once per slot', async () => {
process.env.SNAPSHOT_CRON = '1';
const runAllSnapshots = jest.fn(async () => [{ sport: 'mlb', status: 'ok' }]);
let d = new Date(Date.UTC(2026, 5, 18, 14, 0, 0)); // 14:00 UTC — scheduled
const sched = startSnapshotScheduler({ runAllSnapshots, now: () => d });
await sched.tick();
await sched.tick(); // same slot — must NOT double-fire
expect(runAllSnapshots).toHaveBeenCalledTimes(1);
if (sched.interval && sched.interval.unref) clearInterval(sched.interval);
});
it('does not fire off-schedule (wrong hour / non-zero minute)', async () => {
process.env.SNAPSHOT_CRON = '1';
const runAllSnapshots = jest.fn();
const sched = startSnapshotScheduler({ runAllSnapshots, now: () => new Date(Date.UTC(2026, 5, 18, 15, 0, 0)) });
await sched.tick();
const sched2 = startSnapshotScheduler({ runAllSnapshots, now: () => new Date(Date.UTC(2026, 5, 18, 14, 30, 0)) });
await sched2.tick();
expect(runAllSnapshots).not.toHaveBeenCalled();
[sched, sched2].forEach((s) => s.interval && clearInterval(s.interval));
});
});