'use strict'; /** * S59 SLATE JOIN INVARIANT — re-armed 2026-08-01. * * The invariant drops a graded prop whose player's REAL team is not a * participant in that game. It was written correctly and was silently INERT: * `mlbStatsAdapter.searchPlayer` returned `team: null` for every player * (`/sports/1/players` gives `currentTeam: { id, link }` with no `name`), so * `team` was null on 416/416 stored grades and the guard could never fire. * * Two properties are locked here: * 1. FAIL-SAFE — it drops ONLY on a positive not-in-game. Unknown team, or * unknown game participants, ABSTAIN. Dropping a real prop on absent data * would be a new fabrication, worse than the bad row it guards against. * 2. It must key off the PLAYER'S team, never the prop's own game teams — * comparing a game to itself always matches and would re-disarm it while * looking armed. */ const { buildPlayerStripsFromProps } = require('../../web/src/lib/slateAdapter'); const prop = (player, team) => ({ player, stat_type: 'hits', line: 1.5, side: 'O', team }); const GAME = { home: 'Philadelphia Phillies', away: 'New York Mets' }; const players = (strips) => strips.map((s) => s.player); describe('join invariant — fail-safe by construction', () => { it('DROPS a prop whose player is positively not in this game', () => { const out = buildPlayerStripsFromProps( [prop('In Game', 'Philadelphia Phillies'), prop('Wrong Game', 'Toronto Blue Jays')], {}, {}, Date.now(), GAME, ); expect(players(out)).toEqual(['In Game']); }); it('ABSTAINS when the player team is unknown — never drops on absent data', () => { const out = buildPlayerStripsFromProps( [prop('No Team', null), prop('Empty Team', '')], {}, {}, Date.now(), GAME, ); expect(players(out)).toEqual(['No Team', 'Empty Team']); }); it('ABSTAINS when the GAME participants are unknown', () => { const rows = [prop('Anyone', 'Toronto Blue Jays')]; expect(players(buildPlayerStripsFromProps(rows, {}, {}, Date.now(), null))).toEqual(['Anyone']); expect(players(buildPlayerStripsFromProps(rows, {}, {}, Date.now(), {}))).toEqual(['Anyone']); }); it('matches on either participant, and on abbreviation or full name', () => { const out = buildPlayerStripsFromProps( [prop('Home Guy', 'Philadelphia Phillies'), prop('Away Guy', 'New York Mets')], {}, {}, Date.now(), GAME, ); expect(players(out)).toEqual(['Home Guy', 'Away Guy']); }); }); describe('the invariant’s input is the PLAYER team, not the prop’s own game', () => { it('a grade carrying only home_team/away_team does NOT satisfy the guard', () => { // home_team describes the game the prop came from, so using it as the // player's team compares the game to itself: always a match, guard dead. const row = { player: 'X', stat_type: 'hits', line: 1.5, side: 'O', home_team: 'Toronto Blue Jays', away_team: 'Boston Red Sox' }; const out = buildPlayerStripsFromProps([row], {}, {}, Date.now(), GAME); expect(players(out)).toEqual(['X']); // abstained — no player team known }); });