Intelligence, Advanced Charting & Trading Platform
risk/chartnova-seven-track-safety-2026-10-21
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | import test from 'node:test';import assert from 'node:assert/strict'; |
| 2 | import {inspectTwoSources} from '../src/licensed-provider-selector.mjs'; |
| 3 | const t='2026-10-20T12:00:00Z',now=Date.parse(t),perm={publicDisplay:true,derivedAlerts:true}; |
| 4 | const x={symbol:'USD_IRT_FREE',provider:'one',unit:'IRT_PER_USD',side:'SELL',price:1000,timestamp:t,permission:perm}; |
| 5 | const y={...x,provider:'two',price:1001}; |
| 6 | const run=(p,s,opts={})=>inspectTwoSources(p,s,{nowMs:now,maxClockSkewMs:60000,...opts}); |
| 7 | test('same units/sides two independent licensed sources cross-check',()=>{ |
| 8 | const a=run(x,y);assert.equal(a.status,'CROSSCHECK_PASSED');assert.equal(a.confirmation,'TWO_MATCHING_SOURCES') |
| 9 | }); |
| 10 | test('divergence blocks price output and returns difference',()=>{ |
| 11 | const r=run(x,{...y,price:1200});assert.equal(r.status,'SOURCE_DIVERGENCE'); |
| 12 | assert.equal(r.alertsSuspended,true);assert.equal(r.observation,null);assert.ok(r.divergencePct>2) |
| 13 | }); |
| 14 | test('non-convertible raw units, side and time block, never silently normalize',()=>{ |
| 15 | for(const mismatch of [{unit:'IRR_PER_USD'},{side:'BUY'},{timestamp:'2026-10-20T11:58:00Z'},{provider:'one'}]){ |
| 16 | const r=run(x,{...y,...mismatch});assert.equal(r.alertsSuspended,true); |
| 17 | assert.ok(['INCOMPATIBLE_SOURCES','SOURCE_TIME_SKEW'].includes(r.status)) |
| 18 | } |
| 19 | }); |
| 20 | test('unlicensed primary uses licensed secondary with explicit single-source downgrade',()=>{ |
| 21 | const r=run({...x,permission:null},y); |
| 22 | assert.equal(r.status,'FALLBACK_SINGLE_SOURCE'); |
| 23 | assert.equal(r.confirmation,'ONE_LICENSED_SOURCE_NO_CROSSCHECK'); |
| 24 | }); |
| 25 | test('no rights cannot select any price or license by implication',()=>{ |
| 26 | const r=run({...x,permission:{publicDisplay:false,derivedAlerts:true}}, |
| 27 | {...y,permission:null});assert.equal(r.status,'BOTH_UNAVAILABLE'); |
| 28 | assert.equal(r.observation,null) |
| 29 | }); |
| 30 | test('stale both sources block and fresh single source may survive',()=>{ |
| 31 | const o={...x,timestamp:'2026-10-20T11:30:00Z'}; |
| 32 | assert.equal(run(o,{...y,timestamp:o.timestamp}).status,'BOTH_UNAVAILABLE'); |
| 33 | assert.equal(run(o,y).status,'FALLBACK_SINGLE_SOURCE') |
| 34 | }); |
| 35 | test('rejects invalid configuration',()=>assert.throws(()=>run(x,y,{maxDivergencePct:-1}))); |