Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce965cdbcf | ||
|
|
18ca3be301 | ||
|
|
bf98e9f2cc |
@@ -44,6 +44,26 @@ and this project adheres to [Semantic Versioning 2.0.0](https://semver.org/spec/
|
||||
|
||||
### Fixed
|
||||
|
||||
- A list request without `mode` is answered. `GET /v2/customnode/getmappings`
|
||||
and, with the legacy UI, `/v2/customnode/getlist` and
|
||||
`/v2/externalmodel/getlist` answered 500 with `KeyError: 'mode'` when the
|
||||
request had no `mode` (#2740). Such a request is now answered as one with
|
||||
`mode=cache`. The legacy pages always send `mode`, so nothing changes for
|
||||
them.
|
||||
|
||||
- The Version column of the legacy Custom Nodes Manager no longer shows an
|
||||
older registry version as an update. The column showed `[↑<version>]`
|
||||
whenever the installed version was not the latest version of the registry,
|
||||
so a nodepack installed at 1.78.1 showed `[↑1.47.0]` when the registry had
|
||||
1.47.0 as its latest (#3272). The arrow is now shown only when the version
|
||||
of the registry is newer. For a version that is not only numbers, such as
|
||||
`2.0.0-rc1`, an enabled nodepack shows the arrow when an update is offered
|
||||
for it, and a disabled one is as before. The **Update** button is not
|
||||
changed: it was already offered only for a newer version.
|
||||
|
||||
- Report the `desktop-linux` form factor to the registry for Desktop installs
|
||||
on Linux, which previously reported `other`.
|
||||
|
||||
- aria2 does not download a file that is already there. With aria2 as the
|
||||
downloader, an install of a model whose file was already in its folder
|
||||
downloaded the model once more. aria2 saved the download next to the file
|
||||
|
||||
@@ -20,6 +20,29 @@ lock = asyncio.Lock()
|
||||
|
||||
is_cache_loading = False
|
||||
|
||||
def get_form_factor():
|
||||
"""Form factor reported to the registry, based on environment and platform."""
|
||||
is_desktop = bool(os.environ.get('__COMFYUI_DESKTOP_VERSION__'))
|
||||
system = platform.system().lower()
|
||||
|
||||
if is_desktop:
|
||||
if system == 'windows':
|
||||
return 'desktop-win'
|
||||
if system == 'darwin':
|
||||
return 'desktop-mac'
|
||||
if system == 'linux':
|
||||
return 'desktop-linux'
|
||||
return 'other'
|
||||
|
||||
if system == 'windows':
|
||||
return 'git-windows'
|
||||
if system == 'darwin':
|
||||
return 'git-mac'
|
||||
if system == 'linux':
|
||||
return 'git-linux'
|
||||
return 'other'
|
||||
|
||||
|
||||
async def get_cnr_data(cache_mode=True, dont_wait=True):
|
||||
try:
|
||||
return await _get_cnr_data(cache_mode, dont_wait)
|
||||
@@ -39,12 +62,7 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
|
||||
full_nodes = {}
|
||||
|
||||
|
||||
# Determine form factor based on environment and platform
|
||||
is_desktop = bool(os.environ.get('__COMFYUI_DESKTOP_VERSION__'))
|
||||
system = platform.system().lower()
|
||||
is_windows = system == 'windows'
|
||||
is_mac = system == 'darwin'
|
||||
is_linux = system == 'linux'
|
||||
|
||||
# Get ComfyUI version tag
|
||||
if is_desktop:
|
||||
@@ -53,22 +71,7 @@ async def _get_cnr_data(cache_mode=True, dont_wait=True):
|
||||
else:
|
||||
comfyui_ver = context.get_comfyui_tag() or 'unknown'
|
||||
|
||||
if is_desktop:
|
||||
if is_windows:
|
||||
form_factor = 'desktop-win'
|
||||
elif is_mac:
|
||||
form_factor = 'desktop-mac'
|
||||
else:
|
||||
form_factor = 'other'
|
||||
else:
|
||||
if is_windows:
|
||||
form_factor = 'git-windows'
|
||||
elif is_mac:
|
||||
form_factor = 'git-mac'
|
||||
elif is_linux:
|
||||
form_factor = 'git-linux'
|
||||
else:
|
||||
form_factor = 'other'
|
||||
form_factor = get_form_factor()
|
||||
|
||||
from comfyui_manager.glob import manager_core
|
||||
verbose = manager_core.get_config().get('verbose', False)
|
||||
|
||||
@@ -1427,7 +1427,7 @@ async def fetch_customnode_mappings(request):
|
||||
"""
|
||||
provide unified (node -> node pack) mapping list
|
||||
"""
|
||||
mode = request.rel_url.query["mode"]
|
||||
mode = request.rel_url.query.get("mode", "cache")
|
||||
|
||||
nickname_mode = False
|
||||
if mode == "nickname":
|
||||
|
||||
@@ -22,6 +22,22 @@ const gridId = "node";
|
||||
|
||||
const INVALID_INSTALLATION_GUIDANCE = "This nodepack was not installed through ComfyUI-Manager, or its installation is damaged, so the Manager cannot update it. Reinstalling deletes its folder and installs the nodepack again.";
|
||||
|
||||
function compareVersionSpecs(a, b) {
|
||||
const pa = String(a).split(".").map((x) => /^\d+$/.test(x) ? parseInt(x, 10) : NaN);
|
||||
const pb = String(b).split(".").map((x) => /^\d+$/.test(x) ? parseInt(x, 10) : NaN);
|
||||
if (pa.some(Number.isNaN) || pb.some(Number.isNaN)) {
|
||||
return null;
|
||||
}
|
||||
const len = Math.max(pa.length, pb.length);
|
||||
for (let i = 0; i < len; i++) {
|
||||
const x = pa[i] || 0;
|
||||
const y = pb[i] || 0;
|
||||
if (x > y) return 1;
|
||||
if (x < y) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const pageHtml = `
|
||||
<div class="cn-manager cn-manager-dark">
|
||||
<div class="cn-manager-grid"></div>
|
||||
@@ -850,7 +866,12 @@ export class CustomNodesManager {
|
||||
if(version == 'nightly') {
|
||||
return `<div>${sanitizeHTML(String(version))}</div><div>[${sanitizeHTML(String(rowItem.cnr_latest))}]</div>`;
|
||||
}
|
||||
return `<div>${sanitizeHTML(String(version))}</div><div>[↑${sanitizeHTML(String(rowItem.cnr_latest))}]</div>`;
|
||||
const cmp = compareVersionSpecs(rowItem.cnr_latest, version);
|
||||
const serverChecked = rowItem.state === 'enabled';
|
||||
const newer = cmp === null && serverChecked ? rowItem['update-state'] === 'true' : cmp === null || cmp === 1;
|
||||
if(newer) {
|
||||
return `<div>${sanitizeHTML(String(version))}</div><div>[↑${sanitizeHTML(String(rowItem.cnr_latest))}]</div>`;
|
||||
}
|
||||
}
|
||||
return sanitizeHTML(String(version));
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ async def fetch_customnode_mappings(request):
|
||||
"""
|
||||
provide unified (node -> node pack) mapping list
|
||||
"""
|
||||
mode = request.rel_url.query["mode"]
|
||||
mode = request.rel_url.query.get("mode", "cache")
|
||||
|
||||
nickname_mode = False
|
||||
if mode == "nickname":
|
||||
@@ -1134,14 +1134,16 @@ async def fetch_customnode_list(request):
|
||||
"""
|
||||
provide unified custom node list
|
||||
"""
|
||||
if request.rel_url.query["mode"] == "local":
|
||||
mode = request.rel_url.query.get("mode", "cache")
|
||||
|
||||
if mode == "local":
|
||||
channel = 'local'
|
||||
else:
|
||||
channel = core.get_config()['channel_url']
|
||||
|
||||
node_packs = await core.get_unified_total_nodes(channel, request.rel_url.query["mode"], 'cache')
|
||||
json_obj_github = core.get_data_by_mode(request.rel_url.query["mode"], 'github-stats.json', 'default')
|
||||
json_obj_extras = core.get_data_by_mode(request.rel_url.query["mode"], 'extras.json', 'default')
|
||||
node_packs = await core.get_unified_total_nodes(channel, mode, 'cache')
|
||||
json_obj_github = core.get_data_by_mode(mode, 'github-stats.json', 'default')
|
||||
json_obj_extras = core.get_data_by_mode(mode, 'extras.json', 'default')
|
||||
|
||||
core.populate_github_stats(node_packs, await json_obj_github)
|
||||
core.populate_favorites(node_packs, await json_obj_extras)
|
||||
@@ -1237,7 +1239,7 @@ def check_model_installed(json_obj):
|
||||
@routes.get("/v2/externalmodel/getlist")
|
||||
async def fetch_externalmodel_list(request):
|
||||
# The model list is only allowed in the default channel, yet.
|
||||
json_obj = await core.get_data_by_mode(request.rel_url.query["mode"], 'model-list.json')
|
||||
json_obj = await core.get_data_by_mode(request.rel_url.query.get("mode", "cache"), 'model-list.json')
|
||||
|
||||
check_model_installed(json_obj)
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
"""Form factor the CNR client reports to the registry."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
|
||||
from _install_flags_testutil import import_context
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cnr_utils():
|
||||
import_context()
|
||||
from comfyui_manager.common import cnr_utils
|
||||
|
||||
return cnr_utils
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('system', 'desktop', 'expected'),
|
||||
[
|
||||
('Windows', True, 'desktop-win'),
|
||||
('Darwin', True, 'desktop-mac'),
|
||||
('Linux', True, 'desktop-linux'),
|
||||
('FreeBSD', True, 'other'),
|
||||
('Windows', False, 'git-windows'),
|
||||
('Darwin', False, 'git-mac'),
|
||||
('Linux', False, 'git-linux'),
|
||||
('FreeBSD', False, 'other'),
|
||||
],
|
||||
)
|
||||
def test_form_factor(cnr_utils, monkeypatch, system, desktop, expected):
|
||||
monkeypatch.setattr(cnr_utils.platform, 'system', lambda: system)
|
||||
if desktop:
|
||||
monkeypatch.setenv('__COMFYUI_DESKTOP_VERSION__', '1.0.0')
|
||||
else:
|
||||
monkeypatch.delenv('__COMFYUI_DESKTOP_VERSION__', raising=False)
|
||||
|
||||
assert cnr_utils.get_form_factor() == expected
|
||||
|
||||
|
||||
def test_the_registry_request_carries_the_form_factor(cnr_utils, monkeypatch):
|
||||
from comfyui_manager.glob import manager_core
|
||||
asked = []
|
||||
|
||||
async def get_data_with_cache(uri, **kwargs):
|
||||
asked.append(uri)
|
||||
return {'nodes': [], 'totalPages': 1}
|
||||
|
||||
monkeypatch.setattr(cnr_utils.manager_util, 'get_data_with_cache', get_data_with_cache)
|
||||
monkeypatch.setattr(cnr_utils.manager_util, 'save_to_cache', lambda uri, data: None)
|
||||
monkeypatch.setattr(manager_core, 'get_config', lambda: {})
|
||||
monkeypatch.setattr(cnr_utils.time, 'sleep', lambda seconds: None)
|
||||
monkeypatch.setattr(cnr_utils.platform, 'system', lambda: 'Linux')
|
||||
monkeypatch.setenv('__COMFYUI_DESKTOP_VERSION__', '1.0.0')
|
||||
|
||||
asyncio.run(cnr_utils._get_cnr_data(cache_mode=False))
|
||||
|
||||
assert [uri.partition('&form_factor=')[2] for uri in asked] == ['desktop-linux']
|
||||
@@ -52,6 +52,7 @@ from _install_flags_testutil import ( # noqa: E402
|
||||
)
|
||||
|
||||
_LEGACY_SERVER = None
|
||||
_GET_DATA = None
|
||||
|
||||
|
||||
def _import_legacy_server():
|
||||
@@ -59,7 +60,7 @@ def _import_legacy_server():
|
||||
(idempotent; memoized). Returns the real module object so the tests drive
|
||||
the REAL gate function and REAL handlers — only the runtime *environment*
|
||||
is stubbed, never the gate logic."""
|
||||
global _LEGACY_SERVER
|
||||
global _LEGACY_SERVER, _GET_DATA
|
||||
if _LEGACY_SERVER is not None:
|
||||
return _LEGACY_SERVER
|
||||
|
||||
@@ -108,6 +109,7 @@ def _import_legacy_server():
|
||||
async def _inert_get_data(uri, *a, **k):
|
||||
return {"custom_nodes": [], "models": [], "node_map": {}}
|
||||
|
||||
_GET_DATA = mu.get_data
|
||||
mu.get_data = _inert_get_data
|
||||
|
||||
_LEGACY_SERVER = importlib.import_module("comfyui_manager.legacy.manager_server")
|
||||
@@ -116,7 +118,8 @@ def _import_legacy_server():
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def ms():
|
||||
return _import_legacy_server()
|
||||
yield _import_legacy_server()
|
||||
sys.modules["comfyui_manager.common.manager_util"].get_data = _GET_DATA
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from aiohttp import web
|
||||
|
||||
from legacy_html_testutil import PACKAGE, load_functions
|
||||
from test_default_channel import COMFY_ORG, configure, registry, route, user, write # noqa: F401
|
||||
|
||||
ROUTES = [('glob', 'fetch_customnode_mappings'), ('legacy', 'fetch_customnode_mappings'),
|
||||
('legacy', 'fetch_customnode_list'), ('legacy', 'fetch_externalmodel_list')]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server,name', ROUTES)
|
||||
def test_a_request_without_mode_is_answered_as_mode_cache(user, registry, server, name): # noqa: F811
|
||||
configure(user, None, COMFY_ORG)
|
||||
write(user, f'{server} start')
|
||||
handler = load_functions(PACKAGE / server / 'manager_server.py', {name}, {
|
||||
'core': user.cores[server], 'web': web, 'routes': SimpleNamespace(get=route, post=route), 're': re,
|
||||
'nodes': SimpleNamespace(NODE_CLASS_MAPPINGS={}), 'populate_markdown': lambda row: None,
|
||||
'check_model_installed': lambda listed: None})[name]
|
||||
|
||||
def ask(**query):
|
||||
return json.loads(asyncio.run(handler(SimpleNamespace(rel_url=SimpleNamespace(query=query)))).text)
|
||||
|
||||
assert ask() == ask(mode='cache') != ask(mode='local')
|
||||
@@ -0,0 +1,129 @@
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from js_lift import NODE, JsSource, run_node, slice_braced, slice_object_entry
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
JS = JsSource(os.environ.get("MANAGER_JS_DIR") or (REPO_ROOT / "comfyui_manager" / "js"))
|
||||
|
||||
MANAGER = "custom-nodes-manager.js"
|
||||
COMMON = "common.js"
|
||||
|
||||
VERSION_ANCHOR = "id: 'version',"
|
||||
HELPER_MARKER = "function compareVersionSpecs"
|
||||
|
||||
|
||||
def _helper_source() -> str:
|
||||
return slice_braced(JS.text(MANAGER), HELPER_MARKER)
|
||||
|
||||
|
||||
def _version_formatter() -> str:
|
||||
block = slice_object_entry(JS.text(MANAGER), VERSION_ANCHOR)
|
||||
marker = "formatter:"
|
||||
return block[block.index(marker) + len(marker):].strip()
|
||||
|
||||
|
||||
def _sanitize_html_source() -> str:
|
||||
return JS.lift_declaration(COMMON, "export function sanitizeHTML(")
|
||||
|
||||
|
||||
def _render(formatter_source: str, installed, cnr_latest, **row) -> str:
|
||||
script = "\n".join([
|
||||
_sanitize_html_source(),
|
||||
_helper_source(),
|
||||
"const formatter = %s;" % (formatter_source,),
|
||||
"const rowItem = %s;" % json.dumps({"cnr_latest": cnr_latest, "originalData": {"id": "x"}, **row}),
|
||||
"console.log(JSON.stringify({markup: String(formatter(%s, rowItem, {}))}));"
|
||||
% json.dumps(installed),
|
||||
])
|
||||
return run_node(script)["markup"]
|
||||
|
||||
|
||||
BADGE = "<div>%s</div><div>[↑%s]</div>"
|
||||
|
||||
CASES = [
|
||||
("1.78.1", "1.47.0", "1.78.1",
|
||||
"issue #3272: locally newer must NOT be flagged as updatable"),
|
||||
("1.47.0", "1.47.0", "1.47.0",
|
||||
"equal versions: no badge"),
|
||||
("1.0.0", "1.47.0", BADGE % ("1.0.0", "1.47.0"),
|
||||
"registry is genuinely newer: badge kept"),
|
||||
("1.78.1", "0.0.0", "1.78.1",
|
||||
"manager_core's 'no latest_version' sentinel must not render [↑0.0.0]"),
|
||||
("0.0.0", "1.47.0", BADGE % ("0.0.0", "1.47.0"),
|
||||
"a 0.0.0 install is still older than the registry: badge kept"),
|
||||
("1.2", "1.10.0", BADGE % ("1.2", "1.10.0"),
|
||||
"numeric compare: 1.10.0 > 1.2 (a string compare would miss this update)"),
|
||||
("1.10.0", "1.2", "1.10.0",
|
||||
"numeric compare: 1.10.0 > 1.2, so no badge"),
|
||||
("nightly", "1.47.0", "<div>nightly</div><div>[1.47.0]</div>",
|
||||
"the nightly branch is untouched: no arrow, badge-free"),
|
||||
("1.2.3rc1", "1.47.0", BADGE % ("1.2.3rc1", "1.47.0"),
|
||||
"unparseable spec: legacy string behavior kept"),
|
||||
]
|
||||
|
||||
|
||||
UNORDERED_CASES = [
|
||||
("2.0.0rc1", "1.47.0", "enabled", "false", "2.0.0rc1",
|
||||
"a release candidate of a newer version is not behind the registry"),
|
||||
("1.0.0-beta.2", "0.9.0", "enabled", "false", "1.0.0-beta.2",
|
||||
"a beta of a newer version is not behind the registry"),
|
||||
("1.0.0", "nightly", "enabled", "false", "1.0.0",
|
||||
"a nodepack without a version in the registry has nothing to update to"),
|
||||
("1.2.3rc1", "1.47.0", "enabled", "true", BADGE % ("1.2.3rc1", "1.47.0"),
|
||||
"the server offers the update: badge kept"),
|
||||
("1.2.3rc1", "1.47.0", "disabled", "false", BADGE % ("1.2.3rc1", "1.47.0"),
|
||||
"disabled: the server has no answer, legacy string behavior kept"),
|
||||
("1.78.1", "1.47.0", "enabled", "true", "1.78.1",
|
||||
"versions the helper orders do not read update-state"),
|
||||
]
|
||||
|
||||
|
||||
@unittest.skipIf(NODE is None, "node is required to execute the lifted production JS")
|
||||
class VersionBadgeSemverTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.formatter = _version_formatter()
|
||||
|
||||
def _markup(self, installed, cnr_latest) -> str:
|
||||
return _render(self.formatter, installed, cnr_latest)
|
||||
|
||||
def test_the_badge_follows_numeric_ordering(self):
|
||||
for installed, latest, expected, why in CASES:
|
||||
with self.subTest(installed=installed, cnr_latest=latest):
|
||||
self.assertEqual(self._markup(installed, latest), expected, why)
|
||||
|
||||
def test_an_enabled_nodepack_follows_the_server_for_versions_the_helper_cannot_order(self):
|
||||
for installed, latest, state, update_state, expected, why in UNORDERED_CASES:
|
||||
with self.subTest(installed=installed, cnr_latest=latest, state=state):
|
||||
row = {"state": state, "update-state": update_state}
|
||||
self.assertEqual(_render(self.formatter, installed, latest, **row), expected, why)
|
||||
|
||||
|
||||
@unittest.skipIf(NODE is None, "node is required to execute the lifted production JS")
|
||||
class CompareVersionSpecsTest(unittest.TestCase):
|
||||
def _compare(self, a, b):
|
||||
out = run_node(
|
||||
"%s\nconsole.log(JSON.stringify({r: compareVersionSpecs(%s, %s)}));"
|
||||
% (_helper_source(), json.dumps(a), json.dumps(b))
|
||||
)
|
||||
return out["r"]
|
||||
|
||||
def test_dot_separated_specs_order_numerically(self):
|
||||
self.assertEqual(self._compare("1.2.10", "1.2.9"), 1)
|
||||
self.assertEqual(self._compare("1.10.0", "1.9"), 1)
|
||||
self.assertEqual(self._compare("1.9", "1.10.0"), -1)
|
||||
self.assertEqual(self._compare("1.47.0", "1.47.0"), 0)
|
||||
self.assertEqual(self._compare("1.2", "1.2.0"), 0)
|
||||
|
||||
def test_non_numeric_specs_return_null(self):
|
||||
self.assertIsNone(self._compare("nightly", "1.47.0"))
|
||||
self.assertIsNone(self._compare("1.2.3rc1", "1.47.0"))
|
||||
self.assertIsNone(self._compare("1.47.0", ""))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user