推进 INI 面板 machine session state report helper

This commit is contained in:
2026-06-14 21:53:36 +08:00
parent 7d57bce5de
commit e80ecd4b7a
4 changed files with 209 additions and 0 deletions

View File

@@ -62,6 +62,25 @@ The INI panel updates this state after save, restore, load, run, and error
paths so browser tests and future API consumers can read one machine-readable
state object instead of collecting DOM fields and log text.
## `createMachineSessionStateReport(state)`
This helper converts the richer state snapshot into a stable consumer report
with four sections:
```js
{
readiness: { ini: "...", interp: "...", opfs: "..." },
session: { snapshotLabel: "...", workflow: "...", ini: "...", parameters: "...", toolTable: "...", gcode: "..." },
loaded: { iniWasmPath: "...", parameterWasmPath: "...", toolTableWasmPath: "..." },
program: { source: "snapshot", opfsPath: "...", wasmPath: "..." },
run: { status: "ok", canonicalEventCount: 2, motionSnapshotCount: 2, iniWasmPath: "..." },
status: { lastAction: "run-gcode", error: null, fiveaxisRemap: "ok" }
}
```
The report is intended for upper-level UI consumers or export paths that want a
stable summary shape without touching DOM nodes.
## Boundary Rules
- Do not parse G-code text in this helper.

View File

@@ -63,3 +63,48 @@ export function createMachineSessionStateSnapshot({
error: error ?? null,
};
}
export function createMachineSessionStateReport(state = {}) {
const badges = state.badges ?? {};
const fields = state.fields ?? {};
const sessionSnapshot = state.sessionSnapshot ?? {};
const sessionLoad = state.sessionLoad ?? {};
const selectedProgram = state.selectedProgram ?? {};
const run = state.run ?? {};
return {
readiness: {
ini: badges.ini ?? null,
interp: badges.interp ?? null,
opfs: badges.opfs ?? null,
},
session: {
snapshotLabel: sessionSnapshot.snapshotLabel ?? fields.sessionSnapshot ?? null,
workflow: sessionSnapshot.workflow ?? fields.runWorkflow ?? null,
ini: fields.sessionIni ?? sessionSnapshot.iniOpfsPath ?? sessionLoad.iniWasmPath ?? null,
parameters: fields.sessionParameters ?? sessionSnapshot.parameterOpfsPath ?? sessionLoad.parameterWasmPath ?? null,
toolTable: fields.sessionToolTable ?? sessionSnapshot.toolTableOpfsPath ?? sessionLoad.toolTableWasmPath ?? null,
gcode: fields.sessionGcode ?? sessionSnapshot.gcodeOpfsPath ?? null,
},
loaded: {
iniWasmPath: sessionLoad.iniWasmPath ?? null,
parameterWasmPath: sessionLoad.parameterWasmPath ?? null,
toolTableWasmPath: sessionLoad.toolTableWasmPath ?? null,
},
program: {
source: selectedProgram.source ?? run.programSource ?? fields.runSource ?? null,
opfsPath: selectedProgram.opfsPath ?? run.programOpfsPath ?? fields.runOpfsPath ?? null,
wasmPath: selectedProgram.wasmPath ?? run.programWasmPath ?? fields.runWasmPath ?? null,
},
run: {
status: run.runStatus ?? fields.runStatus ?? null,
canonicalEventCount: run.canonicalEventCount ?? 0,
motionSnapshotCount: run.motionSnapshotCount ?? 0,
iniWasmPath: run.iniWasmPath ?? null,
},
status: {
lastAction: state.lastAction ?? null,
error: state.error ?? null,
fiveaxisRemap: state.fiveaxisRemap ?? null,
},
};
}

View File

@@ -3,6 +3,7 @@ import assert from "node:assert/strict";
import {
createIniPanelStateSummary,
createMachineSessionStateSnapshot,
createMachineSessionStateReport,
} from "../../../runtime/ui/ini-panel/panel-state-summary.js";
const summary = createIniPanelStateSummary({
@@ -186,4 +187,85 @@ assert.deepEqual(
},
);
assert.deepEqual(
createMachineSessionStateReport({
badges: {
ini: "INI WASM: ready",
interp: "Interpreter WASM: ready",
opfs: "OPFS: ready",
},
fields: {
sessionSnapshot: "ui-machine-session/ui-machine-session.json",
sessionIni: "/work/session-machine.ini",
sessionParameters: "/work/session-linuxcnc.var",
sessionToolTable: "/work/session-tool.tbl",
sessionGcode: "linuxcnc/gcode/ui-session.ngc",
runStatus: "ok",
runSource: "snapshot",
runSnapshot: "ui-machine-session/ui-machine-session.json",
runWorkflow: "save-session-snapshot",
runOpfsPath: "linuxcnc/gcode/ui-session.ngc",
runWasmPath: "/work/ui-session.ngc",
},
sessionLoad: {
iniWasmPath: "/work/session-machine.ini",
parameterWasmPath: "/work/session-linuxcnc.var",
toolTableWasmPath: "/work/session-tool.tbl",
},
selectedProgram: {
source: "snapshot",
opfsPath: "linuxcnc/gcode/ui-session.ngc",
wasmPath: "/work/ui-session.ngc",
},
run: {
runStatus: "ok",
programSource: "snapshot",
programOpfsPath: "linuxcnc/gcode/ui-session.ngc",
programWasmPath: "/work/ui-session.ngc",
iniWasmPath: "/work/session-machine.ini",
canonicalEventCount: 2,
motionSnapshotCount: 2,
},
lastAction: "run-gcode",
error: null,
fiveaxisRemap: "ok",
}),
{
readiness: {
ini: "INI WASM: ready",
interp: "Interpreter WASM: ready",
opfs: "OPFS: ready",
},
session: {
snapshotLabel: "ui-machine-session/ui-machine-session.json",
workflow: "save-session-snapshot",
ini: "/work/session-machine.ini",
parameters: "/work/session-linuxcnc.var",
toolTable: "/work/session-tool.tbl",
gcode: "linuxcnc/gcode/ui-session.ngc",
},
loaded: {
iniWasmPath: "/work/session-machine.ini",
parameterWasmPath: "/work/session-linuxcnc.var",
toolTableWasmPath: "/work/session-tool.tbl",
},
program: {
source: "snapshot",
opfsPath: "linuxcnc/gcode/ui-session.ngc",
wasmPath: "/work/ui-session.ngc",
},
run: {
status: "ok",
canonicalEventCount: 2,
motionSnapshotCount: 2,
iniWasmPath: "/work/session-machine.ini",
},
status: {
lastAction: "run-gcode",
error: null,
fiveaxisRemap: "ok",
},
},
);
console.log("ini_panel_state_summary_node_smoke=ok");