Session 52: Coming Soon teaser + infrastructure verification (2239 tests)

Phase 1 — Push-to-Book teaser (feature not live; teaser only):
- StatStrip: "BOOK IT ⟶" per graded prop (hover: "Push-to-Book coming soon").
- GradeResultCard: "PUSH-TO-BOOK · COMING SOON" footer.

Phase 2 — infrastructure verification:
- snapshotScheduler logs armed AND disarmed state (incl SNAPSHOT_CRON) so
  container logs disambiguate off-vs-crashed.
- NEW GET /api/internal/snapshot/status (internal-key gated): cron_armed,
  cron_hours_utc, last_snapshot per sport (gradeCount/deltaCount), redis_keys
  existence map, ticker_count. The post-deploy pipeline health probe.
- Finding: Redis AOF/RDB persistence is a server-side (Coolify) config the app
  can't set/verify — documented.

Phase 3 — delta pipeline (verified sound, no fix needed):
- runSnapshot already rotates :latest->:previous and diffs locked lines; added
  opt-in SNAPSHOT_DEBUG=1 [deltas] log + a trace test asserting :previous is
  preserved verbatim and the delta math is correct.

Backend 2234 -> 2239 tests (+5), 192 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-19 13:55:39 -04:00
parent f0674ca07d
commit cdedecf55b
12 changed files with 221 additions and 5 deletions
+54
View File
@@ -0,0 +1,54 @@
// Session 52 — GET /api/internal/snapshot/status (verification probe).
const express = require('express');
const request = require('supertest');
const mockCacheGet = jest.fn();
jest.mock('../../src/utils/redis', () => ({
cacheGet: (...a) => mockCacheGet(...a),
cacheSet: jest.fn(),
}));
beforeEach(() => {
jest.resetAllMocks();
process.env.VYNDR_INTERNAL_KEY = 'test-internal-key-9999';
});
function mountApp() {
delete require.cache[require.resolve('../../src/routes/internal')];
const internalRoutes = require('../../src/routes/internal');
const app = express();
app.use(express.json());
app.use('/api/internal', internalRoutes);
return app;
}
describe('GET /api/internal/snapshot/status', () => {
it('requires the internal key', async () => {
const res = await request(mountApp()).get('/api/internal/snapshot/status');
expect(res.status).toBe(401);
});
it('reports cron state, last snapshot, redis keys, ticker count', async () => {
process.env.SNAPSHOT_CRON = '1';
mockCacheGet.mockImplementation(async (key) => {
if (key === 'snapshot:mlb:latest') return { updated_at: '2026-06-19T18:00:00Z', grades: [{}, {}, {}], deltas: [{}] };
if (key === 'grades:mlb') return { grades: [{}, {}, {}] };
if (key === 'ticker:items') return [{ type: 'SCAN' }, { type: 'ALERT' }];
return null;
});
const res = await request(mountApp())
.get('/api/internal/snapshot/status')
.set('x-internal-key', 'test-internal-key-9999');
expect(res.status).toBe(200);
expect(res.body.cron_armed).toBe(true);
expect(res.body.last_snapshot.mlb.gradeCount).toBe(3);
expect(res.body.last_snapshot.mlb.deltaCount).toBe(1);
expect(res.body.redis_keys['snapshot:mlb:latest']).toBe(true);
expect(res.body.redis_keys['snapshot:mlb:previous']).toBe(false);
expect(res.body.ticker_count).toBe(2);
delete process.env.SNAPSHOT_CRON;
});
});
+22
View File
@@ -0,0 +1,22 @@
// Session 52 — Push-to-Book "Coming Soon" teaser (source-asserted).
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');
describe('BOOK IT teaser', () => {
it('StatStrip renders the "BOOK IT" teaser on graded props', () => {
const src = read('components/vyndr/StatStrip.tsx');
expect(src).toContain('BookItTeaser');
expect(src).toContain('BOOK IT ⟶');
expect(src).toContain('Push-to-Book coming soon');
expect(src).toContain('<BookItTeaser p={p} />');
});
it('GradeResultCard renders "PUSH-TO-BOOK · COMING SOON"', () => {
const src = read('components/vyndr/GradeResultCard.tsx');
expect(src).toContain('PUSH-TO-BOOK · COMING SOON');
expect(src).toContain('Connect DraftKings, FanDuel, BetMGM');
});
});
+10
View File
@@ -14,6 +14,16 @@ describe('startSnapshotScheduler', () => {
expect(HOURS_UTC).toEqual([14, 19, 22, 1, 3]);
});
it('logs an armed startup message including SNAPSHOT_CRON when started', () => {
process.env.SNAPSHOT_CRON = '1';
const spy = jest.spyOn(console, 'log').mockImplementation(() => {});
const sched = startSnapshotScheduler({ runAllSnapshots: jest.fn(), now: () => new Date(Date.UTC(2026, 5, 18, 12, 30, 0)) });
expect(spy).toHaveBeenCalledWith(expect.stringContaining('[snapshotScheduler] armed'));
expect(spy).toHaveBeenCalledWith(expect.stringContaining('SNAPSHOT_CRON=1'));
spy.mockRestore();
if (sched && sched.interval && sched.interval.unref) clearInterval(sched.interval);
});
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' }]);
+5
View File
@@ -123,10 +123,15 @@ describe('runSnapshot (fully injected)', () => {
{ player: 'Aaron Judge', stat_type: 'total_bases', line, direction: 'over', grade: 'A+', confidence: 80 },
])(sport, props, opts);
await svc.runSnapshot('mlb', d);
const firstLatest = cache.store['snapshot:mlb:latest'];
line = 2.5; // line moved +1.0
const r2 = await svc.runSnapshot('mlb', d);
expect(cache.store['snapshot:mlb:previous']).toBeTruthy();
expect(r2.deltas).toBe(1);
// Session 52 trace: the previous snapshot is preserved verbatim so the next
// run can diff against the exact locked lines (the delta pipeline's input).
expect(cache.store['snapshot:mlb:previous']).toEqual(firstLatest);
expect(cache.store['snapshot:mlb:latest'].deltas[0]).toMatchObject({ delta: 1, gradedLine: 1.5, currentLine: 2.5 });
});
it('pushes ticker events (capped) into ticker:items', async () => {