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 {evaluateQuoteGate} from '../src/alert-data-gate.mjs'; |
| 3 | import {stepAlert,markNotified} from '../src/informational-alert-engine.mjs'; |
| 4 | import {notificationRecord,claimDelivery,recordDeliveryOutcome} from '../src/notification-outbox.mjs'; |
| 5 | import {baleOneMessage} from '../src/bale-once-adapter.mjs'; |
| 6 | import {inspectTwoSources} from '../src/licensed-provider-selector.mjs'; |
| 7 | |
| 8 | const now=Date.parse('2026-10-21T12:30:00.000Z'); |
| 9 | const t=i=>new Date(now-300000+i*60000).toISOString(); |
| 10 | const entitlement={publicDisplay:true,derivedAlerts:true}; |
| 11 | const o=(i,price,extra={})=>({provider:'S1',symbol:'USD_IRT_FREE',unit:'IRT_PER_USD', |
| 12 | side:'SELL',price,timestamp:t(i),permission:entitlement,...extra}); |
| 13 | const cfg={nowMs:now,config:{maxAgeMs:10*60000,recoverySamples:1}}; |
| 14 | const rule={id:'user-optin-test',provider:'S1',symbol:'USD_IRT_FREE',unit:'IRT_PER_USD', |
| 15 | legs:[{type:'ABOVE',side:'SELL',threshold:1050}]}; |
| 16 | const gate=(state,quote,opts={})=>evaluateQuoteGate(state,quote,{...cfg,...opts}); |
| 17 | test('functional integration: spike quarantined until second fresh independent sample; then one threshold event',()=>{ |
| 18 | const a=gate(null,o(0,1000)); |
| 19 | const before=stepAlert(rule,null,o(0,1000),a); |
| 20 | assert.equal(before.events.length,0); |
| 21 | const spike=gate(a.state,o(1,1100)); |
| 22 | assert.equal(spike.status,'SPIKE_PENDING'); |
| 23 | const blocked=stepAlert(rule,before.state,o(1,1100),spike); |
| 24 | assert.equal(blocked.events.length,0); |
| 25 | assert.equal(blocked.reason,'QUALITY_HOLD'); |
| 26 | const confirmed=gate(spike.state,o(2,1101)); |
| 27 | assert.equal(confirmed.status,'GOOD'); |
| 28 | const fired=stepAlert(rule,blocked.state,o(2,1101),confirmed); |
| 29 | assert.equal(fired.events.length,1); |
| 30 | assert.equal(fired.events[0].kind,'INFORMATIONAL_THRESHOLD'); |
| 31 | assert.equal(stepAlert(rule,fired.state,o(3,1101),gate(confirmed.state,o(3,1101))).events.length,0); |
| 32 | }); |
| 33 | test('security integration: rights and cross-source disagreement block all downstream alerts',()=>{ |
| 34 | const unlicensed=o(1,1100,{permission:null}); |
| 35 | assert.equal(gate(null,unlicensed).accepted,null); |
| 36 | assert.equal(stepAlert(rule,null,unlicensed,gate(null,unlicensed)).events.length,0); |
| 37 | const a=o(1,1100),b=o(1,1300,{provider:'S2'}); |
| 38 | const checked=inspectTwoSources(a,b,{nowMs:now,maxAgeMs:600000}); |
| 39 | assert.equal(checked.status,'SOURCE_DIVERGENCE'); |
| 40 | assert.equal(checked.observation,null); |
| 41 | assert.equal(checked.alertsSuspended,true); |
| 42 | }); |
| 43 | test('send-outcome integration: accepted Bale response advances, ambiguous outcome is terminal',async()=>{ |
| 44 | const start=gate(null,o(2,1101)); |
| 45 | const fired=stepAlert(rule,null,o(2,1101),start); |
| 46 | assert.equal(fired.events.length,1); |
| 47 | const eventId=fired.events[0].id; |
| 48 | const message=notificationRecord({id:'msg-1',eventId,recipientChannel:'BALE',createdAt:t(2)}); |
| 49 | let outbox=claimDelivery(message,{now:t(2)}).record; |
| 50 | const token='123456:syntheticTransportTokenPlaceholderOnly'; |
| 51 | const accepted=await baleOneMessage({token,chatId:'12345',text:'آزمون اطلاعرسانی، توصیه مالی نیست', |
| 52 | transport:async url=>url.endsWith('/getChat')? |
| 53 | {status:200,json:async()=>({ok:true,result:{id:12345,type:'private'}})}: |
| 54 | {status:200,json:async()=>({ok:true,result:{chat:{id:12345},message_id:7}})}}); |
| 55 | assert.equal(accepted.status,'SENT'); |
| 56 | outbox=recordDeliveryOutcome(outbox,{at:t(3),success:true,providerMessageId:accepted.messageId}); |
| 57 | assert.equal(outbox.status,'SENT'); |
| 58 | const notified=markNotified(rule,fired.state,{eventId,at:t(3),deliveryId:outbox.providerMessageId}); |
| 59 | assert.equal(notified.phase,'NOTIFIED'); |
| 60 | let n=claimDelivery(notificationRecord({id:'msg-2',eventId,recipientChannel:'BALE',createdAt:t(2)}),{now:t(2)}).record; |
| 61 | const unknown=await baleOneMessage({token,chatId:'12345',text:'آزمون', |
| 62 | transport:async url=>url.endsWith('/getChat')? |
| 63 | {status:200,json:async()=>({ok:true,result:{id:12345,type:'private'}})}: |
| 64 | {status:503,json:async()=>({ok:false})}}); |
| 65 | assert.equal(unknown.status,'UNKNOWN'); |
| 66 | n=recordDeliveryOutcome(n,{at:t(3),success:false,unknown:true}); |
| 67 | assert.equal(n.status,'UNKNOWN'); |
| 68 | assert.equal(claimDelivery(n,{now:t(4)}).claimed,false); |
| 69 | }); |