- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 233 개 전 233 통과 → 후 233 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
82 lines
2.9 KiB
JavaScript
82 lines
2.9 KiB
JavaScript
/* 421 추천 창 「종단 반영」 셈 헬퍼 — `_Initial_Model` 을 그 자리에서 트랜스파일해 Node 로 돌려
|
|
* 종단 반영 값이 서버 답 · 보낸 값 · 옛 캐시 · 서버 기록에서 어떻게 정해지는지 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;
|
|
},
|
|
_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 } };
|
|
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
requireFor: (full) => (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);
|
|
},
|
|
});
|
|
|
|
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,
|
|
}),
|
|
);
|