Files
Aislo/resources/tester/helper_283_route_reset_confirm.cjs
T
eomsangdonandClaude Sonnet 5.5 156ce1cf52 test(508-1b 옛 헬퍼 공용 불러오기 3/7): 헬퍼 28 곳 loadTs 베낌 걷고 makeLoader 로
- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침
- 확인: 이 묶음 헬퍼를 쓰는 시험 218 개 전 218 통과 → 후 218 통과 (시험별 junit 대조 · 어긋남 0)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-21 17:08:08 +09:00

92 lines
3.5 KiB
JavaScript

/* 283 · 493-2 추천 [적용] = 초기화 — 진짜 TS(`logic/B05_Profile_Route_Reset` · `B05_Profile_UI_RouteReset`
* applyResetText)를 Node 로 돌림 · 서버 저장분 받기는 가짜(입력 JSON `server`).
* 입력 argv[2] JSON · 표준출력 JSON 한 벌.
*/
const fs = require("fs");
const path = require("path");
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
const ROOT = path.join(__dirname, "..", "..");
function loadTs(file, stubs = {}) {
return makeLoader({
root: ROOT,
cache: false,
requireFor: (full) => (request) => {
if (stubs[request]) return stubs[request];
throw new Error(`stub 없음: ${request} (${file})`);
},
}).loadTs(path.join(ROOT, file));
}
const reset = loadTs("B05_Profile/logic/B05_Profile_Route_Reset.ts");
/** 서버 저장분 가짜 — 값 = 돌려줄 것 · "fail" = 받기 실패. */
const answer = (value) =>
value === "fail" ? Promise.reject(new Error("받기 실패")) : Promise.resolve(value);
async function applyText(server) {
const ui = loadTs("B05_Profile/B05_Profile_UI_RouteReset.ts", {
"../A00_Common/design/design_page_data": {
pageStructures: () => answer(server.structures),
pagePipes: () => answer(server.pipes),
},
"./B05_Profile_Api_PlusStations": { fetchSavedPlusStations: () => answer(server.plus) },
"./logic/B05_Profile_Route_Reset": reset,
});
return ui.applyResetText("p");
}
/** 493-5 — 추가 측점 저장분 기억: 저장 [127 · 163] → 서버가 [적용]으로 지움 → 다시 세운 페이지가 읽는 값. */
async function plusAfterApply(reload) {
let server = [127, 163];
const drafts = new Map();
global.window = { setTimeout: () => 0, clearTimeout: () => undefined };
global.fetch = async () => ({
ok: true,
json: async () => ({ chainages: server, stations: server.map((c) => ({ chainage_m: c })) }),
});
const plus = loadTs("B05_Profile/B05_Profile_Api_PlusStations.ts", {
"../config/config_frontend": { API_BASE_URL: "", API_TIMEOUT_MS: 1000 },
"../A00_Common/design/design_store": {
draftProjectId: () => "p",
useDesignStore: () => ({
get: (k) => drafts.get(k) ?? null,
set: (k, v) => drafts.set(k, v),
}),
},
"./B05_Profile_UI_Profile_History": { onPageHistory: () => undefined },
});
await plus.loadSavedPlusStations("p");
plus.followPlusDraft("p", { plusStations: [127, 163] }); // 노선 끌기 따라감 기억
const before = plus.plusStationsOf("p");
server = []; // 추천 [적용] — 서버가 지움 · 세션 초안 비움(clearDrafts)
drafts.clear();
if (reload) await plus.reloadSavedPlusStations("p");
await plus.loadSavedPlusStations("p"); // 다시 세운 페이지
return { before, after: plus.plusStationsOf("p"), body: plus.plusStationsPart("p").body };
}
async function main() {
const input = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
const plusApply = { fixed: await plusAfterApply(true), stale: await plusAfterApply(false) };
const texts = {};
for (const [name, server] of Object.entries(input.servers)) texts[name] = await applyText(server);
process.stdout.write(
JSON.stringify({
texts,
plusApply,
notice: reset.routeResetNotice(input.reset, 2),
noticeNone: [
reset.routeResetNotice(undefined),
reset.routeResetNotice({ reset: false, dropped: { pipes: 3 } }),
],
}),
);
}
main().catch((error) => {
process.stderr.write(String(error?.stack ?? error));
process.exit(1);
});