mirror of
https://github.com/Comfy-Org/ComfyUI.git
synced 2026-08-13 13:23:36 +08:00
fix(assets): harden --disable-assets from review feedback
- setup_database() also calls disable_assets_routes() so the off state does not depend on PromptServer construction order, and logs a notice when the deprecated --enable-assets no-op is passed alongside - disabled-mode test fixture: fail fast if the server process exits during startup instead of burning the 90s readiness timeout, kill the process if terminate() hangs, and close log handles if Popen raises - disabled enrichment test also asserts registration is never attempted
This commit is contained in:
3
main.py
3
main.py
@@ -461,6 +461,9 @@ def cleanup_temp():
|
||||
def setup_database():
|
||||
if args.disable_assets:
|
||||
logging.info("Assets system disabled via --disable-assets; skipping database initialization and asset scanning.")
|
||||
if args.enable_assets:
|
||||
logging.info("--enable-assets is a deprecated no-op and does not override --disable-assets.")
|
||||
disable_assets_routes()
|
||||
asset_seeder.disable()
|
||||
return
|
||||
try:
|
||||
|
||||
@@ -23,10 +23,12 @@ def _free_port() -> int:
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
def _wait_assets_disabled(base: str, timeout: float = 90.0) -> None:
|
||||
def _wait_assets_disabled(base: str, proc: subprocess.Popen, timeout: float = 90.0) -> None:
|
||||
start = time.time()
|
||||
last_err = None
|
||||
while time.time() - start < timeout:
|
||||
if proc.poll() is not None:
|
||||
raise RuntimeError(f"ComfyUI exited early with code {proc.returncode}")
|
||||
try:
|
||||
r = requests.get(base + "/api/assets", timeout=5)
|
||||
if r.status_code == 503:
|
||||
@@ -57,33 +59,42 @@ def disabled_comfy(tmp_path_factory: pytest.TempPathFactory):
|
||||
|
||||
comfy_root = Path(__file__).resolve().parent.parent.parent
|
||||
port = _free_port()
|
||||
proc = subprocess.Popen(
|
||||
args=[
|
||||
sys.executable,
|
||||
"main.py",
|
||||
f"--base-directory={str(base_dir)}",
|
||||
f"--database-url=sqlite:///{db_path}",
|
||||
"--disable-assets",
|
||||
"--listen",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
str(port),
|
||||
"--cpu",
|
||||
],
|
||||
stdout=out_log,
|
||||
stderr=err_log,
|
||||
cwd=str(comfy_root),
|
||||
)
|
||||
try:
|
||||
proc = subprocess.Popen(
|
||||
args=[
|
||||
sys.executable,
|
||||
"main.py",
|
||||
f"--base-directory={str(base_dir)}",
|
||||
f"--database-url=sqlite:///{db_path}",
|
||||
"--disable-assets",
|
||||
"--listen",
|
||||
"127.0.0.1",
|
||||
"--port",
|
||||
str(port),
|
||||
"--cpu",
|
||||
],
|
||||
stdout=out_log,
|
||||
stderr=err_log,
|
||||
cwd=str(comfy_root),
|
||||
)
|
||||
except Exception:
|
||||
out_log.close()
|
||||
err_log.close()
|
||||
raise
|
||||
|
||||
base_url = f"http://127.0.0.1:{port}"
|
||||
try:
|
||||
_wait_assets_disabled(base_url)
|
||||
_wait_assets_disabled(base_url, proc)
|
||||
yield base_url, db_path
|
||||
finally:
|
||||
if proc.poll() is None:
|
||||
with contextlib.suppress(Exception):
|
||||
proc.terminate()
|
||||
proc.wait(timeout=15)
|
||||
try:
|
||||
proc.wait(timeout=15)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait(timeout=15)
|
||||
out_log.close()
|
||||
err_log.close()
|
||||
|
||||
|
||||
@@ -54,9 +54,19 @@ def _call(output_ui, *, disable_assets=False, file_exists=True, register_result=
|
||||
class TestEnrichOutputWithAssets(unittest.TestCase):
|
||||
|
||||
def test_disabled_returns_unchanged(self):
|
||||
register_mock = MagicMock(return_value=_make_register_result())
|
||||
mocked = _mocked_modules(disable_assets=True, register_file_in_place=register_mock)
|
||||
output = {"images": [{"filename": "a.png", "subfolder": "", "type": "output"}]}
|
||||
result = _call(output, disable_assets=True)
|
||||
|
||||
with patch.dict("sys.modules", mocked), \
|
||||
patch("os.path.isfile", return_value=True):
|
||||
import importlib
|
||||
import comfy_execution.asset_enrichment as mod
|
||||
importlib.reload(mod)
|
||||
result = mod.enrich_output_with_assets(output)
|
||||
|
||||
self.assertNotIn("id", result["images"][0])
|
||||
register_mock.assert_not_called()
|
||||
|
||||
def test_non_list_value_passed_through(self):
|
||||
output = {"text": "hello"}
|
||||
|
||||
Reference in New Issue
Block a user