Files
Aislo/resources/tester/helper_346_3_route_save.cjs
T
eomsangdonandClaude Sonnet 5.5 8bbdbb9f69 test(508-1b 옛 헬퍼 공용 불러오기 4/7): 헬퍼 28 곳 loadTs 베낌 걷고 makeLoader 로
- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침
- 확인: 이 묶음 헬퍼를 쓰는 시험 236 개 전 230 통과 → 후 230 통과 (시험별 junit 대조 · 어긋남 0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 17:11:59 +09:00

178 lines
6.4 KiB
JavaScript

/* 346-3 노선 저장 이음 헬퍼 — `B05_Profile_UI_RouteEdit_Apply.ts` 를 트랜스파일해 서버 · 화면 창구는 가짜로,
* 가게 · 캐시(`design_store` · `b_page_state`)는 진짜로 돌림. 보낸 본문 · 부른 차례를 적어 JSON 한 벌로 냄.
*/
const fs = require("fs");
const path = require("path");
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const ROOT = path.join(__dirname, "..", "..");
function memoryStorage() {
const map = new Map();
return {
getItem: (key) => (map.has(key) ? map.get(key) : null),
setItem: (key, value) => map.set(key, String(value)),
removeItem: (key) => map.delete(key),
key: (index) => [...map.keys()][index] ?? null,
get length() {
return map.size;
},
};
}
const session = memoryStorage();
globalThis.window = { sessionStorage: session, localStorage: memoryStorage() };
globalThis.sessionStorage = session;
const calls = [];
const bodies = [];
let failReplan = false;
const STUBS = {
"@ui/ui_template_elements": {
showToast: (text, kind) => calls.push(`toast:${kind}:${text}`),
showLoadingOverlay: () => calls.push("overlay:on"),
hideLoadingOverlay: () => calls.push("overlay:off"),
},
"../A00_Common/router": {
currentRoute: () => "b05-profile",
remountRoute: () => calls.push("remount"),
},
"../A00_Common/design/design_pipeline_page": {
commitRouteFacilities: () => calls.push("commit"), // 저장 = 초안 전 관 · 구조물 버림(6-B)
},
"../B06_Section/B06_Section_Section_Store": {
invalidateSectionDetail: (_p, routeId) => calls.push(`invalidate:${routeId ?? "all"}`),
},
// 6-B — 넘김은 서버(Node · 같은 TS) · 여기서는 옛 노선 세션 칸 원본만 냄
"../B06_Section/B06_Section_Station_Keys": {
routeCarryInputs: (_p, from) => (calls.push(`carryInputs:${from}`), { from_keys: [], from }),
},
"../B06_Section/B06_Section_Api_Fetch": {
sectionConfirmBody: (standard, patches, massHaul) => ({ standard, patches, massHaul }),
},
"../B06_Section/B06_Section_UI_Standard_Panel": { readStandardCrossSession: () => ({ std: 1 }) },
"@util/common_util_mass_haul_balance_view": { balloonOffsetsPayload: () => ({ b: [1, 2] }) },
"./B05_Profile_Api_Fetch": {
clearRouteLatestCache: () => calls.push("latest:clear"),
},
"./B05_Profile_Api_Replan": {
replanRoute: async (_p, body) => {
bodies.push(JSON.parse(JSON.stringify(body)));
calls.push("replan");
if (failReplan) throw new Error("체인 실패");
return {
route_id: 9,
pipes: { kept: 3, crossing: 1 },
structures: { moved: 1, far: 0 },
cross_dropped: 1,
drainage_stale: true,
};
},
},
};
const { loadTs } = makeLoader({
root: ROOT,
requireFor: (full) => (request) => {
if (STUBS[request]) return STUBS[request];
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
},
});
const { useDesignStore } = loadTs(path.join(ROOT, "A00_Common", "design", "design_store.ts"));
const { readState, writeState } = loadTs(path.join(ROOT, "A00_Common", "b_page_state.ts"));
const apply = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_RouteEdit_Apply.ts"));
(async () => {
const out = {};
const draft = {
rev: 3,
nodes: [
[0, 0],
[5, 5],
[10, 0],
],
curveOn: [true, true, true],
};
// 편집기 없음 — 가게 routeDraft 를 보냄 · 없으면 null
out.noneAtAll = await apply.pendingRouteSave("p1");
useDesignStore("p1", null).set("routeDraft", draft);
out.storeOnly = await apply.pendingRouteSave("p1");
// 편집기 등록 — 안 바뀌었으면 null(가게에 초안이 있어도 편집기가 정함) · 바뀌면 계약 꼴
let changed = false;
let kept = 0;
let rebuilt = 0;
apply.bindRouteApply({
projectId: "p1",
nodes: () => ({
planned: [
[0, 0],
[5, 5],
[10, 0],
],
curveOn: [true, false],
curveRadius: [null, 25],
}),
changed: () => changed,
terrain: () => "sheet",
snap: () => ({ stationSnap: true, stationSnapStep: 20 }), // 390-5 — 켬끔 · 간격 한 벌
initial: { current: () => ({ mode: "follow" }), keep: () => (kept += 1) },
onApplied: () => (rebuilt += 1),
});
out.unchanged = await apply.pendingRouteSave("p1");
changed = true;
const body = await apply.pendingRouteSave("p1");
out.body = body;
// 저장 — 가게 초안 비움 · 결과 캐시 비움 · 추천 다시 적음
writeState("design-stations", [{ k: 1 }], "p1");
const saved = await apply.saveRouteDraft("p1", body);
out.savedRouteId = saved.route_id;
out.storeAfterSave = useDesignStore("p1", null).get("routeDraft");
out.keptAfterSave = kept;
out.summary = typeof apply.routeSaveSummary; // 498-3 — 결과 한 줄 걷음
// 노선 바뀐 [저장] 횡단 조각(6-B) — 옛 노선 세션 칸 원본 + 표준 횡단 · 풍선 · 저장 뒤 상단측 · 종류 바꿈 비움
calls.length = 0;
writeState("uphill", { "40.00": "right" }, "p1");
writeState("kindreset", { "45.00": "culvert" }, "p1");
const part = apply.routeCarryPart("p1", 7);
out.carry = part.carry;
out.crossBody = part.cross.body;
out.uphillBeforeAfter = readState("uphill", "p1");
await part.cross.after(undefined);
out.uphillAfter = readState("uphill", "p1");
out.kindresetAfter = readState("kindreset", "p1");
out.carryCalls = [...calls];
// 추천 [적용] — as_initial · 잠금 막 · 초안 비움 · 다시 세움
useDesignStore("p1", null).set("routeDraft", draft);
writeState("pipes", [{ chainage_m: 1 }], "p1");
calls.length = 0;
const snapshot = {
planned: [
[1, 1],
[9, 9],
],
curveOn: [true, true],
curveRadius: [null, null],
};
out.recommendOk = await apply.saveRecommendedRoute("p1", snapshot, { mode: "earthwork" }, true);
out.recommendBody = bodies[bodies.length - 1];
out.recommendCalls = calls.filter((c) => !c.startsWith("toast:"));
out.recommendDraftsLeft = {
route: useDesignStore("p1", null).get("routeDraft"),
pipes: readState("pipes", "p1"),
};
out.rebuilt = rebuilt;
// 추천 저장 실패 — false · 오류 한 줄 · 다시 안 세움
failReplan = true;
calls.length = 0;
out.recommendFail = await apply.saveRecommendedRoute("p1", snapshot, null, false);
out.recommendFailCalls = [...calls];
out.rebuiltAfterFail = rebuilt;
console.log(JSON.stringify(out));
})();