import test from 'node:test'; import assert from 'node:assert/strict'; import { routeHistoryRecord } from '../src/core/history-records.mjs'; test('history routing accepts legacy execute_trade records without decision metadata', () => { const routed = routeHistoryRecord({ topic: 'cmd.execute_trade', event: { event_id: 'cmd-legacy-1', event_type: 'execute_trade', venue: 'near-intents', schema_version: 1, ingested_at: '2026-04-02T08:00:00.000Z', payload: { command_id: 'cmd-legacy-1', idempotency_key: 'near-intents:legacy-1', execution_key: 'near-intents:btc->eure', quote_id: 'legacy-1', asset_in: 'nep141:btc.omft.near', asset_out: 'nep141:eure.omft.near', amount_in: '100', amount_out: '200', }, }, }); assert.equal(routed.table, 'execute_trade_commands'); assert.equal(routed.record.decision_key, 'cmd-legacy-1'); }); test('history routing accepts legacy trade_result records without decision metadata', () => { const routed = routeHistoryRecord({ topic: 'exec.trade_result', event: { event_id: 'result-legacy-1', event_type: 'trade_result', venue: 'near-intents', schema_version: 1, ingested_at: '2026-04-02T08:00:00.000Z', payload: { command_id: 'cmd-legacy-1', idempotency_key: 'near-intents:legacy-1', execution_key: 'near-intents:btc->eure', quote_id: 'legacy-1', status: 'simulated_sent', result_code: 'sent', }, }, }); assert.equal(routed.table, 'trade_execution_results'); assert.equal(routed.record.decision_key, 'cmd-legacy-1'); });