fix(b06): 구조물 측점에서 종류를 바꾸면 횡단을 구조물 없는 상태부터 새로 — 저장분 횡단은 빼 두고 새 자리처럼 미리 뜬 횡단 · 되돌리면 저장분 복귀 (317-2 · 요구 213)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C6BNBFXFndbqYxu6sZuknK
This commit is contained in:
2026-10-13 20:04:26 +09:00
co-authored by Claude Opus 5.5
parent 0bf2c6fa8c
commit 5f54a09267
3 changed files with 152 additions and 1 deletions
+24 -1
View File
@@ -160,10 +160,33 @@ export async function withDraftStations(
if (inputs) {
const [pipes, structures, types] = inputs;
const planted = plantedChainages(pipes, structures, types);
// 구조물 측점에서 종류를 바꿈 = 「구조물 없는 상태」부터 새 종류로(요구 213) — 저장분 횡단은 빼 두고
// 새 자리처럼 미리 뜬 횡단을 씀 · 저장분 종류로 되돌리면 빼 둔 횡단이 돌아옴
const [oldPipes, oldStructures] = await savedOf(projectId).catch(
(): [Pipes, StructureInstance[]] => [[], []],
);
const byType = new Map(types.map((type) => [type.type_id, type]));
const kindsAt = (ps: Pipes, ss: StructureInstance[], at: number): string =>
[
...ps
.filter((pipe) => pipeStationMarks(pipe).some((m) => near(m.chainage_m, at)))
.map((pipe) => `p:${pipe.facility ?? "pipe"}`),
...ss
.filter((s) =>
structureStationMarks(s, byType.get(s.type_id)).some((m) => near(m.chainage_m, at)),
)
.map((s) => `s:${s.type_id}`),
]
.sort()
.join(",");
const replaced = (section: CrossSection): boolean => {
const was = kindsAt(oldPipes, oldStructures, section.chainage_m);
return was !== "" && was !== kindsAt(pipes, structures, section.chainage_m);
};
const isStale = (section: CrossSection): boolean =>
section.kind === "irregular" &&
!section.grid &&
planted.every((at) => !near(at, section.chainage_m));
(planted.every((at) => !near(at, section.chainage_m)) || replaced(section));
stale = all.filter(isStale);
live = all.filter((section) => !isStale(section));
const missing = planted.filter(
@@ -0,0 +1,79 @@
/* PLAN 317 단위검증 헬퍼 — 구조물 측점에서 종류를 바꾸면 그 측점 횡단을 새로 뜬 것으로(저장분은 빼 둠).
* `withDraftStations` 를 Node 로 돌림 · 서버 부르는 모듈은 흉내 · 결과 = 표준출력 JSON 한 벌.
* 짝 = `test_317_kind_change_station.py`.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
const state = { draftPipes: null, draftStructures: null, savedPipes: [], savedStructures: [] };
const STUBS = {
"../B04_PreProcess/B04_PreProcess_Api_Fetch": {
fetchDetailPipePoints: async () => ({ pipe_points: state.savedPipes }),
},
"../B05_Profile/B05_Profile_Api_Structures": {
fetchStructures: async () => ({ structures: state.savedStructures }),
fetchStructureTypes: async () => [],
readPendingStructures: () => state.draftStructures,
},
"../B05_Profile/B05_Profile_Api_Pipes_Draft": { readPendingPipes: () => state.draftPipes },
"./B06_Section_Api_Fetch": {
previewStructureSections: async (_p, chainages) =>
chainages.map((at) => ({ chainage_m: at, kind: "irregular", design: { fresh: true } })),
},
};
const cache = new Map();
const load = (file) => {
if (cache.has(file)) return cache.get(file);
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(file, box.exports);
const near = (m) => {
if (STUBS[m]) return STUBS[m];
if (m.startsWith("@util/")) return load(path.join(ROOT, "common_util", `${m.slice(6)}.ts`));
if (m.startsWith(".")) return load(path.join(path.dirname(file), `${m}.ts`));
return new Proxy({}, { get: () => () => {} });
};
new Function("exports", "module", "require", js)(box.exports, box, near);
return box.exports;
};
const { withDraftStations, forgetDraftStations } = load(
path.join(ROOT, "B06_Section", "B06_Section_Section_Drafts.ts"),
);
const detail = {
cross_sections: [
{ chainage_m: 0, kind: "regular", design: { old: true } },
{ chainage_m: 50, kind: "irregular", design: { old: true } },
],
};
const at50 = () => detail.cross_sections.find((s) => Math.abs(s.chainage_m - 50) < 0.01);
const snap = () => ({
count: detail.cross_sections.length,
fresh: Boolean(at50()?.design?.fresh),
old: Boolean(at50()?.design?.old),
preview: Boolean(at50()?.preview),
});
(async () => {
state.savedPipes = [{ chainage_m: 50, facility: "ford_pavement" }];
const out = {};
state.draftPipes = [{ chainage_m: 50, facility: "ford_pavement", options: { ford_width_m: 3 } }];
await withDraftStations(detail, "p1", 1);
out.same_kind = snap();
state.draftPipes = [{ chainage_m: 50, facility: "box_culvert" }];
await withDraftStations(detail, "p1", 1);
out.changed_kind = snap();
state.draftPipes = [{ chainage_m: 50, facility: "ford_pavement" }];
await withDraftStations(detail, "p1", 1);
out.back_to_saved = snap();
forgetDraftStations("p1");
process.stdout.write(JSON.stringify(out));
})().catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});
@@ -0,0 +1,49 @@
"""PLAN 317 — 구조물 측점에서 종류를 바꾸면 횡단을 「구조물 없는 상태」부터 새로(요구 213).
- 저장분과 같은 종류 = 저장분 횡단 그대로
- 다른 종류로 바꿈 = 저장분 횡단은 빼 두고 새 자리처럼 미리 뜬 횡단(옛 구조물 흔적 없음)
- 저장분 종류로 되돌림 = 빼 둔 저장분 횡단이 돌아옴
실제 TS(`withDraftStations`)를 `helper_317_kind_change_station.cjs` 가 Node 로 돌린다(서버 부르는 곳 흉내).
"""
from __future__ import annotations
import json
import os
import subprocess
import pytest
HERE = os.path.dirname(__file__)
ROOT = os.path.join(HERE, "..", "..")
pytestmark = pytest.mark.skipif(
not os.path.isdir(os.path.join(ROOT, "config", "node_modules")),
reason="프론트엔드 의존성 미설치",
)
@pytest.fixture(scope="module")
def result() -> dict:
out = subprocess.run(
["node", os.path.join(HERE, "helper_317_kind_change_station.cjs")],
capture_output=True,
text=True,
encoding="utf-8",
timeout=120,
check=True,
)
return json.loads(out.stdout)
def test_same_kind_keeps_saved_section(result: dict) -> None:
assert result["same_kind"] == {"count": 2, "fresh": False, "old": True, "preview": False}
def test_changed_kind_starts_from_fresh_section(result: dict) -> None:
assert result["changed_kind"] == {"count": 2, "fresh": True, "old": False, "preview": True}
def test_back_to_saved_kind_restores_saved_section(result: dict) -> None:
assert result["back_to_saved"] == {"count": 2, "fresh": False, "old": True, "preview": False}