unrip/test/postgres-intent-requests.test.mjs
philipp 1a7bb89f36
All checks were successful
deploy / deploy (push) Successful in 32s
Fix intent request terminal reason text
Proof: Live request validation showed a not_filled own-request row still displayed the earlier relay-accepted text; the normalizer now prefers terminal outcome reason text and has a regression test for deadline_elapsed_without_settlement.

Assumptions: Terminal request outcome rows are more decisive than submission result text for operator-facing reason copy.

Still fake: Venue-native fill ids and fee-complete realized PnL remain unavailable; completed still depends on durable inventory delta attribution.
2026-04-12 18:48:51 +02:00

68 lines
2.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { normalizeIntentRequestRow } from '../src/lib/postgres.mjs';
test('intent request normalization prefers terminal outcome reason text over relay acceptance text', () => {
const row = normalizeIntentRequestRow({
preflight_observed_at: '2026-04-12T16:45:30.000Z',
preflight_ingested_at: '2026-04-12T16:45:30.000Z',
preflight_payload: {
request_id: 'request-1',
idempotency_key: 'intent-request:request-1',
state: 'draft',
reason_code: 'quote_available',
reason_text: 'Solver quote meets the explicit slippage/minimum receive policy.',
source_asset_id: 'nep141:eure.omft.near',
source_symbol: 'EURe',
source_decimals: 18,
destination_asset_id: 'nep141:btc.omft.near',
destination_symbol: 'BTC',
destination_decimals: 8,
source_amount_units: '5000000000000000000',
min_destination_amount_units: '8090',
selected_quote: { quote_hash: 'quote-hash-1', amount_out: '8214' },
created_at: '2026-04-12T16:45:30.000Z',
deadline_at: '2026-04-12T16:46:28.790Z',
},
submission_observed_at: '2026-04-12T16:45:43.133Z',
submission_ingested_at: '2026-04-12T16:45:43.133Z',
submission_payload: {
request_id: 'request-1',
idempotency_key: 'intent-request:request-1',
submission_id: 'submission-1',
status: 'accepted_by_relay',
result_code: 'publish_intent_accepted',
result_text: 'Relay accepted the signed request. This is not settlement.',
submitted_at: '2026-04-12T16:45:43.133Z',
intent_hash: 'intent-hash-1',
quote_hash: 'quote-hash-1',
relay_status: 'PENDING',
destination_amount_units: '8214',
},
outcome_observed_at: '2026-04-12T16:47:32.958Z',
outcome_payload: {
request_id: 'request-1',
idempotency_key: 'intent-request:request-1',
submission_id: 'submission-1',
intent_hash: 'intent-hash-1',
submission_status: 'accepted_by_relay',
relay_status: 'PENDING',
submitted_at: '2026-04-12T16:45:43.133Z',
outcome_status: 'not_filled',
outcome_observed_at: '2026-04-12T16:47:32.958Z',
outcome_source: 'request_deadline_and_inventory_snapshots',
outcome_reason: 'deadline_elapsed_without_settlement',
attribution_status: 'unattributed',
attribution_method: null,
attributed_inventory_delta: null,
evidence: {},
},
});
assert.equal(row.state, 'not_filled');
assert.equal(row.reason_code, 'deadline_elapsed_without_settlement');
assert.match(row.reason_text, /Deadline and grace window elapsed/i);
assert.doesNotMatch(row.reason_text, /Relay accepted the signed request/i);
assert.equal(row.has_settlement_evidence, false);
});