Files
Aislo/resources/tester/test_349_pipeline_once.py
T
eomsangdonandClaude Opus 5.5 00c86f4ed9 fix(계산묶음): 349 조작 하나 = 묶음 한 번 · 열기만 하면 저장 정본 그대로
- 고리 끊음: 묶음 측점 → 상세 갈아끼움 → 종단도 render · 비정규 측점 · 유토곡선 설정이 묶음을 처음부터 다시 부르던 것 — 다시 시작은 저장 정본(새로 받은 상세 · 새 노선)이 바뀔 때만 · 횡단 입력도 정본 상세에서만 모음
- 열 때(start 차례)는 측점 · 종단을 가게에 안 냄 — 상세 갈아끼움 없음 · 유토곡선 = 저장값
- 저장 노선(열 때 · 초안 버림)은 관 · 구조물 누가거리 · 계획고를 저장값 그대로(다시 투영 안 함 · 되돌리기 뒤 계획고 한 번 더 셈 없음)
- 노선 초안 동안 종단도 render · 비정규 측점이 초안 그림(기준 · 미리보기 가게)을 덮지 않음
- 시험 test_349_pipeline_once 4건(검증_sub7 실제 노선 · 옛 코드에서 4건 실패 재현)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TteK8mfYZetk5P3bEZkyVZ
2026-10-16 14:17:39 +09:00

134 lines
5.1 KiB
Python

"""PLAN 349 sub7 — 조작 하나 = 묶음 한 번 · 열기만 하면 저장 정본 그대로.
· 열 때 묶음 한 번 · 측점 목록 = 저장 측점(갈아끼움 없음 · 관 누가거리 = 저장값)
· 노선 꼭짓점 한 번 끌기 = 한 번(sources [route]) — 갈아끼운 상세 다시 그림이 처음부터 다시 안 부름
· 되돌리기 한 번(열 때로) = 한 번 · 관 · 계획고 = 저장값 · 측점 = 저장 측점
· 다시 열면 같은 값 · 계산 · 알림 안 입력 쓰기 0
짝: `helper_349_pipeline_once.cjs`(실제 TS 를 Node 로 · 서버 창구만 가짜 · 종단 보기 고리 흉내).
"""
from __future__ import annotations
import csv
import json
import subprocess
import sys
import tempfile
from pathlib import Path
import pytest
HERE = Path(__file__).resolve().parent
ROOT = HERE.parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from B05_Profile.B05_Profile_Structures_Schema import structure_type_map # noqa: E402
from common_util.common_util_surface_sampler import dtm_grid_bytes # noqa: E402
from config.config_system_design import STANDARD_CROSS_SECTION # noqa: E402
pytestmark = pytest.mark.skipif(
not (ROOT / "config" / "node_modules" / "typescript").is_dir(),
reason="프론트엔드 의존성 미설치",
)
PROJECT = ROOT / "storage/1/3/6d3b2812-6d5a-4168-a932-40e4ae303d5a" # 검증_sub7
ROUTE = PROJECT / "B05_Profile/route"
SECTION = PROJECT / "B06_Section"
GRID = PROJECT / "B04_PreProcess/models/dtm_classification_smooth.npz"
ONES = {g: {"loose": 1.0, "compacted": 1.0} for g in ("soil", "ripping_rock", "blasting_rock")}
def _csv(path: Path) -> list[list[float]]:
with path.open(encoding="utf-8") as handle:
return [[float(r["x"]), float(r["y"])] for r in csv.DictReader(handle)]
def _json(path: Path):
return json.loads(path.read_text(encoding="utf-8"))
@pytest.fixture(scope="module")
def r() -> dict:
if not (GRID.is_file() and (SECTION / "longitudinal/longitudinal.json").is_file()):
pytest.skip("검증_sub7 없음")
curves = _json(ROUTE / "planned_route_curves.json")
sections = sorted(
(_json(p) for p in (SECTION / "cross_sections").glob("cross_*.json")),
key=lambda s: s["chainage_m"],
)
pipes = _json(PROJECT / "B04_PreProcess/drainage/edits/pipe_points.json")["points"]
job = {
"line": _csv(ROUTE / "planned_route.csv"),
"nodes": _csv(ROUTE / "planned_route_nodes.csv"),
"curves": [
{k: c[k] for k in ("start", "apex", "end", "radius_m")} for c in curves["curves"]
],
"stationSnap": bool(curves.get("station_snap")),
"minRadius": curves["min_radius_m"],
"interval": 20.0,
"types": [
{"type_id": t.type_id, "group": t.group, "placement": t.placement}
for t in structure_type_map().values()
],
"pipes": pipes,
"standard": STANDARD_CROSS_SECTION,
"conversion": ONES,
"detail": {
"longitudinal": _json(SECTION / "longitudinal/longitudinal.json"),
"cross_sections": sections,
},
}
with tempfile.TemporaryDirectory() as folder:
path = Path(folder) / "job.json"
path.write_text(json.dumps(job), encoding="utf-8")
grid = Path(folder) / "grid.bin"
grid.write_bytes(dtm_grid_bytes(GRID))
proc = subprocess.run( # noqa: S603 — 고정 실행 파일
["node", str(HERE / "helper_349_pipeline_once.cjs"), str(path), str(grid)],
capture_output=True,
text=True,
encoding="utf-8",
timeout=300,
)
assert proc.returncode == 0, proc.stderr
out = json.loads(proc.stdout)
out["savedPipes"] = [p["chainage_m"] for p in pipes]
return out
def _same(a: list[float], b: list[float]) -> bool:
return len(a) == len(b) and all(abs(x - y) < 1e-6 for x, y in zip(a, b))
def test_열_때_한_번_저장_측점_그대로(r):
o = r["open"]
assert [x["outcome"] for x in o["runs"]] == ["done"], o["runs"]
assert o["swaps"] == 0 # 열 때 측점을 가게에 안 냄 — 상세 = 저장 정본 그대로
# 묶음 측점 ≈ 저장 측점 — 끝점만 저장 노선 csv 자릿수(0.1 mm)만큼 다를 수 있음(그래서 안 냄)
assert len(o["stations"]) == len(o["saved"])
assert all(abs(x - y) < 0.001 for x, y in zip(o["stations"], o["saved"]))
assert o["pipeChainages"] == r["savedPipes"]
assert o["footprint"] > 0
def test_꼭짓점_끌기_한_번(r):
d = r["drag"]
assert [x["sources"] for x in d["runs"]] == [["route"]], d["runs"]
assert d["swaps"] == 1 # 새 노선 측점으로 갈아끼움은 한 번(고리 아님)
def test_되돌리기_한_번_저장값으로(r):
u = r["undo"]
assert [x["sources"] for x in u["runs"]] == [["route"]], u["runs"]
assert u["pipeChainages"] == r["savedPipes"]
assert u["alignmentSaved"]
assert _same(u["stations"], r["open"]["stations"])
def test_다시_열면_같은_값_고리_없음(r):
assert r["reopen"]["runs"] == 1
assert r["reopen"]["final"] == r["open"]["final"]
assert r["reopen"]["stations"] == r["open"]["stations"]
assert r["blocked"] == 0