mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-04 02:38:05 -05:00
The sweep made a fresh data folder for every test, copying all of Bambu Lab's profiles each time, left tens of gigabytes of run folders behind, and failed outright on a test that only failed while other tests loaded the machine. Each job now keeps one data folder for all its tests, seeded with the Generic Klipper Printer as a person's folder carries over from day to day; a test that fails beside others runs again alone and is remembered as one to run alone; and a passing test's folder is deleted as soon as it passes.
134 lines
6.2 KiB
Python
Executable File
134 lines
6.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Checks where webview_run_javascript runs while a modal dialog is open, where a script cannot look.
|
|
|
|
tools/mcp/orca_mcp.py launch
|
|
tools/mcp/test_webview_modal.py
|
|
|
|
Scripts run in the web view of the topmost modal dialog, whichever dialog it is (the preset bundle
|
|
dialog, by default and by locator, the export bundle dialog above it, the Flushing volumes dialog, each
|
|
known by its page's URL or title);
|
|
the Home tab's web view behind a modal is refused, so is the bundle dialog's own web view once the
|
|
export bundle dialog is above it. A page that closes its dialog replies closed at once, not after the
|
|
timeout. Without a modal, the Home tab's web view still takes scripts, known by its page's URL, since a plugin an
|
|
earlier test left may add web views of its own. The test starts on the Generic Klipper Printer 0.4 nozzle, whose
|
|
sidebar offers Flushing volumes once a second filament is added. Exits 0 when every check passes.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import orca_mcp # noqa: E402
|
|
from checks import GENERIC_PLA, KLIPPER, KLIPPER_STD, start # noqa: E402
|
|
|
|
|
|
def main():
|
|
client, _session = orca_mcp.session_client()
|
|
checks = []
|
|
|
|
def check(name, ok, detail=""):
|
|
checks.append((name, bool(ok), detail))
|
|
|
|
def refusal(**args):
|
|
try:
|
|
client.call("webview_run_javascript", **args)
|
|
return ""
|
|
except orca_mcp.McpError as e:
|
|
return str(e)
|
|
|
|
def dialogs():
|
|
return [d["title"] for d in client.call("app_state")["dialogs"]]
|
|
|
|
def wait_dialogs(count):
|
|
for _ in range(100):
|
|
if len(dialogs()) == count:
|
|
return True
|
|
time.sleep(0.1)
|
|
return False
|
|
|
|
def home_webview():
|
|
snap, texts = client.call_with_text("widget_list", target="main", query="webview")
|
|
for line in (texts[0] if texts else "").splitlines():
|
|
if "webview" in line and "[" in line:
|
|
return line.split("[", 1)[1].split("]", 1)[0]
|
|
return None
|
|
|
|
started = start(client)
|
|
check("start: the Klipper printer with its default process and filament",
|
|
started == {"printer": KLIPPER, "process": KLIPPER_STD, "filaments": [GENERIC_PLA]}, started)
|
|
|
|
# ---- The Home tab's web view, without and with a modal open ----
|
|
client.call("view_set", tab="home")
|
|
home = home_webview()
|
|
check("the Home tab shows a web view", home is not None)
|
|
try:
|
|
reply = client.call("webview_run_javascript", code="1 + 1")
|
|
except orca_mcp.McpError as e:
|
|
reply = {"error": str(e)}
|
|
check("without a modal, the Home page takes a script",
|
|
reply.get("result") == 2 and "web/homepage/index.html" in reply.get("url", ""), reply)
|
|
bundle = client.call("action_run", id="orca_command:preset_bundle:orca")
|
|
check("the bundle dialog opens", wait_dialogs(1), dialogs())
|
|
message = refusal(code="1", target=home)
|
|
check("a web view behind the modal is refused", "modal dialog is open" in message, message)
|
|
check("the bundle dialog's page takes a script", client.call("webview_run_javascript", code="document.title")["result"] == "Preset Bundle")
|
|
found = client.call("webview_run_javascript", code="!!document.getElementById('close_btn')",
|
|
target={"class": "webview", "within": "Preset Bundle"})["result"]
|
|
check("and takes one by locator", found is True, found)
|
|
|
|
# ---- A bundle dialog under the export bundle dialog ----
|
|
client.call("webview_run_javascript", code="SendWXMessage(JSON.stringify({command: 'export_page'}))")
|
|
check("the export bundle dialog opens above it", wait_dialogs(2), dialogs())
|
|
# Its web view shows about:blank until its first navigation starts.
|
|
for _ in range(50):
|
|
if "ExportPresetDialog" in client.call_with_text("widget_list", target="dialog", query="webview")[1][0]:
|
|
break
|
|
time.sleep(0.1)
|
|
message = refusal(code="1", target={"class": "webview", "within": "Preset Bundle"})
|
|
check("the dialog under the topmost is refused", "is under" in message, message)
|
|
url = client.call("webview_run_javascript", code="1")["url"]
|
|
check("without a target the topmost dialog's page is used", "ExportPresetDialog" in url, url)
|
|
client.call("dialog_answer", button="close")
|
|
check("the export dialog closes", wait_dialogs(1), dialogs())
|
|
|
|
# ---- A page that closes its dialog replies at once ----
|
|
began = time.time()
|
|
reply = client.call("webview_run_javascript", code="document.getElementById('close_btn').click()")
|
|
elapsed = time.time() - began
|
|
check("closing the dialog from its page replies closed", reply.get("closed") is True, reply)
|
|
check("and does so within a second", elapsed < 1.0, f"{elapsed:.2f} s")
|
|
client.await_job(bundle)
|
|
check("no dialog is left", wait_dialogs(0), dialogs())
|
|
|
|
# ---- The Flushing volumes dialog takes scripts as any topmost dialog does ----
|
|
client.call("view_set", tab="prepare")
|
|
client.call("widget_click", target={"label": "Add one filament"})
|
|
flush = client.call("widget_click", target={"label": "Flushing volumes"})
|
|
check("the Flushing volumes dialog opens",
|
|
wait_dialogs(1) and dialogs() == ["Flushing volumes for filament change"], dialogs())
|
|
# Its web view, too, shows about:blank until its first navigation starts.
|
|
for _ in range(50):
|
|
if "WipingDialog.html" in client.call_with_text("widget_list", target="dialog", query="webview")[1][0]:
|
|
break
|
|
time.sleep(0.1)
|
|
try:
|
|
reply = client.call("webview_run_javascript", code="typeof document.title")
|
|
except orca_mcp.McpError as e:
|
|
reply = {"error": str(e)}
|
|
check("its page takes a script",
|
|
reply.get("result") == "string" and "web/flush/WipingDialog.html" in reply.get("url", ""), reply)
|
|
client.call("dialog_answer", button="close")
|
|
client.await_job(flush)
|
|
check("no dialog is left at the end", wait_dialogs(0), dialogs())
|
|
|
|
failed = [c for c in checks if not c[1]]
|
|
for name, ok, detail in checks:
|
|
print(("PASS " if ok else "FAIL ") + name + ("" if ok or detail == "" else f": {detail}"))
|
|
print(f"{len(checks) - len(failed)}/{len(checks)} checks passed")
|
|
return 1 if failed else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|