Files
Aislo/resources/tester/test_349_0k_undo_saved.py
T
eomsangdonandClaude Sonnet 5.5 026ca74c52 test(507-4): 검증 스크립트 정비 — 계산 자리 화면 시험 안전장치 · 505-3 교각점 요소 자리 · 검증_sub7 시험 12 파일 지금 검증 프로젝트로 · 공용 TS 불러오기 첫 걸음
- 309-2 화면 시험: 5177 이 8004 로 갈 때만 돎(남의 마스터 안 씀) · 실패해도 판 되돌림(finally) · 읽기는 서버 응답으로 판정
- 505-3 첫 시험: 픽셀 (1199,296) 대신 캔버스 교각점 색으로 찾음 · 포트 · 프로젝트는 환경 변수로
- 349 계열 · 346-2 · 356-4: helper_verify_project 가 OWNERS.md 검증_subN 중 가장 오래 안 바뀐 프로젝트를 읽기만 · 없으면 까닭 글로 건너뜀 · 낡은 기대 xfail
- helper_ts_stub_loader 공용 불러오기 + 새 시험 · 헬퍼 3 곳 옮김

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 16:02:51 +09:00

134 lines
4.9 KiB
Python

"""PLAN 349-0k sub7 — 되돌리기로 저장 노선에 돌아오면 저장 정본 그대로(다시 셈 없음).
· 열기 → 노선 꼭짓점 끌기(상세가 새 노선 측점으로 갈아끼워지고 다시 셈) → 되돌리기 한 번
· 되돌린 뒤 상세 = 열 때 받은 저장 정본 객체 · 측점 · 횡단 · 누가토량 = 열기 값
· 되돌리기 = 묶음 한 번 · 더 안 돎
짝: `helper_349_0k_undo_saved.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 helper_verify_project import ROUTE_SET, SKIP_REASON, find_project # noqa: E402
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 = find_project(*ROUTE_SET) # 지금 있는 검증 프로젝트(읽기만)
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(SKIP_REASON)
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"]
# 저장 횡단 면적 = 서버가 상세를 낼 때 셈(파일엔 없음) — 정본 대신 정한 값
for i, section in enumerate(sections):
section["design"] = {
"ground_type": "soil",
"design_elevation_m": section["center_z"],
"cut_area_m2": 4.0 + (i % 5),
"fill_area_m2": 1.5 + (i % 3),
}
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_0k_undo_saved.cjs"), str(path), str(grid)],
capture_output=True,
text=True,
encoding="utf-8",
timeout=300,
)
assert proc.returncode == 0, proc.stderr
return json.loads(proc.stdout)
def test_열_때_한_번_저장_정본(r):
o = r["open"]
assert [x["outcome"] for x in o["runs"]] == ["done"], o["runs"]
assert o["same"]
assert o["final"] is not None
def test_끌기_새_측점으로_갈아끼움(r):
d = r["drag"]
assert [x["sources"] for x in d["runs"]] == [["route"]], d["runs"]
assert d["swapped"] # 이 시험이 갈아끼움 길을 실제로 거침
assert d["final"] != r["open"]["final"]
def test_되돌리기_열기_값(r):
u, o = r["undo"], r["open"]
assert [x["sources"] for x in u["runs"]] == [["route"]], u["runs"]
assert u["restores"] == [{"saved": True, "back": {"same": True}}]
assert u["sameObject"]
assert u["stations"] == o["stations"]
assert u["cross"] == o["cross"]
assert u["final"] == o["final"]
def test_되돌린_뒤_조용함(r):
assert r["after"]["runs"] == 0
assert r["after"]["blocked"] == 0