mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-09-20 18:51:26 -03:00
feat(recipes): add Unknown base-model filter bucket for undetermined recipes
Normalize undetermined recipe base_model to None in RecipeFormatParser (previously ''). get_base_models now reports an "Unknown" bucket backed by a dedicated __unknown__ marker, and the listing filter matches it against recipes whose base model is falsy. Frontend renders the bucket label as "Unknown" while filtering via the marker. Tests: handler, scanner, parser, and frontend filtering.
This commit is contained in:
@@ -111,6 +111,36 @@ async def test_recipe_format_parser_populates_checkpoint(monkeypatch):
|
||||
assert result["model"] == checkpoint
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_recipe_format_parser_base_model_defaults_to_none_when_unknown(monkeypatch):
|
||||
class _FakeScanner:
|
||||
pass
|
||||
|
||||
# No checkpoint and empty base_model -> unknown renders as None (not "")
|
||||
result = await _parse(
|
||||
monkeypatch,
|
||||
{"title": "T", "base_model": "", "loras": [], "gen_params": {}},
|
||||
_FakeScanner(),
|
||||
)
|
||||
assert result["base_model"] is None
|
||||
|
||||
# Missing base_model key behaves the same
|
||||
result = await _parse(
|
||||
monkeypatch,
|
||||
{"title": "T", "loras": [], "gen_params": {}},
|
||||
_FakeScanner(),
|
||||
)
|
||||
assert result["base_model"] is None
|
||||
|
||||
# A real base_model in recipe metadata is kept
|
||||
result = await _parse(
|
||||
monkeypatch,
|
||||
{"title": "T", "base_model": "Illustrious", "loras": [], "gen_params": {}},
|
||||
_FakeScanner(),
|
||||
)
|
||||
assert result["base_model"] == "Illustrious"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_recipe_format_parser_marks_lora_in_library_by_version(monkeypatch):
|
||||
async def fake_metadata_provider():
|
||||
|
||||
@@ -12,7 +12,7 @@ from py.services import model_scanner as model_scanner_module
|
||||
from py.services.model_cache import ModelCache
|
||||
from py.services.model_hash_index import ModelHashIndex
|
||||
from py.services.model_scanner import CacheBuildResult, ModelScanner
|
||||
from py.services.recipe_scanner import RecipeScanner
|
||||
from py.services.recipe_scanner import RecipeScanner, UNKNOWN_BASE_MODEL_FILTER
|
||||
from py.services import settings_manager as settings_manager_module
|
||||
from py.utils.models import BaseModelMetadata
|
||||
from py.utils.utils import calculate_recipe_fingerprint
|
||||
@@ -1954,6 +1954,59 @@ async def test_get_paginated_data_filters_by_favorite(recipe_scanner):
|
||||
assert len(result_fav_false["items"]) == 2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_paginated_data_filters_by_base_model_unknown_bucket(recipe_scanner):
|
||||
scanner, _ = recipe_scanner
|
||||
|
||||
await scanner.add_recipe(
|
||||
{
|
||||
"id": "known",
|
||||
"file_path": "path/known.png",
|
||||
"title": "Known Base Model",
|
||||
"modified": 1.0,
|
||||
"created_date": 1.0,
|
||||
"base_model": "SDXL 1.0",
|
||||
"loras": [],
|
||||
}
|
||||
)
|
||||
await scanner.add_recipe(
|
||||
{
|
||||
"id": "unknown",
|
||||
"file_path": "path/unknown.png",
|
||||
"title": "Unknown Base Model",
|
||||
"modified": 2.0,
|
||||
"created_date": 2.0,
|
||||
"base_model": None,
|
||||
"loras": [],
|
||||
}
|
||||
)
|
||||
|
||||
await asyncio.sleep(0)
|
||||
await _wait_for_resort(scanner)
|
||||
|
||||
# Exact-name filter matches only the recipe with that base model
|
||||
result_known = await scanner.get_paginated_data(
|
||||
page=1, page_size=10, filters={"base_model": ["SDXL 1.0"]}
|
||||
)
|
||||
assert [item["id"] for item in result_known["items"]] == ["known"]
|
||||
|
||||
# Unknown bucket matches recipes whose base model could not be determined
|
||||
result_unknown = await scanner.get_paginated_data(
|
||||
page=1,
|
||||
page_size=10,
|
||||
filters={"base_model": [UNKNOWN_BASE_MODEL_FILTER]},
|
||||
)
|
||||
assert [item["id"] for item in result_unknown["items"]] == ["unknown"]
|
||||
|
||||
# Mixing known values with the unknown bucket matches both groups
|
||||
result_both = await scanner.get_paginated_data(
|
||||
page=1,
|
||||
page_size=10,
|
||||
filters={"base_model": ["SDXL 1.0", UNKNOWN_BASE_MODEL_FILTER]},
|
||||
)
|
||||
assert {item["id"] for item in result_both["items"]} == {"known", "unknown"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_paginated_data_filters_by_prompt(recipe_scanner):
|
||||
scanner, _ = recipe_scanner
|
||||
|
||||
Reference in New Issue
Block a user