import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { preflightHalConfiguration } from "../workspace/hal-configuration.mjs"; import { parseIni } from "../workspace/ini-parser.mjs"; import { WorkspaceRuntime } from "../workspace/runtime.mjs"; import { loadSimulationCase } from "../workspace/sim-case-loader.mjs"; import { startConfiguration } from "../workspace/configuration-startup.mjs"; const CASE = "linuxcnc/configs/sim/axis/vismach/3axis-tutorial/3axis-tutorial.ini"; const HAL = "linuxcnc/configs/sim/axis/vismach/3axis-tutorial/3axis-tutorial.hal"; const fetchImpl = async (url) => { try { const body = await readFile(new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url)); return { ok: true, text: async () => body.toString("utf8") }; } catch { return { ok: false, text: async () => "" }; } }; const bundle = await loadSimulationCase({ path: CASE, fetchImpl }); assert.equal(bundle.status, "ready"); const workspace = new WorkspaceRuntime({ files: bundle.files }); const ini = parseIni({ workspace, entrypoint: CASE }); const lines = workspace.read(`/workspace/${HAL}`).split(/\r?\n/); const manifest = bundle.halManifest; const preflight = preflightHalConfiguration({ lines, variables: ini.sections, manifest, webEquivalentPrograms: ["./3axis-tutorial"] }); assert.equal(preflight.status, "ready"); assert.equal(preflight.blocked_count, 0); const model = preflight.records.find((row) => row.command === "loadusr" && row.program === "./3axis-tutorial"); assert.equal(model.capability, "WEB-EQUIV"); assert.equal(preflight.records.filter((row) => row.command === "loadrt").map((row) => row.module).join(","), "trivkins,motmod,ddt,hypot"); assert.equal(preflight.records.filter((row) => row.command === "net").length, 21); const startup = startConfiguration({ workspace, entrypoint: CASE, core: { _sim_create() { return 0; }, _sim_load_workspace() { return 0; } }, halManifest: manifest }); assert.equal(startup.status, "ready"); assert.equal(startup.hal.blocked_count, 0); assert.ok(startup.hal.records.some((row) => row.program === "./3axis-tutorial" && row.capability === "WEB-EQUIV")); console.log(JSON.stringify({ schema: "axis3-tutorial-hal-adapter.v1", status: "verified", case: CASE, hal: { record_count: preflight.record_count, loadrt: preflight.records.filter((row) => row.command === "loadrt").map((row) => row.module), net_count: preflight.records.filter((row) => row.command === "net").length, web_equivalent: model.program, capability: model.capability }, startup: { state: startup.state, hal_blocked: startup.hal.blocked_count, state_hash: startup.state_hash } }));