推进 INI 面板 session summary helper
This commit is contained in:
@@ -26,6 +26,11 @@ import {
|
||||
createRunSummary,
|
||||
summarizeRunResult,
|
||||
} from "./run-summary.js";
|
||||
import {
|
||||
createSessionSnapshotSummary,
|
||||
sessionSnapshotMetadataLogLines,
|
||||
sessionSnapshotSummaryLogLines,
|
||||
} from "./session-summary.js";
|
||||
|
||||
const SAMPLE_PATH =
|
||||
"../../../vendor/linuxcnc/configs/sim/axis/vismach/5axis/table-dual-rotary/xyzab-tdr.ini";
|
||||
@@ -343,10 +348,7 @@ function sessionSnapshotMetadata() {
|
||||
}
|
||||
|
||||
function sessionMetadataLogLines(metadata = {}) {
|
||||
return [
|
||||
`Workflow: ${metadata.workflow ?? "-"}`,
|
||||
`Default G-code: ${metadata.defaultGcodeOpfsPath ?? "-"}`,
|
||||
];
|
||||
return sessionSnapshotMetadataLogLines(createSessionSnapshotSummary({ metadata }));
|
||||
}
|
||||
|
||||
function runSessionContextLogLines(program, snapshot = restoredSessionSnapshot) {
|
||||
@@ -576,15 +578,15 @@ document.getElementById("save-session-snapshot").addEventListener("click", async
|
||||
setField("sessionToolTable", snapshot.payload.files.toolTable);
|
||||
setField("sessionGcode", snapshot.payload.files.gcode);
|
||||
setField("sessionSnapshot", sessionSnapshotLabel(UI_SESSION));
|
||||
const summary = createSessionSnapshotSummary(snapshot, sessionSnapshotLabel(UI_SESSION));
|
||||
setLog(
|
||||
[
|
||||
"Saved machine session snapshot to OPFS.",
|
||||
`Snapshot: ${sessionSnapshotLabel(UI_SESSION)}`,
|
||||
...sessionMetadataLogLines(snapshot.metadata),
|
||||
`INI: ${snapshot.payload.files.ini}`,
|
||||
`Parameter file: ${snapshot.payload.files.parameters}`,
|
||||
`Tool table file: ${snapshot.payload.files.toolTable}`,
|
||||
`G-code: ${snapshot.payload.files.gcode}`,
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
`INI: ${summary.iniOpfsPath}`,
|
||||
`Parameter file: ${summary.parameterOpfsPath}`,
|
||||
`Tool table file: ${summary.toolTableOpfsPath}`,
|
||||
`G-code: ${summary.gcodeOpfsPath}`,
|
||||
].join("\n"),
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -595,15 +597,15 @@ document.getElementById("save-session-snapshot").addEventListener("click", async
|
||||
document.getElementById("restore-session-snapshot").addEventListener("click", async () => {
|
||||
try {
|
||||
const snapshot = await restoreSessionSnapshotToEditor();
|
||||
const summary = createSessionSnapshotSummary(snapshot, sessionSnapshotLabel(snapshot.sessionId));
|
||||
setLog(
|
||||
[
|
||||
"Restored machine session snapshot from OPFS.",
|
||||
`Snapshot: ${sessionSnapshotLabel(snapshot.sessionId)}`,
|
||||
...sessionMetadataLogLines(snapshot.metadata),
|
||||
`INI: ${snapshot.payload.files.ini}`,
|
||||
`Parameter file: ${snapshot.payload.files.parameters}`,
|
||||
`Tool table file: ${snapshot.payload.files.toolTable}`,
|
||||
`G-code: ${snapshot.payload.files.gcode ?? "-"}`,
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
`INI: ${summary.iniOpfsPath}`,
|
||||
`Parameter file: ${summary.parameterOpfsPath}`,
|
||||
`Tool table file: ${summary.toolTableOpfsPath}`,
|
||||
`G-code: ${summary.gcodeOpfsPath ?? "-"}`,
|
||||
].join("\n"),
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -634,17 +636,17 @@ document.getElementById("restore-load-session").addEventListener("click", async
|
||||
const snapshot = await restoreSessionSnapshotToEditor();
|
||||
await loadMachineSessionIntoWasm();
|
||||
setField("sessionGcode", snapshot.payload.files.gcode);
|
||||
const summary = createSessionSnapshotSummary(snapshot, sessionSnapshotLabel(snapshot.sessionId));
|
||||
setLog(
|
||||
[
|
||||
"Restored and loaded machine session snapshot.",
|
||||
`Snapshot: ${sessionSnapshotLabel(snapshot.sessionId)}`,
|
||||
...sessionMetadataLogLines(snapshot.metadata),
|
||||
...sessionSnapshotSummaryLogLines(summary),
|
||||
`INI: ${loadedSession.ini.opfsPath} -> ${loadedSession.ini.wasmPath}`,
|
||||
`Parameter file: ${loadedSession.parameters.opfsPath} -> ${loadedSession.parameters.wasmPath}`,
|
||||
`Parameters: ${loadedSession.parameters.result.trim()}`,
|
||||
`Tool table file: ${loadedSession.toolTable.opfsPath} -> ${loadedSession.toolTable.wasmPath}`,
|
||||
`Tool table: ${loadedSession.toolTable.result.trim()}`,
|
||||
`G-code: ${snapshot.payload.files.gcode ?? "-"}`,
|
||||
`G-code: ${summary.gcodeOpfsPath ?? "-"}`,
|
||||
].join("\n"),
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
28
wasm-port/runtime/ui/ini-panel/session-summary.js
Normal file
28
wasm-port/runtime/ui/ini-panel/session-summary.js
Normal file
@@ -0,0 +1,28 @@
|
||||
export function createSessionSnapshotSummary(snapshot, fallbackLabel = null) {
|
||||
const metadata = snapshot?.metadata ?? {};
|
||||
const files = snapshot?.payload?.files ?? {};
|
||||
return {
|
||||
snapshotLabel: fallbackLabel ?? metadata.snapshotLabel ?? null,
|
||||
workflow: metadata.workflow ?? null,
|
||||
defaultGcodeOpfsPath: metadata.defaultGcodeOpfsPath ?? null,
|
||||
iniOpfsPath: files.ini ?? null,
|
||||
parameterOpfsPath: files.parameters ?? null,
|
||||
toolTableOpfsPath: files.toolTable ?? null,
|
||||
gcodeOpfsPath: files.gcode ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
export function sessionSnapshotSummaryLogLines(summary) {
|
||||
return [
|
||||
`Snapshot: ${summary.snapshotLabel ?? "-"}`,
|
||||
`Workflow: ${summary.workflow ?? "-"}`,
|
||||
`Default G-code: ${summary.defaultGcodeOpfsPath ?? "-"}`,
|
||||
];
|
||||
}
|
||||
|
||||
export function sessionSnapshotMetadataLogLines(summary) {
|
||||
return [
|
||||
`Workflow: ${summary.workflow ?? "-"}`,
|
||||
`Default G-code: ${summary.defaultGcodeOpfsPath ?? "-"}`,
|
||||
];
|
||||
}
|
||||
74
wasm-port/tests/ui/node/verify_ini_panel_session_summary.mjs
Normal file
74
wasm-port/tests/ui/node/verify_ini_panel_session_summary.mjs
Normal file
@@ -0,0 +1,74 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
createSessionSnapshotSummary,
|
||||
sessionSnapshotMetadataLogLines,
|
||||
sessionSnapshotSummaryLogLines,
|
||||
} from "../../../runtime/ui/ini-panel/session-summary.js";
|
||||
|
||||
const snapshot = {
|
||||
metadata: {
|
||||
workflow: "save-session-snapshot",
|
||||
snapshotLabel: "ui-machine-session/ui-machine-session.json",
|
||||
defaultGcodeOpfsPath: "linuxcnc/gcode/ui-session.ngc",
|
||||
},
|
||||
payload: {
|
||||
files: {
|
||||
ini: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||
parameters: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
toolTable: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
gcode: "linuxcnc/gcode/ui-session.ngc",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const summary = createSessionSnapshotSummary(snapshot);
|
||||
assert.deepEqual(summary, {
|
||||
snapshotLabel: "ui-machine-session/ui-machine-session.json",
|
||||
workflow: "save-session-snapshot",
|
||||
defaultGcodeOpfsPath: "linuxcnc/gcode/ui-session.ngc",
|
||||
iniOpfsPath: "linuxcnc/machines/xyzab-tdr/machine.ini",
|
||||
parameterOpfsPath: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
toolTableOpfsPath: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
gcodeOpfsPath: "linuxcnc/gcode/ui-session.ngc",
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
createSessionSnapshotSummary(snapshot, "override-session/override.json"),
|
||||
{
|
||||
...summary,
|
||||
snapshotLabel: "override-session/override.json",
|
||||
},
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
sessionSnapshotSummaryLogLines(summary),
|
||||
[
|
||||
"Snapshot: ui-machine-session/ui-machine-session.json",
|
||||
"Workflow: save-session-snapshot",
|
||||
"Default G-code: linuxcnc/gcode/ui-session.ngc",
|
||||
],
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
sessionSnapshotMetadataLogLines(summary),
|
||||
[
|
||||
"Workflow: save-session-snapshot",
|
||||
"Default G-code: linuxcnc/gcode/ui-session.ngc",
|
||||
],
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
createSessionSnapshotSummary(null),
|
||||
{
|
||||
snapshotLabel: null,
|
||||
workflow: null,
|
||||
defaultGcodeOpfsPath: null,
|
||||
iniOpfsPath: null,
|
||||
parameterOpfsPath: null,
|
||||
toolTableOpfsPath: null,
|
||||
gcodeOpfsPath: null,
|
||||
},
|
||||
);
|
||||
|
||||
console.log("ini_panel_session_summary_node_smoke=ok");
|
||||
6
wasm-port/tests/ui/node/verify_ini_panel_session_summary.sh
Executable file
6
wasm-port/tests/ui/node/verify_ini_panel_session_summary.sh
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
|
||||
|
||||
node "$ROOT_DIR/tests/ui/node/verify_ini_panel_session_summary.mjs"
|
||||
@@ -4,5 +4,6 @@ set -euo pipefail
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
|
||||
|
||||
"$ROOT_DIR/tests/ui/node/verify_ini_panel_run_summary.sh"
|
||||
"$ROOT_DIR/tests/ui/node/verify_ini_panel_session_summary.sh"
|
||||
|
||||
echo "ui_node_smokes=ok"
|
||||
|
||||
Reference in New Issue
Block a user