Files
Aislo/resources/tester/helper_349_pipeline_once.cjs
T
eomsangdonandClaude Opus 5.5 7cc5c9ee91 test(508-1a): 늘 빨간 시험 16 가림 — 233_4 짝 본문 찾기 · 349 계열 기다림 · 낡은 기대 고침 · xfail = 제품 흠 둘만 · 309-2 화면 시험 로그 행 지움 · 포트 = 이 폴더 줄
- 233_4 다섯: 500-2 누름 잡는 단계(capture) 본문 찾기
- 0d: 410 좌표 낡음 판정 — 가짜 구조물 정수 측점 · 그 측점을 낳는 옆 좌표
- 0l · 0s · 0q · 0o 되돌리기: 472-5 덧 그리기 멈춤 풀림(pipelineHolding)까지 기다림
- pipeline_once: 77be773c0 상세 가게 칸 채움(keepSavedDetail)
- 0u: 저장 곡선 반지름 초안 · 끈 꼭짓점 다음 꺾임점 기준
- 남은 xfail 둘(0o 끌기 · 횡단 보기 진입) = cross 군더더기 차례 제품 흠(a02367e61)
- 309-2 화면: 표식 user_agent 로그 행 지움 · 포트 = OWNERS.md 이 폴더 줄(다른 폴더 사본이 8004 판을 고치던 흠)

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

263 lines
9.9 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 finalCumulative = require("./helper_454_final_cumulative.cjs");
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");
// 상세 가게 칸(472-5) — 실제는 상세 가게가 받을 때 채움 · 여기선 종단도가 내주는 저장 상세 그대로(갈아끼움 제외)
const slots = load("B06_Section", "B06_Section_Section_Canon.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;
slots.keepSavedDetail(P, 7, 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: finalCumulative(load, pipe, job.conversion),
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: finalCumulative(load, again.pipe, job.conversion),
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);
});