Intelligence, Advanced Charting & Trading Platform
feature/chartnova-multimarket-chart-ws-foundation
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 { |
| 4 | normalizeIranianQuote, |
| 5 | canonicalObservation, |
| 6 | providerHealth, |
| 7 | } from '../src/provider-contract.mjs'; |
| 8 | |
| 9 | test('normalizes provider rial values to canonical toman', () => { |
| 10 | assert.equal(normalizeIranianQuote({ value: 1_000_000, unit: 'IRR_PER_USD' }), 100_000); |
| 11 | }); |
| 12 | |
| 13 | test('keeps canonical toman values unchanged', () => { |
| 14 | assert.equal(normalizeIranianQuote({ value: 100_000, unit: 'IRT_PER_USD' }), 100_000); |
| 15 | }); |
| 16 | |
| 17 | test('rejects unsupported units instead of guessing', () => { |
| 18 | assert.throws(() => normalizeIranianQuote({ value: 100, unit: 'UNKNOWN' }), /unsupported unit/i); |
| 19 | }); |
| 20 | |
| 21 | test('creates an auditable canonical observation with distinct source and receive timestamps', () => { |
| 22 | const observation = canonicalObservation({ |
| 23 | providerCode: 'example', |
| 24 | canonicalSymbol: 'USD_IRT_FREE', |
| 25 | providerTimestamp: new Date('2026-10-05T12:00:00Z'), |
| 26 | receivedAt: new Date('2026-10-05T12:00:02Z'), |
| 27 | price: 100_000, |
| 28 | rawUnit: 'IRT_PER_USD', |
| 29 | }); |
| 30 | assert.deepEqual(observation, { |
| 31 | providerCode: 'example', |
| 32 | canonicalSymbol: 'USD_IRT_FREE', |
| 33 | providerTimestamp: '2026-10-05T12:00:00.000Z', |
| 34 | receivedAt: '2026-10-05T12:00:02.000Z', |
| 35 | price: 100_000, |
| 36 | canonicalUnit: 'IRT_PER_USD', |
| 37 | rawUnit: 'IRT_PER_USD', |
| 38 | }); |
| 39 | }); |
| 40 | |
| 41 | test('marks provider stale when last successful observation exceeds threshold', () => { |
| 42 | const result = providerHealth({ |
| 43 | now: new Date('2026-10-05T12:05:00Z'), |
| 44 | lastSuccessAt: new Date('2026-10-05T12:00:00Z'), |
| 45 | staleAfterMs: 60_000, |
| 46 | }); |
| 47 | assert.equal(result.status, 'STALE'); |
| 48 | assert.equal(result.ageMs, 300_000); |
| 49 | }); |