Intelligence, Advanced Charting & Trading Platform
feature/paper-trading-risk-controls-2026-10-14
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'; |
| 2 | import assert from 'node:assert/strict'; |
| 3 | import {validatePaperQuote} from '../src/paper-quote-guard.mjs'; |
| 4 | |
| 5 | const NOW='2026-10-14T20:00:00Z'; |
| 6 | const q=()=>({ |
| 7 | symbol:'XAU_USD',source:'licensed_paper_feed',unit:'USD_PER_TROY_OUNCE', |
| 8 | dataKind:'bid_ask_quote',usage:'PAPER_ONLY_BID_ASK',entitlement:'reviewed_simulation_display', |
| 9 | quality:'GOOD',isMarketOpen:true,sequence:2,bid:'100',ask:'100.2', |
| 10 | sourceTimestamp:'2026-10-14T19:59:55Z',receivedAt:'2026-10-14T19:59:57Z' |
| 11 | }); |
| 12 | const opts=(side='LONG')=>({symbol:'XAU_USD',side,now:NOW,lastSequence:1,approvedSources:['licensed_paper_feed']}); |
| 13 | test('LONG uses bid as conservative hypothetical exit mark',()=>{ |
| 14 | const out=validatePaperQuote(q(),opts()); |
| 15 | assert.equal(out.hypotheticalExitMark,100); |
| 16 | assert.equal(out.kind,'PAPER_QUOTE_ELIGIBLE'); |
| 17 | }); |
| 18 | test('SHORT uses ask as conservative hypothetical exit mark',()=>{ |
| 19 | assert.equal(validatePaperQuote(q(),opts('SHORT')).hypotheticalExitMark,100.2); |
| 20 | }); |
| 21 | test('rejects ECB reference points and unapproved sources',()=>{ |
| 22 | let x=q();x.dataKind='daily_reference_point_not_ohlc'; |
| 23 | assert.throws(()=>validatePaperQuote(x,opts()),/type\/usage/); |
| 24 | x=q();x.source='ecb_exr'; |
| 25 | assert.throws(()=>validatePaperQuote(x,opts()),/source not approved/); |
| 26 | }); |
| 27 | test('rejects stale source and stale receive timestamps',()=>{ |
| 28 | let x=q();x.sourceTimestamp='2026-10-14T19:00:00Z'; |
| 29 | assert.throws(()=>validatePaperQuote(x,opts()),/stale/); |
| 30 | x=q();x.receivedAt='2026-10-14T19:00:00Z'; |
| 31 | assert.throws(()=>validatePaperQuote(x,opts()),/stale/); |
| 32 | }); |
| 33 | test('rejects replay, missing sequence, future timestamp',()=>{ |
| 34 | let x=q();x.sequence=1; |
| 35 | assert.throws(()=>validatePaperQuote(x,opts()),/replayed/); |
| 36 | x=q();x.sequence=1.1; |
| 37 | assert.throws(()=>validatePaperQuote(x,opts()),/replayed/); |
| 38 | x=q();x.receivedAt='2026-10-14T20:03:00Z'; |
| 39 | assert.throws(()=>validatePaperQuote(x,opts()),/future/); |
| 40 | }); |
| 41 | test('rejects market closure or bad quality',()=>{ |
| 42 | let x=q();x.quality='STALE'; |
| 43 | assert.throws(()=>validatePaperQuote(x,opts()),/not healthy/); |
| 44 | x=q();x.isMarketOpen=false; |
| 45 | assert.throws(()=>validatePaperQuote(x,opts()),/not healthy/); |
| 46 | }); |
| 47 | test('rejects missing simulation entitlement',()=>{ |
| 48 | let x=q();delete x.entitlement; |
| 49 | assert.throws(()=>validatePaperQuote(x,opts()),/not authorized/); |
| 50 | }); |
| 51 | test('rejects crossed quotes and excessive spreads',()=>{ |
| 52 | let x=q();x.bid=102; |
| 53 | assert.throws(()=>validatePaperQuote(x,opts()),/crossed/); |
| 54 | x=q();x.ask=110; |
| 55 | assert.throws(()=>validatePaperQuote(x,opts()),/spread/); |
| 56 | }); |
| 57 | test('rejects invalid symbol, side, units and nonpositive prices',()=>{ |
| 58 | let x=q();x.bid='0'; |
| 59 | assert.throws(()=>validatePaperQuote(x,opts()),/positive/); |
| 60 | x=q();x.unit='USD/?'; |
| 61 | assert.throws(()=>validatePaperQuote(x,opts()),/canonical/); |
| 62 | assert.throws(()=>validatePaperQuote(q(),opts('BUY')),/side/); |
| 63 | assert.throws(()=>validatePaperQuote(q(),{...opts(),symbol:'BTC_USD'}),/symbol mismatch/); |
| 64 | }); |
| 65 | test('rejects unattested source lists and invalid tolerances',()=>{ |
| 66 | assert.throws(()=>validatePaperQuote(q(),{...opts(),approvedSources:[]}),/source not approved/); |
| 67 | assert.throws(()=>validatePaperQuote(q(),{...opts(),maxAgeMs:100000}),/freshness/); |
| 68 | }); |