feat(backend): gate Other Models behind opt-in management toggles

Other Models management is now opt-in: enable_other_models (default false)
plus the enabled_other_sub_types allow-list replace the unreleased additive
enabled_other_folders key.

- config._get_enabled_other_folder_keys() is the single scan gate; a new
  refresh_other_roots() rebuilds roots and preview roots on toggle.
- ModelScanner gains a _should_keep_cached_entry() hydration hook and
  on_library_changed(reconcile=...) so switching a sub_type off drops its
  entries (and hash/autov3 rows) at load time and switching it on rescans.
- OtherScanner filters location-derived entries accordingly.
- Other routes reject every other type while off (or a disabled sub_type) and
  expose an "other_disabled" page flag; download routing returns a disabled
  marker instead of guessing; the download manager refuses other-type
  downloads and default-path routing for switched-off sub_types.
- Doctor / init-status / refresh-all skip the other scanner while off; the
  scanner stays registered so staged pending-deletes still merge.
- Tests updated with explicit opt-in fixtures plus new gating coverage.
This commit is contained in:
Will Miao
2026-09-13 07:59:28 +08:00
parent f88fe2665c
commit 28fbb86dce
19 changed files with 583 additions and 84 deletions
+43 -2
View File
@@ -26,6 +26,14 @@ def _make_config(**overrides) -> config_module.Config:
return config
@pytest.fixture(autouse=True)
def enable_other_models():
"""Other Models is opt-in; enable it for the enabled-state tests."""
manager = get_settings_manager()
manager.set("enable_other_models", True)
yield
class TestPrepareOtherPaths:
"""Unit tests for Config._prepare_other_paths."""
@@ -196,7 +204,7 @@ class TestInitOtherPaths:
controlnet_dir.mkdir()
self._stub_folder_paths(monkeypatch, {"controlnet": str(controlnet_dir)})
get_settings_manager().set("enabled_other_folders", ["controlnet"])
get_settings_manager().set("enabled_other_sub_types", ["controlnet"])
config = _make_config()
roots = config._init_other_paths()
@@ -207,12 +215,45 @@ class TestInitOtherPaths:
== "controlnet"
)
def test_disabled_sub_type_is_not_scanned(self, monkeypatch, tmp_path):
vae_dir = tmp_path / "vae"
upscaler_dir = tmp_path / "upscale_models"
vae_dir.mkdir()
upscaler_dir.mkdir()
self._stub_folder_paths(
monkeypatch, {"vae": str(vae_dir), "upscale_models": str(upscaler_dir)}
)
get_settings_manager().set("enabled_other_sub_types", ["vae"])
config = _make_config()
roots = config._init_other_paths()
assert roots == [_normalize(str(vae_dir))]
assert _normalize(str(upscaler_dir)) not in config.other_root_subtypes
def test_feature_disabled_scans_nothing(self, monkeypatch, tmp_path):
vae_dir = tmp_path / "vae"
vae_dir.mkdir()
self._stub_folder_paths(monkeypatch, {"vae": str(vae_dir)})
get_settings_manager().set("enable_other_models", False)
config = _make_config()
roots = config._init_other_paths()
assert roots == []
assert config.other_root_subtypes == {}
assert config.other_folder_roots == {}
def test_unknown_opt_in_keys_are_ignored(self, monkeypatch, tmp_path):
vae_dir = tmp_path / "vae"
vae_dir.mkdir()
self._stub_folder_paths(monkeypatch, {"vae": str(vae_dir)})
get_settings_manager().set("enabled_other_folders", ["not_a_real_key", 42])
get_settings_manager().set(
"enabled_other_sub_types", ["vae", "not_a_real_key", 42]
)
config = _make_config()
roots = config._init_other_paths()