mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-25 07:05:43 -03:00
fix(recipes): normalize relocated preview paths
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
@@ -183,3 +184,35 @@ async def test_update_lora_entry_updates_cache_and_file(tmp_path: Path, recipe_s
|
||||
cached_recipe = next(item for item in cache.raw_data if item["id"] == recipe_id)
|
||||
assert cached_recipe["loras"][0]["hash"] == target_hash
|
||||
assert cached_recipe["fingerprint"] == expected_fingerprint
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_load_recipe_rewrites_missing_image_path(tmp_path: Path, recipe_scanner):
|
||||
scanner, _ = recipe_scanner
|
||||
recipes_dir = Path(config.loras_roots[0]) / "recipes"
|
||||
recipes_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
recipe_id = "moved"
|
||||
old_root = tmp_path / "old_root"
|
||||
old_path = old_root / "recipes" / f"{recipe_id}.webp"
|
||||
recipe_path = recipes_dir / f"{recipe_id}.recipe.json"
|
||||
current_image = recipes_dir / f"{recipe_id}.webp"
|
||||
current_image.write_bytes(b"image-bytes")
|
||||
|
||||
recipe_data = {
|
||||
"id": recipe_id,
|
||||
"file_path": str(old_path),
|
||||
"title": "Relocated",
|
||||
"modified": 0.0,
|
||||
"created_date": 0.0,
|
||||
"loras": [],
|
||||
}
|
||||
recipe_path.write_text(json.dumps(recipe_data))
|
||||
|
||||
loaded = await scanner._load_recipe_file(str(recipe_path))
|
||||
|
||||
expected_path = os.path.normpath(str(current_image))
|
||||
assert loaded["file_path"] == expected_path
|
||||
|
||||
persisted = json.loads(recipe_path.read_text())
|
||||
assert persisted["file_path"] == expected_path
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@@ -148,3 +150,8 @@ async def test_save_recipe_reports_duplicates(tmp_path):
|
||||
assert scanner.last_fingerprint is not None
|
||||
assert os.path.exists(result.payload["json_path"])
|
||||
assert scanner._cache.raw_data
|
||||
|
||||
stored = json.loads(Path(result.payload["json_path"]).read_text())
|
||||
expected_image_path = os.path.normpath(result.payload["image_path"])
|
||||
assert stored["file_path"] == expected_image_path
|
||||
assert service._exif_utils.appended[0] == expected_image_path
|
||||
|
||||
Reference in New Issue
Block a user