BAT-035 (dcy-025): trex.snapshot.req → trex.slots.req 즉시 교체
- topology: SNAPSHOT_REQ_QUEUE 제거, SLOTS_REQ_QUEUE = "trex.slots.req" 추가
- portfolio.py: View/build_snapshot_envelope/SnapshotEnvelope/_asset_to_dict 제거;
slot_to_dict 시그니처 확장(snapshot_store/watchdog_store/pause_store/watchdog_timeout_sec)
— asset_quantity(hub)/cash_balance/cash_estimated/warned/watchdog{}/paused 병합 (REQ-074)
- messaging_handlers.py: make_snapshot_rpc_handler 제거, make_slots_rpc_handler 추가
— filter(all/inactive/pending/holding/error) + spy(bool) 처리; strategy 필드 제외 (REQ-073/074)
- daemon.py: _snapshot_rpc_loop → _slots_rpc_loop, make_slots_rpc_handler 연결
- cli.py: universe/slots → slots_queue + spy=True + server-side filter; buyable→inactive 매핑 (REQ-063)
- rabbitmq.py: snapshot_queue → slots_queue
- docs: interface-contract.md + runtime-flows.md slots.req 계약으로 업데이트 (REQ-075)
- REQ-028: Implemented → Deprecated (코드 삭제 완료)
- 테스트: test_snapshot_handler/selection/rpc_watchdog/messaging_snapshot_consumer 삭제;
test_slots_handler.py(신규, 13 cases), test_killswitch_masking_resume 재작성,
test_ledger_option_d._apply_cash_estimate → slots handler 경유, test_topology/cli_operator 갱신
BAT-036 (dcy-024): per-instance safety_sell_enabled 플래그
- config.py: DaemonInstanceConfig + DaemonConfig 에 safety_sell_enabled: bool = True 추가;
from_toml 파싱, from_config 전파
- daemon.py: start() workers 조건부 — safety_sell_enabled=false 시 trex-safety-sell 미기동 + WARNING
- tests: test_instance_config.py 에 safety_sell_enabled 파싱 3개 케이스 추가
REQ: 073/074/075/021/034/063/048/005 Approved → Implemented
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
"""Kill-switch day-exclusion store + resume tests (REQ-046 / BAT-012).
|
|
|
|
Tests the InMemoryKillSwitchStore and KillSwitchService.resume().
|
|
View-masking through build_snapshot_envelope was removed in BAT-035 (dcy-025).
|
|
Exclusion semantics are now tested at the store level.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
import pytest
|
|
|
|
from trex_core.application.killswitch import KillSwitchService
|
|
from trex_core.application.portfolio import (
|
|
GLOBAL_KILLSWITCH,
|
|
InMemoryKillSwitchStore,
|
|
)
|
|
from trex_core.domain.slot import SlotService
|
|
from trex_core.domain.slot.in_memory_repository import InMemorySlotRepository
|
|
|
|
_DAY = date(2026, 6, 7)
|
|
_DAY_NEXT = date(2026, 6, 8)
|
|
|
|
|
|
@pytest.fixture
|
|
def ks_store():
|
|
return InMemoryKillSwitchStore()
|
|
|
|
|
|
def test_portfolio_exclusion_recorded(ks_store):
|
|
"""AC-1: excluding a portfolio records it in the store for the day."""
|
|
ks_store.exclude("pf-A", _DAY)
|
|
assert "pf-A" in ks_store.list_excluded(_DAY)
|
|
assert "pf-B" not in ks_store.list_excluded(_DAY)
|
|
|
|
|
|
def test_global_exclusion_uses_sentinel(ks_store):
|
|
"""AC-2: global exclusion uses GLOBAL_KILLSWITCH sentinel."""
|
|
ks_store.exclude(GLOBAL_KILLSWITCH, _DAY)
|
|
assert GLOBAL_KILLSWITCH in ks_store.list_excluded(_DAY)
|
|
|
|
|
|
def test_day_scoped_auto_recovery(ks_store):
|
|
"""AC-4: next trading day, the exclusion is absent (day-scoped)."""
|
|
ks_store.exclude("pf-A", _DAY)
|
|
assert "pf-A" not in ks_store.list_excluded(_DAY_NEXT)
|
|
|
|
|
|
def test_persistence_same_day(ks_store):
|
|
"""AC-5: same day, exclusion persists across repeated calls."""
|
|
ks_store.exclude("pf-A", _DAY)
|
|
assert "pf-A" in ks_store.list_excluded(_DAY)
|
|
assert "pf-A" in ks_store.list_excluded(_DAY)
|
|
|
|
|
|
def test_resume_clears_exclusion(ks_store):
|
|
"""AC-6: resume (clear) removes the exclusion for that day."""
|
|
repo = InMemorySlotRepository()
|
|
svc = KillSwitchService(slot_repo=repo, slot_service=SlotService(repo),
|
|
killswitch_store=ks_store)
|
|
ks_store.exclude("pf-A", _DAY)
|
|
assert "pf-A" in ks_store.list_excluded(_DAY)
|
|
svc.resume(scope="portfolio", portfolio_id="pf-A",
|
|
now=__import__("datetime").datetime(2026, 6, 7, 6,
|
|
tzinfo=__import__("datetime").timezone.utc))
|
|
assert "pf-A" not in ks_store.list_excluded(_DAY)
|
|
|
|
|
|
def test_no_exclusion_empty_list(ks_store):
|
|
"""Baseline: with no exclusions, list_excluded returns empty set."""
|
|
assert ks_store.list_excluded(_DAY) == set()
|
|
|
|
|
|
def test_clear_without_prior_exclude_is_noop(ks_store):
|
|
"""Clearing a non-excluded portfolio is safe (no exception)."""
|
|
ks_store.clear("pf-X", _DAY)
|
|
assert ks_store.list_excluded(_DAY) == set()
|