49 lines
3.5 KiB
JavaScript
49 lines
3.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import { loadSimulationCase, toWorkerConfiguration } from "./sim-case-loader.mjs";
|
|
|
|
const fetchImpl = async (url) => {
|
|
const path = new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url);
|
|
try {
|
|
const body = await readFile(path);
|
|
return { ok: true, text: async () => body.toString("utf8") };
|
|
} catch {
|
|
return { ok: false, text: async () => "" };
|
|
}
|
|
};
|
|
|
|
const ready = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/corexy/corexy_by_hal.ini", fetchImpl });
|
|
assert.equal(ready.status, "ready");
|
|
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/corexy_base.inc"]);
|
|
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/3joint_xyz.hal"]);
|
|
assert.ok(ready.files["linuxcnc/configs/sim/axis/corexy/corexy_by_hal.hal"]);
|
|
assert.equal(toWorkerConfiguration(ready).entrypoint, ready.entrypoint);
|
|
assert.match(ready.state_hash, /^fnv1a64:/);
|
|
|
|
const blocked = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/ini_with_includes/includes_demo.ini", fetchImpl });
|
|
assert.equal(blocked.status, "blocked");
|
|
assert.ok(blocked.missing.includes("linuxcnc/configs/sim/axis/ini_with_includes/nosuchfile"));
|
|
assert.notEqual(blocked.catalog.status, "ready");
|
|
assert.equal((await loadSimulationCase({ path: ready.entrypoint, fetchImpl })).state_hash, ready.state_hash);
|
|
assert.equal(Object.hasOwn(ready.files, "linuxcnc/configs/sim/axis/corexy/linuxcnc.var"), true);
|
|
assert.equal(Object.hasOwn(ready.files, "linuxcnc/configs/sim/axis/corexy/tool.tbl"), true);
|
|
assert.equal(ready.files["linuxcnc/configs/sim/axis/corexy/linuxcnc.var"], "");
|
|
assert.equal(ready.files["linuxcnc/configs/sim/axis/corexy/tool.tbl"], "");
|
|
assert.deepEqual(ready.runtime_fixtures.filter((row) => row.resource_path?.includes("corexy/")).map((row) => row.kind).sort(), ["parameter_file", "tool_table"]);
|
|
const runtimeGenerated = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/lathe.ini", fetchImpl });
|
|
assert.equal(runtimeGenerated.status, "ready");
|
|
assert.equal(runtimeGenerated.missing.length, 0);
|
|
assert.equal(runtimeGenerated.files["linuxcnc/configs/sim/axis/sim-lathe.var"], "");
|
|
assert.ok(runtimeGenerated.runtime_fixtures.some((row) => row.kind === "parameter_file"));
|
|
const optionalGraphic = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini", fetchImpl });
|
|
assert.equal(optionalGraphic.status, "ready");
|
|
assert.ok(optionalGraphic.optional_missing.some((row) => row.path.endsWith("/emc2.gif")));
|
|
const emptyOpenFile = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/anglejog/anglejog.ini", fetchImpl });
|
|
assert.equal(emptyOpenFile.status, "ready");
|
|
assert.equal(emptyOpenFile.missing.includes("linuxcnc/configs/sim/axis/anglejog"), false);
|
|
const optionalOpenFile = await loadSimulationCase({ path: "linuxcnc/configs/sim/axis/lathe_multispindle/lathe.ini", fetchImpl });
|
|
assert.equal(optionalOpenFile.status, "ready");
|
|
assert.equal(optionalOpenFile.missing.some((path) => path.endsWith("lathe_pawn.ngc")), false);
|
|
assert.ok(optionalOpenFile.optional_missing.some((row) => row.path.endsWith("examples/lathe_pawn.ngc")));
|
|
console.log(JSON.stringify({ schema: "simulation-case-loader-sample.v1", status: "verified", case: { entrypoint: ready.entrypoint, files: ready.fetched.length, missing: ready.missing.length, state_hash: ready.state_hash }, blocked: { entrypoint: blocked.entrypoint, missing: blocked.missing.length, state_hash: blocked.state_hash } }));
|