# BAT-010 Implementation - Status: completed - Batch: BAT-010 ## Plan Summary - REQ-041 → REQ-035 → REQ-034 → REQ-036 순서로 구현. 각 단계 unit test green 확인 후 다음으로 진행. ## Changed Files ### 신규 파일 - `trex_core/application/watchdog.py` — WatchdogStore class (REQ-034) - `trex_core/adapters/persistence/sql/004_add_price_thresholds.sql` — additive DB migration (REQ-035) - `tests/runtime/test_safety_sell_config.py` — REQ-041 AC 검증 4종 - `tests/application/test_watchdog.py` — REQ-034 AC 검증 11종 - `tests/application/test_snapshot_rpc_watchdog.py` — REQ-034 handler 통합 4종 - `tests/domain/slot/test_service_sell.py` — REQ-036 AC 검증 6종 - `tests/domain/slot/test_price_threshold_fields.py` — REQ-035 AC 검증 7종 ### 기존 파일 수정 - `trex_core/runtime/config.py` — SafetySellConfig dataclass 추가 + DaemonConfig 5종 env var 파싱 (REQ-041) - `trex_core/domain/slot/models.py` — stop_loss_price / take_profit_price Optional[Decimal] 필드 추가 + EXPECTED_SLOT_FIELDS 갱신 (REQ-035) - `trex_core/adapters/persistence/postgresql.py` — _SLOT_COLUMNS 갱신, update_slot SET절 확장, _row_to_slot 인덱스 조정 (REQ-035) - `trex_core/application/intents.py` — BuyIntent에 price fields + Decimal import (REQ-035) - `trex_core/domain/slot/service.py` — transit_slot에 stop_loss_price / take_profit_price 파라미터 추가, _apply_transition_fields 확장(reset + preserve), sell() 메서드 신설, Decimal import (REQ-035, REQ-036) - `trex_core/application/messaging_handlers.py` — WatchdogStore import + SlotState import + make_snapshot_rpc_handler watchdog_store= 파라미터 + 홀딩 슬롯 update 로직 + buy intent payload _opt_decimal 파싱 (REQ-034, REQ-035) ## Execution Log 1. M1 — REQ-041: SafetySellConfig + DaemonConfig.from_env() 5종 파싱. test_safety_sell_config.py 4종 green. 2. M2 — REQ-035: models.py 필드 추가 + EXPECTED_SLOT_FIELDS 갱신 → test_contract.py 통과. postgresql.py _SLOT_COLUMNS / update_slot / _row_to_slot 갱신. SQL 마이그레이션 004 생성. intents.py BuyIntent 확장. service.py transit_slot + _apply_transition_fields 확장. test_price_threshold_fields.py 7종 green. 3. M3 — REQ-034: watchdog.py 신규. messaging_handlers.py make_snapshot_rpc_handler 확장. test_watchdog.py 11종 green. test_snapshot_rpc_watchdog.py 4종 green. 4. M4 — REQ-036: service.py sell() 신설. test_service_sell.py 6종 green. 5. M5 — 전체 회귀 95 passed (httpx 미설치 환경 기인 test_daemon_no_http_surface 1건 기존 실패, BAT-010 무관). ## Validation - 신규 테스트: 32종 100% green - 회귀 테스트: 95 passed (domain/ + runtime/ + application/ 대상, httpx 불필요 범위) - test_contract.py: EXPECTED_SLOT_FIELDS ↔ dataclasses.fields(Slot) 계약 통과 (price fields 포함) - `WatchdogStore.in_grace_period()` + `is_expired()` 조합 패턴 단위 테스트로 고정 ## Remaining Risks - R-2 (Medium → Low): DB 마이그레이션은 실 PostgreSQL 없이 검증 불가. 004 migration이 `ALTER TABLE ... ADD COLUMN IF NOT EXISTS` 패턴 사용 → 멱등 보장. 실 DB 검증은 BAT-011 환경 포함 후 수행. - R-3 (Low): test_daemon_no_http_surface 기존 실패 — httpx 미설치 환경 이슈. BAT-010 변경 무관. 런타임 환경에서 httpx 설치 시 해소.