From eb3a33f124bfe780bdbf049a99e8e5ecd6d3f80b Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Mon, 13 Jul 2026 00:06:48 +0900 Subject: [PATCH] feat(dotnet): add parity contract and wiring --- .gitea/workflows/ci.yml | 3 + AGENTS.md | 2 + docs/ROADMAP_WBS.md | 1 + docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml | 83 +++++++++++++++++ spec/41_release_dag.yaml | 16 ++++ ...test_validate_dotnet_parity_contract_v1.py | 39 ++++++++ tools/validate_dotnet_parity_contract_v1.py | 89 +++++++++++++++++++ 7 files changed, 233 insertions(+) create mode 100644 docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml create mode 100644 tests/unit/test_validate_dotnet_parity_contract_v1.py create mode 100644 tools/validate_dotnet_parity_contract_v1.py diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 40a99e2a..aa8c6bcd 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -172,6 +172,9 @@ jobs: - name: Validate Dotnet Migration Execution Plan run: python3 tools/validate_dotnet_migration_execution_plan_v1.py + - name: Validate Dotnet Parity Contract + run: python3 tools/validate_dotnet_parity_contract_v1.py + - name: Build Calibration Priority Backlog diff --git a/AGENTS.md b/AGENTS.md index 36da3055..71d5c604 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -99,8 +99,10 @@ - `docs/WBS_10_DOTNET_MIGRATION_ROADMAP.yaml`: `.NET 엔진 고도화` 상세 WBS와 각 WBS별 성공 데이터 가이드. - `docs/WBS_10_DOTNET_MIGRATION_INVENTORY.yaml`: WBS-10 전환 우선순위용 실행 경로 인벤토리. - `docs/WBS_10_DOTNET_MIGRATION_EXECUTION_PLAN.yaml`: WBS-10 착수용 실행 분해 계획. +- `docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml`: WBS-10 핵심 계산기 parity 계약. - `tools/validate_dotnet_migration_roadmap_v1.py`: WBS-10 상세 로드맵 YAML validator. - `tools/validate_dotnet_migration_execution_plan_v1.py`: WBS-10 실행 분해 계획 validator. +- `tools/validate_dotnet_parity_contract_v1.py`: WBS-10 parity 계약 validator. - `Temp/snapshot_admin_approval_packet_v1.json`: snapshot admin approval packet export. - `Temp/snapshot_admin_approval_packet_v1.md`: snapshot admin approval packet summary. - `Temp/`: 실행 결과와 캐시. 라우팅 대상은 아니며 runtime consumer만 읽는다. diff --git a/docs/ROADMAP_WBS.md b/docs/ROADMAP_WBS.md index 8e4946ff..4d6fed96 100644 --- a/docs/ROADMAP_WBS.md +++ b/docs/ROADMAP_WBS.md @@ -1468,6 +1468,7 @@ WBS-8.8 (KIS 리팩터) — 독립적 (원격 병행) > 실행 경로 인벤토리: [WBS_10_DOTNET_MIGRATION_INVENTORY.yaml](./WBS_10_DOTNET_MIGRATION_INVENTORY.yaml) > 실행 분해 계획: [WBS_10_DOTNET_MIGRATION_EXECUTION_PLAN.yaml](./WBS_10_DOTNET_MIGRATION_EXECUTION_PLAN.yaml) > 실행 분해 검증기: `tools/validate_dotnet_migration_execution_plan_v1.py` +> parity 계약: [WBS_10_DOTNET_PARITY_CONTRACT.yaml](./WBS_10_DOTNET_PARITY_CONTRACT.yaml) > 현황 진단(2026-06-26): .NET 프로젝트는 Python 엔진(41 모듈, 14,500 LOC) 대비 5~10%(~1,400 LOC) 수준. > Domain 계산기 6개·데이터 모델 8개·KIS/Naver/Yahoo 클라이언트·PostgreSQL 마이그레이션·Razor Pages 어드민 대시보드 기본 구현 완료. diff --git a/docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml b/docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml new file mode 100644 index 00000000..760810fd --- /dev/null +++ b/docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml @@ -0,0 +1,83 @@ +formula_id: WBS_10_DOTNET_PARITY_CONTRACT_V1 +owner: QuantEngine +status: draft +source_of_truth: + - src/dotnet/QuantEngine.Core/Domain/FormulaEngine.cs + - src/dotnet/QuantEngine.Core/Domain/ExitDecisions.cs + - src/dotnet/QuantEngine.Core/Domain/FactorCalculator.cs + - src/dotnet/QuantEngine.Core.Tests/FormulaEngineTests.cs + - src/dotnet/QuantEngine.Core.Tests/FactorCalculatorTests.cs + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + +goal: "Python reference와 .NET domain 결과를 데이터 기반 parity 계약으로 고정한다." + +targets: + - target_id: formula_engine_timing + symbol: FormulaEngine.ComputeTimingDecision + tolerance: + numeric: 0 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/FormulaEngineTests.cs + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "timing action/reason이 reference와 동일" + + - target_id: formula_engine_sell + symbol: FormulaEngine.ComputeSellDecision + tolerance: + numeric: 0 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/FormulaEngineTests.cs + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "sell action/ratio/validation이 reference와 동일" + + - target_id: formula_engine_final + symbol: FormulaEngine.ComputeFinalDecision + tolerance: + numeric: 0 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/FormulaEngineTests.cs + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "final action/priority/source가 reference와 동일" + + - target_id: exit_stop_price + symbol: ExitDecisions.ComputeStopPriceCore + tolerance: + numeric: 0.0001 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "stop price within tolerance" + + - target_id: exit_stop_ladder + symbol: ExitDecisions.ComputeStopActionLadder + tolerance: + numeric: 0 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "exit action ladder exact match" + + - target_id: exit_heat_thresholds + symbol: ExitDecisions.ComputeDynamicHeatThresholds + tolerance: + numeric: 0 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/ParityTests/DomainParityTests.cs + pass_condition: "heat thresholds exact match" + + - target_id: factor_calculator + symbol: FactorCalculator.CalculateFactors + tolerance: + numeric: 0.000001 + text: exact + evidence: + - src/dotnet/QuantEngine.Core.Tests/FactorCalculatorTests.cs + pass_condition: "factor outputs stable and deterministic" + +execution_notes: + - "Parity is a contract, not a guess." + - "Do not add new parity targets without updating reference fixtures and tolerances." diff --git a/spec/41_release_dag.yaml b/spec/41_release_dag.yaml index af44e914..0d324c23 100644 --- a/spec/41_release_dag.yaml +++ b/spec/41_release_dag.yaml @@ -2313,6 +2313,22 @@ dag: - Temp/wbs_10_dotnet_migration_execution_plan_v1.json strict: true timeout_sec: 60 + validate_dotnet_parity_contract: + artifact_policy: keep + cache_key: validate_dotnet_parity_contract_v1 + command: + - python + - tools/validate_dotnet_parity_contract_v1.py + depends_on: [] + id: validate_dotnet_parity_contract + inputs: + - tools/validate_dotnet_parity_contract_v1.py + - docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml + note: WBS-10 핵심 계산기 parity 계약과 허용오차를 검증한다. + outputs: + - Temp/wbs_10_dotnet_parity_contract_v1.json + strict: true + timeout_sec: 60 validate_specs: artifact_policy: keep cache_key: validate_specs_v1 diff --git a/tests/unit/test_validate_dotnet_parity_contract_v1.py b/tests/unit/test_validate_dotnet_parity_contract_v1.py new file mode 100644 index 00000000..bc39a2b6 --- /dev/null +++ b/tests/unit/test_validate_dotnet_parity_contract_v1.py @@ -0,0 +1,39 @@ +from __future__ import annotations + +import json +import subprocess +import sys +from pathlib import Path + + +def test_validate_dotnet_parity_contract_passes() -> None: + root = Path(__file__).resolve().parents[2] + proc = subprocess.run( + [sys.executable, str(root / "tools" / "validate_dotnet_parity_contract_v1.py")], + cwd=root, + capture_output=True, + text=True, + ) + assert proc.returncode == 0, proc.stdout + proc.stderr + payload = json.loads(proc.stdout) + assert payload["gate"] == "PASS" + assert payload["formula_id"] == "WBS_10_DOTNET_PARITY_CONTRACT_V1" + + +def test_validate_dotnet_parity_contract_reports_missing_target() -> None: + root = Path(__file__).resolve().parents[2] + temp = root / "Temp" / "test_wbs_10_parity_contract_bad.yaml" + temp.write_text( + "formula_id: WBS_10_DOTNET_PARITY_CONTRACT_V1\ngoal: Python reference와 .NET domain 결과를 데이터 기반 parity 계약으로 고정한다.\ntargets: []\n", + encoding="utf-8", + ) + proc = subprocess.run( + [sys.executable, str(root / "tools" / "validate_dotnet_parity_contract_v1.py"), "--contract", str(temp)], + cwd=root, + capture_output=True, + text=True, + ) + assert proc.returncode != 0 + payload = json.loads(proc.stdout) + assert payload["gate"] == "FAIL" + assert "formula_engine_timing missing" in payload["missing"] diff --git a/tools/validate_dotnet_parity_contract_v1.py b/tools/validate_dotnet_parity_contract_v1.py new file mode 100644 index 00000000..3cbecb78 --- /dev/null +++ b/tools/validate_dotnet_parity_contract_v1.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import argparse +import json +from pathlib import Path +from typing import Any + +import yaml + + +REQUIRED_TARGETS = { + "formula_engine_timing", + "formula_engine_sell", + "formula_engine_final", + "exit_stop_price", + "exit_stop_ladder", + "exit_heat_thresholds", + "factor_calculator", +} + + +def load_yaml(path: Path) -> dict[str, Any]: + if not path.exists(): + raise FileNotFoundError(path) + return yaml.safe_load(path.read_text(encoding="utf-8")) + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description="Validate WBS-10 dotnet parity contract") + parser.add_argument("--contract", default="docs/WBS_10_DOTNET_PARITY_CONTRACT.yaml") + args = parser.parse_args(argv) + + contract_path = Path(args.contract).resolve() + payload: dict[str, Any] = { + "formula_id": "WBS_10_DOTNET_PARITY_CONTRACT_V1", + "gate": "FAIL", + "missing": [], + "evidence": {"contract": str(contract_path)}, + } + + try: + data = load_yaml(contract_path) + except FileNotFoundError: + payload["missing"].append("contract missing") + print(json.dumps(payload, ensure_ascii=False, indent=2)) + return 1 + + if data.get("formula_id") != "WBS_10_DOTNET_PARITY_CONTRACT_V1": + payload["missing"].append("formula_id") + if data.get("goal") != "Python reference와 .NET domain 결과를 데이터 기반 parity 계약으로 고정한다.": + payload["missing"].append("goal") + + targets = data.get("targets") or [] + target_ids: set[str] = set() + for target in targets: + target_id = target.get("target_id", "") + target_ids.add(target_id) + if not target.get("symbol"): + payload["missing"].append(f"{target_id}.symbol") + tolerance = target.get("tolerance") or {} + if "numeric" not in tolerance: + payload["missing"].append(f"{target_id}.tolerance.numeric") + if "text" not in tolerance: + payload["missing"].append(f"{target_id}.tolerance.text") + if not target.get("evidence"): + payload["missing"].append(f"{target_id}.evidence") + if not target.get("pass_condition"): + payload["missing"].append(f"{target_id}.pass_condition") + + for required in sorted(REQUIRED_TARGETS - target_ids): + payload["missing"].append(f"{required} missing") + + payload["gate"] = "PASS" if not payload["missing"] else "FAIL" + payload["message"] = ( + "WBS-10 dotnet parity contract validation passed." + if payload["gate"] == "PASS" + else "WBS-10 dotnet parity contract validation failed." + ) + + out_path = contract_path.parent.parent / "Temp" / "wbs_10_dotnet_parity_contract_v1.json" + out_path.parent.mkdir(parents=True, exist_ok=True) + out_path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8") + print(json.dumps(payload, ensure_ascii=False, indent=2)) + return 0 if payload["gate"] == "PASS" else 1 + + +if __name__ == "__main__": + raise SystemExit(main())