"""WBS-7.11(2026-06-22) — spec-코드 동기화 게이트 단위 테스트.""" from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) import tools.validate_specs as vs def test_real_repo_has_no_missing_code_path(): """현재 저장소 상태에서 1차 태깅된 파일들은 모두 code_path가 실존해야 한다.""" errors: list[str] = [] result = vs.validate_spec_code_sync(errors) assert result["gate"] == "PASS" assert result["missing_code_path_count"] == 0 assert result["checked_count"] >= 10 assert not errors def test_missing_code_path_fails(tmp_path, monkeypatch): (tmp_path / "spec").mkdir() (tmp_path / "governance").mkdir() (tmp_path / "spec" / "fake_contract.yaml").write_text( "meta:\n has_code_implementation: true\n code_path: \"tools/does_not_exist_v1.py\"\n", encoding="utf-8", ) monkeypatch.setattr(vs, "ROOT", tmp_path) errors: list[str] = [] result = vs.validate_spec_code_sync(errors) assert result["gate"] == "FAIL" assert result["missing_code_path_count"] == 1 assert any("does_not_exist_v1.py" in e for e in errors) def test_redirect_only_and_has_code_is_contradiction(tmp_path, monkeypatch): (tmp_path / "spec").mkdir() (tmp_path / "governance").mkdir() (tmp_path / "spec" / "contradiction.yaml").write_text( "meta:\n has_code_implementation: true\n redirect_only: true\n", encoding="utf-8", ) monkeypatch.setattr(vs, "ROOT", tmp_path) errors: list[str] = [] result = vs.validate_spec_code_sync(errors) assert result["gate"] == "FAIL" assert any("contradiction" in e for e in errors) def test_files_without_the_field_are_skipped_not_failed(tmp_path, monkeypatch): (tmp_path / "spec").mkdir() (tmp_path / "governance").mkdir() (tmp_path / "spec" / "untouched.yaml").write_text( "meta:\n title: legacy doc with no sync field\n", encoding="utf-8", ) monkeypatch.setattr(vs, "ROOT", tmp_path) errors: list[str] = [] result = vs.validate_spec_code_sync(errors) assert result["gate"] == "PASS" assert result["checked_count"] == 0 assert result["total_spec_files"] == 1 assert not errors