test_check_deps.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Tests for check_deps.py — focuses on parsing logic that doesn't need a server."""
  2. from __future__ import annotations
  3. from check_deps import (
  4. NODE_TO_PACKAGE,
  5. model_present,
  6. normalize_for_match,
  7. suggest_install_command,
  8. )
  9. class TestNormalizeForMatch:
  10. def test_basic(self):
  11. s = normalize_for_match("model.safetensors")
  12. assert "model.safetensors" in s
  13. assert "model" in s
  14. def test_subfolder(self):
  15. s = normalize_for_match("subdir/model.pt")
  16. assert "subdir/model.pt" in s
  17. assert "model.pt" in s
  18. assert "model" in s
  19. class TestModelPresent:
  20. def test_exact_match(self):
  21. assert model_present("a.safetensors", {"a.safetensors", "b.safetensors"}) is True
  22. def test_extension_difference(self):
  23. # User said "model" but installed is "model.safetensors"
  24. assert model_present("model", {"model.safetensors"}) is True
  25. # Reverse direction — also matches
  26. assert model_present("model.safetensors", {"model"}) is True
  27. def test_subfolder_match(self):
  28. # Installed list has "subdir/model.safetensors", workflow asks "model.safetensors"
  29. assert model_present("model.safetensors", {"subdir/model.safetensors"}) is True
  30. def test_missing(self):
  31. assert model_present("missing.safetensors", {"a.safetensors", "b.safetensors"}) is False
  32. def test_empty_installed(self):
  33. assert model_present("anything.safetensors", set()) is False
  34. class TestSuggestInstallCommand:
  35. def test_known_node(self):
  36. cmd = suggest_install_command("VHS_VideoCombine")
  37. assert cmd == "comfy node install comfyui-videohelpersuite"
  38. def test_unknown_node(self):
  39. assert suggest_install_command("SomeRandomNodeName123") is None
  40. class TestNodePackageMap:
  41. def test_no_duplicates(self):
  42. # Each node should map to exactly one package
  43. keys = list(NODE_TO_PACKAGE.keys())
  44. assert len(keys) == len(set(keys))
  45. def test_packages_are_safe_for_shell(self):
  46. # Registry slugs must be alphanumerics + hyphens/underscores only
  47. # (passed straight to `comfy node install <pkg>`).
  48. import re
  49. safe = re.compile(r"^[A-Za-z0-9][A-Za-z0-9._\-]*$")
  50. for pkg in NODE_TO_PACKAGE.values():
  51. assert safe.match(pkg), f"Unsafe package slug: {pkg!r}"