Files
QuantEngineByItz/tools/validate_execution_precedence_lock_v2.py
kjh2064 af1236202d WBS-7.3: GAS→Python 마이그레이션 5개 항목 완료 (F14, F02-F06)
- F14: late_chase_risk_score 검증
  * GAS가 유일한 생산처 (Python canonical 없음)
  * migration_action: KEEP_IN_GAS로 정정, status: DONE

- F02/F03/F04/F06: priceBasis 로직 포팅
  * formulas/price_basis_v1.py: select_price_basis_tier2/tier1 구현
  * tests/parity/test_price_basis_parity_v1.py: 8 parity 테스트 (모두 PASS)
  * GAS Number.isFinite() 의미론 정확히 재현 (math.isfinite 사용)
  * 모든 테스트 112/112 PASS

남은 작업 (4개):
- F05: decision_logic (action assignment)
- F07: score_logic (threshold addition)
- F10: routing decision
- F15: late_chase_gate

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-22 22:45:00 +09:00

84 lines
3.2 KiB
Python

"""validate_execution_precedence_lock_v2.py — P0-004 수용 검증기
AUDIT_ONLY 상태에서 HTS 주문 행수가 0이고,
child_engine_internal_allowed와 global_execution_gate가 명시적으로 분리됨을 검증한다.
"""
from __future__ import annotations
import json
from pathlib import Path
from v7_hardening_common import ROOT, TEMP, load_json, save_json
DEFAULT_OUT = TEMP / "execution_precedence_lock_v2.json"
import sys
if sys.stdout.encoding and sys.stdout.encoding.lower() not in ("utf-8", "utf8"):
sys.stdout = open(sys.stdout.fileno(), mode="w", encoding="utf-8", buffering=1)
def main() -> int:
v4 = load_json(TEMP / "final_execution_decision_v4.json")
scr = (
load_json(TEMP / "smart_cash_recovery_v7.json")
or load_json(TEMP / "smart_cash_recovery_v6.json")
or load_json(TEMP / "smart_cash_recovery_v5.json")
)
errors: list[str] = []
if not v4:
errors.append("final_execution_decision_v4.json not found — run build_final_execution_decision_v4.py")
else:
global_gate = str(v4.get("global_execution_gate") or "")
hts_count = int(v4.get("hts_order_count") or 0)
child_internal = v4.get("child_engine_internal_allowed")
# AUDIT_ONLY에서 HTS 주문 수는 반드시 0
if global_gate == "AUDIT_ONLY" and hts_count > 0:
errors.append(f"AUDIT_ONLY 상태에서 hts_order_count={hts_count} > 0 — P0-004 위반")
# child_engine_internal_allowed 필드가 존재해야 함
if "child_engine_internal_allowed" not in v4:
errors.append("child_engine_internal_allowed 필드 누락 — P0-004 명시적 분리 미완")
# child=true이더라도 global=AUDIT_ONLY이면 HTS 0임을 확인
if child_internal is True and global_gate == "AUDIT_ONLY" and hts_count == 0:
pass # 정상 상태
# smart_cash의 execution_allowed가 있더라도 v4에서 명시적으로 분리됐는지
scr_exec = scr.get("execution_allowed")
if scr_exec is True and global_gate == "AUDIT_ONLY":
# child가 허용이어도 global이 AUDIT_ONLY면 HTS 0이어야 함 → 이미 체크됨
pass
# precedence_note 또는 child_execution_state 존재
if "child_execution_state" not in v4:
errors.append("child_execution_state 필드 누락")
status = "PASS" if not errors else "FAIL"
result = {
"formula_id": "EXECUTION_PRECEDENCE_LOCK_V2",
"status": status,
"errors": errors,
"global_execution_gate": v4.get("global_execution_gate") if v4 else "MISSING",
"hts_order_count": v4.get("hts_order_count") if v4 else None,
"child_engine_internal_allowed": v4.get("child_engine_internal_allowed") if v4 else None,
"child_execution_state": v4.get("child_execution_state") if v4 else None,
}
save_json(str(DEFAULT_OUT), result)
print(json.dumps(result, ensure_ascii=False, indent=2))
if status == "PASS":
print("EXECUTION_PRECEDENCE_LOCK_V2_OK")
else:
print("EXECUTION_PRECEDENCE_LOCK_V2_FAIL")
for e in errors:
print(f" ERROR: {e}")
return 0 if status == "PASS" else 1
if __name__ == "__main__":
raise SystemExit(main())