收敛 INI 面板状态 API namespace

This commit is contained in:
2026-06-14 22:23:02 +08:00
parent 25268404cb
commit a1c34e454e
5 changed files with 105 additions and 6 deletions

View File

@@ -12,8 +12,11 @@ state so browser tests or future UI consumers can compare panel state without
reading ad hoc DOM text.
Upper-level UI/API consumers should read `createMachineSessionStateReport(...)`
or `window.getMachineSessionStateReport()` rather than scraping DOM nodes or
depending on `window.linuxCncIniPanelMachineSessionState` directly.
or `window.linuxCncIniPanelApi.getMachineSessionStateReport()` rather than
scraping DOM nodes or depending on `window.linuxCncIniPanelMachineSessionState`
directly. The legacy `window.getMachineSessionStateReport()` and
`window.getMachineSessionStateReportExport()` globals remain as compatibility
shims.
## `createIniPanelStateSummary(input)`

View File

@@ -174,6 +174,10 @@ function updatePanelMachineSessionState(patch = {}) {
return panelMachineSessionState;
}
window.linuxCncIniPanelApi = {
getMachineSessionStateReport,
getMachineSessionStateReportExport,
};
window.getMachineSessionStateReport = getMachineSessionStateReport;
window.getMachineSessionStateReportExport = getMachineSessionStateReportExport;
window.linuxCncIniPanelMachineSessionState = panelMachineSessionState;

View File

@@ -367,6 +367,10 @@ TOOL_TABLE = browser-tool.tbl
() => uiDocument.getElementById("opfs-badge")?.textContent.includes("ready"),
"INI panel OPFS readiness",
);
const uiApi = uiDocument.defaultView.linuxCncIniPanelApi;
if (!uiApi?.getMachineSessionStateReport || !uiApi?.getMachineSessionStateReportExport) {
throw new Error("INI panel API namespace did not expose state report getters");
}
uiDocument.getElementById("ini-editor").value = iniText;
uiDocument.getElementById("query").click();
@@ -493,7 +497,7 @@ TOOL_TABLE = browser-tool.tbl
) {
throw new Error(`UI saved snapshot log missing metadata summary: ${savedSnapshotLog}`);
}
const savedMachineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
const savedMachineSessionStateReport = uiApi.getMachineSessionStateReport();
assertEqual(
savedMachineSessionStateReport.session.snapshotLabel,
"ui-machine-session/ui-machine-session.json",
@@ -588,7 +592,7 @@ TOOL_TABLE = browser-tool.tbl
) {
throw new Error(`UI restore/load session log missing OPFS default file mapping: ${uiLog}`);
}
const restoredLoadedMachineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
const restoredLoadedMachineSessionStateReport = uiApi.getMachineSessionStateReport();
assertEqual(
restoredLoadedMachineSessionStateReport.session.snapshotLabel,
"ui-machine-session/ui-machine-session.json",
@@ -697,7 +701,7 @@ TOOL_TABLE = browser-tool.tbl
2,
"UI snapshot run summary motion snapshot count",
);
const machineSessionStateReport = uiDocument.defaultView.getMachineSessionStateReport();
const machineSessionStateReport = uiApi.getMachineSessionStateReport();
assertEqual(
machineSessionStateReport.status.lastAction,
"run-gcode",
@@ -743,7 +747,7 @@ TOOL_TABLE = browser-tool.tbl
2,
"UI machine session state report motion snapshot count",
);
const machineSessionStateReportExport = uiDocument.defaultView.getMachineSessionStateReportExport();
const machineSessionStateReportExport = uiApi.getMachineSessionStateReportExport();
assertEqual(
machineSessionStateReportExport.filename,
"machine-session-state-report.json",
@@ -769,6 +773,16 @@ TOOL_TABLE = browser-tool.tbl
"snapshot",
"UI machine session state report export program source",
);
assertEqual(
uiDocument.defaultView.getMachineSessionStateReport().status.lastAction,
machineSessionStateReport.status.lastAction,
"UI legacy machine session state report getter matches API namespace",
);
assertEqual(
uiDocument.defaultView.getMachineSessionStateReportExport().text,
machineSessionStateReportExport.text,
"UI legacy machine session state report export getter matches API namespace",
);
if (
!runLog.includes("canon_event=STRAIGHT_TRAVERSE") ||
!runLog.includes("canon_event=STRAIGHT_FEED")

View File

@@ -330,4 +330,15 @@ assert.deepEqual(
},
);
assert.deepEqual(
{
getMachineSessionStateReport: typeof globalThis.window?.linuxCncIniPanelApi?.getMachineSessionStateReport,
getMachineSessionStateReportExport: typeof globalThis.window?.linuxCncIniPanelApi?.getMachineSessionStateReportExport,
},
{
getMachineSessionStateReport: "undefined",
getMachineSessionStateReportExport: "undefined",
},
);
console.log("ini_panel_state_summary_node_smoke=ok");