"""PLAN 386-2b sub7 — 노선 id 한 칸(design_page_data). 못박는 것 - 출처 하나 = `pageSectionContext`(횡단 context · 세션 캐시)가 채운 칸 — 두 보기는 context 를 이것으로만 받음. - 읽는 곳(옛 출처 다섯) = 종단 보기 [저장] 몫(PA) · 횡단 보기 · 종단도 render · 평면 횡단 판(RC) · 3D · 측점 그림 — `pageRouteId` 만 · 묶음(PP)은 종단도 `pipelineSource().routeId`(= 칸)를 받음. - 칸 = 저장 정본 바뀜(invalidate)엔 그대로 · 페이지 떠남에 비움 · context 노선 없음 = null. 짝: `helper_384_2_page_data.cjs`(진짜 TS · 서버 흉내) — `test_384_2_page_data.py` 와 같은 헬퍼. """ from __future__ import annotations import json import re import subprocess from pathlib import Path import pytest HERE = Path(__file__).resolve().parent ROOT = HERE.parents[1] READERS = { "B05_Profile/B05_Profile_UI_Page_Actions.ts": "pageRouteId(projectId)", "A00_Common/design/design_view_cross.ts": "currentRouteId = pageRouteId(projectId);", "A00_Common/design/design_profile.ts": "pageRouteId(projectId) ?? givenRouteId", "B05_Profile/B05_Profile_UI_RouteEdit_Cross.ts": "pageRouteId(projectId)", "A00_Common/design/design_view_profile.ts": "pageRouteId(activeProjectId)", "A00_Common/design/design_view_profile_3d.ts": "pageRouteId(projectId)", "A00_Common/design/design_view_profile_sections.ts": "pageRouteId(projectId)", } def _read(rel: str) -> str: return (ROOT / rel).read_text(encoding="utf-8") @pytest.fixture(scope="module") def r() -> dict: proc = subprocess.run( # noqa: S603 — 고정 실행 파일 ["node", str(HERE / "helper_384_2_page_data.cjs")], capture_output=True, text=True, encoding="utf-8", timeout=60, ) assert proc.returncode == 0, proc.stderr return json.loads(proc.stdout) def test_칸_채움_비움(r): route = r["route"] assert route["before"] is None and route["context"] == 304 and route["after"] == 304 assert route["keptOnSave"] == 304 # 저장 정본 바뀜(비움)엔 그대로 assert route["leaving"] is None # 페이지 떠남 assert route["none"] is None # context 노선 없음 @pytest.mark.parametrize("rel", sorted(READERS)) def test_읽는_곳은_칸만(rel): src = _read(rel) assert READERS[rel] in src assert "context.route_id" not in src used = [ line for line in src.splitlines() if re.search(r"(latest(Response)?|ctx\.latest\(\))\??\.route\??\.id\b", line) and "!==" not in line # 노선이 바뀌었나 견줌(다시 세움) = 출처 아님 ] assert not used def test_출처는_자료_줄_하나(): data = _read("A00_Common/design/design_page_data.ts") assert "setPageRouteId(projectId, context.route_id)" in data slot = _read("A00_Common/design/design_page_route.ts") assert not re.search(r"^import ", slot, re.M) # 끄는 모듈 없음 found = subprocess.run( # noqa: S603, S607 — 고정 실행 파일 ["git", "grep", "-l", "setPageRouteId(", "--", "*.ts"], cwd=ROOT, capture_output=True, text=True, encoding="utf-8", ) users = set(found.stdout.split()) | { "A00_Common/design/design_page_route.ts" } # 새 파일(추적 전) assert sorted(users) == [ "A00_Common/design/design_page_data.ts", "A00_Common/design/design_page_route.ts", ] for rel in ( "A00_Common/design/design_view_cross.ts", "A00_Common/design/design_view_profile.ts", ): src = _read(rel) assert "fetchSectionContext(" not in src and "pageSectionContext(" in src cross = _read("B05_Profile/B05_Profile_UI_RouteEdit_Cross.ts") assert "routeStateKeys" not in cross # 노선 번호를 몰라 훑던 길 지움 page = _read("A00_Common/design/design_page.ts") assert "forgetPageData(projectId, true)" in page