Files
Aislo/resources/tester/helper_349_pipeline_once.cjs
T
eomsangdonandClaude Opus 5.5 bdd6255763 fix(계산묶음): 349-0r cross 입력에 암 경계 기본값 — 초안 새 측점도 서버 config 값(화면이 문맥에서 기억)
- design_pipeline_cross pipelineCrossSource 입력에 rockBoundaryDefaultM: readRockBoundaryDefault(projectId)
- 그 모듈을 가짜로 갈음하는 도움 파일 10개 가짜에 readRockBoundaryDefault: () => -0.5
- 검증_sub2b 같은 끌기(진짜 cross 입력 길): 미리보기 1,184.7 대 정본 1,184.0
- 시험: 바뀐 도움 파일 시험 10 + 349-0n · 0p = 77 통과 · typecheck 0

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QfHKQs7J3hQELKMWQMUJEy
2026-10-16 17:06:58 +09:00

259 lines
9.6 KiB
JavaScript

/* PLAN 349 sub7 헬퍼 — 페이지 계산 묶음이 조작 하나에 한 번만 도는지 · 열기만 하면 저장 측점 목록 그대로인지.
* 진짜 TS(`design_pipeline_page` · 단계 파일 전부)를 트랜스파일해 Node 로 돌림 · 서버 창구만 가짜.
* 종단 보기 고리(가게 stations → 상세 갈아끼움 → 종단도 render · 비정규 측점 · 유토곡선 설정)를 흉내 냄 —
* `design_view_profile_sections.followSwap` · `design_profile.render` 가 부르는 그대로.
* 입력 argv[2] JSON · argv[3] 격자 이진. 결과 = 표준출력 JSON. 짝 = `test_349_pipeline_once.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");
const ROOT = path.join(__dirname, "..", "..");
const job = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
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;
},
};
}
globalThis.window = {
sessionStorage: memoryStorage(),
localStorage: memoryStorage(),
setTimeout,
clearTimeout,
};
// 흙 배분 서버 — 늦게 답함 · 끊기면 버림
globalThis.fetch = (url, init) =>
new Promise((resolve, reject) => {
const timer = setTimeout(
() => resolve({ ok: true, json: async () => ({ haul_plan: { blocks: [], url } }) }),
20,
);
init.signal.addEventListener("abort", () => {
clearTimeout(timer);
reject(new Error("aborted"));
});
});
const STUBS = {};
const cache = new Map();
function loadTs(full) {
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 (CATALOG.isCatalogRequest(request)) return CATALOG;
const key = Object.keys(STUBS).find((name) => request.endsWith(name));
if (key) return STUBS[key];
if (request.startsWith("@config/")) return { API_BASE_URL: "http://fake" };
if (request.startsWith("@util/"))
return loadTs(path.join(ROOT, "common_util", `${request.slice(6)}.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);
return box.exports;
}
const load = (...parts) => loadTs(path.join(ROOT, ...parts));
const sampler = load("common_util", "common_util_surface_sampler.ts");
const bytes = fs.readFileSync(process.argv[3]);
const grid = sampler.parseDtmGrid(
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.length),
);
const local = { grid, design: "las" };
STUBS["B05_Profile_Api_Replan"] = {
analysisTerrain: () => "las",
fetchRoutePlan: async () => ({
planned: job.line,
curves: job.curves,
min_radius_m: job.minRadius,
station_snap: job.stationSnap,
}),
};
STUBS["B05_Profile_Api_Structures"] = {
fetchStructures: async () => ({ structures: [] }),
fetchStructureTypes: async () => job.types,
};
STUBS["B05_Profile_Api_TerrainGrid"] = {
loadDesignTerrainGrid: async () => local,
groundStageDeps: () => ({ grid: () => local, remote: async () => [] }),
};
STUBS["B04_PreProcess_Api_Fetch"] = {
fetchDetailPipePoints: async () => ({
pipe_points: job.pipes.map((pipe) => ({ ...pipe, lonlat: [0, 0] })),
}),
};
STUBS["B06_Section_UI_Standard_Panel"] = {
effectiveStandardCross: () => job.standard,
readRockBoundaryDefault: () => -0.5,
};
const pageMod = load("A00_Common", "design", "design_pipeline_page.ts");
const storeMod = load("A00_Common", "design", "design_store.ts");
const alignment = load("B05_Profile", "logic", "B05_Profile_UI_Profile_Alignment.ts");
const page = load("A00_Common", "b_page_state.ts");
const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
const runs = () => globalThis.__aisloPipeline?.runs ?? [];
/** 묶음이 조용해질 때까지 — 마지막 기록이 끝나고 새 기록이 더 안 생김(고리면 계속 생김). */
async function quiet() {
let seen = -1;
for (let i = 0; i < 400; i += 1) {
await tick(15);
const last = runs()[runs().length - 1];
const count = runs().length;
if (count === seen && (!last || last.outcome !== "running")) return;
seen = count;
}
throw new Error("묶음이 조용해지지 않음");
}
const n = job.nodes.length;
const draftOf = (nodes) => ({
nodes,
curveOn: Array(n).fill(true),
curveRadius: Array(n).fill(null),
curveLock: Array(n).fill(null),
curveArc: Array(n).fill(null),
stationSnap: job.stationSnap,
});
const shift = (index, dx, dy) =>
job.nodes.map((node, i) => (i === index ? [node[0] + dx, node[1] + dy] : node));
const chainagesOf = (stations) => (stations ?? []).map((s) => s.chainageM);
async function openOnce(P) {
window.localStorage.setItem("frd_current_project_id", P);
const savedAlignment = job.detail.longitudinal.profile_alignment;
const savedBase = alignment.toAlignmentBase(savedAlignment);
let detail = job.detail;
const swaps = [];
const grades = [];
const link = {
pipelineSource: () => ({ base: savedBase, edits: savedAlignment.edits, detail, routeId: 7 }),
// 종단도 adoptPipeline → rebuild → pipelineGrade(지금 가게 편집)
adoptPipeline: (base, edits, draft) => {
const now = draft ? edits : savedAlignment.edits;
grades.push(draft);
pageMod.pipelineGrade(P, now);
},
redraw: () => undefined,
side: null,
};
const before = runs().length;
pageMod.routeDraftBridge(P, link, { stationIntervalM: job.interval });
// 종단 보기 · 횡단 보기 고리 — 측점 목록이 다르면 상세를 갈아끼우고(지반 표본 배열은 그대로) render
const stop = storeMod.useDesignStore(P, null).subscribe("stations", (stations) => {
if (!stations?.length) return;
const now = detail.cross_sections.map((s) => s.chainage_m);
const same =
now.length === stations.length &&
stations.every((s, i) => Math.abs(s.chainageM - now[i]) < 1e-6);
if (same) return;
swaps.push(stations.length);
void Promise.resolve().then(() => {
detail = {
...detail,
longitudinal: {
...detail.longitudinal,
stations: stations.map((s) => ({ chainage_m: s.chainageM, kind: s.kind })),
},
cross_sections: stations.map((s) => ({
...(detail.cross_sections.find((c) => Math.abs(c.chainage_m - s.chainageM) < 0.01) ?? {}),
chainage_m: s.chainageM,
})),
};
pageMod.restartPagePipeline(P); // profilePanel.render
pageMod.restartPagePipeline(P); // setIrregularStations
pageMod.pipelineEarthwork(P, { conversion: job.conversion }); // B06 render
});
});
pageMod.pipelineEarthwork(P, { conversion: job.conversion });
pageMod.restartPagePipeline(P); // 첫 render(묶음 준비 전)
await quiet();
const pipe = pageMod.pagePipeline(P);
return { link, pipe, before, swaps, grades, stop, savedAlignment };
}
async function run() {
const P = "proj-349";
const ctx = await openOnce(P);
const { pipe, swaps } = ctx;
const openRuns = runs().slice(ctx.before);
const stations = pipe.output("ground")?.stations ?? [];
const open = {
runs: openRuns.map((r) => ({ sources: r.sources, outcome: r.outcome })),
swaps: swaps.length,
stations: chainagesOf(stations),
saved: job.detail.cross_sections.map((s) => s.chainage_m),
pipeChainages: (pipe.input("pipes") ?? []).map((p) => p.chainage_m),
final: pipe.output("masshaul")?.haulInput?.final_cumulative_m3 ?? null,
footprint: pipe.output("footprint")?.records.length ?? 0,
};
// 노선 꼭짓점 한 번 끌어 놓기
let mark = runs().length;
const dragMark = swaps.length;
const bridge = pageMod.routeDraftBridge(P, ctx.link);
bridge.edited(draftOf(shift(1, 6, -4)));
await quiet();
const drag = {
runs: runs()
.slice(mark)
.map((r) => ({ sources: r.sources, outcome: r.outcome })),
swaps: swaps.length - dragMark,
};
// 되돌리기 한 번(열 때로)
mark = runs().length;
const swapMark = swaps.length;
bridge.edited(null);
await quiet();
const undo = {
runs: runs()
.slice(mark)
.map((r) => ({ sources: r.sources, outcome: r.outcome })),
pipeChainages: (pipe.input("pipes") ?? []).map((p) => p.chainage_m),
alignmentSaved:
JSON.stringify(pipe.input("alignment")) === JSON.stringify(ctx.savedAlignment.edits),
stations: chainagesOf(pipe.output("ground")?.stations),
swapsAfter: swaps.length - swapMark,
};
const blocked = pipe.blockedWrites;
ctx.stop();
pageMod.disposePagePipeline(P);
page.clearDrafts(P);
// 다시 열기 — 같은 입력이면 같은 값
const again = await openOnce("proj-349b");
const reopen = {
runs: runs().slice(again.before).length,
final: again.pipe.output("masshaul")?.haulInput?.final_cumulative_m3 ?? null,
stations: chainagesOf(again.pipe.output("ground")?.stations),
};
again.stop();
pageMod.disposePagePipeline("proj-349b");
return { open, drag, undo, reopen, blocked };
}
run()
.then((out) => {
process.stdout.write(JSON.stringify(out));
process.exit(0);
})
.catch((error) => {
process.stderr.write(String(error && error.stack ? error.stack : error));
process.exit(1);
});