Files
Aislo/resources/tester/helper_54_10_soil_tiers.cjs
T
eomsangdonandClaude Opus 5.5 281c71b55b refactor(logic): 348-1 순수 계산 TS 49 파일 <페이지>/logic/ 로 옮김 — 이름 앞머리 그대로 · 동작 고침 없음
- 옮김: B04 2 · B05 23 · B06 11 · A00_Common/design 13 (9,299 줄) · 이미 logic/ 에 있던 16 파일 그대로
- 안 옮김: 묶음 입구(package.json build:*) · 파이썬 · 순수지만 계산 아닌 8 (보기 결선 · 콜백 · API 타입 · 갈아끼움 알림판)
- import 266 줄(142 파일) · 시험 · 주석 · 짝 표시 문자열 경로 고침 · B05 · B06 CLAUDE.md 짝 줄 logic/
- 시험 도우미 새 경로: 가짜 require 열쇠 · B05()/B06() 부름 · 형제 import 자리 · tsc 묶어 돌리는 시험 · 정규식 · rglob
- design_view_cross 줄 한도 시험 685 → 688 (긴 import 경로 줄바꿈 3줄)
- 확인: typecheck 0 · 서버 묶음 넷(corridor · server-calc · b07-extent · b07-note) 다시 지어 코드 같음(//#region 경로 주석만 다름) · 관련 시험 270 파일 — 남은 실패 19 는 옮기기 전과 같음

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014utrjfoW831Vc5wJUd13kL
2026-10-16 13:44:50 +09:00

232 lines
8.2 KiB
JavaScript

/* 다단 흙막이 ↔ 흙막이 컨테이너(PLAN 54-10) 단위검증 헬퍼 — TS 를 그 자리에서 트랜스파일해 Node 로 돌린다.
* ① 폼 → 다단 그림(`applyPipeOptionsToCache`) ② 밖에서 정한 개수보다 많은 컨테이너 값은 가리기만(`createSpecForm`).
* 결과는 표준출력에 JSON 한 벌. 짝 = `test_54_10_soil_tiers.py`.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const CATALOG = require("./helper_322_catalog_module.cjs"); // 구조물 표(322-1)
const ROOT = path.join(__dirname, "..", "..");
const cache = new Map();
// ── 화면 그릇 흉내 — 태그 · 클래스 · data 만 ─────────────────────────────────
class FakeNode {
constructor(tag) {
this.tagName = tag.toUpperCase();
this.children = [];
this.dataset = {};
this.style = {};
this._classes = new Set();
this._text = "";
this.value = "";
const self = this;
this.classList = {
add: (...n) => n.forEach((c) => self._classes.add(c)),
remove: (...n) => n.forEach((c) => self._classes.delete(c)),
toggle: (c, f) =>
(f ?? !self._classes.has(c)) ? self._classes.add(c) : self._classes.delete(c),
contains: (c) => self._classes.has(c),
};
}
set className(v) {
this._classes = new Set(String(v).split(/\s+/).filter(Boolean));
}
set textContent(v) {
this._text = String(v);
this.children = [];
}
get textContent() {
return this._text + this.children.map((c) => c.textContent ?? "").join("");
}
append(...kids) {
kids.forEach((k) => this.children.push(typeof k === "string" ? { textContent: k } : k));
}
replaceChildren(...kids) {
this.children = [];
this.append(...kids);
}
add(kid) {
this.children.push(kid);
}
setAttribute(n, v) {
this[n] = v;
}
addEventListener() {}
closest() {
return null;
}
matches(sel) {
return sel.split(",").some((s) => {
s = s.trim();
return s.startsWith(".") ? this._classes.has(s.slice(1)) : this.tagName === s.toUpperCase();
});
}
querySelectorAll(sel) {
const found = [];
const walk = (n) =>
(n.children ?? []).forEach((k) => {
if (k.matches?.(sel)) found.push(k);
walk(k);
});
walk(this);
return found;
}
querySelector(sel) {
return this.querySelectorAll(sel)[0] ?? null;
}
}
globalThis.document = { createElement: (t) => new FakeNode(t) };
globalThis.queueMicrotask = (fn) => fn(); // 폼 되돌림을 바로 받아 봄
globalThis.Option = function (text, value) {
const o = new FakeNode("option");
o.textContent = text;
o.value = value;
return o;
};
const toasts = [];
const STUBS = {
"@ui/ui_template_elements": { showToast: (msg) => toasts.push(msg) },
"@config/config_frontend": { FORD_MANNING_N: 0.03, FORD_SLOPE: 0.02 },
"./ui_template_checkbox.css": {},
"./B06_Section_UI_Page_Ford_Controls": {
applyFordFormOptions: () => {},
applyBoxFormOptions: () => {},
},
"../../B05_Profile/B05_Profile_UI_Structures_Summary_Row": { buildSummaryRow: () => null },
};
function loadTs(file) {
const full = path.resolve(file);
if (cache.has(full)) return cache.get(full);
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(full, box.exports);
const localRequire = (request) => {
if (CATALOG.isCatalogRequest(request)) return CATALOG;
if (STUBS[request]) return STUBS[request];
if (request.startsWith("@util/"))
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.ts`));
return loadTs(path.join(path.dirname(full), `${request}.ts`));
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
const out = {};
// ── ① 폼 → 다단 그림 ──────────────────────────────────────────────────────
const { applyPipeOptionsToCache } = loadTs(
path.join(ROOT, "B06_Section", "B06_Section_UI_Page_Pipe_Options.ts"),
);
const adjusts = {};
const updates = [];
const tiers = [];
const overrides = [];
const section = {
chainage_m: 100,
culvert: { diameter_m: 1, hidden_pipe: false, inlet: {}, outlet: { revet_form: "돌쌓기(찰)" } },
};
const ctx = {
detail: () => ({ cross_sections: [section] }),
ford: {},
box: {},
revetOffset: {
adjustFor: (_s, role) => adjusts[role] ?? { x: 0, d: null, h: null, m: null },
update: (_c, role, patch) => {
updates.push({ role, ...patch });
const now = adjusts[role] ?? { x: 0, d: null, h: null, m: null };
const m = patch.m === undefined ? now.m : patch.m;
// 기하 되받기(syncApplied) 흉내 — 형태별 높이 한도 없음(54-42 · 입력 높이 그대로)
const h = patch.h === undefined ? now.h : patch.h;
adjusts[role] = { ...now, h, m };
},
},
structureSpan: {
tierValuesFor: () => ({ lengthM: 10, beforeM: 5, afterM: 5 }),
updateTier: (_s, key, patch) => tiers.push({ key, ...patch }),
},
soilTiers: () => 2,
overrideOptions: (_c, values) => overrides.push(values),
refreshCard: () => {},
};
applyPipeOptionsToCache(ctx, 100, {
soil_add_1_form: "콘크리트",
soil_add_1_height: 1.8,
soil_add_1_length: 8,
soil_add_1_before: 3,
soil_add_1_after: 5,
soil_add_2_form: "돌쌓기(메)",
soil_add_2_height: 2.5,
soil_add_3_height: 1.2, // 지형이 못 세운 단 — 그림에 안 감
});
out.filled = { updates: updates.splice(0), tiers: tiers.splice(0), overrides: overrides.splice(0) };
out.toasts = toasts.splice(0);
// 같은 값을 다시 보내면 다시 그리지 않음
applyPipeOptionsToCache(ctx, 100, {
soil_add_1_form: "콘크리트",
soil_add_1_height: 1.8,
soil_add_2_form: "돌쌓기(메)",
soil_add_2_height: 2.5,
});
out.same = { updates: updates.splice(0), tiers: tiers.splice(0) };
// 그림이 안 서는 높이(0 이하)만 하한 0.1 에서 멈춰 폼에 되돌림 · 토스트 없음(54-51)
applyPipeOptionsToCache(ctx, 100, {
soil_add_1_form: "콘크리트",
soil_add_1_height: 0,
soil_add_2_form: "돌쌓기(메)",
soil_add_2_height: 2.5,
});
out.floor = { updates: updates.splice(0), overrides: overrides.splice(0) };
out.toasts.push(...toasts.splice(0));
// 비운 칸 = 자동(높이 · 형태) · 구간값은 그대로
applyPipeOptionsToCache(ctx, 100, {});
out.cleared = { updates: updates.splice(0), tiers: tiers.splice(0) };
// 독립 기슭막이(관 숨김)는 다단을 안 만짐
section.culvert.hidden_pipe = true;
applyPipeOptionsToCache(ctx, 100, { soil_add_1_height: 1.0 });
out.hidden = updates.splice(0);
// ── ② 개수보다 많은 컨테이너 값은 가리기만 · 값은 남김 ───────────────────────
const { createSpecForm } = loadTs(
path.join(ROOT, "A00_Common", "design", "design_structure_form.ts"),
);
const { PIPE_SPEC } = loadTs(
path.join(ROOT, "A00_Common", "design", "logic", "design_structure_pipe.ts"),
);
let count = 1;
const form = createSpecForm(null, { count: (c) => (c.id === "soil_add" ? count : undefined) });
form.write(PIPE_SPEC, {
pipe_diameter_mm: 1000,
soil_add_1_form: "콘크리트",
soil_add_2_form: "돌망태",
soil_add_2_height: 1.5,
chute_add_1_structure: "돌붙임",
});
// 상자 이름표 단추(136-3) — 글 「삭제」 + title
out.remove = form.root
.querySelectorAll("button")
.filter((b) => b.dataset.specRemove)
.map((b) => ({ id: b.dataset.specRemove, text: b.textContent, title: b.title }));
const boxes = () =>
form.root.children.filter((k) => k.dataset?.specContainer === "soil_add").length;
const soilKeys = () =>
Object.keys(form.read())
.filter((k) => k.startsWith("soil_add_"))
.sort();
out.form = { shown1: boxes(), keys1: soilKeys() };
count = 0; // 단 수 0 저장 — 옛 흙막이 값도 남음
form.recount();
out.form.shown0 = boxes();
out.form.keys0 = soilKeys();
count = 3;
form.recount();
out.form.shown3 = boxes();
out.form.keys3 = soilKeys();
process.stdout.write(JSON.stringify(out));