import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { createExecutorStateStore } from '../src/core/executor-state-store.mjs'; test('executor state store persists processing and submission state', () => { const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'unrip-executor-')); const store = createExecutorStateStore({ stateDir }); store.markProcessing('cmd-1', { quote_id: 'quote-1' }); assert.equal(store.get('cmd-1').status, 'processing'); store.markSubmitted('cmd-1', { result_event_id: 'result-1' }); assert.equal(store.get('cmd-1').status, 'submitted'); const reloaded = createExecutorStateStore({ stateDir }); assert.equal(reloaded.get('cmd-1').status, 'submitted'); assert.equal(reloaded.get('cmd-1').result_event_id, 'result-1'); }); test('executor state store normalizes legacy completed markers to submitted', () => { const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'unrip-executor-')); const statePath = path.join(stateDir, 'trade-executor-commands.json'); fs.writeFileSync( statePath, JSON.stringify({ commands: { 'cmd-legacy': { status: 'completed', result_event_id: 'result-legacy', }, }, }), ); const store = createExecutorStateStore({ stateDir }); assert.equal(store.get('cmd-legacy').status, 'submitted'); assert.equal(store.getState().commands['cmd-legacy'].status, 'submitted'); });