Files
Comfy-Org-ComfyUI-Manager/tests/test_update_result_rendering.py
Dr.Lt.Data 307bec483e Enable a disabled node pack requested through cm-api before restarting (#3525)
When an extension asks through cm.try-install-custom-node for a node
pack that is disabled, the user is asked whether to enable it and
restart. On confirmation the handler posted to
/customnode/toggle_active, which the server does not have, did not
look at the answer, and restarted: ComfyUI came back with the pack
still disabled.

- Enable the pack as the Custom Nodes Manager does: find its row in
  /customnode/getlist, put it in the queue, start the queue, and wait
  for the queue to report the pack
- Restart only when the queue reports success; otherwise show why the
  pack was not enabled
- Leave a queue that is already running alone
- End the wait when the started queue reports without the pack, or
  does not report within a minute; a listener left waiting would take
  a later report for the same row and restart ComfyUI unasked
- Show the reason when a request made while enabling gets no answer
- Show "Rebooting..." when the restart request gets no answer, which
  is what happens when ComfyUI restarts
- Remove the branch for a pack that is not installed: the server does
  not send this request for one, and the route it posted to does not
  exist
- Leave the queue listener of the Manager menu when the menu has not
  been created; a queue started from here made it raise
- Add browser tests of the handler and of the menu listener
- Add a CHANGELOG entry

The same change for manager-v4 is #3526.
2026-11-14 23:42:36 +09:00

83 lines
3.6 KiB
Python

"""Render actual update-completion handlers in an isolated browser."""
from pathlib import Path
import pytest
from js_lift import JsSource
from test_grid_highlight_escaping import browser # noqa: F401 -- fixture
JS = JsSource(Path(__file__).resolve().parent.parent / "js")
@pytest.mark.parametrize("status", ["success", "failed"])
def test_update_results_preserve_links_titles_and_missing_url_labels(status):
playwright = pytest.importorskip("playwright.sync_api")
helpers = JS.lift_declaration("common.js", "export function sanitizeHTML(")
helpers += JS.lift_span(
"common.js", "export const SAFE_URL_SCHEMES",
"export const safeHref = (url) => sanitizeHTML(sanitizeUrl(url));",
).replace("export ", "")
helpers += JS.lift_declaration("common.js", "export function show_message(")
handler = JS.lift_declaration("comfyui-manager.js", "async function onQueueStatus(")
url = "https://example.test/guide?q=O'Reilly&lang=en"
title = "Guide <draft> & notes"
fallback_id = "Pack <draft>"
with playwright.sync_playwright() as driver:
if not Path(driver.chromium.executable_path).exists():
pytest.skip("install Chromium with: playwright install chromium")
browser = driver.chromium.launch()
page = browser.new_page()
page.route("**/*", lambda route: route.abort())
page.set_content('<div id="dialog"></div>')
page.add_script_tag(content="""
let is_updating = true;
const update_all_button = document.createElement('button');
function reset_action_buttons() {}
function setNeedRestart() {}
function infoToast() {}
const app = {ui: {dialog: {
element: document.getElementById('dialog'),
show(message) { this.element.innerHTML = message; }
}}};
""" + helpers + handler)
page.evaluate("event => onQueueStatus(event)", {"detail": {
"status": "done", "nodepack_result": {
"comfyui": "skip",
"pack-link": {"url": url, "title": title, "msg": status},
fallback_id: {"msg": status},
},
}})
items = page.locator("#dialog li")
assert items.all_text_contents() == [title, fallback_id]
assert items.nth(0).locator("a").get_attribute("href") == url
assert set(items.nth(0).locator("a").evaluate("node => node.getAttributeNames()")) == {
"href", "target", "rel",
}
assert items.nth(0).locator("a").get_attribute("rel") == "noopener noreferrer"
assert items.nth(1).locator("a").count() == 0
assert page.locator("#dialog draft").count() == 0
browser.close()
@pytest.mark.parametrize("status", ["in_progress", "done"])
def test_a_queue_report_before_the_manager_menu_exists_is_ignored(browser, status): # noqa: F811
handler = JS.lift_declaration("comfyui-manager.js", "async function set_inprogress_mode(")
handler += JS.lift_declaration("comfyui-manager.js", "async function reset_action_buttons(")
handler += JS.lift_declaration("comfyui-manager.js", "async function onQueueStatus(")
page = browser.new_page()
errors = []
page.on("pageerror", lambda error: errors.append(str(error)))
page.add_script_tag(content="""
let is_updating = false;
let update_all_button = null, update_comfyui_button = null, switch_comfyui_button = null;
""" + handler)
page.evaluate("event => onQueueStatus(event)", {"detail": {
"status": status, "nodepack_result": {}, "done_count": 0, "total_count": 1,
}})
page.wait_for_timeout(100)
assert errors == []
page.close()