Files
vyndr/tests/unit/lockLineRetired.test.js
builtbykev 0657b71d18 Drop lock_lines and retire its writer (dead table, dead writer)
lock_lines was built in Session 64 for a staleness audit - join lock-time
per-book lines to closing_captures and ask whether our locked line was
stale-high vs consensus. That audit was never written. ruler-comparison.sql
records why: only 43 settled rows ever joined it with >=2 two-sided books.

Measured before removal: 367,595 rows, 104 MB, zero readers in src/, scripts/
or web/src/ - the only from('lock_lines') was an upsert, every other mention a
comment. Zero dependents: no FK, no view, no trigger. The newest pg_dump held
all 367,595 rows, pg_restore-verified before the drop.

The write is off too, because a dead table that keeps refilling is only half
solved: it was accruing 36,440 rows/day, 10.3 MB/day, 23% of all database
growth, for a question nobody was asking. buildLockRows is kept and still
tested - the logic was never what was wrong, and re-arming is one flag plus
re-creating the table.

DB 510 MB -> 406 MB: 81% of the 500 MB cap, +94 MB headroom, under it for the
first time in months.

Moat and grade untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-12 01:18:10 -04:00

105 lines
4.4 KiB
JavaScript

'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('');
});
});