@davoodmehraban89 / VELYQOR / commits / d5c827b
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(risk): license-guarded dual source matching, downgrade, bad units and provider outage

davoodmehraban89 committed Oct 21, 2026 at 08:51 UTC d5c827bbb567dcbe29f27d4f92d5a6c3ec5363b0
1 file changed +35
packages/market-domain/test/licensed-provider-selector.test.mjs new
+35
@@ -0,0 +1,35 @@
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})));