Files
Aislo/resources/tester/helper_421_profile_toggle.cjs
T
eomsangdonandClaude Opus 5.5 67de77c48c feat(B05 노선 추천 창): 측점 맞춤 → 종단 반영 단추 · [재계산] 늘 켜짐 + recompute · [적용] 균형 종단 = 단추 값 (421)
- 「종단 반영」 단추(기본 켬 · 다섯 갈래 · 누르면 바로 셈) · 요청에 with_profile 늘 실음 · 답 with_profile 먼저
- [재계산] = 입력 오류 · 셈 중 빼고 늘 켜짐 · recompute: true 보냄(서버 420 짝)
- [적용] · [저장] 의 initial 에 with_profile · 다시 열 때 단추 되살림 · 옛 기록은 갈래로
- 맞추기 전 선(unsnapped) 화면에서 걷음 · 도움말 글(측점 맞춤 늘 · 종단 반영 · 재계산)
- 시험 test_421_recommend_profile · 383_3 · 383_1 · 351_2 고쳐 씀

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ji4nuyLVHcxrXWHTdb5nRD
2026-10-18 12:32:41 +09:00

92 lines
3.4 KiB
JavaScript

/* 421 추천 창 「종단 반영」 셈 헬퍼 — `_Initial_Model` 을 그 자리에서 트랜스파일해 Node 로 돌려
* 종단 반영 값이 서버 답 · 보낸 값 · 옛 캐시 · 서버 기록에서 어떻게 정해지는지 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 cache = new Map();
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;
},
_map: map,
};
}
const session = memoryStorage();
globalThis.window = { localStorage: memoryStorage(), sessionStorage: session };
globalThis.fetch = () => Promise.resolve({ ok: false });
const STUBS = { "@ui/ui_template_palette": { themeColor: (_name, fallback) => fallback } };
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 (STUBS[request]) return STUBS[request];
if (request.endsWith(".css")) return {};
if (request.startsWith("@ui/"))
return loadTs(path.join(ROOT, "ui_template", `${request.slice(4)}.ts`));
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
return require(request);
};
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
cache.set(full, box.exports);
return box.exports;
}
const model = loadTs(path.join(ROOT, "B05_Profile", "B05_Profile_UI_RouteEdit_Initial_Model.ts"));
const answer = {
nodes: [
{ x: 0, y: 0 },
{ x: 10, y: 5 },
],
curves: [],
};
const fromSent = model.normalizeRouteInitial(answer, "earthwork", null, null, false);
const fromServer = model.normalizeRouteInitial(
{ ...answer, with_profile: true, unsnapped: { planned: [[0, 0]] } },
"earthwork",
null,
null,
false,
);
const oldFollow = model.normalizeRouteInitial(answer, "follow", null);
const oldEarth = model.normalizeRouteInitial(answer, "earthwork", null);
const base = model.serverBase({ logic: "gentle", with_profile: false });
const oldBase = model.serverBase({ logic: "gentle" });
model.writeInitialChoice("p421", fromSent);
const readBack = model.readInitialChoice("p421");
process.stdout.write(
JSON.stringify({
sent: fromSent.withProfile,
server: fromServer.withProfile,
serverHasUnsnapped: "unsnapped" in fromServer,
oldFollow: model.choiceWithProfile(oldFollow),
oldEarth: model.choiceWithProfile(oldEarth),
base: base.withProfile,
oldBase: oldBase.withProfile ?? null,
baseProfile: model.choiceWithProfile(base),
oldBaseProfile: model.choiceWithProfile(oldBase),
sameOff: model.sameBase({ ...fromSent, logic: "gentle" }, base),
sameOn: model.sameBase({ ...fromServer, logic: "gentle" }, base),
sameOld: model.sameBase({ ...fromServer, logic: "gentle" }, oldBase),
readBack: readBack && readBack.withProfile,
}),
);