推进 INI 面板 shell integration browser workflow smoke

This commit is contained in:
2026-06-15 07:54:19 +08:00
parent 1f9a8c33b0
commit a663c8dbca
5 changed files with 291 additions and 0 deletions

View File

@@ -0,0 +1,181 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LinuxCNC INI Shell Integration Workflow Smoke</title>
</head>
<body>
<pre id="status">running</pre>
<script type="module">
function assertEqual(actual, expected, label) {
if (actual !== expected) {
throw new Error(`${label}: expected ${expected}, got ${actual}`);
}
}
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function waitFor(predicate, label) {
const deadline = performance.now() + 10000;
while (performance.now() < deadline) {
const value = predicate();
if (value) {
return value;
}
await delay(50);
}
throw new Error(`Timed out waiting for ${label}`);
}
async function loadFrame(src) {
const frame = document.createElement("iframe");
frame.src = src;
document.body.appendChild(frame);
await new Promise((resolve, reject) => {
frame.addEventListener("load", resolve, { once: true });
frame.addEventListener("error", reject, { once: true });
});
return frame.contentDocument;
}
try {
const iniText = `[EMC]
MACHINE = browser-shell-integration
[TRAJ]
LINEAR_UNITS = mm
COORDINATES = X Y Z
[KINS]
KINEMATICS = trivkins
JOINTS = 3
[RS274NGC]
PARAMETER_FILE = browser-shell-linuxcnc.var
[EMCIO]
TOOL_TABLE = browser-shell-tool.tbl
`;
const launchDoc = await loadFrame("../../runtime/ui/ini-panel/launch.html");
const launchApi = launchDoc.defaultView.linuxCncIniPanelLaunchApi;
if (
!launchApi?.getShellIntegrationManifest ||
!launchApi?.getShellIntegrationReadiness
) {
throw new Error("launch API namespace did not expose shell integration helpers");
}
const integrationManifest = launchApi.getShellIntegrationManifest();
const readiness = launchApi.getShellIntegrationReadiness();
assertEqual(readiness.phase, "ready", "shell integration readiness phase");
assertEqual(readiness.ready, true, "shell integration readiness");
assertEqual(readiness.missing.join(","), "", "shell integration readiness missing checks");
assertEqual(readiness.apiNames.launch, "ini-panel-launch", "shell integration launch API name");
assertEqual(
readiness.apiNames.controlPage,
"ini-panel-control-page",
"shell integration control-page API name",
);
assertEqual(
integrationManifest.compatibility.launchApiManifest,
true,
"shell integration launch compatibility",
);
assertEqual(
integrationManifest.compatibility.controlPageApiManifest,
true,
"shell integration control-page compatibility",
);
const controlTarget = integrationManifest.launchApiManifest.targetPages.find(
(page) => page.entryId === "control-view",
);
assertEqual(controlTarget.href, "./control-page.html", "shell integration control target");
const controlDoc = await loadFrame(`../../runtime/ui/ini-panel/${controlTarget.href.slice(2)}`);
const controlPageApi = controlDoc.defaultView.linuxCncIniPanelControlPageApi;
if (
!controlPageApi?.getControlPageApiManifest ||
!controlPageApi?.readControlPageStatus ||
!controlPageApi?.loadControlPageSessionState
) {
throw new Error("control page API namespace did not expose readonly helpers");
}
assertEqual(
controlPageApi.getControlPageApiManifest().apiName,
integrationManifest.controlPageApiManifest.apiName,
"shell integration control manifest handoff",
);
const panelFrame = controlDoc.getElementById("panel-frame");
const panelDoc = await waitFor(
() => panelFrame?.contentDocument,
"embedded INI panel frame",
);
await waitFor(
() => panelDoc.defaultView?.linuxCncIniPanelApi?.getMachineSessionControlView?.(),
"embedded INI panel API",
);
assertEqual(
controlPageApi.loadControlPageSessionState().phase,
"ready",
"shell integration control-page session readiness",
);
assertEqual(
controlPageApi.readControlPageStatus().status.lastAction,
null,
"shell integration initial readonly status",
);
panelDoc.getElementById("ini-editor").value = iniText;
panelDoc.getElementById("query").click();
await waitFor(
() => panelDoc.getElementById("field-parameter-file")?.textContent.includes("browser-shell-linuxcnc.var"),
"shell integration query",
);
panelDoc.getElementById("save-machine-files").click();
await waitFor(
() => panelDoc.getElementById("log")?.textContent.includes("Saved machine text files"),
"shell integration save machine files",
);
panelDoc.getElementById("load-session").click();
await waitFor(
() => panelDoc.getElementById("log")?.textContent.includes("Loaded machine session"),
"shell integration load session",
);
const readonlyStatus = controlPageApi.readControlPageStatus();
assertEqual(
readonlyStatus.workflowStatus.lastAction,
"load-session",
"shell integration readonly workflow last action",
);
assertEqual(
readonlyStatus.session.parameterFile,
"browser-shell-linuxcnc.var",
"shell integration readonly session parameter file",
);
assertEqual(
readonlyStatus.stateBundle.report.readiness.toolTable,
"browser-shell-tool.tbl",
"shell integration readonly state bundle tool table",
);
assertEqual(
controlDoc.getElementById("control-page-status").textContent,
"load-session | not-run | -",
"shell integration control-page DOM status",
);
status.textContent = "browser_ini_shell_integration_workflow_smoke=ok";
console.log("browser_ini_shell_integration_workflow_smoke=ok");
} catch (error) {
status.textContent = `browser_ini_shell_integration_workflow_smoke=failed: ${error.message}`;
console.error(error);
throw error;
}
</script>
</body>
</html>

View File

@@ -63,9 +63,11 @@ PORT="$(cat "$PORT_FILE")"
URL="http://127.0.0.1:$PORT/tests/browser/ini_panel_smoke.html"
CONTROL_URL="http://127.0.0.1:$PORT/tests/browser/ini_panel_control_page_smoke.html"
LAUNCH_URL="http://127.0.0.1:$PORT/tests/browser/ini_panel_launch_smoke.html"
SHELL_INTEGRATION_URL="http://127.0.0.1:$PORT/tests/browser/ini_panel_shell_integration_workflow_smoke.html"
OUT="$TMP_DIR/chromium.out"
CONTROL_OUT="$TMP_DIR/chromium-control.out"
LAUNCH_OUT="$TMP_DIR/chromium-launch.out"
SHELL_INTEGRATION_OUT="$TMP_DIR/chromium-shell-integration.out"
"$CHROMIUM" \
--headless=new \
@@ -117,3 +119,20 @@ if ! grep -Fq "browser_ini_launch_smoke=ok" "$LAUNCH_OUT"; then
fi
echo "browser_ini_launch_smoke=ok"
"$CHROMIUM" \
--headless=new \
--disable-gpu \
--no-sandbox \
--user-data-dir="$CHROME_PROFILE" \
--virtual-time-budget=10000 \
--dump-dom \
"$SHELL_INTEGRATION_URL" >"$SHELL_INTEGRATION_OUT" 2>&1
if ! grep -Fq "browser_ini_shell_integration_workflow_smoke=ok" "$SHELL_INTEGRATION_OUT"; then
echo "browser INI shell integration workflow smoke failed" >&2
sed -n '1,220p' "$SHELL_INTEGRATION_OUT" >&2
exit 1
fi
echo "browser_ini_shell_integration_workflow_smoke=ok"