Intelligence, Advanced Charting & Trading Platform
risk/chartnova-alert-runtime-atomic-2026-10-22
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 { evaluateObservationQuality } from '../src/data-quality.mjs'; |
| 4 | |
| 5 | test('flags an excessive move from the previous observation as a price spike', () => { |
| 6 | const result = evaluateObservationQuality({ |
| 7 | price: 110, |
| 8 | previousPrice: 100, |
| 9 | maxMovePct: 5, |
| 10 | ageMs: 1_000, |
| 11 | maxAgeMs: 60_000, |
| 12 | }); |
| 13 | |
| 14 | assert.equal(result.state, 'DEGRADED'); |
| 15 | assert.ok(result.flags.includes('PRICE_SPIKE')); |
| 16 | assert.ok(Math.abs(result.movePct - 10) < 1e-9); |
| 17 | }); |
| 18 | |
| 19 | test('does not flag a move at the configured boundary', () => { |
| 20 | const result = evaluateObservationQuality({ |
| 21 | price: 105, |
| 22 | previousPrice: 100, |
| 23 | maxMovePct: 5, |
| 24 | ageMs: 1_000, |
| 25 | maxAgeMs: 60_000, |
| 26 | }); |
| 27 | |
| 28 | assert.equal(result.state, 'GOOD'); |
| 29 | assert.ok(Math.abs(result.movePct - 5) < 1e-9); |
| 30 | }); |
| 31 | |
| 32 | test('staleness remains the dominant state when a stale observation also spikes', () => { |
| 33 | const result = evaluateObservationQuality({ |
| 34 | price: 120, |
| 35 | previousPrice: 100, |
| 36 | maxMovePct: 5, |
| 37 | ageMs: 120_000, |
| 38 | maxAgeMs: 60_000, |
| 39 | }); |
| 40 | |
| 41 | assert.equal(result.state, 'STALE'); |
| 42 | assert.ok(result.flags.includes('STALE_SOURCE')); |
| 43 | assert.ok(result.flags.includes('PRICE_SPIKE')); |
| 44 | }); |
| 45 | |
| 46 | test('rejects an invalid previous price or spike threshold', () => { |
| 47 | assert.throws(() => evaluateObservationQuality({ |
| 48 | price: 100, |
| 49 | previousPrice: 0, |
| 50 | maxMovePct: 5, |
| 51 | ageMs: 1_000, |
| 52 | maxAgeMs: 60_000, |
| 53 | }), /previousPrice/); |
| 54 | |
| 55 | assert.throws(() => evaluateObservationQuality({ |
| 56 | price: 100, |
| 57 | previousPrice: 99, |
| 58 | maxMovePct: -1, |
| 59 | ageMs: 1_000, |
| 60 | maxAgeMs: 60_000, |
| 61 | }), /maxMovePct/); |
| 62 | }); |