Files
Aislo/resources/tester/helper_m02_so_def_spec.cjs
T
eomsangdonandClaude Opus 5.5 103a207cee feat(M02): 구조물 옵션 정의 = 명세 이름 고치기 칸(명세 있는 종류 · 52-11)
- 명세가 있는 종류(STRUCTURE_SPECS)는 컨테이너 제목 › 항목 이름 › 값 이름 나무 · 이름만 고침 · 키 · 필수/선택 · 꼴은 읽기만
- 필수 컨테이너 제목 = 정의 그룹 이름 자리 · 나머지 = 종류.이름 표(B05 · B06 그리기와 같은 차례)
- 미리보기 = B05 · B06 명세 폼에 고친 이름 · 빈 이름은 저장 막음 · [저장] = 새 판 + 이력(48장 길 그대로)
- 옛 편집기(옵션 · 배치 · 그룹 · 규칙 · 기준 측점)는 명세 종류에서 숨김 · 명세 없는 종류는 그대로
- 시험: test_m02_so_def_spec(정의 사본) · ui_checks/52-11_정의_이름고치기

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UoSr2sqvYtBf1dtQdus88s
2026-10-05 23:42:11 +09:00

65 lines
3.0 KiB
JavaScript

/* M02 구조물 명세 이름 고치기(`M02_SO_Def_Spec_Model.ts` · PLAN 52-11) 단위검증 헬퍼 —
* TS 를 그 자리에서 트랜스파일해 Node 로 돌리고 결과를 JSON 으로 냄(pytest 가 판정).
* 정의는 진짜 `구조물정의.json` 을 읽어 메모리 사본만 고침(파일 쓰기 없음). */
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
const load = (...parts) => {
const js = ts.transpileModule(fs.readFileSync(path.join(ROOT, ...parts), "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
new Function("exports", "module", "require", js)(box.exports, box, require);
return box.exports;
};
const m = load("M02_MasterTemplete", "StructOptions", "M02_SO_Def_Spec_Model.ts");
const { PIPE_SPEC } = load("A00_Common", "design", "design_structure_pipe.ts");
const real = () =>
JSON.parse(
fs.readFileSync(path.join(ROOT, "resources", "master_template", "구조물정의.json"), "utf8"),
);
const out = {};
const def = real();
const rows = m.specNameRows(def, PIPE_SPEC);
out.levels = [0, 1, 2].map((lv) => rows.filter((r) => r.level === lv).length);
out.unique = new Set(rows.map((r) => r.nameKey)).size === rows.length;
out.pipeTitle = rows.find((r) => r.nameKey === "pipe");
out.optional = rows.find((r) => r.nameKey === "soil_add");
out.basinForm = rows.find((r) => r.nameKey === "inlet.form=I");
// 이름 고침 — 그룹 제목 · 항목 · 값 · 선택 컨테이너
const work = real();
const pick = (k) => m.specNameRows(work, PIPE_SPEC).find((r) => r.nameKey === k);
m.setSpecName(work, "pipe", pick("pipe"), "관 본체");
m.setSpecName(work, "pipe", pick("pipe.diameter"), "관 지름");
m.setSpecName(work, "pipe", pick("pipe.diameter=800"), "Ø800");
m.setSpecName(work, "pipe", pick("soil_add"), "흙막이 더");
out.groupName = work.그룹.pipe.find((g) => g.id === "grv6lny").이름;
out.names = ["pipe", "pipe.diameter", "pipe.diameter=800", "soil_add"].map(
(k) => work.종류.pipe.이름[k] ?? null,
);
out.reread = ["pipe", "pipe.diameter", "pipe.diameter=800", "soil_add"].map((k) => pick(k).label);
// 구조는 그대로 — types · 동작 · 다른 종류 · 이름 표 키 수(새 키 없음)
const before = real();
out.sameTypes = JSON.stringify(work.types) === JSON.stringify(before.types);
out.sameKeys =
Object.keys(work.종류.pipe.이름).length === Object.keys(before.종류.pipe.이름).length;
// 이름 표가 빈 종류 — 명세 글로 읽고 고치면 이름 표가 생김
const bare = real();
delete bare.종류.pipe.이름;
const bareRows = m.specNameRows(bare, PIPE_SPEC);
out.bareLabel = bareRows.find((r) => r.nameKey === "inlet.structure=기슭막이").label;
m.setSpecName(
bare,
"pipe",
bareRows.find((r) => r.nameKey === "inlet"),
"유입",
);
out.bareGroup = bare.그룹.pipe.find((g) => g.id === "gnbf9m9").이름;
process.stdout.write(JSON.stringify(out));