355615d27e
The backend already refuses to state a probability it cannot certify. The card
did not. `gradeAdapter.js:59` read
input.confidence != null ? Math.round(Number(input.confidence)) : 0
and `GradeResultCard` printed `{d.confidence}% confidence` unconditionally, so
an UNCERTIFIED Read — which by contract carries no exact probability — would
have rendered "0% CONFIDENCE" to a user. That is `Number(null) === 0`, the
standing fabrication bug in this codebase, arriving at the last surface before
the eye.
Found by running two REAL production rows (model_snapshots 453021 and 453033
from proven cohort 27ce152f) through the real serving seam and the real adapter,
before rendering anything.
Repaired at the two places it lives, presentation only:
- the adapter carries null through instead of coercing;
- the card renders "Confidence unavailable" as TEXT when there is no number.
Wording follows the house pattern already in `readHistory.js` ("History
unavailable") — no dash, no dimmed zero, no icon-only state, and no engineering
language: a test forbids isotonic / artifact / probability_contract /
UNCERTIFIED / certification_version reaching the card.
A second, narrower correction: the derived-field withdrawal was
`if (f in out) out[f] = null`, so it depended on whether the input happened to
carry the key and a field added by a later merge would have arrived
un-withdrawn. An uncertified row now DECLARES each probability-derived claim
null rather than merely lacking it.
The uncertified fixture is the strong case, not a convenient one: Luis Robert
carries value:true and ev_pct 38.5 on the raw row, so the contract has a live
VALUE badge to withdraw rather than an absent one to leave absent. Verified
withdrawn, while grade B+, the side, the Read and the market (book -160,
fair -135) all survive.
The certified case moves the number materially and visibly: raw 0.798 -> served
0.638, and EV is recomputed from the served probability, not carried from raw.
PriceTriplet needed no change — it already renders an absent leg as a dash and
was documented never to print a zero.
Suite 407/407, 5,691 passed. Teeth 45/45 + 10/10 + 23/23. Live OFF.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQJeAG8vcDoL5zkiaJyVb8
130 lines
5.9 KiB
JavaScript
130 lines
5.9 KiB
JavaScript
'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(/<span>\{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('<span'); // rendered as readable text
|
|
// it must not be conveyed by a dash or an empty node
|
|
expect(clause).not.toContain('—');
|
|
expect(clause).not.toMatch(/>\s*—\s*</);
|
|
});
|
|
|
|
it('no engineering language reaches the user', () => {
|
|
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');
|
|
});
|
|
});
|