feat(slot): BAT-027 M2/M3 — 상태머신 inactive 재정의 + 인스턴스 스코프 advisory lock (dcy-020/REQ-057)
안 B 점진의 2/3단계. runtime 무변경(idle/closed 별칭 흡수)으로 cascade 통제. - state.py: SlotState.INACTIVE 추가 + idle/closed 별칭 normalize_state(); 전이 집합 inactive 기준 재정의(inactive↔pending_buy↔holding↔pending_sell), closed→idle 제거; is_allowed_transition 양쪽 정규화; slot_advisory_lock_id(instance_key) 헬퍼 - service.py: SlotService(instance_key) + advisory lock 인스턴스 스코프(self._lock_id) - __init__: normalize_state/slot_advisory_lock_id export; daemon: instance_key 전달 - 테스트 갱신: test_state(전이/멤버7/락/size12), test_service(closed→idle 제거→reallocation), test_slot_entry_count, test_postgresql_repository(closed→idle 거부+reallocation) 검증: 단위 375 passed / 35 skipped, PG-gated(trex_core_test) 8 passed (마이그레이션 009 드리프트 + lifecycle/reallocation), ruff clean. REQ-056/057 은 토대만 충족 → Approved 유지(entry_count/trading_date drop·literal inactive 전면 전환은 BAT-δ; confirm-req-implemented 는 dcy-020 후속 배치 완료 후). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
# BAT-027 Implementation
|
||||
|
||||
- Status: in-progress (M1 완료, M2/M3 대기)
|
||||
- Status: completed (M1·M2·M3 완료)
|
||||
- Batch: BAT-027
|
||||
|
||||
## 구현 요약
|
||||
- 안 B(점진/additive-first). M1(REQ-056 additive 모델+마이그레이션+persistence) 완료. M2/M3(상태머신 inactive 별칭 + 인스턴스 스코프 lock + 소비처 cascade)는 다음 단계.
|
||||
- 안 B(점진/additive-first). M1(additive 모델+마이그레이션+persistence)·M2(상태머신 inactive 별칭+인스턴스 스코프 lock)·M3(소비처 cascade — runtime 무변경, idle/closed 별칭으로 흡수) 완료. 전체 375 passed + PG-gated 8 passed, ruff clean.
|
||||
|
||||
## 변경 내역
|
||||
|
||||
@@ -13,14 +13,21 @@
|
||||
- `trex_core/adapters/persistence/sql/009_add_slot_instance_key_and_retired_at.sql`(신규): instance_key NOT NULL DEFAULT 'default', retired_at, 부분 UNIQUE(instance_key, portfolio_id) WHERE portfolio_id IS NOT NULL. additive·멱등.
|
||||
- `trex_core/adapters/persistence/postgresql.py`: `_SLOT_COLUMNS` +instance_key/retired_at(row[19]/[20]), `_row_to_slot` 매핑, `update_slot` SET. pre_allocate INSERT 는 DEFAULT 의존(변경 없음).
|
||||
|
||||
### M2 — REQ-057 상태머신+인스턴스 lock (대기)
|
||||
- state.py inactive 표준 + idle/closed 별칭(closed→idle 제거), advisory lock 인스턴스 스코프(2-int).
|
||||
### M2 — REQ-057 상태머신 + 인스턴스 lock (완료)
|
||||
- `trex_core/domain/slot/state.py`: `SlotState.INACTIVE` 추가 + `idle`/`closed` 를 별칭으로 `normalize_state()` 매핑. `_BASE_TRANSITIONS` 를 inactive 기준으로 재정의(`inactive↔pending_buy↔holding↔pending_sell`), **`closed→idle` 복구 제거**(inactive self-loop). `is_allowed_transition` 가 양쪽 정규화. `slot_advisory_lock_id(instance_key)` 헬퍼(전역 base ⊕ crc32(instance_key)).
|
||||
- `trex_core/domain/slot/service.py`: `SlotService(repository, instance_key="default")` + advisory lock 을 `self._lock_id`(인스턴스 스코프)로 3개소 치환. holding 은 status 로컬 정본(불변).
|
||||
- `trex_core/domain/slot/__init__.py`: `normalize_state`/`slot_advisory_lock_id` export. `trex_core/runtime/daemon.py`: `SlotService(..., instance_key=config.instance_key)`.
|
||||
|
||||
### M3 — 소비처 cascade 정합 (대기)
|
||||
- execution/intents/cli/ops_checks/service 등 idle·closed·전역 lock 참조 정합.
|
||||
### M3 — 소비처 cascade (완료, runtime 무변경)
|
||||
- idle/closed 가 inactive 별칭으로 흡수되어 **execution/cli/ops_checks/postgresql 의 idle·closed 사용은 그대로 유효**(별칭 정규화). closed→idle 은 runtime 미사용이라 무파손. → 별도 소비처 코드 변경 없음. (실제 inactive 전면 전환·컬럼 drop 은 BAT-δ.)
|
||||
- 테스트 갱신: test_state(새 전이/멤버/락), test_service(closed→idle 제거→reallocation), test_slot_entry_count, test_postgresql_repository(PG).
|
||||
|
||||
## 테스트
|
||||
- M1: 도메인 슬롯 단위 79 + 전체 375 passed / 35 skipped, ruff clean(additive 무파손). PG 마이그레이션 009 round-trip 은 verification 단계에서 test DSN 검증.
|
||||
- 단위 전체: 375 passed / 35 skipped / 1 deselected.
|
||||
- PG-gated(실 trex_core_test): `test_migration_and_drift`(마이그레이션 009 + `EXPECTED_SLOT_FIELDS`↔컬럼 드리프트, instance_key/retired_at 포함) + `test_postgresql_repository`(lifecycle + closed→idle 거부 + closed→pending_buy reallocation) → **8 passed**.
|
||||
- `ruff check trex_core tests` All passed.
|
||||
|
||||
## 검증 실행
|
||||
- M1: `TREX_BROKER=paper pytest -q` → 375 passed / 35 skipped / 1 deselected. `ruff check trex_core` All passed.
|
||||
- `TREX_BROKER=paper pytest -q --deselect …test_sandbox…` → 375 passed / 35 skipped / 1 deselected.
|
||||
- `TREX_POSTGRESQL_TEST_DSN=…(trex_core_test) pytest tests/adapters/persistence/test_migration_and_drift.py test_postgresql_repository.py` → 8 passed.
|
||||
- `ruff check trex_core tests` → All checks passed.
|
||||
|
||||
@@ -1,13 +1,38 @@
|
||||
# BAT-027 Verification
|
||||
|
||||
- Status: not-started
|
||||
- Status: verified (배치 범위 — 안 B 토대)
|
||||
- Batch: BAT-027
|
||||
|
||||
## Acceptance Mapping
|
||||
- (draft-batch-verification / confirm-batch-verification 단계에서 작성)
|
||||
|
||||
### REQ-056 (영구 슬롯 스키마, 안 B 부분)
|
||||
| AC | 상태 | Evidence |
|
||||
|----|------|----------|
|
||||
| instance_key·retired_at·`UNIQUE(instance_key, portfolio_id)` 존재 | ✅ | 마이그레이션 009 + test_migration_and_drift(PG) green |
|
||||
| `EXPECTED_SLOT_FIELDS` ↔ daily_slot 컬럼 일치(+instance_key/retired_at) | ✅ | test_contract + test_migration_and_drift(PG) |
|
||||
| 중복 (instance_key, portfolio_id) 거부 | ✅ | 부분 UNIQUE 인덱스(WHERE portfolio_id NOT NULL) |
|
||||
| `entry_count`/슬롯 `trading_date` 컬럼 **부재** | ⏳ 이월(BAT-δ) | 안 B로 유지 — cutover(REQ-064)에서 drop |
|
||||
|
||||
### REQ-057 (상태머신 재정의 + 인스턴스 lock)
|
||||
| AC | 상태 | Evidence |
|
||||
|----|------|----------|
|
||||
| 전이 집합 inactive 기준(closed→idle 제거) | ✅ | test_state(allowed/disallowed/size 12) |
|
||||
| 종료 시 inactive 복귀(idle/closed 별칭) | ✅(별칭) | test_state·test_service. 엄밀 literal `inactive` 산출 전면 전환은 BAT-δ |
|
||||
| 인스턴스별 락 비교차 | ✅ | test_state::test_slot_advisory_lock_id_is_instance_scoped |
|
||||
| 동일 슬롯 직렬화(단일 writer) | ✅ | test_service Advisory lock 직렬화 |
|
||||
| holding 로컬 정본 | ✅ | status 로컬(hub 미의존) — 수량 정본 분리는 REQ-062/BAT-γ |
|
||||
|
||||
## Evidence
|
||||
- (대기)
|
||||
- 단위 전체: `375 passed / 35 skipped / 1 deselected`(KIS sandbox live-env 1건 deselect).
|
||||
- PG-gated(실 trex_core_test): `8 passed` — 마이그레이션 009 적용 + 드리프트 가드(instance_key/retired_at 포함) + lifecycle/closed→idle 거부/closed→pending_buy reallocation.
|
||||
- `ruff check trex_core tests` All passed.
|
||||
|
||||
## Carried-Over (REQ 완전 충족은 후속 배치)
|
||||
- REQ-056 `entry_count`/`trading_date` 컬럼 drop → **BAT-δ(cutover, REQ-064)**.
|
||||
- REQ-057 literal `inactive` 전면 산출(별칭 제거) → BAT-δ.
|
||||
- admission/capacity(REQ-059)·reconcile(REQ-058)·intent 자산 키(REQ-061)·수량/불일치(REQ-062)·운영자 뷰(REQ-063) → BAT-β/γ.
|
||||
- 따라서 **REQ-056/057 은 본 배치에서 Implemented 로 확정하지 않고 Approved 유지**(토대만 충족; 전체 AC 는 dcy-020 후속 배치 완료 시 confirm-req-implemented).
|
||||
|
||||
## Result
|
||||
- Ready for Release: false (구현 전)
|
||||
- Ready for Release: false (dcy-020 전체 delivery 미완 — 토대 배치)
|
||||
- Blocking Issues: 없음(배치 범위 단위/PG green). 단, dcy-020 REQ 완전 충족은 BAT-β/γ/δ 필요.
|
||||
|
||||
Reference in New Issue
Block a user