Intelligence, Advanced Charting & Trading Platform
risk/chartnova-atomic-outbox-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 { normalizeProviderObservation, deriveGoldMetrics } from '../src/pipeline.mjs'; |
| 4 | |
| 5 | test('normalizes an Iranian rial provider observation and preserves audit input', () => { |
| 6 | const result = normalizeProviderObservation({ |
| 7 | providerCode: 'navasan', |
| 8 | canonicalSymbol: 'USD_IRT_FREE', |
| 9 | providerTimestamp: new Date('2026-10-05T12:00:00Z'), |
| 10 | receivedAt: new Date('2026-10-05T12:00:02Z'), |
| 11 | price: 1_000_000, |
| 12 | rawUnit: 'IRR_PER_USD', |
| 13 | rawPayload: { value: '1000000' }, |
| 14 | referencePrice: 100_100, |
| 15 | maxDivergencePct: 1, |
| 16 | maxAgeMs: 60_000, |
| 17 | }); |
| 18 | |
| 19 | assert.equal(result.tick.price, 100_000); |
| 20 | assert.equal(result.tick.quality.state, 'GOOD'); |
| 21 | assert.equal(result.raw.price, 1_000_000); |
| 22 | assert.equal(result.raw.rawUnit, 'IRR_PER_USD'); |
| 23 | assert.deepEqual(result.raw.rawPayload, { value: '1000000' }); |
| 24 | }); |
| 25 | |
| 26 | test('derives theoretical gold and premium with complete source provenance', () => { |
| 27 | const target = new Date('2026-10-05T12:00:00Z'); |
| 28 | const result = deriveGoldMetrics({ |
| 29 | target, |
| 30 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:59:50Z') }, |
| 31 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:59:45Z') }, |
| 32 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T11:59:40Z') }, |
| 33 | maxAgeMs: 60_000, |
| 34 | formulaVersion: 'gold18-v1', |
| 35 | }); |
| 36 | |
| 37 | assert.equal(result.quality, 'GOOD'); |
| 38 | assert.equal(result.formulaVersion, 'gold18-v1'); |
| 39 | assert.equal(result.sourceSnapshot.targetTimestamp, '2026-10-05T12:00:00.000Z'); |
| 40 | assert.equal(result.sourceSnapshot.xau.timestamp, '2026-10-05T11:59:50.000Z'); |
| 41 | assert.equal(result.sourceSnapshot.usdIrt.timestamp, '2026-10-05T11:59:45.000Z'); |
| 42 | assert.equal(result.sourceSnapshot.marketGold.timestamp, '2026-10-05T11:59:40.000Z'); |
| 43 | assert.ok(result.theoreticalIrtPerGram > 0); |
| 44 | assert.ok(Number.isFinite(result.premium.absoluteIrt)); |
| 45 | assert.ok(Number.isFinite(result.premium.percent)); |
| 46 | }); |
| 47 | |
| 48 | test('marks derived gold metrics stale when any required source is stale', () => { |
| 49 | const target = new Date('2026-10-05T12:00:00Z'); |
| 50 | const result = deriveGoldMetrics({ |
| 51 | target, |
| 52 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:59:50Z') }, |
| 53 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:55:00Z') }, |
| 54 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T11:59:40Z') }, |
| 55 | maxAgeMs: 60_000, |
| 56 | formulaVersion: 'gold18-v1', |
| 57 | }); |
| 58 | assert.equal(result.quality, 'STALE'); |
| 59 | }); |
| 60 | |
| 61 | test('rejects a market-gold observation from the future', () => { |
| 62 | assert.throws(() => deriveGoldMetrics({ |
| 63 | target: new Date('2026-10-05T12:00:00Z'), |
| 64 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:59:50Z') }, |
| 65 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:59:45Z') }, |
| 66 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T12:00:01Z') }, |
| 67 | maxAgeMs: 60_000, |
| 68 | formulaVersion: 'gold18-v1', |
| 69 | }), /after target/); |
| 70 | }); |