Intelligence, Advanced Charting & Trading Platform
feature/chartnova-neon-direct-history
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 { nextProviderState } from '../src/provider-recovery.mjs'; |
| 4 | |
| 5 | test('healthy success keeps provider healthy', () => { |
| 6 | const next = nextProviderState({ |
| 7 | previous: { status: 'HEALTHY', consecutiveFailures: 0 }, |
| 8 | event: { type: 'SUCCESS', at: '2026-10-05T12:00:00Z' }, |
| 9 | }); |
| 10 | assert.deepEqual(next, { |
| 11 | status: 'HEALTHY', |
| 12 | consecutiveFailures: 0, |
| 13 | lastSuccessAt: '2026-10-05T12:00:00.000Z', |
| 14 | lastFailureAt: null, |
| 15 | recoveredAt: null, |
| 16 | }); |
| 17 | }); |
| 18 | |
| 19 | test('first failure degrades provider and increments counter', () => { |
| 20 | const next = nextProviderState({ |
| 21 | previous: { status: 'HEALTHY', consecutiveFailures: 0 }, |
| 22 | event: { type: 'FAILURE', at: '2026-10-05T12:01:00Z' }, |
| 23 | downAfterFailures: 3, |
| 24 | }); |
| 25 | assert.equal(next.status, 'DEGRADED'); |
| 26 | assert.equal(next.consecutiveFailures, 1); |
| 27 | }); |
| 28 | |
| 29 | test('provider becomes down at configured failure threshold', () => { |
| 30 | const next = nextProviderState({ |
| 31 | previous: { status: 'DEGRADED', consecutiveFailures: 2 }, |
| 32 | event: { type: 'FAILURE', at: '2026-10-05T12:03:00Z' }, |
| 33 | downAfterFailures: 3, |
| 34 | }); |
| 35 | assert.equal(next.status, 'DOWN'); |
| 36 | assert.equal(next.consecutiveFailures, 3); |
| 37 | }); |
| 38 | |
| 39 | test('success after outage records recovery and resets failures', () => { |
| 40 | const next = nextProviderState({ |
| 41 | previous: { |
| 42 | status: 'DOWN', |
| 43 | consecutiveFailures: 4, |
| 44 | lastFailureAt: '2026-10-05T12:03:00.000Z', |
| 45 | }, |
| 46 | event: { type: 'SUCCESS', at: '2026-10-05T12:05:00Z' }, |
| 47 | downAfterFailures: 3, |
| 48 | }); |
| 49 | assert.equal(next.status, 'HEALTHY'); |
| 50 | assert.equal(next.consecutiveFailures, 0); |
| 51 | assert.equal(next.recoveredAt, '2026-10-05T12:05:00.000Z'); |
| 52 | }); |
| 53 | |
| 54 | test('rejects invalid chronology', () => { |
| 55 | assert.throws(() => nextProviderState({ |
| 56 | previous: { status: 'HEALTHY', consecutiveFailures: 0, lastSuccessAt: '2026-10-05T12:05:00.000Z' }, |
| 57 | event: { type: 'FAILURE', at: '2026-10-05T12:04:00Z' }, |
| 58 | }), /chronology/i); |
| 59 | }); |