Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Turn assets off unless --enable-assets, and scan the output folder again (#16929)

Simon Pinfold0ebee95bbbdd
diff --git a/app/assets/api/routes.py b/app/assets/api/routes.py
index 9f13c99f4..52abca2dc 100644
--- a/app/assets/api/routes.py
+++ b/app/assets/api/routes.py
@@ -91,7 +91,7 @@ def _require_assets_feature_enabled(handler):
return _build_error_response(
503,
"SERVICE_DISABLED",
- "Assets system is disabled because the server was started with --disable-assets.",
+ "Assets system is disabled. Start the server with --enable-assets, and without --disable-assets, to use this feature.",
)
return await handler(request)
@@ -1036,7 +1036,7 @@ _PRUNE_POLL_SECONDS = 0.25
@ROUTES.post("/api/assets/seed")
@_require_assets_feature_enabled
async def seed_assets(request: web.Request) -> web.Response:
- """Trigger asset seeding for specified roots (models, input).
+ """Trigger asset seeding for specified roots (models, input, output).
Query params:
wait: If "true", block until scan completes (synchronous behavior for tests)
@@ -1048,11 +1048,11 @@ async def seed_assets(request: web.Request) -> web.Response:
"""
try:
payload = await request.json()
- roots = payload.get("roots", ["models", "input"])
+ roots = payload.get("roots", ["models", "input", "output"])
except Exception:
- roots = ["models", "input"]
+ roots = ["models", "input", "output"]
- valid_roots = tuple(r for r in roots if r in ("models", "input"))
+ valid_roots = tuple(r for r in roots if r in ("models", "input", "output"))
if not valid_roots:
return _build_error_response(400, "INVALID_BODY", "No valid roots specified")
diff --git a/app/assets/lifecycle.py b/app/assets/lifecycle.py
index 753b57725..02f86e7ab 100644
--- a/app/assets/lifecycle.py
+++ b/app/assets/lifecycle.py
@@ -101,12 +101,12 @@ def start_asset_seeder() -> bool:
from app.assets.seeder import asset_seeder
started = asset_seeder.start(
- roots=("models", "input"),
+ roots=("models", "input", "output"),
prune_first=True,
compute_hashes=args.enable_asset_hashing,
)
if started:
- logging.info("Background asset scan initiated for models, input")
+ logging.info("Background asset scan initiated for models, input, output")
return started
diff --git a/app/assets/manager.py b/app/assets/manager.py
index 7cef190af..8b89a5a48 100644
--- a/app/assets/manager.py
+++ b/app/assets/manager.py
@@ -1,6 +1,6 @@
"""Selects and implements the enabled and disabled asset managers.
-``default_asset_manager`` chooses ``NoAssets`` only for ``--disable-assets``; main.py
+``default_asset_manager`` chooses ``NoAssets`` unless assets are enabled (see cli_args); main.py
stops startup before that if assets are on and the database packages are missing.
"""
@@ -21,7 +21,7 @@ from comfy.cli_args import args
# does not touch these names.
if dependencies_available():
from app.assets.api.routes import register_assets_routes
- from app.assets.seeder import asset_seeder
+ from app.assets.seeder import ScanPhase, asset_seeder
from app.assets.services.ingest import (
register_cached_output as ingest_register_cached_output,
register_executed_output as ingest_register_executed_output,
@@ -165,13 +165,19 @@ class AssetsEnabled:
register_assets_routes(app, user_manager)
def ensure_scan_started(self) -> None:
- asset_seeder.start(roots=("models", "input"))
+ asset_seeder.start(roots=("models", "input", "output"))
def pause_background_scan(self) -> None:
asset_seeder.pause()
def queue_output_scan(self) -> None:
- return None
+ if not asset_seeder.is_disabled():
+ # FULL, not ENRICH: only a walk finds outputs a node never declared. Do not downgrade without re-weighing the cost.
+ asset_seeder.enqueue_scan(
+ roots=("output",),
+ phase=ScanPhase.FULL,
+ compute_hashes=self._args.enable_asset_hashing,
+ )
def resume_background_scan(self) -> None:
asset_seeder.resume()
diff --git a/app/assets/seeder.py b/app/assets/seeder.py
index a01ee8fa4..84dbced3f 100644
--- a/app/assets/seeder.py
+++ b/app/assets/seeder.py
@@ -219,7 +219,7 @@ class _AssetSeeder:
def start(
self,
- roots: tuple[RootType, ...] = ("models", "input"),
+ roots: tuple[RootType, ...] = ("models", "input", "output"),
phase: ScanPhase = ScanPhase.FULL,
progress_callback: ProgressCallback | None = None,
prune_first: bool = False,
@@ -271,7 +271,7 @@ class _AssetSeeder:
def start_fast(
self,
- roots: tuple[RootType, ...] = ("models", "input"),
+ roots: tuple[RootType, ...] = ("models", "input", "output"),
progress_callback: ProgressCallback | None = None,
prune_first: bool = False,
) -> bool:
diff --git a/comfy/cli_args.py b/comfy/cli_args.py
index 18748fb1e..ec8efa0ec 100644
--- a/comfy/cli_args.py
+++ b/comfy/cli_args.py
@@ -275,9 +275,9 @@ database_default_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "user", "comfyui.db")
)
parser.add_argument("--database-url", type=str, default=None, help="Specify the database URL, e.g. for an in-memory database you can use 'sqlite:///:memory:'. Defaults to 'comfyui.db' in the effective user directory.")
-parser.add_argument("--disable-assets", action="store_true", help="Disable the assets system (API routes, database synchronization, and background scanning).")
-parser.add_argument("--enable-assets", action="store_true", help="Deprecated: the assets system is on by default, so this does nothing. Use --disable-assets to turn it off.")
-parser.add_argument("--enable-asset-hashing", action="store_true", help="Compute blake3 content hashes when scanning assets. Files uploaded through the API are hashed either way. Hashing enables future asset-portability features (deduplication, cross-machine model resolution) but adds startup cost and per-output cost on large models directories. Off by default; enable to opt in.")
+parser.add_argument("--enable-assets", action="store_true", help="Enable the assets system (API routes, database synchronization, and background scanning). Off by default.")
+parser.add_argument("--disable-assets", action="store_true", help="Disable the assets system, even when --enable-assets is also given.")
+parser.add_argument("--enable-asset-hashing", action="store_true", help="Compute blake3 content hashes when scanning assets. Files uploaded through the API are hashed either way. Hashing enables future asset-portability features (deduplication, cross-machine model resolution) but adds startup cost and per-output cost on large models directories. Off by default; enable to opt in. Requires --enable-assets.")
parser.add_argument("--feature-flag", type=str, action='append', default=[], metavar="KEY[=VALUE]", help="Set a server feature flag. Use KEY=VALUE to set an explicit value, or bare KEY to set it to true. Can be specified multiple times. Boolean values (true/false) and numbers are auto-converted. Examples: --feature-flag show_signin_button=true or --feature-flag show_signin_button")
parser.add_argument("--list-feature-flags", action="store_true", help="Print the registry of known CLI-settable feature flags as JSON and exit.")
@@ -301,6 +301,10 @@ if args.disable_api_nodes:
if args.offline:
args.disable_partner_nodes = True
+# Assets are off unless --enable-assets is given; --disable-assets wins over it.
+if not args.enable_assets:
+ args.disable_assets = True
+
if args.disable_auto_launch:
args.auto_launch = False
diff --git a/main.py b/main.py
index 6f85e9adf..b93c2a81c 100644
--- a/main.py
+++ b/main.py
@@ -55,12 +55,12 @@ if __name__ == "__main__":
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
logging.warning("On windows we are currently forcing single GPU mode in ComfyUI due to a Nvidia related issue, if you want to disable this use: --cuda-device all")
+ if args.enable_asset_hashing and args.disable_assets:
+ logging.warning("--enable-asset-hashing is ignored because the assets system is off. Start ComfyUI with --enable-assets, and without --disable-assets, to use it.")
+
if args.disable_api_nodes:
logging.warning("--disable-api-nodes is deprecated and will be removed in a future version. It currently behaves like --offline. Use --offline to keep the frontend offline, or --disable-partner-nodes to only disable partner nodes.")
- if args.enable_assets:
- logging.warning("--enable-assets is deprecated and does nothing: the assets system is on unless ComfyUI is started with --disable-assets.")
-
faulthandler.enable(file=sys.stderr, all_threads=args.debug_hang)
if __name__ == "__main__" and args.debug_hang:
dumping_traceback = False
@@ -558,7 +558,7 @@ WARNING WARNING WARNING WARNING WARNING
Another ComfyUI is already using this install's asset database:
{db_path}
-This ComfyUI was started with --disable-assets, so it doesn't use that database and will start anyway.
+This ComfyUI doesn't have the assets system on, so it doesn't use that database and will start anyway.
________________________________________________________________________
""".strip()
)
diff --git a/tests-unit/app_test/test_assets_default_on_processes.py b/tests-unit/app_test/test_assets_default_on_processes.py
index a49e50e13..0a7e25c40 100644
--- a/tests-unit/app_test/test_assets_default_on_processes.py
+++ b/tests-unit/app_test/test_assets_default_on_processes.py
@@ -1,5 +1,5 @@
-"""Real ComfyUI starts: assets are on unless --disable-assets, and a database that can't be
-opened stops startup."""
+"""Real ComfyUI starts: assets are off unless --enable-assets (and --disable-assets wins), and a
+database that can't be opened stops startup."""
import contextlib
import socket
@@ -14,7 +14,7 @@ import requests
from alembic.script import ScriptDirectory
REPO_ROOT = Path(__file__).resolve().parents[2]
-DEPRECATED = "--enable-assets is deprecated and does nothing"
+ENABLED_EVENT = "[assets-event] assets.enabled "
HEAD = ScriptDirectory(str(REPO_ROOT / "alembic_db")).get_current_head()
@@ -53,31 +53,36 @@ def _revision(db: Path) -> str:
@pytest.mark.parametrize(("flags", "hashing"), [((), "false"), (("--enable-asset-hashing",), "true")])
-def test_assets_are_on_by_default_and_hashing_stays_opt_in(tmp_path, flags, hashing):
- result = _quick_start(tmp_path, *flags)
+def test_enable_assets_turns_assets_on_and_hashing_stays_opt_in(tmp_path, flags, hashing):
+ result = _quick_start(tmp_path, "--enable-assets", *flags)
output = result.stdout + result.stderr
assert result.returncode == 0, result.stderr
assert _revision(_db(tmp_path)) == HEAD
- assert [line.split("assets.enabled ", 1)[1] for line in output.splitlines() if "[assets-event] assets.enabled " in line] == [
+ assert [line.split("assets.enabled ", 1)[1] for line in output.splitlines() if ENABLED_EVENT in line] == [
f"hashing_enabled={hashing}"
]
- assert DEPRECATED not in result.stderr
+ assert "--enable-asset-hashing is ignored" not in output
-def test_enable_assets_is_accepted_and_says_once_that_it_does_nothing(tmp_path):
- result = _quick_start(tmp_path, "--enable-assets")
[email protected]("flags", [(), ("--disable-assets",), ("--enable-assets", "--disable-assets")])
+def test_hashing_with_assets_off_is_ignored_with_one_warning(tmp_path, flags):
+ result = _quick_start(tmp_path, "--enable-asset-hashing", *flags)
+ output = result.stdout + result.stderr
assert result.returncode == 0, result.stderr
- assert result.stderr.count(DEPRECATED) == 1
- assert _revision(_db(tmp_path)) == HEAD
+ assert output.count("--enable-asset-hashing is ignored because the assets system is off. Start ComfyUI with --enable-assets, and without --disable-assets, to use it.") == 1
+ assert not _db(tmp_path).exists()
+ assert ENABLED_EVENT not in output
-def test_disable_assets_leaves_the_database_alone(tmp_path):
- result = _quick_start(tmp_path, "--disable-assets")
[email protected]("flags", [(), ("--disable-assets",), ("--enable-assets", "--disable-assets")])
+def test_assets_off_leaves_the_database_alone(tmp_path, flags):
+ result = _quick_start(tmp_path, *flags)
assert result.returncode == 0, result.stderr
assert not _db(tmp_path).exists()
+ assert ENABLED_EVENT not in result.stdout + result.stderr
def test_database_from_a_newer_comfyui_stops_startup_without_a_traceback(tmp_path):
@@ -86,7 +91,7 @@ def test_database_from_a_newer_comfyui_stops_startup_without_a_traceback(tmp_pat
conn.execute("CREATE TABLE alembic_version (version_num VARCHAR(32) NOT NULL)")
conn.execute("INSERT INTO alembic_version VALUES ('0099_from_a_newer_release')")
- result = _quick_start(tmp_path)
+ result = _quick_start(tmp_path, "--enable-assets")
assert result.returncode == 1, result.stderr
assert "ASSETS_STARTUP_FAILED: newer_revision" in result.stderr
@@ -98,7 +103,7 @@ def test_starts_with_a_percent_sign_in_the_database_path(tmp_path):
base = tmp_path / "50% data"
base.mkdir()
- result = _quick_start(base)
+ result = _quick_start(base, "--enable-assets")
assert result.returncode == 0, result.stderr
assert _revision(_db(base)) == HEAD
@@ -111,13 +116,13 @@ def _free_port() -> int:
@pytest.fixture
-def default_server(tmp_path):
- yield from _serve(tmp_path)
+def enabled_server(tmp_path):
+ yield from _serve(tmp_path, "--enable-assets")
@pytest.fixture
-def disabled_server(tmp_path):
- yield from _serve(tmp_path, "--disable-assets")
+def default_server(tmp_path):
+ yield from _serve(tmp_path)
def _serve(tmp_path, *flags):
@@ -151,28 +156,57 @@ def _serve(tmp_path, *flags):
server.wait()
-def test_default_server_serves_assets_and_registers_uploads(default_server):
+def test_enabled_server_serves_assets_and_registers_uploads(enabled_server):
upload = requests.post(
- f"{default_server}/upload/image",
- files={"image": ("default-on.png", b"default-on-bytes", "image/png")},
+ f"{enabled_server}/upload/image",
+ files={"image": ("enabled.png", b"enabled-bytes", "image/png")},
data={"type": "input"},
timeout=10,
)
assert upload.status_code == 200
- assert upload.json()["asset"]["name"] == "default-on.png"
- view = requests.get(f"{default_server}/view", params={"filename": "default-on.png", "type": "input"}, timeout=10)
- assert view.content == b"default-on-bytes"
+ assert upload.json()["asset"]["name"] == "enabled.png"
+ view = requests.get(f"{enabled_server}/view", params={"filename": "enabled.png", "type": "input"}, timeout=10)
+ assert view.content == b"enabled-bytes"
- listed = requests.get(f"{default_server}/api/assets", timeout=10)
+ listed = requests.get(f"{enabled_server}/api/assets", timeout=10)
assert listed.status_code == 200
- assert "default-on.png" in [asset["name"] for asset in listed.json()["assets"]]
- assert requests.get(f"{default_server}/features", timeout=10).json()["assets"] is True
+ assert "enabled.png" in [asset["name"] for asset in listed.json()["assets"]]
+ assert requests.get(f"{enabled_server}/features", timeout=10).json()["assets"] is True
-def test_disabled_server_reports_assets_off(disabled_server):
- disabled = requests.get(f"{disabled_server}/api/assets", timeout=10)
+def test_default_server_reports_assets_off(default_server):
+ disabled = requests.get(f"{default_server}/api/assets", timeout=10)
assert disabled.status_code == 503
- assert "--disable-assets" in disabled.json()["error"]["message"]
- assert requests.get(f"{disabled_server}/features", timeout=10).json()["assets"] is False
+ assert "--enable-assets" in disabled.json()["error"]["message"]
+ assert requests.get(f"{default_server}/features", timeout=10).json()["assets"] is False
+
+
+def _listed_names(base_url):
+ return [asset["name"] for asset in requests.get(f"{base_url}/api/assets", timeout=10).json()["assets"]]
+
+
+# main.py always loads the checkout's extra_model_paths.yaml, whose model folders the startup scan would walk.
[email protected]((REPO_ROOT / "extra_model_paths.yaml").exists(), reason="checkout has an extra_model_paths.yaml")
+def test_running_a_prompt_rescans_the_output_folder(enabled_server, tmp_path):
+ log_path = tmp_path / "server.log"
+ deadline = time.monotonic() + 60
+ while requests.get(f"{enabled_server}/api/assets/seed/status", timeout=10).json()["state"] != "IDLE":
+ assert time.monotonic() < deadline, f"startup scan did not finish\n{log_path.read_text()[-4000:]}"
+ time.sleep(0.25)
+ # Written behind ComfyUI's back, so only a scan of the output folder can find it.
+ (tmp_path / "output").mkdir(exist_ok=True)
+ (tmp_path / "output" / "undeclared.png").write_bytes(b"undeclared-bytes")
+ assert "undeclared.png" not in _listed_names(enabled_server)
+
+ prompt = {
+ "1": {"class_type": "EmptyImage", "inputs": {"width": 8, "height": 8, "batch_size": 1, "color": 0}},
+ "2": {"class_type": "PreviewImage", "inputs": {"images": ["1", 0]}},
+ }
+ assert requests.post(f"{enabled_server}/prompt", json={"prompt": prompt}, timeout=10).status_code == 200
+
+ deadline = time.monotonic() + 60
+ while "undeclared.png" not in _listed_names(enabled_server):
+ assert time.monotonic() < deadline, f"the output folder was not rescanned after the prompt\n{log_path.read_text()[-4000:]}"
+ time.sleep(0.25)
diff --git a/tests-unit/app_test/test_db_assets_off.py b/tests-unit/app_test/test_db_assets_off.py
index 210ebaae2..62187c997 100644
--- a/tests-unit/app_test/test_db_assets_off.py
+++ b/tests-unit/app_test/test_db_assets_off.py
@@ -127,7 +127,7 @@ def test_assets_off_warns_and_continues_when_another_process_holds_the_lock(
warning = startup_warnings[0]
assert "Another ComfyUI is already using this install's asset database" in warning
assert db_path in warning
- assert "This ComfyUI was started with --disable-assets, so it doesn't use that database and will start anyway" in warning
+ assert "This ComfyUI doesn't have the assets system on, so it doesn't use that database and will start anyway" in warning
assert "--database-url" not in warning
diff --git a/tests-unit/app_test/test_db_lock_processes.py b/tests-unit/app_test/test_db_lock_processes.py
index 9cbe73ea5..06deb1d8e 100644
--- a/tests-unit/app_test/test_db_lock_processes.py
+++ b/tests-unit/app_test/test_db_lock_processes.py
@@ -87,7 +87,7 @@ def held_lock(tmp_path):
def test_running_assets_off_instance_does_not_block_an_assets_on_start(tmp_path):
# A previous assets-on run leaves the database and its lock file behind, as on a real install.
- first = _quick_start(tmp_path)
+ first = _quick_start(tmp_path, "--enable-assets")
assert first.returncode == 0, first.stderr
port = _free_port()
@@ -105,7 +105,7 @@ def test_running_assets_off_instance_does_not_block_an_assets_on_start(tmp_path)
except AssertionError as e:
raise AssertionError(f"{e}\n{server_log.read_text()[-4000:]}") from None
- second = _quick_start(tmp_path)
+ second = _quick_start(tmp_path, "--enable-assets")
assert server.poll() is None
finally:
@@ -116,8 +116,9 @@ def test_running_assets_off_instance_does_not_block_an_assets_on_start(tmp_path)
assert LOCK_HELD not in second.stderr
-def test_assets_off_start_warns_and_continues_when_the_database_is_held(tmp_path, held_lock):
- result = _quick_start(tmp_path, "--disable-assets")
[email protected]("flags", [(), ("--disable-assets",)])
+def test_assets_off_start_warns_and_continues_when_the_database_is_held(tmp_path, held_lock, flags):
+ result = _quick_start(tmp_path, *flags)
assert result.returncode == 0, result.stderr
assert IN_USE in result.stderr
@@ -127,7 +128,7 @@ def test_assets_off_start_warns_and_continues_when_the_database_is_held(tmp_path
def test_assets_on_start_still_fails_when_the_database_is_held(tmp_path, held_lock):
- result = _quick_start(tmp_path)
+ result = _quick_start(tmp_path, "--enable-assets")
assert result.returncode == 1, result.stderr
assert LOCK_HELD in result.stderr
diff --git a/tests-unit/assets_test/services/test_batched_marking.py b/tests-unit/assets_test/services/test_batched_marking.py
index 6590fe4cf..7f77c4168 100644
--- a/tests-unit/assets_test/services/test_batched_marking.py
+++ b/tests-unit/assets_test/services/test_batched_marking.py
@@ -556,7 +556,7 @@ async def test_a_seed_request_during_an_api_prune_waits_for_it_then_starts(monke
await prune
assert response.status == 202
- assert started == [("models", "input")]
+ assert started == [("models", "input", "output")]
@pytest.mark.asyncio
diff --git a/tests-unit/assets_test/services/test_lifecycle.py b/tests-unit/assets_test/services/test_lifecycle.py
index 75e2f9703..cd07435ea 100644
--- a/tests-unit/assets_test/services/test_lifecycle.py
+++ b/tests-unit/assets_test/services/test_lifecycle.py
@@ -18,6 +18,7 @@ from app.assets.lifecycle import (
run_asset_shutdown_cleanup,
run_asset_startup,
run_startup,
+ start_asset_seeder,
wipe_temp_db_rows,
)
from app.assets.scanner import get_temp_prefixes, sync_temp_references_safely
@@ -172,6 +173,13 @@ def test_run_startup_enabled_delegates_to_asset_startup_not_bare_sweep():
cleanup_mock.assert_not_called()
+def test_startup_scan_covers_models_input_and_output():
+ with patch.object(asset_seeder, "start", return_value=True) as start_mock:
+ start_asset_seeder()
+
+ assert start_mock.call_args.kwargs["roots"] == ("models", "input", "output")
+
+
def test_run_startup_logs_and_absorbs_disabled_filesystem_failure(caplog):
with patch("app.assets.lifecycle.cleanup_temp_filesystem", side_effect=RuntimeError("filesystem failure")):
run_startup(enable_assets=False)
diff --git a/tests-unit/assets_test/services/test_manager_isolated.py b/tests-unit/assets_test/services/test_manager_isolated.py
index 2af1cb9b0..ef600f4e7 100644
--- a/tests-unit/assets_test/services/test_manager_isolated.py
+++ b/tests-unit/assets_test/services/test_manager_isolated.py
@@ -18,7 +18,7 @@ from app.assets import scanner, seeder as seeder_module
from app.assets.database.models import Asset, AssetContent
from app.assets.database.queries.records import create_content, create_record
from app.assets.manager import AssetsEnabled
-from app.assets.seeder import ScanStatus, asset_seeder
+from app.assets.seeder import ScanPhase, ScanStatus, asset_seeder
from app.database.models import Base
from app.assets.services.schemas import RegisteredAsset, UploadAssetView
@@ -89,7 +89,7 @@ def output_seeder(monkeypatch: pytest.MonkeyPatch) -> Iterator[_OutputSeeder]:
_ = seeder.shutdown()
-def test_queue_output_scan_does_not_register_undeclared_output(
+def test_queue_output_scan_registers_undeclared_output(
enabled_manager: AssetsEnabled,
asset_roots: tuple[Path, Path, Path],
threaded_create_session: Callable[[], AbstractContextManager[Session]],
@@ -110,7 +110,8 @@ def test_queue_output_scan_does_not_register_undeclared_output(
.where(AssetContent.path == str(output_path.resolve()))
)
)
- assert rows == []
+ assert rows[0].job_id is None
+ assert len(rows) == 1
def test_queue_output_scan_does_not_duplicate_declared_output(
@@ -149,8 +150,37 @@ def test_queue_output_scan_does_not_duplicate_declared_output(
)
)
assert rows[0].job_id == "declared-job"
+ assert undeclared_rows[0].job_id is None
assert len(rows) == 1
- assert undeclared_rows == []
+ assert len(undeclared_rows) == 1, (
+ "the undeclared sibling proves the walk ran, so the declared row's count of 1 is a real skip rather than a silently-failed scan"
+ )
+
+
[email protected]("hashing", [False, True])
+def test_queue_output_scan_queues_a_full_output_walk_with_the_hashing_setting(
+ monkeypatch: pytest.MonkeyPatch, hashing: bool
+) -> None:
+ enqueue = Mock(return_value=True)
+ monkeypatch.setattr(asset_seeder, "enqueue_scan", enqueue)
+ monkeypatch.setattr(asset_seeder, "is_disabled", lambda: False)
+
+ args = _ArgsStub()
+ args.enable_asset_hashing = hashing
+
+ AssetsEnabled(args).queue_output_scan()
+
+ enqueue.assert_called_once_with(roots=("output",), phase=ScanPhase.FULL, compute_hashes=hashing)
+
+
+def test_queue_output_scan_does_nothing_while_the_seeder_is_disabled(monkeypatch: pytest.MonkeyPatch) -> None:
+ enqueue = Mock(return_value=True)
+ monkeypatch.setattr(asset_seeder, "enqueue_scan", enqueue)
+ monkeypatch.setattr(asset_seeder, "is_disabled", lambda: True)
+
+ AssetsEnabled(_ArgsStub()).queue_output_scan()
+
+ enqueue.assert_not_called()
def test_executed_and_cached_outputs_share_unhashed_content(
@@ -254,7 +284,7 @@ def test_ensure_scan_started_starts_the_lazy_object_info_scan(
enabled_manager.ensure_scan_started()
- seeder_start.assert_called_once_with(roots=("models", "input"))
+ seeder_start.assert_called_once_with(roots=("models", "input", "output"))
def test_shutdown_runs_lifecycle_cleanup_when_seeder_shutdown_times_out(
diff --git a/tests-unit/assets_test/services/test_noassets_parity.py b/tests-unit/assets_test/services/test_noassets_parity.py
index 7458b534b..6d373143d 100644
--- a/tests-unit/assets_test/services/test_noassets_parity.py
+++ b/tests-unit/assets_test/services/test_noassets_parity.py
@@ -1,6 +1,9 @@
+import subprocess
+import sys
from collections.abc import Callable
from contextlib import AbstractContextManager
from pathlib import Path
+from types import SimpleNamespace
from unittest.mock import Mock, patch
import pytest
@@ -18,7 +21,6 @@ from app.assets.manager import AssetsEnabled, NoAssets
from app.assets.mode import hashing_enabled
from app.assets.seeder import asset_seeder
from app.assets.services.hash_mode_state import read_stored_mode
-from comfy.cli_args import parser
class _Args:
@@ -47,7 +49,7 @@ async def test_noassets_register_routes_returns_service_disabled_and_disables_se
assert response.status == 503
error = (await response.json())["error"]
assert error["code"] == "SERVICE_DISABLED"
- assert "--disable-assets" in error["message"]
+ assert "--enable-assets" in error["message"]
assert asset_seeder.is_disabled()
@@ -184,15 +186,25 @@ def test_noassets_is_disabled() -> None:
@pytest.mark.parametrize(
("flags", "expected"),
[
- ([], AssetsEnabled),
+ ([], NoAssets),
(["--enable-assets"], AssetsEnabled),
(["--disable-assets"], NoAssets),
(["--enable-assets", "--disable-assets"], NoAssets),
],
)
-def test_assets_are_on_unless_disabled(
+def test_assets_are_off_unless_enabled(
flags: list[str], expected: type, monkeypatch: pytest.MonkeyPatch
) -> None:
- monkeypatch.setattr(manager, "args", parser.parse_args(flags))
+ # A fresh interpreter, because the rules after parse_args only run when comfy.cli_args is imported.
+ parsed = subprocess.run(
+ [sys.executable, "-c", "import comfy.options; comfy.options.enable_args_parsing(); "
+ "from comfy.cli_args import args; print(args.disable_assets)", *flags],
+ cwd=Path(__file__).resolve().parents[3],
+ capture_output=True,
+ text=True,
+ check=True,
+ )
+ disable_assets = {"True": True, "False": False}[parsed.stdout.strip()]
+ monkeypatch.setattr(manager, "args", SimpleNamespace(disable_assets=disable_assets, enable_asset_hashing=False))
assert isinstance(manager.default_asset_manager(), expected)
diff --git a/tests-unit/assets_test/test_crud.py b/tests-unit/assets_test/test_crud.py
index f34cb1d77..c3e6cfbe0 100644
--- a/tests-unit/assets_test/test_crud.py
+++ b/tests-unit/assets_test/test_crud.py
@@ -8,14 +8,14 @@ def test_missing_content_remains_in_list_after_rm_with_missing_tag(
http, api_base, asset_factory, comfy_tmp_base_dir, make_asset_bytes
):
record = asset_factory(
- "missing.png", ["input", "unit-tests"], {}, make_asset_bytes("missing")
+ "missing.png", ["output", "unit-tests"], {}, make_asset_bytes("missing")
)
- next((comfy_tmp_base_dir / "input").glob("*.png")).unlink()
+ next((comfy_tmp_base_dir / "output").glob("*.png")).unlink()
response = None
for _attempt in range(5):
response = http.post(
- f"{api_base}/api/assets/seed?wait=true", json={"roots": ["input"]}
+ f"{api_base}/api/assets/seed?wait=true", json={"roots": ["output"]}
)
if response.status_code != 409:
break
diff --git a/tests-unit/assets_test/test_no_assets_regression.py b/tests-unit/assets_test/test_no_assets_regression.py
index e44f9ae95..0a3becc6c 100644
--- a/tests-unit/assets_test/test_no_assets_regression.py
+++ b/tests-unit/assets_test/test_no_assets_regression.py
@@ -57,7 +57,7 @@ def no_assets_server(tmp_path: Path):
def test_no_assets_keeps_legacy_upload_and_view(no_assets_server: str):
disabled = requests.get(f"{no_assets_server}/api/assets", timeout=10)
assert disabled.status_code == 503
- assert "--disable-assets" in disabled.json()["error"]["message"]
+ assert "--enable-assets" in disabled.json()["error"]["message"]
upload = requests.post(
f"{no_assets_server}/upload/image",
diff --git a/tests-unit/assets_test/test_startup_without_asset_dependencies.py b/tests-unit/assets_test/test_startup_without_asset_dependencies.py
index 4fe75203b..892ba28f9 100644
--- a/tests-unit/assets_test/test_startup_without_asset_dependencies.py
+++ b/tests-unit/assets_test/test_startup_without_asset_dependencies.py
@@ -41,12 +41,13 @@ def run_quick_startup(tmp_path: Path, *flags: str) -> subprocess.CompletedProces
)
-def test_starts_without_asset_dependencies_when_assets_disabled(tmp_path: Path) -> None:
[email protected]("flags", [(), ("--disable-assets",), ("--enable-assets", "--disable-assets")])
+def test_starts_without_asset_dependencies_when_assets_off(tmp_path: Path, flags: tuple[str, ...]) -> None:
stale_temp_file = tmp_path / "temp" / "stale.png"
stale_temp_file.parent.mkdir()
stale_temp_file.write_bytes(b"")
- result = run_quick_startup(tmp_path, "--disable-assets")
+ result = run_quick_startup(tmp_path, *flags)
assert result.returncode == 0, result.stdout + result.stderr
assert "Traceback" not in result.stderr
@@ -54,9 +55,8 @@ def test_starts_without_asset_dependencies_when_assets_disabled(tmp_path: Path)
assert not stale_temp_file.exists()
[email protected]("flags", [(), ("--enable-assets",)])
-def test_missing_dependencies_stop_startup_and_name_the_fix(tmp_path: Path, flags: tuple[str, ...]) -> None:
- result = run_quick_startup(tmp_path, *flags)
+def test_missing_dependencies_stop_startup_and_name_the_fix(tmp_path: Path) -> None:
+ result = run_quick_startup(tmp_path, "--enable-assets")
output = result.stdout + result.stderr
assert result.returncode == 1, output
diff --git a/tests/execution/test_execution.py b/tests/execution/test_execution.py
index d55df4d19..6778fbb77 100644
--- a/tests/execution/test_execution.py
+++ b/tests/execution/test_execution.py
@@ -21,6 +21,8 @@ from app.assets.services.file_utils import list_files_recursively
ASSET_HEALTH_TIMEOUT_SECONDS = 120
+ASSET_SEED_RETRY_ATTEMPTS = 10
+ASSET_SEED_RETRY_DELAY_SECONDS = 3
ASSET_STATUS_POLL_DELAY_SECONDS = 1
ASSET_CAPTURE_TAIL_LINES = 80
@@ -51,14 +53,16 @@ ASSET_FATAL_LOG_PREFIXES = (
)
-def _asset_json_request(url, deadline):
+def _asset_json_request(url, deadline, data=None):
remaining = deadline - time.monotonic()
if remaining <= 0:
raise AssertionError(
f"Asset health check failure (i): deadline/transport failure before requesting {url}"
)
- request = urllib.request.Request(url)
+ request = urllib.request.Request(url, data=data)
+ if data is not None:
+ request.add_header("Content-Type", "application/json")
try:
with urllib.request.urlopen(request, timeout=max(0.01, remaining)) as response:
@@ -88,6 +92,64 @@ def _asset_json_request(url, deadline):
return status, payload
+def _seed_output_assets(base_url, deadline):
+ request_data = json.dumps({"roots": ["output"]}).encode("utf-8")
+ last_conflict_payload = None
+ for attempt in range(1, ASSET_SEED_RETRY_ATTEMPTS + 1):
+ if last_conflict_payload is not None and deadline - time.monotonic() <= 0:
+ raise AssertionError(
+ "Asset health check failure (ii): 409-retries-exhausted before the deadline; "
+ f"last payload={last_conflict_payload!r}"
+ )
+
+ url = f"{base_url}/api/assets/seed?wait=true"
+ status, payload = _asset_json_request(url, deadline, request_data)
+ if status == 409:
+ if payload.get("status") != "already_running":
+ raise AssertionError(
+ "Asset health check failure (iv): malformed JSON/schema "
+ f"from {url}: status={status}, payload={payload!r}"
+ )
+ last_conflict_payload = payload
+ if attempt == ASSET_SEED_RETRY_ATTEMPTS:
+ raise AssertionError(
+ "Asset health check failure (ii): 409-retries-exhausted after "
+ f"{attempt} attempts; last payload={payload!r}"
+ )
+ remaining = deadline - time.monotonic()
+ if remaining <= 0:
+ raise AssertionError(
+ "Asset health check failure (ii): 409-retries-exhausted before the deadline; "
+ f"last payload={payload!r}"
+ )
+ time.sleep(min(ASSET_SEED_RETRY_DELAY_SECONDS, remaining))
+ continue
+ if status != 200:
+ raise AssertionError(
+ "Asset health check failure (iv): unexpected-HTTP-status "
+ f"from {url}: status={status}, payload={payload!r}"
+ )
+
+ progress = payload.get("progress")
+ errors = payload.get("errors")
+ progress_fields = ("scanned", "total", "created", "skipped")
+ if (
+ payload.get("status") != "completed"
+ or not isinstance(progress, dict)
+ or any(type(progress.get(field)) is not int for field in progress_fields)
+ or not isinstance(errors, list)
+ ):
+ raise AssertionError(
+ "Asset health check failure (iv): malformed JSON/schema "
+ f"from {url}: status={status}, payload={payload!r}"
+ )
+ if errors:
+ raise AssertionError(
+ f"Asset health check failure (iii): scan-completed-with-errors: errors={errors!r}"
+ )
+ return
+
+
def _wait_for_stable_asset_idle(base_url, deadline):
stable_reads = 0
last_payload = None
@@ -218,13 +280,14 @@ def _assert_no_fatal_asset_logs(capture_path):
)
-def _assert_assets_healthy(listen, port, output_dir, capture_path, initial_output_paths):
+def _assert_assets_healthy(listen, port, output_dir, capture_path):
deadline = time.monotonic() + ASSET_HEALTH_TIMEOUT_SECONDS
base_url = f"http://{listen}:{port}"
+ _seed_output_assets(base_url, deadline)
_wait_for_stable_asset_idle(base_url, deadline)
api_paths = _fetch_output_asset_paths(base_url, deadline)
- disk_paths = _list_output_files_on_disk(output_dir) - initial_output_paths
+ disk_paths = _list_output_files_on_disk(output_dir)
if not api_paths or not disk_paths:
raise AssertionError(
"Asset health check reconcile failure: expected non-empty sets: "
@@ -436,10 +499,10 @@ class TestExecution:
if not assets_enabled:
pargs.append('--disable-assets')
else:
+ pargs.append('--enable-assets')
assets_tmp_dir = tmp_path_factory.mktemp("execution-assets")
database_path = assets_tmp_dir / "assets.db"
capture_path = assets_tmp_dir / "server.log"
- initial_output_paths = _list_output_files_on_disk(args_pytest["output_dir"])
pargs += ["--database-url", f"sqlite:///{database_path}"]
print("Running server with args:", pargs) # noqa: T201
if assets_enabled:
@@ -467,7 +530,6 @@ class TestExecution:
args_pytest["port"],
args_pytest["output_dir"],
capture_path,
- initial_output_paths,
)
except AssertionError as error:
health_failure = error