Files
QuantEngineByItz/tools/validate_docs_no_formula_duplication_v1.py
T
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

80 lines
2.6 KiB
Python

"""validate_docs_no_formula_duplication_v1.py — P8-T02 문서 내 공식/수식 중복 기재 방지 검증기
docs/ (doctrine.md, runbook.md 등) 및 AGENTS.md 내에 하드코딩된 수식이나 공식
정의가 중복 기재되어 있지 않은지 엄격히 검증한다.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
# Windows stdout 인코딩 에러 방지
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)
ROOT = Path(__file__).resolve().parents[1]
# 검사 대상 파일 목록
TARGET_DOCS = [
ROOT / "AGENTS.md",
ROOT / "docs" / "doctrine.md",
ROOT / "docs" / "runbook.md",
]
def main() -> int:
duplication_count = 0
errors: list[str] = []
# 공식/수식으로 판단되는 패턴 예: "Formula =", "Score = ", "Decision = ", "QEDD_R_Score =" 등
# 또는 'f(x) =' 등 수학식 하드코딩 스타일
math_patterns = [
"QEDD_R_Score =",
"Decision = f(",
"Report = copy(",
"Release_PASS = all(",
"NewRule = Contract",
]
for doc_path in TARGET_DOCS:
if not doc_path.exists():
continue
try:
content = doc_path.read_text(encoding="utf-8")
except Exception as e:
errors.append(f"Failed to read {doc_path.name}: {e}")
continue
# docs 디렉토리 내 문서와 AGENTS.md에 하드코딩 수식이 존재하면 중복으로 판단
for pattern in math_patterns:
if pattern in content:
duplication_count += 1
errors.append(
f"Duplicated formula pattern '{pattern}' found in human doc: {doc_path.name}"
)
status = "PASS" if duplication_count == 0 else "FAIL"
result = {
"formula_id": "VALIDATE_DOCS_NO_FORMULA_DUPLICATION_V1",
"status": status,
"docs_formula_duplication_count": duplication_count,
"errors": errors,
}
out_path = ROOT / "Temp" / "docs_no_formula_duplication_v1.json"
out_path.parent.mkdir(parents=True, exist_ok=True)
out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
print(json.dumps(result, ensure_ascii=True, indent=2))
if status == "PASS":
print("VALIDATE_DOCS_NO_FORMULA_DUPLICATION_OK")
else:
print("VALIDATE_DOCS_NO_FORMULA_DUPLICATION_FAIL")
for err in errors:
print(f" ERROR: {err}")
return 0 if status == "PASS" else 1
if __name__ == "__main__":
raise SystemExit(main())