diff --git a/B06_Section/B06_Section_Router_Confirm.py b/B06_Section/B06_Section_Router_Confirm.py index 3a23ceddf..e535d552f 100644 --- a/B06_Section/B06_Section_Router_Confirm.py +++ b/B06_Section/B06_Section_Router_Confirm.py @@ -186,6 +186,18 @@ async def _recompute_stored_designs(project_id: UUID, route_id: int) -> None: ) +def _prune_cross_files(project_root: Path, longitudinal_file_path: str) -> None: + """측점을 고친 뒤 옛 cross_*.json 을 지움 — GET 은 안 지우므로 쓰는 쪽(저장 · 확정)이 맡음.""" + from B05_Profile.B05_Profile_Engine_Sections import prune_stale_cross_files + + path = project_root / longitudinal_file_path + try: + stations = json.loads(path.read_text(encoding="utf-8")).get("stations") or [] + except (OSError, ValueError, AttributeError): + return # 측점을 못 읽으면 안 지움(오삭제 막음) + prune_stale_cross_files(path.parent.parent / "cross_sections", stations) + + async def _prebuild_corridor(project_id: UUID, route_id: int, project_root: Path) -> None: """3D 길 모형을 서버 Node 가 지어 남긴다(342-2) — 정본이 다시 선 [저장] · [확정] 끝. @@ -261,6 +273,10 @@ async def save_sections( missing = await get_cross_sections_missing_design_chainages(connection, route_id) project_root = Path(resolve_stored_project_path(stored_path)) + # 측점 맞춤이 지운 자리의 옛 횡단 파일 정리(쓰는 쪽 몫) + await asyncio.to_thread( + _prune_cross_files, project_root, str(existing["longitudinal_file_path"]) + ) rowless = missing + await asyncio.to_thread( _rowless_station_chainages, project_root, @@ -341,6 +357,10 @@ async def confirm_sections( known = await get_cross_section_chainages(connection, route_id) marks.append(("조회(종단·경로·미지정 측점)", time.perf_counter())) project_root = Path(resolve_stored_project_path(stored_path)) + # 측점 맞춤이 지운 자리의 옛 횡단 파일 정리(쓰는 쪽 몫) + await asyncio.to_thread( + _prune_cross_files, project_root, str(existing["longitudinal_file_path"]) + ) # 행 자체가 없는 측점(구조물 등 비정규)도 확정 대상에 넣는다 — 정본이 없으면 # 조회 때마다 프리뷰가 다시 계산돼 3D·수량이 확정 결과가 아니게 된다(2026-08-24). missing = missing + await asyncio.to_thread( diff --git a/resources/tester/test_346_3_route_save.py b/resources/tester/test_346_3_route_save.py index ce90c8efd..3a0618cb5 100644 --- a/resources/tester/test_346_3_route_save.py +++ b/resources/tester/test_346_3_route_save.py @@ -539,3 +539,23 @@ def test_계획고_옮김은_앞_그대로_뒤_밂(tmp_path, monkeypatch): assert edits["40.000"] == 0.7 # 바뀐 구간 앞 — 그대로 assert "200.000" not in edits # 바뀐 구간 안 — 새 지반 assert edits[f"{380.0 + delta:.3f}"] == 0.3 # 뒤 — 길이 차만큼 밂 + + +def test_저장_확정이_옛_횡단_파일을_지움(tmp_path): + from B05_Profile.B05_Profile_Engine_Sections import cross_filename + + long_path = tmp_path / "B06_Section" / "longitudinal" / "longitudinal.json" + cross_dir = tmp_path / "B06_Section" / "cross_sections" + long_path.parent.mkdir(parents=True) + cross_dir.mkdir(parents=True) + long_path.write_text(json.dumps({"stations": [{"chainage_m": 0.0}, {"chainage_m": 20.0}]})) + for at in (0.0, 20.0, 37.0): + (cross_dir / cross_filename(at)).write_text("{}") + b06_confirm._prune_cross_files(tmp_path, "B06_Section/longitudinal/longitudinal.json") + assert sorted(p.name for p in cross_dir.glob("cross_*.json")) == sorted( + cross_filename(at) for at in (0.0, 20.0) + ) + source = (ROOT / "B06_Section" / "B06_Section_Router_Confirm.py").read_text("utf-8") + for name in ("async def save_sections(", "async def confirm_sections("): + body = source[source.index(name) :] + assert body.index("_stand_patch_stations(") < body.index("_prune_cross_files,")