Files
vyndr/tests/unit/colorContract.test.js
builtbykev 0997334f8b Order B: retire edge_pct display. Promotion gate NOT passed — no flip.
THE PROMOTION WAS NOT PERFORMED. Champion grade path byte-identical (diff empty
across intelligence/, gradeSlateService, snapshotService). Projection, p_win and
the CLV instrument untouched.

REVIEW ZERO IS A GATE AND THREE OF FOUR PREREQUISITES FAIL:
  0.1 scores are ESTIMATED priors from the founding spec, not measured. The
      premise's cited values are not in the code either — the module holds
      nba:points .80 and mlb:total_bases .55; there is no NBA 0.72 and no WNBA
      score at all.
  0.2 VERSION-BOUNDARY TAG DID NOT LAND — config/modelEras.js has zero shading
      references. It was deliberately not applied twice (nothing had been
      promoted) and reported both times. The order's own rule says STOP.
  0.3 NO ROLLBACK FLAG EXISTS — zero occurrences of SHADING_ENABLED /
      EDGE_SHADING / shadingEnabled anywhere in src/.
  0.4 takeable tags DID land (migration 034, 1246/1254 rows). PASS.

AND THE APPROVED DELTA DOES NOT MATCH THE MEASURED ONE. Approved: 43.6% of
grades re-letter, efficient markets tighten and soft hold. Measured on all 1250
live rows: 97.4% change (1217), 79.8% move UP, 17.6% down, resulting in 79.0%
A-family (MLB 93.4%) against the champion's 0.2%. And rows_actually_shaded = 0
of 1250 — 96.5% of markets are unscored (f=1) and the one scored market present
is the anchor (f=1.0 by construction). The entire re-letter comes from switching
to edge-vs-fixed-bar grading, NOT from efficiency shading, which is inert on
this board. That is an unapproved grading-basis change riding along, which the
order's own "no new scaling changes riding along" guardrail forbids.

Flipping would re-letter 97.4% of an append-only public record, move 79.8% of
grades UP and mint A's on 79% of the board, on a letter whose measured
correlation with outcomes is r ~ 0.005 — the exact scenario the permanent
founder ruling forbids.

SHIPPED — ORDER B (independent of the promotion, and a live falsehood):
edge_pct display retired from GradeResultCard (confidence strip, EDGE stat cell
now honest-absent, alt-ladder rung) and SoccerGradeResult. DeskShowcase kept
(already honest). Computation and the board's signed-edge sort fallback SURVIVE
— deleting them would re-break the sort fixed on 2026-07-29; a test asserts all
three survive and the sort still orders agrees -> disagrees -> absent.

Fixed two build-breakers the retirement caused (orphaned edgeColor import,
orphaned edge_pct destructure; edge_pct stays on the props contract). Two
pre-existing tests superseded rather than deleted: they asserted the edge figure
is sign-coloured, and now assert the stronger property that no edge percentage
renders at all.

Floor: 314 suites / 3908 tests green (9 new), web build exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QJs13VsyiSKYQP6rj3NNmc
2026-07-31 00:57:57 -04:00

166 lines
7.4 KiB
JavaScript

// DS3 — THE COLOR CONTRACT (DESIGN-SPEC Part 1).
// The contract is enforced as failing tests: green means ONE thing (edge),
// edge/CLV is colored by SIGN, grades by TIER, glow is A/A+ only, and NO
// archetype hue may dilute the signal green. Extends the QA.20-22 discipline.
const fs = require('fs');
const path = require('path');
const WEB = path.join(__dirname, '..', '..', 'web', 'src');
const read = (rel) => fs.readFileSync(path.join(WEB, rel), 'utf8');
const cc = require('../../web/src/lib/colorContract');
const tokens = require('../../web/src/lib/vyndrTokens');
const arch = require('../../web/src/lib/archetypes');
const svc = require('../../src/services/archetypeService');
describe('colorContract.edgeColor — edge/CLV/delta colored by SIGN (#3)', () => {
it('positive edge is signal-green', () => {
expect(cc.edgeColor(6.2)).toBe('var(--g-a)');
expect(cc.edgeColor('12')).toBe('var(--g-a)');
});
it('NEGATIVE edge is muted red — a -33.3% edge NEVER renders green', () => {
expect(cc.edgeColor(-33.3)).toBe('var(--miss)');
expect(cc.edgeColor(-0.1)).toBe('var(--miss)');
expect(cc.edgeColor('-5')).toBe('var(--miss)');
expect(cc.edgeColor(-33.3)).not.toBe('var(--g-a)');
});
it('zero / null / NaN is NO edge → neutral (never a fake green)', () => {
expect(cc.edgeColor(0)).toBe('var(--text-2)');
expect(cc.edgeColor(null)).toBe('var(--text-2)');
expect(cc.edgeColor(undefined)).toBe('var(--text-2)');
expect(cc.edgeColor('n/a')).toBe('var(--text-2)');
});
});
describe('colorContract.gradeTierColor — grades colored by TIER', () => {
it('A/A+ green, B blue, C amber, D/F red', () => {
expect(cc.gradeTierColor('A+')).toBe('var(--g-ap)');
expect(cc.gradeTierColor('A')).toBe('var(--g-a)');
expect(cc.gradeTierColor('A-')).toBe('var(--g-a)');
expect(cc.gradeTierColor('B')).toBe('var(--g-b)');
expect(cc.gradeTierColor('C')).toBe('var(--g-c)');
expect(cc.gradeTierColor('D')).toBe('var(--g-d)');
expect(cc.gradeTierColor('F')).toBe('var(--g-d)');
});
it('is case/whitespace tolerant, unknown → neutral', () => {
expect(cc.gradeTierColor(' a+ ')).toBe('var(--g-ap)');
expect(cc.gradeTierColor('???')).toBe('var(--text-0)');
});
it('stays in lockstep with vyndrTokens.gradeColor for shared keys', () => {
for (const g of ['A+', 'A', 'A-', 'B+', 'B', 'B-', 'C', 'D']) {
expect(cc.gradeTierColor(g)).toBe(tokens.gradeColor(g));
}
});
});
describe('colorContract.gradeGlows — GLOW = A/A+ ONLY (#4)', () => {
it('true for A and A+ only', () => {
expect(cc.gradeGlows('A+')).toBe(true);
expect(cc.gradeGlows('A')).toBe(true);
});
it('false for every non-A tier — a glowing C devalues the cue', () => {
for (const g of ['A-', 'B+', 'B', 'B-', 'C', 'D', 'F', '', null, undefined]) {
expect(cc.gradeGlows(g)).toBe(false);
}
});
});
describe('colorContract.deltaE / isSignalGreen — perceptual gate', () => {
it('deltaE of a color with itself is 0', () => {
expect(cc.deltaE('#00D4A0', '#00D4A0')).toBeCloseTo(0, 5);
});
it('flags the signal green itself and near-clones', () => {
expect(cc.isSignalGreen('#00D4A0')).toBe(true);
expect(cc.isSignalGreen('#34D399')).toBe(true); // the old MIRROR green
});
it('clears clearly-different hues (amber, blue, red)', () => {
expect(cc.isSignalGreen('#FFB347')).toBe(false);
expect(cc.isSignalGreen('#4A9EFF')).toBe(false);
expect(cc.isSignalGreen('#FF5252')).toBe(false);
});
});
describe('ARCHETYPE DEDUP — no archetype hue dilutes the signal green (#15,§5)', () => {
it('every FRONTEND archetype color clears the signal-green ΔE gate', () => {
const offenders = [];
for (const [name, info] of Object.entries(arch.ARCHETYPE_MAP)) {
if (cc.isSignalGreen(info.c)) offenders.push(`${name} ${info.c} (ΔE ${cc.deltaE(info.c, cc.SIGNAL_GREEN).toFixed(1)})`);
}
expect(offenders).toEqual([]);
});
it('every BACKEND archetype color clears the gate too', () => {
const offenders = [];
for (const [name, a] of Object.entries(svc.ARCHETYPES)) {
if (cc.isSignalGreen(a.color)) offenders.push(`${name} ${a.color}`);
}
expect(offenders).toEqual([]);
});
it('NO archetype is the literal signal green #00D4A0 (case-insensitive)', () => {
const hits = Object.values(arch.ARCHETYPE_MAP).map((i) => i.c.toUpperCase()).filter((c) => c === '#00D4A0');
expect(hits).toEqual([]);
});
it('frontend + backend colors still agree after the shift', () => {
for (const [name, a] of Object.entries(svc.ARCHETYPES)) {
expect(arch.archetypeColor(name)).toBe(a.color);
}
});
});
// ---- SOURCE-GREP VIOLATION LOCKS -------------------------------------------
// These fail if the ad-hoc green-on-negative / non-A-glow patterns creep back.
describe('GradeResultCard.tsx — edge by sign, glow by tier', () => {
const src = read('components/vyndr/GradeResultCard.tsx');
// SUPERSEDED 2026-07-31 by ORDER B: the edge figure is retired from the card,
// so there is no edge to colour. `edgeColor` itself is untouched and still
// enforced for its other consumers (see MarketBreadth). The retirement is the
// stronger guarantee — an unshown number cannot be mis-coloured.
it('renders no edge figure to colour at all (ORDER B retirement)', () => {
expect(src).not.toContain('color: edgeColor(d.edge)');
expect(src).not.toMatch(/\{d\.edge\}% edge/);
expect(src).toMatch(/l: 'EDGE', v: '—'/);
});
it('does NOT color an edge figure unconditionally green', () => {
// the old bug: a green span wrapping the edge %, agnostic to sign
expect(src).not.toMatch(/color: 'var\(--g-a\)' \}\}>\{d\.edge/);
expect(src).not.toMatch(/d\.edge != null \? 'var\(--g-a\)'/);
});
it('gates the grade-hero glow (textShadow) to A/A+ via gradeGlows', () => {
expect(src).toContain('gradeGlows(d.grade) ?');
// the ungated always-on glow must be gone
expect(src).not.toMatch(/textShadow: `0 0 28px \$\{hex\}aa, 0 0 60px \$\{hex\}55`,/);
});
});
describe('GradeBadge.tsx — glow gated to A-tier', () => {
const src = read('components/vyndr/GradeBadge.tsx');
it('boxShadow glow only when glow && isA (A/A+)', () => {
expect(src).toContain("const isA = grade === 'A+' || grade === 'A'");
expect(src).toMatch(/boxShadow: glow && isA \?/);
});
});
describe('LiveHeroProp.tsx — the disagreement display (item 5)', () => {
// The hero card now shows the book's line vs VYNDR's model side by side (the
// largest model-vs-market gap), not a signed edge %. Model = green (our
// number, the signal), book line = neutral. No static Jokic fallback.
const src = read('components/LiveHeroProp.tsx');
it('renders BOOK LINE vs VYNDR MODEL, model in green', () => {
expect(src).toContain('LINE'); // "{bookLabel} LINE"
expect(src).toContain('VYNDR MODEL');
expect(src).toMatch(/VYNDR MODEL[^]*?color: 'var\(--grade-a\)'/);
});
it('has no hand-written static fallback (no hardcoded Jokic example)', () => {
expect(src).not.toContain('Nikola Jokic');
expect(src).not.toContain('aria-label="Example grade"'); // the old EXAMPLE chip is gone
expect(src).not.toContain('26.5'); // the old hardcoded line
});
});
describe('VYNDR INTELLIGENCE panel — de-flooded (#15)', () => {
const src = read('components/vyndr/GradeResultCard.tsx');
it('the panel border is a neutral token, not a green wash', () => {
expect(src).not.toContain("border: '1px solid rgba(0,212,160,0.24)'");
});
});