/* 472-5 남음 헬퍼 — 노선 바뀐 [저장] 뒤 옛 노선 세션 칸 · 초안 전 hold 비움(`design_save.ts` 그대로 · 서버 창구 · * 세션 창구는 가짜). 짝 = `test_472_5r_rock_owner.py`. 표준출력 JSON. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const ROOT = path.join(__dirname, "..", ".."); globalThis.window = { setTimeout, clearTimeout }; const anything = () => new Proxy({}, { get: (_target, key) => (key === "__esModule" ? false : () => undefined) }); function load(file, stubs) { const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; new Function("exports", "module", "require", js)(box.exports, box, (r) => stubs[r] ?? anything()); return box.exports; } async function once(newRouteId, fail) { const calls = []; const KEYS = ["settings", "pipes", "structures", "plusStations", "alignment"]; const save = load(path.join(ROOT, "A00_Common", "design", "design_save.ts"), { "../b_page_state": { clearRouteDrafts: (p, r) => calls.push(`clearRouteDrafts:${p}:${r}`), clearState: (name, p) => calls.push(`clearState:${name}:${p}`), stateKey: () => null, }, "./design_save_api": { SAVE_PART_KEYS: [...KEYS, "cross"], DesignSaveError: Error, postDesignSave: async () => { calls.push("post"); if (fail) throw new Error("서버 500"); return { waited: false, steps: { route: { route_id: newRouteId } } }; }, }, "../../B05_Profile/B05_Profile_UI_RouteEdit_Apply": { pendingRouteSave: async () => ({ draft: 1 }), routeCarryPart: () => ({ carry: {}, cross: { body: {} } }), routeSaved: () => calls.push("routeSaved"), routeSaveSummary: () => "", rebuildAfterRouteSave: async () => calls.push("rebuild"), }, }); const done = await save.saveDesign({ projectId: "p1", routeId: () => 3, crossPart: async () => null, failed: () => calls.push("failed"), }); // 저장 뒤 정리와 무관한 칸(종류 캐시)은 빼고 봄 return { done, calls: calls.filter((c) => !c.includes("structure-type-cache")) }; } (async () => { const out = { moved: await once(9, false), same: await once(3, false), failed: await once(9, true), }; process.stdout.write(JSON.stringify(out)); })().catch((error) => { process.stderr.write(String(error.stack || error)); process.exit(1); });