mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-08-26 07:21:27 -03:00
fix(update): align update-check summary count with Updates filter scope (#1083)
This commit is contained in:
@@ -187,6 +187,144 @@ def test_has_update_for_base_rejects_other_base_models():
|
||||
assert record.has_update_for_base(10, "Flux") is False
|
||||
|
||||
|
||||
def test_has_update_for_local_bases_detects_same_base_newer_version():
|
||||
record = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(6, in_library=False, base_model="pony"),
|
||||
)
|
||||
|
||||
assert record.has_update_for_local_bases() is True
|
||||
|
||||
|
||||
def test_has_update_for_local_bases_rejects_cross_base_only_update():
|
||||
"""Issue #1083: a newer remote version targeting another base model must
|
||||
not count when the report is scoped like the Updates filter."""
|
||||
record = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(6, in_library=False, base_model="Flux.1"),
|
||||
)
|
||||
|
||||
assert record.has_update_for_local_bases() is False
|
||||
assert record.has_update() is True
|
||||
|
||||
|
||||
def test_has_update_for_local_bases_hits_when_any_scope_qualifies():
|
||||
record = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(6, in_library=False, base_model="Flux.1"),
|
||||
make_version(7, in_library=False, base_model="Pony"),
|
||||
)
|
||||
|
||||
assert record.has_update_for_local_bases() is True
|
||||
|
||||
|
||||
def test_has_update_for_local_bases_respects_ignore_and_hides():
|
||||
ignored = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(6, in_library=False, base_model="Pony", should_ignore=True),
|
||||
)
|
||||
assert ignored.has_update_for_local_bases() is False
|
||||
|
||||
paid = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(
|
||||
6,
|
||||
in_library=False,
|
||||
base_model="Pony",
|
||||
is_paid=True,
|
||||
paid_access='{"permanent": true, "endsAt": null}',
|
||||
),
|
||||
)
|
||||
assert paid.has_update_for_local_bases() is True
|
||||
assert paid.has_update_for_local_bases(hide_paid=True) is False
|
||||
|
||||
timed_early_access = make_record(
|
||||
make_version(5, in_library=True, base_model="Pony"),
|
||||
make_version(
|
||||
6,
|
||||
in_library=False,
|
||||
base_model="Pony",
|
||||
early_access_ends_at="2099-01-01T00:00:00Z",
|
||||
is_early_access=True,
|
||||
),
|
||||
)
|
||||
assert timed_early_access.has_update_for_local_bases() is True
|
||||
assert timed_early_access.has_update_for_local_bases(hide_early_access=True) is False
|
||||
|
||||
|
||||
def test_has_update_for_local_bases_falls_back_when_no_local_scopes_known():
|
||||
"""Without any known in-library base (e.g. a local version delisted from
|
||||
Civitai before its first refresh), the aggregate falls back to the
|
||||
unscoped predicate so the summary cannot silently drop models the
|
||||
item-level Updates filter may still flag from file metadata."""
|
||||
delisted_local = make_record(
|
||||
make_version(5, in_library=True, base_model=None),
|
||||
make_version(6, in_library=False, base_model="Pony"),
|
||||
)
|
||||
assert delisted_local.has_update_for_local_bases() is True
|
||||
|
||||
remote_only = make_record(make_version(6, in_library=False, base_model="Pony"))
|
||||
assert remote_only.has_update_for_local_bases() is True
|
||||
|
||||
|
||||
def test_build_record_from_remote_synthesizes_base_from_local_map(tmp_path):
|
||||
"""Versions missing from the remote listing are synthesized with the base
|
||||
model collected from cache items, so same-base scoping survives a version
|
||||
being delisted upstream."""
|
||||
db_path = tmp_path / "updates.sqlite"
|
||||
service = ModelUpdateService(str(db_path))
|
||||
remote = [make_version(6, in_library=False, base_model="Pony")]
|
||||
|
||||
record = service._build_record_from_remote(
|
||||
model_type="lora",
|
||||
model_id=1,
|
||||
local_versions=[5],
|
||||
remote_versions=remote,
|
||||
existing=None,
|
||||
timestamp=1.0,
|
||||
local_base_models={5: "Pony"},
|
||||
)
|
||||
v5 = next(v for v in record.versions if v.version_id == 5)
|
||||
assert v5.base_model == "Pony"
|
||||
|
||||
record_without_map = service._build_record_from_remote(
|
||||
model_type="lora",
|
||||
model_id=1,
|
||||
local_versions=[5],
|
||||
remote_versions=remote,
|
||||
existing=None,
|
||||
timestamp=1.0,
|
||||
)
|
||||
v5_plain = next(v for v in record_without_map.versions if v.version_id == 5)
|
||||
assert v5_plain.base_model is None
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_refresh_synthesizes_base_model_from_cache_items(tmp_path):
|
||||
"""End-to-end: a locally-held version absent from the remote listing keeps
|
||||
its cache-item base model, keeping it countable under same-base scoping."""
|
||||
db_path = tmp_path / "updates.sqlite"
|
||||
service = ModelUpdateService(str(db_path), ttl_seconds=0)
|
||||
raw_data = [{"civitai": {"modelId": 1, "id": 11}, "base_model": "Pony"}]
|
||||
scanner = DummyScanner(raw_data)
|
||||
provider = DummyProvider(
|
||||
{
|
||||
"modelVersions": [
|
||||
{"id": 12, "baseModel": "Pony", "files": [], "images": []},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
await service.refresh_for_model_type("lora", scanner, provider)
|
||||
record = await service.get_record("lora", 1)
|
||||
|
||||
assert record is not None
|
||||
v11 = next(v for v in record.versions if v.version_id == 11)
|
||||
assert v11.base_model == "Pony"
|
||||
assert record.has_update() is True
|
||||
assert record.has_update_for_local_bases() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_refresh_persists_versions_and_uses_cache(tmp_path):
|
||||
db_path = tmp_path / "updates.sqlite"
|
||||
|
||||
Reference in New Issue
Block a user