Render directional-CLV badge — Analyst+Desk, server-gated, receipt-bearing

CARD BADGE ONLY. Ticker-CLV explicitly DEFERRED (named, not lost).

PHASE 1 — SERVER-SIDE GATE AT THE DATA LAYER. A Free request never
RECEIVES dclv data: the CLV columns are appended to the SELECT only behind
canAccess(tier,'clv_badge') (new capability, analyst+desk), and responses
are ALSO stripped as defence in depth so a future SELECT change cannot
quietly leak. No CSS/client gate — data that reaches the browser has left
the building. dclv_fair_lock/fair_close are de-vig internals and are never
sent at all.

SURFACE AUDIT, all six channels, each test-locked to contain no CLV:
public profile (share link), snapshot/card feed, ticker feed, share
card/OG, embeddable widget, newsletter. A test also asserts no
ledger_entries read uses select('*') — a star would auto-leak every new
column, which is exactly how a gate becomes theatre.

PHASE 2 — IMMUTABLE ONCE COMPUTED. A settle can re-run (stat correction,
protested game) and a badge that flips positive->negative AFTER a user saw
or screenshotted it is a credibility failure. First computation wins: dclv
is only computed when dclv_computed_at is null, so a re-settle can never
rewrite a shown badge. Same discipline as the locked grade.

PHASE 3 — RENDER, test-first, ABSENCE IS HONEST. unknown / flat / null /
missing-receipt all render NOTHING — no element, no placeholder, no
"pending". Proven on an ALL-NULL board (today: 0 badges) and a MIXED board
(tomorrow: 1 of 4 badged, badge-less cards clean). Binary states only:
  positive -> MOVED TOWARD US  "graded -110 · closed -145"
  negative -> MOVED AWAY       "graded -110 · closed +120"
The RECEIPT is the persuasive part, so a badge with no numbers is
suppressed rather than shown as a bare claim. Negative is neutral context
and NEVER touches the locked grade — no back-door re-grading.

NO aggregate, count or rollup exists by construction: the module exports
exactly {clvBadge, fmtPrice} and a badge payload carries exactly
{tone,label,receipt} — asserted by test, because an on-screen tally would
be the held aggregate claim through the side door.

Build gotcha hit and fixed: clvBadge is CommonJS (allowJs) with no TS
types, so the .tsx needed an explicit cast at the call site — the build
worker exits 1 on type errors even though compilation "succeeds".

Suite 288/3473 green, build exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SmNjJAwEnqHPtXbvSZR8kA
This commit is contained in:
Kev
2026-07-20 13:37:52 -04:00
parent dcdad60896
commit da8bfdf1db
8 changed files with 309 additions and 6 deletions
+50
View File
@@ -0,0 +1,50 @@
/**
* Directional-CLV badge model (Session 64). CommonJS so it is unit-testable
* and shared by the card without a React import.
*
* ABSENCE IS HONEST. unknown / flat / null / missing render NOTHING — not a
* placeholder, not a zero, not "pending". A board where some reads are badged
* and others are not is the REAL state (closes are captured per game as each
* locks), so a badge-less card must never look broken or worse.
*
* THE RECEIPT IS THE POINT. "MOVED TOWARD US" alone is a claim; "graded 110 ·
* closed 145" is evidence. The numbers are what make it persuasive, so the
* badge always carries them and is suppressed if they are missing.
*
* NO AGGREGATE. There is deliberately no count, rollup, or "N reads moved
* toward us" — an on-screen tally is the held aggregate claim through the side
* door. Per-read only.
*/
/** Format an American price for the receipt. */
function fmtPrice(v) {
if (v == null || v === '') return null;
const n = Number(v);
if (!Number.isFinite(n)) return null;
return n > 0 ? `+${Math.round(n)}` : `${Math.round(n)}`;
}
/**
* @param {Object} read { dclv_state, locked_odds, closing_odds }
* @returns {null|{tone,label,receipt}} null = render NOTHING
*/
function clvBadge(read) {
if (!read) return null;
const state = read.dclv_state;
// flat and unknown are both silence — a held line is not news, and a missing
// close is not a zero.
if (state !== 'positive' && state !== 'negative') return null;
const graded = fmtPrice(read.locked_odds);
const closed = fmtPrice(read.closing_odds);
// No receipt → no badge. A bare label is an assertion without evidence.
if (!graded || !closed) return null;
return {
tone: state === 'positive' ? 'confirm' : 'caution',
label: state === 'positive' ? 'MOVED TOWARD US' : 'MOVED AWAY',
receipt: `graded ${graded} · closed ${closed}`,
};
}
module.exports = { clvBadge, fmtPrice };