Intelligence, Advanced Charting & Trading Platform
risk/chartnova-seven-track-safety-2026-10-21
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 { analyzeObservationSeries } from './data-proof.mjs'; |
| 2 | |
| 3 | function nonNegative(value, name) { |
| 4 | if (!Number.isFinite(value) || value < 0) throw new RangeError(`${name} must be non-negative and finite`); |
| 5 | } |
| 6 | |
| 7 | export function buildDataProofReport({ providerCode, canonicalSymbol, observations, checkedAt, thresholds }) { |
| 8 | if (!providerCode || !canonicalSymbol) throw new TypeError('providerCode and canonicalSymbol are required'); |
| 9 | if (!Array.isArray(observations) || observations.length === 0) throw new RangeError('at least one observation is required'); |
| 10 | if (!(checkedAt instanceof Date) || Number.isNaN(checkedAt.valueOf())) throw new TypeError('checkedAt must be a valid Date'); |
| 11 | if (!thresholds || typeof thresholds !== 'object') throw new TypeError('thresholds are required'); |
| 12 | for (const key of ['maxGapMs','maxFreshnessMs','maxDuplicateCount','maxOutOfOrderCount']) nonNegative(thresholds[key], key); |
| 13 | |
| 14 | const series = analyzeObservationSeries(observations); |
| 15 | const latestMs = new Date(series.lastTimestamp).valueOf(); |
| 16 | const freshnessMs = checkedAt.valueOf() - latestMs; |
| 17 | if (freshnessMs < 0) throw new RangeError('checkedAt cannot be before the latest observation'); |
| 18 | |
| 19 | const failures = []; |
| 20 | if (series.maxGapMs !== null && series.maxGapMs > thresholds.maxGapMs) failures.push('MAX_GAP_EXCEEDED'); |
| 21 | if (freshnessMs > thresholds.maxFreshnessMs) failures.push('STALE_LATEST_OBSERVATION'); |
| 22 | if (series.duplicateTimestampCount > thresholds.maxDuplicateCount) failures.push('DUPLICATE_TIMESTAMPS'); |
| 23 | if (series.outOfOrderCount > thresholds.maxOutOfOrderCount) failures.push('OUT_OF_ORDER_OBSERVATIONS'); |
| 24 | |
| 25 | return { |
| 26 | providerCode, |
| 27 | canonicalSymbol, |
| 28 | checkedAt: checkedAt.toISOString(), |
| 29 | status: failures.length === 0 ? 'PASS' : 'FAIL', |
| 30 | failures, |
| 31 | thresholds: { ...thresholds }, |
| 32 | metrics: { ...series, freshnessMs }, |
| 33 | }; |
| 34 | } |