Files
ComfyAssets-ComfyUI_PromptM…/tests/test_extension_web_dir.py
T
Vito Sansevero b1bfce702d fix: first CI run on Windows and macOS; tests now enforce closed database files
The first push of the branch ran the Tests matrix on all three operating
systems. Every Python job failed; the causes were:

- numpy missing in CI: the WD14 engine tests import it (requirements-dev)
- macOS: temp directories resolve through /private; the admin API tests
  now use the real path like the gallery roots they compare against
- Windows: the startup banner printed an emoji, which raises
  UnicodeEncodeError on a legacy-code-page console and aborted loading
  the whole node; the banner is ASCII now and a test loads the package
  under a cp1252 stdout
- Windows: gallery subfolders came back with backslashes, which neither
  the folder tree nor the search filter understand; they are "/" joined
  on every platform. A relative DEFAULT_DB_PATH kept its forward slashes
  after being joined to the extension root; it is normalised now
- Windows: sqlite connections opened with `with sqlite3.connect()` are
  not closed by the context manager and linger until garbage collection,
  which holds a file lock there. Production sites (vacuum, diagnostics,
  restore inspection) close explicitly; a restore that swaps the API's
  database object closes the previous one; PromptModel keeps a registry
  so a shutdown or a test can close every instance
- Windows: served files were still open when their temp directory was
  removed (tests now read the body), a log download test compared text
  mode newlines, two tests compared paths with a hard-coded separator

tests/open_handles.py makes the Linux run fail the way Windows would:
every database test base checks, right before deleting its files, that
nothing in the process still holds them open.
2026-10-08 18:24:18 -07:00

66 lines
2.4 KiB
Python

"""ComfyUI loads only the canvas extension, not the admin or gallery bundles.
ComfyUI serves every .js file under WEB_DIRECTORY into the canvas page, so the
directory must hold nothing but the node extension.
"""
import os
import sys
import tempfile
import unittest
TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.dirname(TESTS_DIR)
sys.path.insert(0, ROOT)
sys.path.insert(0, TESTS_DIR)
from test_init_package import close_every_database, load_package # noqa: E402
class TestExtensionWebDir(unittest.TestCase):
package_name = "prompt_manager_pkg_web"
@classmethod
def setUpClass(cls):
cls.tmp = tempfile.TemporaryDirectory()
output_dir = os.path.join(cls.tmp.name, "output")
os.makedirs(output_dir)
cls.package, _ = load_package(
cls.package_name, os.path.join(cls.tmp.name, "prompts.db"), output_dir
)
@classmethod
def tearDownClass(cls):
monitor = getattr(cls.package, "_global_image_monitor", None)
if monitor is not None:
monitor.stop_monitoring()
sys.modules.pop(cls.package_name, None)
close_every_database() # the package's database must not hold the temp dir open
cls.tmp.cleanup()
def test_web_directory_is_the_canvas_extension_folder(self):
self.assertEqual(self.package.WEB_DIRECTORY, "web/comfy")
self.assertIn("WEB_DIRECTORY", self.package.__all__)
def test_comfyui_resolves_the_folder_next_to_the_package(self):
# ComfyUI joins the module directory with WEB_DIRECTORY and checks isdir
folder = os.path.join(ROOT, self.package.WEB_DIRECTORY)
self.assertTrue(os.path.isdir(folder))
self.assertEqual(sorted(os.listdir(folder)), ["prompt_manager.js"])
def test_extension_was_moved_not_copied(self):
self.assertFalse(os.path.exists(os.path.join(ROOT, "web", "prompt_manager.js")))
def test_extension_registers_with_the_canvas_app(self):
path = os.path.join(ROOT, "web", "comfy", "prompt_manager.js")
with open(path, encoding="utf-8") as f:
source = f.read()
self.assertIn("app.registerExtension(", source)
# Served at /extensions/<name>/prompt_manager.js, so ComfyUI's app module
# is two levels up regardless of where the file lives on disk.
self.assertIn('from "../../scripts/app.js"', source)
if __name__ == "__main__":
unittest.main()