unrip/test/executor-command-expiry.test.mjs
philipp 92aa636dc0
Some checks failed
deploy / deploy (push) Failing after 52s
Restore live trading under quote pressure
Proof: npm test (209/209) covers stale command expiry, bounded executor state, bounded strategy quote cache, bounded quote outcome refresh, and resource guardrails.

Assumptions: current DB pair config and armed state remain the operator-approved live trading controls; stale quote commands are unsafe to submit after their min_deadline_ms.

Still fake: quote outcomes still infer fills from inventory deltas rather than a venue-native terminal fill event.
2026-05-18 12:51:25 +02:00

45 lines
1.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { classifyExecuteCommandExpiry } from '../src/core/executor-command-expiry.mjs';
test('execute command expiry rejects commands older than their quote deadline', () => {
const result = classifyExecuteCommandExpiry({
observed_at: '2026-05-13T10:00:00.000Z',
ingested_at: '2026-05-13T10:00:01.000Z',
payload: {
min_deadline_ms: '15000',
},
}, {
now: Date.parse('2026-05-13T10:00:16.000Z'),
});
assert.equal(result.expired, true);
assert.equal(result.reason, 'command_deadline_elapsed');
assert.equal(result.deadline_at, '2026-05-13T10:00:15.000Z');
});
test('execute command expiry keeps fresh commands eligible for relay submission', () => {
const result = classifyExecuteCommandExpiry({
observed_at: '2026-05-13T10:00:00.000Z',
payload: {
min_deadline_ms: '15000',
},
}, {
now: Date.parse('2026-05-13T10:00:14.999Z'),
});
assert.equal(result.expired, false);
assert.equal(result.reason, null);
});
test('execute command expiry fails closed when timestamps are missing', () => {
const result = classifyExecuteCommandExpiry({
payload: {
min_deadline_ms: '15000',
},
});
assert.equal(result.expired, true);
assert.equal(result.reason, 'command_timestamp_missing');
});