Blast radius: exclude projection<=0 grades from the public model record

The degraded grades (projection=0 → model_value=0) are already settled in the
append-only ledger and must NOT be deleted (Data Semantics law). But their
hit/miss is noise, not model skill — they never had a real projection. So
getModelAggregate now filters `.gt('model_value', 0)` on both the settled and
pending queries: the rows stay in ledger_entries, but leave the public hit_pct /
CLV / per-tier record. `.gt` also drops NULL model_value. Post-fix no such row
can be written (projection<=0 refuses), so this only sheds the historical set.

This is the functional form of the "marking" the work order asked for — the
degraded locks are effectively marked as non-counting without mutating history.

Test builder mocks gained `.gt`; a lock asserts the filter is applied to both
queries. Suite 269/3253 green, web build exit 0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-07-17 03:15:50 -04:00
parent 888d103f95
commit 9fc4edf3a9
7 changed files with 21 additions and 3 deletions
+1
View File
@@ -24,6 +24,7 @@ function mockChain() {
is(col, val) { b._filters.push(['is', col, val]); return b; },
not(col, op, val) { b._filters.push(['not', col, op, val]); return b; },
gte(col, val) { b._filters.push(['gte', col, val]); return b; },
gt(col, val) { b._filters.push(['gt', col, val]); return b; },
ilike(col, val) { b._filters.push(['ilike', col, val]); return b; },
order() { return b; },
limit() {
+1
View File
@@ -33,6 +33,7 @@ function mockChain(table) {
b.is = rec('is');
b.not = rec('not');
b.gte = rec('gte');
b.gt = rec('gt');
b.order = () => b;
b.maybeSingle = () => {
mockState.filters.push([table, b._filters]);
+1
View File
@@ -32,6 +32,7 @@ function mockChain(table) {
b.is = rec('is');
b.not = rec('not');
b.gte = rec('gte');
b.gt = rec('gt');
b.order = () => b;
b.maybeSingle = () => {
mockState.filters.push([table, b._filters]);
+7
View File
@@ -15,6 +15,7 @@ function makeSb(captured, rows) {
b.is = rec('is');
b.not = rec('not');
b.gte = rec('gte');
b.gt = rec('gt');
b.order = () => b;
b.limit = () => { captured.push(b._filters); return Promise.resolve({ data: rows, error: null, count: 0 }); };
b.then = (resolve, reject) => {
@@ -37,6 +38,12 @@ describe('getModelAggregate scoping', () => {
}
expect(agg.hit_pct).toBeNull();
expect(agg.min_sample).toBe(ledgerService.MIN_AGG_SAMPLE);
// 2026-07 — projection<=0 grades (the degradation blast radius) are excluded
// from the public record on BOTH queries (kept in the append-only ledger,
// just never counted). `.gt('model_value', 0)` also drops NULL model_value.
for (const filters of captured) {
expect(filters).toContainEqual(['gt', 'model_value', 0]);
}
});
test('userId scopes BOTH queries to that user and never touches the public scope', async () => {
+1
View File
@@ -24,6 +24,7 @@ function fakeSb() {
not() { return b; },
lt() { return b; },
gte() { return b; },
gt() { return b; },
in(col, ids) {
if (b._update) {
calls.updates.push({ values: b._update, ids });
+1 -1
View File
@@ -154,7 +154,7 @@ describe('ledgerService.settleLedger — WNBA settles vs the ESPN game log', ()
upsert() { return Promise.resolve({ error: null }); },
update(v) { b._update = v; return b; },
select() { return b; }, eq() { return b; }, is() { return b; },
not() { return b; }, lt() { return b; }, gte() { return b; }, order() { return b; },
not() { return b; }, lt() { return b; }, gte() { return b; }, gt() { return b; }, order() { return b; },
in(col, ids) {
if (b._update) { calls.updates.push({ values: b._update, ids }); return Promise.resolve({ error: null }); }
return terminal();