import test from 'node:test'; import assert from 'node:assert/strict'; import { deriveServiceHealth, shouldContainExecutorForAlerts, shouldRaiseIngestPublishStale, } from '../src/core/runtime-health.mjs'; test('publish stale does not raise before any matching quote exists', () => { assert.equal(shouldRaiseIngestPublishStale({ lastMatchingQuoteAt: null, lastPublishedAt: null, matchingQuoteAgeMs: null, publishedAgeMs: null, publishStaleMs: 30_000, }), false); }); test('publish stale raises after a matching quote exists but no publish follows', () => { assert.equal(shouldRaiseIngestPublishStale({ lastMatchingQuoteAt: '2026-04-08T20:45:00.000Z', lastPublishedAt: null, matchingQuoteAgeMs: 10_000, publishedAgeMs: null, publishStaleMs: 30_000, }), true); }); test('executor containment stays disabled for quote-stale-only conditions', () => { assert.equal(shouldContainExecutorForAlerts([{ alert_code: 'near_intents_quotes_stale', severity: 'critical', }]), false); }); test('executor containment stays disabled even for broken truth path alerts', () => { assert.equal(shouldContainExecutorForAlerts([{ alert_code: 'near_intents_ingest_disconnected', severity: 'critical', }]), false); assert.equal(shouldContainExecutorForAlerts([{ alert_code: 'near_intents_publish_stale', severity: 'critical', }]), false); assert.equal(shouldContainExecutorForAlerts([{ alert_code: 'history_writer_stalled', severity: 'critical', }]), false); }); test('armed service treats critical truth alerts for any active pair as critical', () => { const health = deriveServiceHealth({ service: 'strategy-engine', snapshot: { reachable: true, state: { armed: true, }, health: { ok: true, }, }, activePairs: [ 'btc->eure', 'btc->usdc', ], activeAlerts: [{ alert_code: 'reference_price_stale', severity: 'critical', service_scope: 'strategy-engine', pair: 'btc->usdc', }], now: '2026-05-18T10:00:00.000Z', }); assert.equal(health.status, 'critical'); assert.equal(health.label, 'armed on stale truth'); });