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>
This commit is contained in:
2026-06-22 22:45:00 +09:00
parent 4266039d1c
commit af1236202d
64 changed files with 13127 additions and 2760 deletions
@@ -0,0 +1,108 @@
#!/usr/bin/env python3
from __future__ import annotations
import json
import sys
from pathlib import Path
import yaml
ROOT = Path(__file__).resolve().parent.parent
def main() -> int:
expected_precedence = ["risk_exit", "cash_floor", "anti_late_entry", "smart_money", "momentum"]
files_to_check = [
ROOT / "spec" / "strategy" / "pre_distribution_early_warning_v4.yaml",
ROOT / "spec" / "strategy" / "smart_money_liquidity_gate_v1.yaml",
ROOT / "spec" / "09_decision_flow.yaml"
]
conflict_without_precedence_count = 0
errors = []
# 1. Check spec files for conflict precedence configuration
for fpath in files_to_check:
if not fpath.exists():
errors.append(f"Spec file missing: {fpath.name}")
conflict_without_precedence_count += 1
continue
try:
data = yaml.safe_load(fpath.read_text(encoding="utf-8")) or {}
# Check meta or root level for conflict_precedence
precedence = data.get("conflict_precedence") or (data.get("meta", {}) if isinstance(data.get("meta"), dict) else {}).get("conflict_precedence")
if not precedence:
errors.append(f"conflict_precedence not defined in {fpath.name}")
conflict_without_precedence_count += 1
elif precedence != expected_precedence:
errors.append(f"Invalid precedence in {fpath.name}: {precedence}. Expected: {expected_precedence}")
conflict_without_precedence_count += 1
except Exception as e:
errors.append(f"Failed to parse {fpath.name}: {e}")
conflict_without_precedence_count += 1
# 2. Check gate_trace for conflict resolutions
json_path = ROOT / "GatherTradingData.json"
gate_trace_missing_count = 0
if json_path.exists():
try:
raw_data = json.loads(json_path.read_text(encoding="utf-8"))
hctx = raw_data.get("data", {}).get("_harness_context", {})
decisions = hctx.get("decisions_json", [])
if isinstance(decisions, str):
decisions = json.loads(decisions)
# Verify if there is change from base to final, and check if explained
for dec in decisions:
if not isinstance(dec, dict):
continue
ticker = dec.get("ticker", "")
base = dec.get("base_action", "")
final = dec.get("final_action", "")
if base and final and base != final:
gate_trace = hctx.get("gate_trace_json", [])
if isinstance(gate_trace, str):
try:
gate_trace = json.loads(gate_trace)
except:
gate_trace = []
trace_found = False
for trace in gate_trace:
if isinstance(trace, dict) and trace.get("ticker") == ticker:
trace_found = True
if not trace.get("explanation") and not trace.get("reason"):
gate_trace_missing_count += 1
errors.append(f"Ticker {ticker} action changed from {base} to {final} but gate_trace explanation is missing")
break
if not trace_found:
is_cash_block = (final == "WATCH_TIMING_SETUP" or final == "SELL_READY") and hctx.get("cash_floor_status") == "HARD_BLOCK"
if not is_cash_block:
gate_trace_missing_count += 1
errors.append(f"Ticker {ticker} action changed from {base} to {final} but no trace found in gate_trace_json")
except Exception as e:
errors.append(f"Failed to check trace in GatherTradingData.json: {e}")
gate_passed = (conflict_without_precedence_count == 0) and (gate_trace_missing_count == 0)
result = {
"formula_id": "FACTOR_CONFLICT_PRECEDENCE_VALIDATOR_V1",
"conflict_without_precedence_count": conflict_without_precedence_count,
"gate_trace_missing_count": gate_trace_missing_count,
"errors": errors,
"gate": "PASS" if gate_passed else "FAIL"
}
# Write output to Temp
out_dir = ROOT / "Temp"
out_dir.mkdir(parents=True, exist_ok=True)
out_path = out_dir / "factor_conflict_precedence_validation_v1.json"
out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(result, ensure_ascii=True, indent=2))
return 0 if gate_passed else 1
if __name__ == "__main__":
sys.exit(main())