Intelligence, Advanced Charting & Trading Platform
phase-1/market-calendar
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 { deriveGoldMetrics } from '../src/pipeline.mjs'; |
| 4 | |
| 5 | test('derived gold exposes numeric quality score and source-quality provenance', () => { |
| 6 | const result = deriveGoldMetrics({ |
| 7 | target: new Date('2026-10-05T12:00:00Z'), |
| 8 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:59:50Z'), quality: { state: 'GOOD', score: 98 } }, |
| 9 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:59:45Z'), quality: { state: 'DEGRADED', score: 76 } }, |
| 10 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T11:59:40Z'), quality: { state: 'GOOD', score: 95 } }, |
| 11 | maxAgeMs: 60_000, |
| 12 | formulaVersion: 'gold18-v1', |
| 13 | }); |
| 14 | |
| 15 | assert.equal(result.quality, 'DEGRADED'); |
| 16 | assert.equal(result.qualityScore, 76); |
| 17 | assert.equal(result.sourceSnapshot.xau.quality.score, 98); |
| 18 | assert.equal(result.sourceSnapshot.usdIrt.quality.score, 76); |
| 19 | assert.equal(result.sourceSnapshot.marketGold.quality.score, 95); |
| 20 | }); |
| 21 | |
| 22 | test('staleness caps derived score even when supplied source scores are high', () => { |
| 23 | const result = deriveGoldMetrics({ |
| 24 | target: new Date('2026-10-05T12:00:00Z'), |
| 25 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:55:00Z'), quality: { state: 'GOOD', score: 99 } }, |
| 26 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:59:45Z'), quality: { state: 'GOOD', score: 99 } }, |
| 27 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T11:59:40Z'), quality: { state: 'GOOD', score: 99 } }, |
| 28 | maxAgeMs: 60_000, |
| 29 | formulaVersion: 'gold18-v1', |
| 30 | }); |
| 31 | |
| 32 | assert.equal(result.quality, 'STALE'); |
| 33 | assert.ok(result.qualityScore <= 30); |
| 34 | }); |
| 35 | |
| 36 | test('derived quality falls back safely when legacy inputs have no numeric scores', () => { |
| 37 | const result = deriveGoldMetrics({ |
| 38 | target: new Date('2026-10-05T12:00:00Z'), |
| 39 | xau: { value: 4_000, timestamp: new Date('2026-10-05T11:59:50Z') }, |
| 40 | usdIrt: { value: 100_000, timestamp: new Date('2026-10-05T11:59:45Z') }, |
| 41 | marketGold: { value: 10_000_000, timestamp: new Date('2026-10-05T11:59:40Z') }, |
| 42 | maxAgeMs: 60_000, |
| 43 | formulaVersion: 'gold18-v1', |
| 44 | }); |
| 45 | |
| 46 | assert.equal(result.quality, 'GOOD'); |
| 47 | assert.equal(result.qualityScore, 100); |
| 48 | }); |