All checks were successful
deploy / deploy (push) Successful in 52s
Proof: Core bootstrap is shell-only; page endpoints, canonical lifecycle selection, cursor submissions, persisted statistics reads, bounded dashboard transactions, and resilient client resources are covered by targeted regressions, full npm test, and the production dashboard build. Assumptions: Existing durable indexes and history-writer maintenance path remain valid; persisted lifecycle statistics and retained terminal attribution are the truthful dashboard sources. Still fake: Exact all-time submission totals remain unavailable, venue-native fill truth remains limited to retained durable evidence, and production latency/deployment evidence remains to be collected after push.
106 lines
4.5 KiB
JavaScript
106 lines
4.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
buildDashboardCorePayload,
|
|
} from '../src/core/operator-dashboard.mjs';
|
|
import {
|
|
decodeSubmissionCursor,
|
|
encodeSubmissionCursor,
|
|
loadSuccessfulQuoteLifecycleEvidence,
|
|
loadSubmissionPage,
|
|
withDashboardRead,
|
|
} from '../src/lib/postgres.mjs';
|
|
import { dashboardReducer, initialDashboardState } from '../src/operator-dashboard/static/state/dashboardReducer.js';
|
|
|
|
test('core payload is shell-only and carries freshness/capability metadata', () => {
|
|
const payload = buildDashboardCorePayload({
|
|
auth: { authenticated: true },
|
|
config: {},
|
|
liveState: { recent_submission_count: 2, last_submission_at: '2026-07-25T00:00:00.000Z' },
|
|
});
|
|
assert.equal(payload.default_page, 'funds');
|
|
assert.ok(payload.navigation.pages.includes('strategy'));
|
|
assert.ok(payload.generated_at);
|
|
assert.equal(Object.hasOwn(payload, 'funds'), false);
|
|
assert.equal(Object.hasOwn(payload, 'submissions'), false);
|
|
});
|
|
|
|
test('submission cursors are versioned, opaque, and preserve timestamp plus event id', () => {
|
|
const cursor = encodeSubmissionCursor({ at: '2026-07-25T00:00:00.000Z', eventId: 'event-42' });
|
|
assert.match(cursor, /^[A-Za-z0-9_-]+$/);
|
|
assert.deepEqual(decodeSubmissionCursor(cursor), {
|
|
at: '2026-07-25T00:00:00.000Z', event_id: 'event-42',
|
|
});
|
|
assert.throws(() => decodeSubmissionCursor('eyJ2IjoyfQ'), /invalid_cursor/);
|
|
});
|
|
|
|
test('submission loader is bounded and has no exact count query', async () => {
|
|
const queries = [];
|
|
const pool = { query: async (sql, params) => {
|
|
queries.push({ sql, params });
|
|
return { rows: Array.from({ length: 3 }, (_, index) => ({
|
|
event_id: `event-${index}`,
|
|
result_observed_at: `2026-07-25T00:0${index}:00.000Z`,
|
|
result_ingested_at: `2026-07-25T00:0${index}:00.000Z`,
|
|
result_payload: { status: 'submitted', quote_id: `quote-${index}` },
|
|
command_payload: null, decision_payload: null, outcome_payload: null,
|
|
})) };
|
|
} };
|
|
const page = await loadSubmissionPage(pool, { limit: 2 });
|
|
assert.equal(page.items.length, 2);
|
|
assert.equal(page.has_more, true);
|
|
assert.equal(page.total, null);
|
|
assert.equal(queries.length, 1);
|
|
assert.doesNotMatch(queries[0].sql, /COUNT\s*\(/i);
|
|
assert.match(queries[0].sql, /event_id DESC/);
|
|
assert.equal(queries[0].params[0], 3);
|
|
});
|
|
|
|
test('successful lifecycle candidate query is canonical and excludes submitted-only history', async () => {
|
|
const queries = [];
|
|
const pool = { query: async (sql) => {
|
|
queries.push(sql);
|
|
return { rows: [] };
|
|
} };
|
|
await loadSuccessfulQuoteLifecycleEvidence(pool, { limit: 50 });
|
|
assert.match(queries[0], /quote_outcome_attributions/);
|
|
assert.match(queries[0], /outcome_status = 'completed'/);
|
|
assert.match(queries[0], /attributed_inventory_delta IS NOT NULL/);
|
|
assert.doesNotMatch(queries[0], /trade_execution_results/);
|
|
assert.doesNotMatch(queries[0], /UNION ALL/);
|
|
assert.match(queries[0], /LIMIT \$1/);
|
|
});
|
|
|
|
test('dashboard read deadline rolls back and releases the client', async () => {
|
|
const statements = [];
|
|
let released = false;
|
|
const client = {
|
|
query: async (sql) => {
|
|
statements.push(sql);
|
|
if (sql.includes('SELECT')) throw Object.assign(new Error('cancelled'), { code: '57014' });
|
|
},
|
|
release: () => { released = true; },
|
|
};
|
|
await assert.rejects(withDashboardRead({ connect: async () => client }, () => client.query('SELECT 1')), /cancelled/);
|
|
assert.ok(statements.some((sql) => sql.includes('statement_timeout')));
|
|
assert.ok(statements.includes('ROLLBACK'));
|
|
assert.equal(released, true);
|
|
});
|
|
|
|
test('resource reducer retains successful data as stale and ignores older completions', () => {
|
|
let state = dashboardReducer(initialDashboardState, { type: 'resource.request', resource: 'funds', request_id: 2 });
|
|
state = dashboardReducer(state, {
|
|
type: 'resource.success', resource: 'funds', request_id: 2,
|
|
data: { funds: { value: 'new' }, generated_at: '2026-07-25T00:00:00.000Z' },
|
|
});
|
|
state = dashboardReducer(state, { type: 'resource.request', resource: 'funds', request_id: 3 });
|
|
state = dashboardReducer(state, { type: 'resource.failure', resource: 'funds', request_id: 3, error: 'source down' });
|
|
assert.equal(state.resources.funds.status, 'stale');
|
|
assert.equal(state.dashboard.funds.value, 'new');
|
|
const unchanged = dashboardReducer(state, {
|
|
type: 'resource.success', resource: 'funds', request_id: 1,
|
|
data: { funds: { value: 'old' }, generated_at: '2026-07-24T00:00:00.000Z' },
|
|
});
|
|
assert.equal(unchanged.dashboard.funds.value, 'new');
|
|
});
|