Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

test(oracle): score the calibration factor against the probability a band claims

nirholas46892f1de7c8
diff --git a/tests/api/oracle-calibrate-cron.test.js b/tests/api/oracle-calibrate-cron.test.js
index 33fb18de6..d2e59c6e3 100644
--- a/tests/api/oracle-calibrate-cron.test.js
+++ b/tests/api/oracle-calibrate-cron.test.js
@@ -1,7 +1,8 @@
// api/cron/oracle-calibrate.js: conviction-band calibration rollup.
//
// Pins the math that drives the sniper optimizer's Rule O: a band's correction
-// factor is observed win rate / predicted rate, computed ONLY once the band has
+// factor is observed win rate / the probability the band's score actually claims
+// (probabilityFromScore, NOT score/100), computed ONLY once the band has
// MIN_BAND_SAMPLE real closed trades, and clamped to [0.7, 1.3] so a thin or
// extreme sample can never swing entries wildly. Also pins the wrapped 5xx when
// the join query itself fails.
@@ -22,6 +23,7 @@ vi.mock('../../api/_lib/alerts.js', () => ({ sendOpsAlert: vi.fn() }));
vi.mock('../../api/_lib/zauth.js', () => ({ instrument: () => false, drain: vi.fn() }));
const { default: handler } = await import('../../api/cron/oracle-calibrate.js');
+const { probabilityFromScore } = await import('../../api/_lib/oracle/conviction.js');
function call(method = 'GET', auth = 'Bearer test-cron-secret') {
const res = {
@@ -72,15 +74,30 @@ describe('GET/POST /api/cron/oracle-calibrate', () => {
});
it('a confident winning band computes factor = observed / predicted', async () => {
- // Five closed winning trades scored 90: predicted 0.9, observed 1.0.
+ // Five closed trades scored 90, four of them winners: observed 0.8. The
+ // prediction is what the score CLAIMS, not the score over 100: a 90 claims
+ // P=0.679, so the factor is 0.8/0.679, comfortably inside the clamp.
sqlMock.mockResolvedValueOnce(
- Array.from({ length: 5 }, () => ({ score: 90, win: 1, pnl_pct: 10 })),
+ Array.from({ length: 5 }, (_, i) => ({ score: 90, win: i < 4 ? 1 : 0, pnl_pct: 10 })),
);
const res = await call();
const band = res.body.bands.find((b) => b.band === '85-100');
expect(band.samples).toBe(5);
+ expect(band.observed_rate).toBe(0.8);
+ expect(band.correction_factor).toBeCloseTo(0.8 / probabilityFromScore(90), 3);
+ expect(band.correction_factor).toBeLessThan(1.3);
+ });
+
+ it('clamps the factor at 1.3 for a band that always wins', async () => {
+ // Observed 1.0 against a claimed 0.679 is a 1.47 correction; the ceiling is
+ // what stops one lucky band from swinging every entry threshold.
+ sqlMock.mockResolvedValueOnce(
+ Array.from({ length: 5 }, () => ({ score: 90, win: 1, pnl_pct: 10 })),
+ );
+ const res = await call();
+ const band = res.body.bands.find((b) => b.band === '85-100');
expect(band.observed_rate).toBe(1);
- expect(band.correction_factor).toBeCloseTo(1 / 0.9, 2);
+ expect(band.correction_factor).toBe(1.3);
});
it('clamps the factor at 0.7 for a band that always loses', async () => {