/* 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 CATALOG = require("./helper_322_catalog_module.cjs"); // 구조물 표(322-1) const ROOT = path.join(__dirname, "..", ".."); let refreshCalls = 0; const STUBS = { "../B06_Section/B06_Section_Cross_Refresh": { refreshCrossDesigns: async () => { refreshCalls += 1; return []; }, holdScreenAlignment: () => () => {}, // 화면 선 맡김(342-1) — 이 시험 몫 아님 }, }; 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 (CATALOG.isCatalogRequest(m)) return CATALOG; 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: {} }), alignment: () => null, 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); });