|
| 1 | +import { |
| 2 | + aggregateTerminalOperationalTelemetrySeverity, |
| 3 | + buildTerminalOperationalHealthRead, |
| 4 | +} from '../src/terminal-operational-health'; |
| 5 | +import { buildV27CryptoTelemetryRecord } from '../src/telemetry'; |
| 6 | + |
| 7 | +const issuedAt = 'terminal-operational-health-test'; |
| 8 | + |
| 9 | +describe('Terminal operational health read', () => { |
| 10 | + it('surfaces all deployment lanes and blocks value-bearing mainnet without approval root', () => { |
| 11 | + const read = buildTerminalOperationalHealthRead({ issuedAt }); |
| 12 | + |
| 13 | + expect(read.lanes.map((lane) => lane.lane)).toEqual([ |
| 14 | + 'local', |
| 15 | + 'regtest', |
| 16 | + 'signet', |
| 17 | + 'testnet', |
| 18 | + 'mainnet-ready', |
| 19 | + 'mainnet-value-bearing', |
| 20 | + ]); |
| 21 | + expect(read.lanes.find((lane) => lane.lane === 'testnet')).toMatchObject({ |
| 22 | + label: 'Public testnet', |
| 23 | + state: 'ready', |
| 24 | + bitcoinNetwork: 'testnet', |
| 25 | + }); |
| 26 | + expect(read.lanes.find((lane) => lane.lane === 'mainnet-value-bearing')).toMatchObject({ |
| 27 | + state: 'blocked', |
| 28 | + valueBearing: true, |
| 29 | + operationalApprovalRoot: null, |
| 30 | + missingEnvironmentKeys: ['BITCODE_OPERATIONAL_APPROVAL_ROOT'], |
| 31 | + readinessReceipt: null, |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('admits value-bearing mainnet only when an operational approval root is present', () => { |
| 36 | + const read = buildTerminalOperationalHealthRead({ |
| 37 | + issuedAt, |
| 38 | + operationalApprovalRoots: { |
| 39 | + 'mainnet-value-bearing': 'approval-root', |
| 40 | + }, |
| 41 | + }); |
| 42 | + const mainnetValueLane = read.lanes.find((lane) => lane.lane === 'mainnet-value-bearing'); |
| 43 | + |
| 44 | + expect(mainnetValueLane).toMatchObject({ |
| 45 | + state: 'ready', |
| 46 | + operationalApprovalRoot: 'approval-root', |
| 47 | + valueBearing: true, |
| 48 | + }); |
| 49 | + expect(mainnetValueLane?.readinessReceipt?.mainnetValueBearingBlocked).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + it('aggregates telemetry into broadcaster and observer health', () => { |
| 53 | + const telemetryRecords = [ |
| 54 | + buildV27CryptoTelemetryRecord({ |
| 55 | + event: 'btc_fee.broadcast_rejected', |
| 56 | + subjectId: 'fee-1', |
| 57 | + issuedAt, |
| 58 | + }), |
| 59 | + buildV27CryptoTelemetryRecord({ |
| 60 | + event: 'ledger_provider.disagreement', |
| 61 | + subjectId: 'anchor-1', |
| 62 | + issuedAt, |
| 63 | + }), |
| 64 | + ]; |
| 65 | + const read = buildTerminalOperationalHealthRead({ issuedAt, telemetryRecords }); |
| 66 | + |
| 67 | + expect(aggregateTerminalOperationalTelemetrySeverity(telemetryRecords)).toBe('critical'); |
| 68 | + expect(read.telemetry.severity).toBe('critical'); |
| 69 | + expect(read.broadcaster).toMatchObject({ |
| 70 | + state: 'review', |
| 71 | + severity: 'warning', |
| 72 | + }); |
| 73 | + expect(read.observer).toMatchObject({ |
| 74 | + state: 'blocked', |
| 75 | + severity: 'critical', |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + it('keeps upgrade, rollback, migration, and generated type refresh visible', () => { |
| 80 | + const read = buildTerminalOperationalHealthRead({ |
| 81 | + issuedAt, |
| 82 | + rollbackPlanRoot: 'rollback-root', |
| 83 | + generatedTypeRefreshState: 'current', |
| 84 | + }); |
| 85 | + |
| 86 | + expect(read.upgrade).toMatchObject({ |
| 87 | + state: 'planned', |
| 88 | + migrationRoot: 'terminal-migration-root', |
| 89 | + rollbackPlanRoot: 'rollback-root', |
| 90 | + approvalReceiptRoot: 'terminal-approval-root', |
| 91 | + generatedTypeRefresh: { |
| 92 | + state: 'current', |
| 93 | + source: 'packages/orm/src/types/database.generated.ts', |
| 94 | + }, |
| 95 | + }); |
| 96 | + expect(read.upgrade.receipt.kind).toBe('btd.protocol_upgrade'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('declares GitHub as the active VCS path and leaves broader providers future-scoped', () => { |
| 100 | + const read = buildTerminalOperationalHealthRead({ issuedAt }); |
| 101 | + |
| 102 | + expect(read.providers).toEqual( |
| 103 | + expect.arrayContaining([ |
| 104 | + expect.objectContaining({ provider: 'github', state: 'ready' }), |
| 105 | + expect.objectContaining({ provider: 'gitlab', state: 'future' }), |
| 106 | + expect.objectContaining({ provider: 'bitbucket', state: 'future' }), |
| 107 | + expect.objectContaining({ provider: 'generic-git', state: 'future' }), |
| 108 | + ]), |
| 109 | + ); |
| 110 | + }); |
| 111 | + |
| 112 | + it('uses Bitcoin Taproot/PSBT as first-class and keeps Binance-family pilots disabled', () => { |
| 113 | + const read = buildTerminalOperationalHealthRead({ issuedAt }); |
| 114 | + |
| 115 | + expect(read.settlementNetworks).toEqual( |
| 116 | + expect.arrayContaining([ |
| 117 | + expect.objectContaining({ id: 'bitcoin-taproot-psbt', state: 'ready' }), |
| 118 | + expect.objectContaining({ id: 'bsc', state: 'disabled' }), |
| 119 | + expect.objectContaining({ id: 'opbnb', state: 'disabled' }), |
| 120 | + expect.objectContaining({ id: 'binance-web3-wallet', state: 'disabled' }), |
| 121 | + ]), |
| 122 | + ); |
| 123 | + }); |
| 124 | + |
| 125 | + it('builds a synthetic testnet minting readback that can be ledger/database diffed', () => { |
| 126 | + const read = buildTerminalOperationalHealthRead({ issuedAt }); |
| 127 | + |
| 128 | + expect(read.testnetMinting.measurementReceipt.kind).toBe('btd.measure_mint'); |
| 129 | + expect(read.testnetMinting.measurementReceipt.tokenCount).toBe(1); |
| 130 | + expect(read.testnetMinting.mintReceipt.kind).toBe('btd.asset_pack_mint'); |
| 131 | + expect(read.testnetMinting.assetPackRange.tokenCount).toBe(1); |
| 132 | + expect(read.testnetMinting.ledgerAnchor).toMatchObject({ |
| 133 | + chain: 'bitcoin', |
| 134 | + network: 'signet', |
| 135 | + commitmentMethod: 'taproot', |
| 136 | + finalityState: 'prepared', |
| 137 | + }); |
| 138 | + expect(read.testnetMinting.terminalJournalRows.map((row) => row.transactionKind)).toEqual([ |
| 139 | + 'asset_pack_mint', |
| 140 | + 'asset_pack_anchor', |
| 141 | + ]); |
| 142 | + expect(read.testnetMinting.terminalJournalDiff.blocking).toBe(false); |
| 143 | + expect(read.testnetMinting.ledgerDatabaseReconciliation.blocking).toBe(false); |
| 144 | + expect(read.testnetMinting.ledgerObservedFacts).toEqual(read.testnetMinting.databaseProjectedFacts.map((fact) => ({ |
| 145 | + factId: fact.factId, |
| 146 | + ledgerRoot: fact.projectedLedgerRoot, |
| 147 | + finalityState: fact.projectedFinalityState, |
| 148 | + }))); |
| 149 | + }); |
| 150 | +}); |
0 commit comments