'use strict'; /** * Reclaim 2 — the lock_lines writer is retired. * * The table was built for a staleness audit that was never written: 367,595 * rows, 104 MB, zero readers in src/, scripts/ or web/src/, still accruing * 36,440 rows/day (23% of all database growth) for a question nobody asked. * * A dead table that keeps refilling is only half-solved, so the WRITE is off * too. `buildLockRows` is deliberately kept and still tested: it is pure and * correct, and re-arming is one flag plus re-creating the table. */ const llc = require('../../src/services/lockLineCapture'); const PROPS = [ { player: 'Aaron Judge', stat_type: 'hits', book: 'draftkings', line: 0.5, over_odds: -120, under_odds: 100, game_time: '2026-08-12T23:05:00Z' }, { player: 'Aaron Judge', stat_type: 'hits', book: 'pinnacle', line: 0.5, over_odds: -115, under_odds: -105, game_time: '2026-08-12T23:05:00Z' }, ]; const KEYS = new Set([llc.lockKey('Aaron Judge', 'hits')]); describe('the writer is retired', () => { it('persist() writes NOTHING and says so', async () => { let opened = false; const out = await llc.persist([{ sport: 'mlb' }], { getClient: () => { opened = true; return {}; } }); expect(out.written).toBe(0); expect(out.retired).toBe(true); expect(out.skipped).toBe(true); expect(opened).toBe(false); // never even reaches for a client }); it('reports what it DID NOT write, so the drop stays visible in the log', async () => { const rows = llc.buildLockRows('mlb', PROPS, KEYS, { lockedAt: 'T0' }); const out = await llc.persist(rows, {}); expect(out.attempted).toBe(rows.length); expect(out.written).toBe(0); }); it('re-arms behind the flag', async () => { const chunks = []; const out = await llc.persist([{ sport: 'mlb', player_key: 'a' }], { armed: true, getClient: () => ({ from: () => ({ upsert: async (c) => { chunks.push(...c); return { error: null }; } }) }), }); expect(out.written).toBe(1); expect(out.retired).toBeUndefined(); expect(chunks).toHaveLength(1); }); it('captureArmed reads the env flag', () => { const prev = process.env.LOCK_LINE_CAPTURE; delete process.env.LOCK_LINE_CAPTURE; expect(llc.captureArmed()).toBe(false); process.env.LOCK_LINE_CAPTURE = '1'; expect(llc.captureArmed()).toBe(true); if (prev === undefined) delete process.env.LOCK_LINE_CAPTURE; else process.env.LOCK_LINE_CAPTURE = prev; }); }); describe('buildLockRows is KEPT and still correct', () => { it('still builds the rows it always did — the logic is not what was wrong', () => { const rows = llc.buildLockRows('mlb', PROPS, KEYS, { lockedAt: 'T0' }); expect(rows).toHaveLength(2); // one per book expect(rows.map((r) => r.book).sort()).toEqual(['draftkings', 'pinnacle']); expect(rows.find((r) => r.book === 'pinnacle').line_type).toBe('sharp'); expect(rows.every((r) => r.locked_at === 'T0')).toBe(true); }); it('still skips a book with neither price — honest-absent survives', () => { const rows = llc.buildLockRows('mlb', [{ ...PROPS[0], over_odds: null, under_odds: null }], KEYS, {}); expect(rows).toHaveLength(0); }); it('still grades-only: an ungraded prop is not captured', () => { expect(llc.buildLockRows('mlb', PROPS, new Set(), {})).toHaveLength(0); }); }); describe('the snapshot pass survives a retired capture', () => { it('the call site distinguishes RETIRED from a missing-env skip', () => { const src = require('fs').readFileSync( require('path').join(__dirname, '..', '..', 'src/services/snapshotService.js'), 'utf8'); expect(src).toMatch(/lr\.retired/); expect(src).toMatch(/RETIRED \(table dropped/); }); it('persist never throws, so the snapshot cannot break on it', async () => { await expect(llc.persist(null, {})).resolves.toMatchObject({ written: 0 }); await expect(llc.persist([], {})).resolves.toMatchObject({ written: 0 }); }); }); describe('nothing reads lock_lines (the precondition for the drop)', () => { it('no source file selects from it', () => { const { execSync } = require('child_process'); const root = require('path').join(__dirname, '..', '..'); const hits = execSync( "grep -rn \"from('lock_lines')\\|FROM lock_lines\" --include='*.js' --include='*.ts' --include='*.tsx' --include='*.sql' src scripts web/src 2>/dev/null | grep -v upsert || true", { cwd: root, encoding: 'utf8' }, ).trim(); expect(hits).toBe(''); }); });