'use strict'; /** * THE INTERFACE MUST NOT RESTORE THE LIE. * * The backend already refuses to state a probability it cannot certify. This * holds the presentation layer to the same standard: an uncertified Read shows * the Read, the grade, the side and the market — and says plainly that the * exact confidence is unavailable, rather than printing a number nobody stands * behind. * * Found by this suite before any pixel was rendered: `gradeAdapter` coerced a * null confidence to 0, so `GradeResultCard` rendered "0% confidence". */ const fs = require('fs'); const path = require('path'); const { mapScanToGradeResult } = require('../../web/src/lib/gradeAdapter'); const sp = require('../../src/services/model/servedProbability'); const registry = require('../../src/services/model/artifactRegistry'); const ERA = 'engine1@2026-08-07-fullwindow'; const CARD = fs.readFileSync(path.join(__dirname, '../../web/src/components/vyndr/GradeResultCard.tsx'), 'utf8'); /** REAL production rows from proven shadow cohort 27ce152f, run through the * REAL serving seam with live forced on for the test process only. */ // Exact production values, model_snapshots ids 453021 and 453033. const REAL = { // raw 0.798 -> served 0.638: calibration materially moves the displayed number certified: { sport: 'mlb', stat_type: 'hits', player: 'Christian Encarnacion Strand', line: 1.5, side: 'under', direction: 'under', model_version: ERA, p_win: 0.798, confidence: 80, grade: 'B+', ev_pct: 17.9, value: false, book_odds: -210, fair_odds: -173, fair_prob: 0.633, over_odds: 155, under_odds: -210, tier: 'desk' }, // raw 0.852, and it carries value:true / ev 38.5 — so the contract has a real // actionability badge to withdraw, not merely an absent one to leave absent. uncertified: { sport: 'mlb', stat_type: 'hits', player: 'Luis Robert', line: 1.5, side: 'under', direction: 'under', model_version: ERA, p_win: 0.852, confidence: 85, grade: 'B+', ev_pct: 38.5, value: true, book_odds: -160, fair_odds: -135, fair_prob: 0.575, over_odds: 120, under_odds: -160, tier: 'desk' }, }; const live = (row) => sp.applyToRows([{ ...row }], { liveState: { live: 'ON' } })[0]; const card = (row) => mapScanToGradeResult(live(row)); describe('the live contract reaches the card correctly', () => { it('CERTIFIED: the card shows the SERVED probability, not the raw one', () => { const served = registry.applyCurve(registry.load('mlb', 'hits'), 0.798); const d = card(REAL.certified); expect(d.confidence).toBe(Math.round(Math.round(served * 1000) / 1000 * 100)); expect(d.confidence).not.toBe(80); // the raw confidence expect(String(d.confidence)).not.toBe('0'); }); it('CERTIFIED: EV comes from the served probability, not the raw one', () => { const out = live(REAL.certified); const { evPct } = require('../../src/utils/devig'); expect(out.ev_pct).toBe(evPct(out.p_win, -210)); expect(out.ev_pct).not.toBe(17.9); // the raw-derived value }); it('UNCERTIFIED: confidence is NULL — never 0, never 50, never NaN', () => { const d = card(REAL.uncertified); expect(d.confidence).toBeNull(); expect(d.confidence).not.toBe(0); expect(d.confidence).not.toBe(50); expect(Number.isNaN(d.confidence)).toBe(false); }); it('UNCERTIFIED: no raw probability survives anywhere the card can print it', () => { const d = card(REAL.uncertified); const json = JSON.stringify(d); expect(json).not.toContain('0.852'); expect(json).not.toContain('"confidence":85'); expect(json).not.toContain('38.5'); // raw EV }); it('UNCERTIFIED: the Read, the grade, the side and the market all survive', () => { const d = card(REAL.uncertified); expect(d.grade).toBe('B+'); // grade untouched expect(d.player).toBe('Luis Robert'); // Read exists expect(d.priceTriplet.book_odds).toBe(-160); // market visible expect(d.priceTriplet.model_odds).toBeNull(); // model leg withheld expect(d.priceTriplet.ev_pct).toBeNull(); }); it('UNCERTIFIED: a TRUE value badge is withdrawn, not left standing', () => { expect(REAL.uncertified.value).toBe(true); // the raw row claims VALUE const out = live(REAL.uncertified); expect(out.value).toBeNull(); // and the contract withdraws it expect(out.kelly).toBeNull(); expect(out.model_odds).toBeNull(); expect(out.ev_pct).toBeNull(); }); }); describe('what the card actually renders', () => { it('renders a WORD, not a number, when confidence is unavailable', () => { expect(CARD).toContain('Confidence unavailable'); // and the numeric clause is conditional, not unconditional expect(CARD).toContain('d.confidence != null'); expect(CARD).not.toMatch(/\{d\.confidence\}% confidence<\/span>\s*\n\s*<\/div>/); }); it('the unavailable state is TEXT — not colour, an icon or an absence', () => { const i = CARD.indexOf('Confidence unavailable'); const clause = CARD.slice(i - 200, i + 60); expect(clause).toContain('\s*—\s* { for (const term of ['isotonic', 'artifact', 'knot_digest', 'probability_contract', 'UNCERTIFIED', 'CERTIFIED_CALIBRATED', 'certification_version', 'model era']) { expect(CARD).not.toContain(term); } }); it('grade and confidence availability stay separate concepts', () => { const d = card(REAL.uncertified); expect(d.confidence).toBeNull(); expect(d.grade).toBe('B+'); // no strike-through / revision styling tied to the confidence state const i = CARD.indexOf('Confidence unavailable'); expect(CARD.slice(i - 300, i + 100)).not.toContain('line-through'); }); });