"""PLAN 322-0 ③ — 판 확인: 서버 관 기본값 · 판 읽기 길이 정의 사본을 바로 따름(서버 다시 켜기 없음). - `_registry_defaults` = 정의 파일이 바뀌면 다음 부름부터 새 기본값(옛 lru = 서버 다시 켤 때까지 옛 값). - `GET /api/m02/structure-definition/version` = 지금 판 `{판}` 만(화면 종류 캐시가 판을 볼 때 · 한 벌 안 받음). 화면 캐시 쪽은 `test_322_0_golden.py::test_type_cache_follows_definition_version`. """ from __future__ import annotations import json from pathlib import Path import pytest from fastapi import FastAPI from fastapi.testclient import TestClient from B05_Profile import B05_Profile_Structures_Schema as schema from B06_Section.B06_Section_Engine_Culvert import _registry_defaults from common_util.common_util_auth import verify_session from M02_MasterTemplete.StructOptions.M02_SO_Router import read_router @pytest.fixture def copy(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: """정의 사본 — 마스터 정본은 안 씀.""" path = tmp_path / "구조물정의.json" path.write_text(Path(schema.DEFINITION_PATH).read_text("utf-8"), "utf-8") monkeypatch.setattr(schema, "DEFINITION_PATH", str(path)) return path def _rewrite(path: Path, change) -> None: doc = json.loads(path.read_text("utf-8")) change(doc) path.write_text(json.dumps(doc, ensure_ascii=False), "utf-8") def test_registry_defaults_follow_definition_file(copy: Path) -> None: before = _registry_defaults("pipe")["pipe_diameter_mm"] def bump(doc: dict) -> None: pipe = next(t for t in doc["types"] if t["type_id"] == "pipe") option = next(o for o in pipe["options"] if o["key"] == "pipe_diameter_mm") option["default"] = "1200" if before != "1200" else "800" _rewrite(copy, bump) assert _registry_defaults("pipe")["pipe_diameter_mm"] != before def test_version_endpoint_reads_current_version(copy: Path) -> None: app = FastAPI() app.include_router(read_router) app.dependency_overrides[verify_session] = lambda: {"role": "USER", "user_id": 2} client = TestClient(app) now = json.loads(copy.read_text("utf-8"))["판"] assert client.get("/api/m02/structure-definition/version").json() == {"판": now} _rewrite(copy, lambda doc: doc.update(판=now + 3)) assert client.get("/api/m02/structure-definition/version").json() == {"판": now + 3}