chore: commit current workspace changes
This commit is contained in:
@@ -89,19 +89,26 @@ def test_portfolio_id_absent_skips_ledger_but_transitions_slot():
|
||||
|
||||
|
||||
def test_duplicate_execution_id_results_in_zero_duplicate_in_ledger():
|
||||
"""REQ-019 AC-1: same execution_id enqueued twice = 1 ledger entry."""
|
||||
"""REQ-019 AC-1: same execution_id processed twice = 1 ledger entry."""
|
||||
ledger = InMemoryLedger()
|
||||
repo, svc, intents, execution, outbox, writer = _wire(PaperBroker(fill_after_polls=0),
|
||||
ledger=ledger)
|
||||
_buy(intents).slot_id
|
||||
_buy(intents)
|
||||
execution.run_once()
|
||||
writer.run_once()
|
||||
assert ledger.count() == 1
|
||||
# Re-enqueue the same trade explicitly (simulate accidental re-fill).
|
||||
# Same correlation_id arriving again (re-enqueue) is dedup'd at the outbox.
|
||||
first = outbox.all_items()[0]
|
||||
outbox.enqueue(first.trade) # idempotent on correlation_id
|
||||
stats = writer.run_once() # still terminal-completed; reports duplicate
|
||||
assert stats.duplicates >= 1
|
||||
outbox.enqueue(first.trade)
|
||||
assert len(outbox.all_items()) == 1
|
||||
# And even if the writer somehow re-processes (simulated by a fresh outbox
|
||||
# row for the same execution_id, e.g. after a manual replay), the ledger
|
||||
# adapter dedup'd it server-side and the outcome is duplicate_completed.
|
||||
replay_outbox = InMemoryLedgerOutbox()
|
||||
replay_writer = LedgerWriter(replay_outbox, ledger)
|
||||
replay_outbox.enqueue(first.trade)
|
||||
stats = replay_writer.run_once()
|
||||
assert stats.duplicates == 1 and stats.completed == 0
|
||||
assert ledger.count() == 1 # no duplicate in the ledger
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user