"""PLAN 449 — B05 [저장] 관 목록 · 노선 저장 뒤 실패(433-7 · 433-12 · 433-6). · 관 정본 PUT = 세션 관 초안 한 번(B06 고침 직후 [저장] = 초안 값) · 배수판 메모리는 안 보냄 · 초안 없음 = [저장] PUT 없음(판이 안 서도 관 수 그대로) · [확정] = 칸 없이(서버 저장분) · 빈 초안 = 다 지움 · 노선 저장 뒤 구조물 차례 실패 → 0 칸 계획고가 새 노선 칸에 · 횡단 초안 넘김(저장 없이) · 다시 세움 → 다음 [저장]이 새 노선으로 계획고를 보냄 · 넘김 자체가 실패하면 두 번 안 넘김 · 관 PUT 끝 측점 맞춤 실패 = 응답 `stations_failed` 짝: `helper_449_save_pipes.cjs`(실제 `design_save.ts` 를 Node 로 · 서버 창구만 가짜). """ from __future__ import annotations import asyncio import json import subprocess import sys from pathlib import Path from uuid import uuid4 import pytest HERE = Path(__file__).resolve().parent ROOT = HERE.parents[1] if str(ROOT) not in sys.path: sys.path.insert(0, str(ROOT)) @pytest.fixture(scope="module") def out() -> dict: if not (ROOT / "config" / "node_modules" / "typescript").is_dir(): pytest.skip("프론트엔드 의존성 미설치") proc = subprocess.run( # noqa: S603 — 고정 실행 파일 ["node", str(HERE / "helper_449_save_pipes.cjs")], capture_output=True, text=True, encoding="utf-8", timeout=120, ) assert proc.returncode == 0, proc.stderr return json.loads(proc.stdout) def _saves(case: dict) -> list: """472-6 — 노선 안 바뀐 저장 = 한 본문 창구 한 번 · ["SAVE", 관 칸(points · "none"), 확정].""" return [call for call in case["calls"] if call[0] == "SAVE"] def test_관_PUT_은_초안_한_번(out): case = out["draft"] assert case["ok"] and _saves(case) == [ ["SAVE", [{"chainage_m": 15, "source": "user", "id": "p1"}], False] ] assert case["calls"].index(["RELOAD"]) > case["calls"].index( _saves(case)[0] ) # 화면은 뒤에 받기만 assert case["left"] is None def test_초안_없으면_PUT_없음(out): assert out["noDraft"]["ok"] and _saves(out["noDraft"]) == [["SAVE", "none", False]] def test_확정은_칸_없이_다시_셈(out): assert _saves(out["confirmNoDraft"]) == [["SAVE", None, True]] def test_빈_초안은_다_지움(out): assert _saves(out["emptyDraft"]) == [["SAVE", [], False]] def test_노선_저장_뒤_실패_초안_새_노선(out): case = out["routeFail"] assert not case["ok"] and "구조물" in case["failure"] assert case["calls"] == [["ROUTE"], ["CARRY", 7, 8, False], ["REBUILD"]] assert out["alignAfterFail"] == {"8": {"pvi": {"120": 1.5}}} # 0 칸 비움 · 새 노선 칸 align = [call for call in out["nextSave"]["calls"] if call[0] == "ALIGN"] assert align == [["ALIGN", 8, {"pvi": {"120": 1.5}}]] def test_넘김_실패면_두_번_안_넘김(out): case = out["carryFail"] assert not case["ok"] assert [call for call in case["calls"] if call[0] == "CARRY"] == [["CARRY", 7, 8, True]] assert case["calls"][-1] == ["REBUILD"] def test_공용_저장이_판_메모리를_안_보냄(): shared = (ROOT / "A00_Common/design/design_shared.ts").read_text(encoding="utf-8") panel = (ROOT / "B05_Profile/B05_Profile_UI_Drainage_Panel.ts").read_text(encoding="utf-8") assert "savePipes" not in shared and "saveDetailPipePoints" not in panel def test_측점_맞춤_실패는_응답에(monkeypatch): from B04_PreProcess import B04_PreProcess_Router_Basins as basins from B06_Section import B06_Section_Router_Stations as stations async def boom(_project_id): raise RuntimeError("샘플링 없음") async def fine(_project_id): return 1 monkeypatch.setattr(stations, "ensure_structure_stations", boom) assert asyncio.run(basins._stand_pipe_stations(uuid4())) is False monkeypatch.setattr(stations, "ensure_structure_stations", fine) assert asyncio.run(basins._stand_pipe_stations(uuid4())) is True