fix(cli): BAT-022 slots 명령이 universe 대신 실제 슬롯 상태 표시 (dcy-016 후속)
`trex-core slots` 가 snapshot RPC 의 universe `assets`(portfolio)를 슬롯 상태로 오인 표시하던 갭 정정. snapshot envelope 이 슬롯 상태를 운반하지 않아 발생 (10개 슬롯인데 universe 1개·status 없음 — BAT-007 HTTP 슬롯 read 제거 후 슬롯 상태 read 표면 부재가 근인). - REQ-028 (CHG-20260608-01): snapshot envelope 에 read-only per-slot `slots[]` additive 추가(AC-4). strategy `assets[]`(universe, no-price) 불변. - REQ-032 (CHG-20260608-03): `_cmd_slots` 가 envelope `slots[]`(실제 슬롯 상태) 표시 + `--status` 를 슬롯 status 기준 client-side 필터 + watchdog 결합. `universe` 는 `assets[]` 유지. `universe --json` 도 universe 데이터로 scope. - canonical `portfolio.slot_to_dict` 단일화 — BAT-007 stub / BAT-008 envelope 두 경로가 동일 슬롯 스키마(외부명 `entry_price` 유지, dcy-012 호환). - interface-contract 에 `slots[]` 계약 + `assets[]` vs `slots[]` 구분 반영. 검증: 단위 338 passed + ruff clean + 신규 코드 데몬으로 실 PostgreSQL/RabbitMQ 운영 재현 PASS(slots=10·status·DB 일치·universe 분리·비침습). REQ-028/032 Implemented, BAT-022 release-candidate. pytest 인프라 게이트는 Human Approval Memo 수용(운영 재현이 실 경로 커버). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -43,8 +43,11 @@ def test_envelope_shape_returned():
|
||||
correlation_id="snap-1",
|
||||
))
|
||||
body = resp.payload
|
||||
assert set(body.keys()) == {"assets", "view", "available_slots", "degraded", "reason", "message"}
|
||||
# BAT-022: `slots[]` additive operator-facing per-slot state.
|
||||
assert set(body.keys()) == {"assets", "view", "available_slots", "degraded",
|
||||
"reason", "message", "slots"}
|
||||
assert isinstance(body["assets"], list)
|
||||
assert isinstance(body["slots"], list)
|
||||
assert body["view"] == "all"
|
||||
assert body["degraded"] is False
|
||||
assert body["reason"] is None
|
||||
|
||||
@@ -146,8 +146,12 @@ def test_envelope_shape_no_price_field():
|
||||
store, pause, repo, svc = _wire()
|
||||
env = _env(store, pause, repo, available_slots=3, view=View.ALL)
|
||||
d = env.to_dict()
|
||||
assert set(d.keys()) == {"assets", "view", "available_slots", "degraded", "reason", "message"}
|
||||
# BAT-022: `slots[]` is an additive operator-facing field alongside assets.
|
||||
assert set(d.keys()) == {"assets", "view", "available_slots", "degraded",
|
||||
"reason", "message", "slots"}
|
||||
assert isinstance(d["assets"], list)
|
||||
assert isinstance(d["slots"], list)
|
||||
# strategy-facing assets[] keep the strict no-price shape (REQ-028 AC-3).
|
||||
for asset in d["assets"]:
|
||||
assert set(asset.keys()) == {"symbol", "asset_id", "cash_balance",
|
||||
"asset_quantity", "active_strategy_id",
|
||||
|
||||
@@ -29,6 +29,18 @@ _SNAPSHOT = {
|
||||
"assets": [{"asset_id": "PF-1", "symbol": "005930", "asset_quantity": 0,
|
||||
"active_strategy_id": "orb"}],
|
||||
"view": "all", "available_slots": 9, "degraded": False, "reason": None,
|
||||
# BAT-022: envelope per-slot state (operator-facing). `slots` queries read
|
||||
# this, not the universe `assets[]`.
|
||||
"slots": [
|
||||
{"slot_id": "S-1", "trading_date": "2026-06-08", "status": "holding",
|
||||
"symbol": "005930", "qty": 10.0, "avg_price": 28700.0, "entry_price": None,
|
||||
"allocated_capital": None, "strategy_id": "orb", "sell_strategy_id": None,
|
||||
"portfolio_id": "PF-1", "forced_close_at": None},
|
||||
{"slot_id": "S-2", "trading_date": "2026-06-08", "status": "idle",
|
||||
"symbol": None, "qty": None, "avg_price": None, "entry_price": None,
|
||||
"allocated_capital": None, "strategy_id": None, "sell_strategy_id": None,
|
||||
"portfolio_id": None, "forced_close_at": None},
|
||||
],
|
||||
}
|
||||
_ADMITTED = {"intent_id": "i", "status": "admitted", "slot_id": "S-1", "reason": None}
|
||||
_REJECTED = {"intent_id": "i", "status": "rejected", "slot_id": None,
|
||||
@@ -47,18 +59,50 @@ def test_universe_uses_snapshot_queue_with_operator_suppression(capsys):
|
||||
assert "PF-1" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_slots_status_holding_maps_to_held_view():
|
||||
def test_universe_json_is_scoped_to_universe(capsys):
|
||||
"""BAT-022: `universe --json` emits universe data only — `slots[]`/`watchdog[]`
|
||||
(operator slot table) are NOT leaked into the universe view."""
|
||||
rpc = _RpcRecorder(_SNAPSHOT)
|
||||
cli.main(["universe", "--json"], rpc=rpc)
|
||||
out = json.loads(capsys.readouterr().out)
|
||||
assert set(out.keys()) == {"instance", "view", "assets", "available_slots",
|
||||
"degraded", "reason"}
|
||||
assert "slots" not in out and "watchdog" not in out
|
||||
|
||||
|
||||
def test_slots_shows_real_slot_state_not_universe(capsys):
|
||||
"""BAT-022: `slots` shows envelope `slots[]` (slot table) with status,
|
||||
not the universe `assets[]`."""
|
||||
rpc = _RpcRecorder(_SNAPSHOT)
|
||||
cli.main(["slots"], rpc=rpc)
|
||||
out = capsys.readouterr().out
|
||||
# request stays non-invasive (operator suppression)
|
||||
assert rpc.calls[0]["payload"]["actor"] == "operator"
|
||||
assert rpc.calls[0]["payload"]["touch_watchdog"] is False
|
||||
# both slots shown, with status column (slot state, not universe assets)
|
||||
assert "count=2" in out
|
||||
assert "S-1\tholding" in out and "S-2\tidle" in out
|
||||
|
||||
|
||||
def test_slots_status_filters_by_slot_status(capsys):
|
||||
"""BAT-022: `--status` filters by slot status client-side (no view mapping)."""
|
||||
rpc = _RpcRecorder(_SNAPSHOT)
|
||||
cli.main(["slots", "--status", "holding"], rpc=rpc)
|
||||
assert rpc.calls[0]["payload"]["view"] == "held"
|
||||
out = capsys.readouterr().out
|
||||
assert "count=1" in out and "S-1\tholding" in out and "S-2" not in out
|
||||
|
||||
|
||||
def test_slots_marks_watchdog_owned(capsys):
|
||||
"""dcy-017: slots flags strategy-absent (watchdog-owned) positions."""
|
||||
resp = {
|
||||
"assets": [{"asset_id": "PF-1", "symbol": "005930", "asset_quantity": 10,
|
||||
"active_strategy_id": "orb"}],
|
||||
"view": "held", "available_slots": 9, "degraded": False, "reason": None,
|
||||
"assets": [], "view": "all", "available_slots": 9, "degraded": False,
|
||||
"reason": None,
|
||||
"slots": [{"slot_id": "S-1", "trading_date": "2026-06-08",
|
||||
"status": "holding", "symbol": "005930", "qty": 10.0,
|
||||
"avg_price": 28700.0, "entry_price": None,
|
||||
"allocated_capital": None, "strategy_id": "orb",
|
||||
"sell_strategy_id": None, "portfolio_id": "PF-1",
|
||||
"forced_close_at": None}],
|
||||
"watchdog": [{"slot_id": "S-1", "portfolio_id": "PF-1", "symbol": "005930",
|
||||
"expired": True, "last_seen": None}],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user