unrip/test/executor-state-store.test.mjs
philipp e0dfd24a8b
All checks were successful
deploy / deploy (push) Successful in 32s
Link quote outcomes to settled inventory
Proof: Adds a durable quote outcome attribution model, refreshes it from submitted execution results plus inventory snapshots, and updates dashboard lifecycle rows so submitted, blocked, rejected, not-filled, and completed states are separated by durable evidence. Lowers the approved live strategy edge threshold to 1.49%.

Assumptions: Exact asset-unit inventory deltas inside the attribution window are acceptable as heuristic settlement evidence for the active BTC/EURe NEAR Intents path when the uncertainty is stored and shown. Deadline-plus-inventory non-fill is inferred until venue terminal events are persisted.

Still fake: No venue-native terminal fill event or per-trade fee/cost ledger is stored yet; heuristic completed and not-filled records remain explicitly labeled as inferred where applicable, and realized net PnL is still not claimed.
2026-04-10 11:24:22 +02:00

42 lines
1.5 KiB
JavaScript

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');
});