Files
Aislo/resources/tester/helper_317_stale_preview.cjs
T
eomsangdonandClaude Opus 5.5 972baf989d fix(b05): [3D 업데이트] = 낡은 횡단 설계부터 다시 셈한 뒤 예상형상 · 그린 뒤 생긴 낡음도 다시 셈(같은 낡음은 한 번) (317-1 · 요구 213)
- 공용 낡음 지문 staleKey(Section_Common) · 그래프가 그릴 때 잰 지문을 패널에 넘김(Render onStaleDesigns)
- 패널 = 새 지문일 때만 다시 셈 예약(Preview scheduleIfStale · 서버 폴백 반복 막음)
- 단추 refreshCorridor = 짓기 전 refreshStaleDesigns(세션 계획선 초안 → 저장분 · B06 과 같은 규칙)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C6BNBFXFndbqYxu6sZuknK
2026-10-13 20:17:05 +09:00

79 lines
2.6 KiB
JavaScript

/* PLAN 317-1 단위검증 헬퍼 — 낡음 지문(`staleKey`) · 같은 지문이면 다시 셈 안 함(`scheduleIfStale`).
* 화면 TS 를 그 자리에서 트랜스파일해 Node 로 돌림 · 다시 셈 창구는 흉내(부른 횟수만 셈).
* 짝 = `test_317_3d_update.py`.
*/
const fs = require("fs");
const path = require("path");
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
const ROOT = path.join(__dirname, "..", "..");
let refreshCalls = 0;
const STUBS = {
"../B06_Section/B06_Section_Cross_Refresh": {
refreshCrossDesigns: async () => {
refreshCalls += 1;
return [];
},
},
};
globalThis.window = { setTimeout: (fn) => (fn(), 1), clearTimeout: () => {} };
const cache = new Map();
const load = (file) => {
if (cache.has(file)) return cache.get(file);
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
}).outputText;
const box = { exports: {} };
cache.set(file, box.exports);
const near = (m) => {
if (STUBS[m]) return STUBS[m];
if (m.startsWith("@util/")) return load(path.join(ROOT, "common_util", `${m.slice(6)}.ts`));
if (m.startsWith(".")) return load(path.join(path.dirname(file), `${m}.ts`));
return new Proxy({}, { get: () => () => {} });
};
new Function("exports", "module", "require", js)(box.exports, box, near);
return box.exports;
};
const { staleKey } = load(path.join(ROOT, "B06_Section", "B06_Section_UI_Section_Common.ts"));
const { createCrossPreview } = load(
path.join(ROOT, "B05_Profile", "B05_Profile_UI_Profile_Preview.ts"),
);
const detailOf = (sections) => ({
longitudinal: { design_profiles: [] },
cross_sections: sections,
});
const fordStale = {
chainage_m: 50,
ford_pavement: {},
design: { design_elevation_m: 1, paved: true },
};
const fordFresh = { ...fordStale, design: { ...fordStale.design, tilted: true } };
(async () => {
const out = {
key_stale: staleKey(detailOf([fordStale])),
key_fresh: staleKey(detailOf([fordFresh])),
};
const preview = createCrossPreview({
projectId: "p1",
detail: () => detailOf([fordStale]),
routeId: () => 1,
edits: () => ({ station_offsets: {}, curve_radii: {} }),
debounceMs: () => 0,
onApplied: () => {},
});
const calls = [];
for (const key of ["a", "a", "", "a", "b"]) {
preview.scheduleIfStale(key);
await Promise.resolve();
calls.push(refreshCalls);
}
out.calls = calls;
process.stdout.write(JSON.stringify(out));
})().catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});