fix: close broker uncertainty audit gaps
This commit is contained in:
@@ -9,7 +9,8 @@ from __future__ import annotations
|
||||
import psycopg
|
||||
|
||||
from trex_core.adapters.persistence.migrate import apply_migrations, migration_files
|
||||
from trex_core.domain.slot import EXPECTED_SLOT_FIELDS
|
||||
from trex_core.adapters.persistence.postgresql import PostgreSQLSlotRepository
|
||||
from trex_core.domain.slot import EXPECTED_SLOT_FIELDS, SlotService, SlotState
|
||||
|
||||
_EXPECTED_TABLES = {
|
||||
"daily_slot",
|
||||
@@ -61,3 +62,22 @@ def test_apply_migrations_is_idempotent(pg_dsn):
|
||||
# applying twice must not error (CREATE ... IF NOT EXISTS)
|
||||
apply_migrations(pg_dsn)
|
||||
apply_migrations(pg_dsn)
|
||||
|
||||
|
||||
def test_migration_replay_accepts_existing_auto_venue_row(pg_clean):
|
||||
repo = PostgreSQLSlotRepository(pg_clean)
|
||||
service = SlotService(repo, instance_key="migration-auto")
|
||||
repo.reconcile_universe("migration-auto", {"pf-auto": "005930"})
|
||||
slot = repo.find_slot_by_portfolio("migration-auto", "pf-auto")
|
||||
service.transit_slot(
|
||||
slot.slot_id,
|
||||
SlotState.INACTIVE,
|
||||
SlotState.PENDING_BUY,
|
||||
reason="migration_replay",
|
||||
actor="test",
|
||||
venue="AUTO",
|
||||
)
|
||||
|
||||
apply_migrations(pg_clean)
|
||||
|
||||
assert repo.fetch_slot(slot.slot_id).venue == "AUTO"
|
||||
|
||||
@@ -132,6 +132,29 @@ def test_dispatch_queue_instance_scoped(pg_clean):
|
||||
assert repo_a.list_dispatched_pending("inst-b") == []
|
||||
|
||||
|
||||
def test_cancel_attempt_reservation_is_compare_and_set(pg_clean):
|
||||
repo, _, intents = _wire(pg_clean)
|
||||
repo.reconcile_universe(INST, {"PF-1": "005930"})
|
||||
decision = intents.submit_buy(
|
||||
BuyIntent(intent_id="pg-cancel-cas", qty=1, portfolio_id="PF-1")
|
||||
)
|
||||
assert repo.mark_dispatched(decision.slot_id, "ord-cas")
|
||||
assert repo.mark_cancel_outcome(
|
||||
decision.slot_id,
|
||||
"ord-cas",
|
||||
"unknown",
|
||||
only_if_unset=True,
|
||||
)
|
||||
assert not repo.mark_cancel_outcome(
|
||||
decision.slot_id,
|
||||
"ord-cas",
|
||||
"unknown",
|
||||
only_if_unset=True,
|
||||
)
|
||||
assert repo.mark_cancel_outcome(decision.slot_id, "ord-cas", "requested")
|
||||
assert repo.fetch_slot(decision.slot_id).cancel_state == "requested"
|
||||
|
||||
|
||||
# dcy-028 / REQ-079·081 (BAT-042): strategy-state store + occupancy_seq column
|
||||
def test_strategy_state_store_pg(pg_clean):
|
||||
from trex_core.adapters.persistence.postgresql import PgStrategyStateStore
|
||||
|
||||
Reference in New Issue
Block a user