blackout: persist session_id across queued intent lifecycle (#375)
All checks were successful
Gitea CI / test (push) Successful in 32s
Gitea CI / test (pull_request) Successful in 33s

This commit is contained in:
agentson
2026-03-02 03:09:33 +09:00
parent ccceb38483
commit 8e02b1ea4f
4 changed files with 24 additions and 3 deletions

View File

@@ -35,6 +35,7 @@ def test_recovery_batch_only_after_blackout_exit() -> None:
intent = QueuedOrderIntent(
market_code="KR",
exchange_code="KRX",
session_id="KRX_REG",
stock_code="005930",
order_type="BUY",
quantity=1,
@@ -64,6 +65,7 @@ def test_requeued_intent_is_processed_next_non_blackout_cycle() -> None:
intent = QueuedOrderIntent(
market_code="KR",
exchange_code="KRX",
session_id="KRX_REG",
stock_code="005930",
order_type="BUY",
quantity=1,
@@ -90,6 +92,7 @@ def test_queue_overflow_drops_oldest_and_keeps_latest() -> None:
first = QueuedOrderIntent(
market_code="KR",
exchange_code="KRX",
session_id="KRX_REG",
stock_code="000001",
order_type="BUY",
quantity=1,
@@ -100,6 +103,7 @@ def test_queue_overflow_drops_oldest_and_keeps_latest() -> None:
second = QueuedOrderIntent(
market_code="KR",
exchange_code="KRX",
session_id="KRX_REG",
stock_code="000002",
order_type="BUY",
quantity=1,
@@ -110,6 +114,7 @@ def test_queue_overflow_drops_oldest_and_keeps_latest() -> None:
third = QueuedOrderIntent(
market_code="KR",
exchange_code="KRX",
session_id="KRX_REG",
stock_code="000003",
order_type="SELL",
quantity=2,

View File

@@ -6543,6 +6543,7 @@ def test_blackout_queue_overflow_keeps_latest_intent() -> None:
with patch("src.main.BLACKOUT_ORDER_MANAGER", manager):
assert _maybe_queue_order_intent(
market=market,
session_id="KRX_REG",
stock_code="005930",
order_type="BUY",
quantity=1,
@@ -6551,6 +6552,7 @@ def test_blackout_queue_overflow_keeps_latest_intent() -> None:
)
assert _maybe_queue_order_intent(
market=market,
session_id="KRX_REG",
stock_code="000660",
order_type="BUY",
quantity=2,
@@ -6564,6 +6566,7 @@ def test_blackout_queue_overflow_keeps_latest_intent() -> None:
batch = manager.pop_recovery_batch()
assert len(batch) == 1
assert batch[0].stock_code == "000660"
assert batch[0].session_id == "KRX_REG"
@pytest.mark.asyncio
@@ -6587,6 +6590,7 @@ async def test_process_blackout_recovery_executes_valid_intents() -> None:
intent.quantity = 1
intent.price = 100.0
intent.source = "test"
intent.session_id = "NXT_AFTER"
intent.attempts = 0
blackout_manager = MagicMock()
@@ -6617,7 +6621,7 @@ async def test_process_blackout_recovery_executes_valid_intents() -> None:
assert row is not None
assert row[0] == "BUY"
assert row[1] == 1
assert row[2] == "KRX_REG"
assert row[2] == "NXT_AFTER"
assert row[3].startswith("[blackout-recovery]")
@@ -6642,6 +6646,7 @@ async def test_process_blackout_recovery_drops_policy_rejected_intent() -> None:
intent.quantity = 1
intent.price = 100.0
intent.source = "test"
intent.session_id = "KRX_REG"
intent.attempts = 0
blackout_manager = MagicMock()
@@ -6691,6 +6696,7 @@ async def test_process_blackout_recovery_drops_intent_on_excessive_price_drift()
intent.quantity = 1
intent.price = 100.0
intent.source = "test"
intent.session_id = "US_PRE"
intent.attempts = 0
blackout_manager = MagicMock()
@@ -6741,6 +6747,7 @@ async def test_process_blackout_recovery_drops_overseas_intent_on_excessive_pric
intent.quantity = 1
intent.price = 100.0
intent.source = "test"
intent.session_id = "KRX_REG"
intent.attempts = 0
blackout_manager = MagicMock()
@@ -6790,6 +6797,7 @@ async def test_process_blackout_recovery_requeues_intent_when_price_lookup_fails
intent.quantity = 1
intent.price = 100.0
intent.source = "test"
intent.session_id = "KRX_REG"
intent.attempts = 0
blackout_manager = MagicMock()