feat(recipe): send embedded recipe workflow to ComfyUI canvas

This commit is contained in:
Will Miao
2026-08-20 22:18:13 +08:00
parent 0905e2be6e
commit 3ebf256c5d
24 changed files with 1145 additions and 27 deletions
+83
View File
@@ -551,3 +551,86 @@ class TestPersistentRecipeCache:
loaded = cache.load_cache()
assert loaded is not None
assert loaded.image_id_map == {"222": "new-only"}
class TestHasWorkflowColumn:
"""has_workflow column persistence (plan 3.1)."""
def test_save_and_load_roundtrip(self, temp_db_path):
"""has_workflow must round-trip through save_cache()/load_cache()."""
cache = PersistentRecipeCache(db_path=temp_db_path)
recipes = [
{"id": "wf-1", "title": "Has Workflow", "has_workflow": True},
{"id": "wf-2", "title": "No Workflow", "has_workflow": False},
{"id": "wf-3", "title": "Unset Workflow"},
]
cache.save_cache(recipes)
loaded = cache.load_cache()
assert loaded is not None
by_id = {r["id"]: r for r in loaded.raw_data}
assert by_id["wf-1"]["has_workflow"] is True
assert by_id["wf-2"]["has_workflow"] is False
assert by_id["wf-3"]["has_workflow"] is False
def test_prepare_recipe_row_matches_column_order(self, temp_db_path):
"""The prepared row must append has_workflow in column order."""
cache = PersistentRecipeCache(db_path=temp_db_path)
row_true = cache._prepare_recipe_row({"id": "r1", "has_workflow": True}, "")
row_false = cache._prepare_recipe_row({"id": "r2", "has_workflow": False}, "")
assert row_true[-1] == 1
assert row_false[-1] == 0
assert len(row_true) == len(cache._RECIPE_COLUMNS)
assert cache._RECIPE_COLUMNS[-1] == "has_workflow"
def test_update_recipe_preserves_has_workflow(self, temp_db_path):
"""update_recipe() must write the has_workflow column correctly."""
cache = PersistentRecipeCache(db_path=temp_db_path)
cache.save_cache([{"id": "wf-update", "title": "x", "has_workflow": True}])
cache.update_recipe({"id": "wf-update", "title": "y", "has_workflow": False})
loaded = cache.load_cache()
assert loaded is not None
assert loaded.raw_data[0]["has_workflow"] is False
def test_migrates_legacy_database_adds_has_workflow(self, temp_db_path):
"""A database created before has_workflow existed must still load."""
import sqlite3
conn = sqlite3.connect(temp_db_path)
conn.execute(
"""
CREATE TABLE recipes (
recipe_id TEXT PRIMARY KEY,
file_path TEXT,
json_path TEXT,
title TEXT,
folder TEXT,
source_path TEXT,
base_model TEXT,
fingerprint TEXT,
created_date REAL,
modified REAL,
file_mtime REAL,
file_size INTEGER,
favorite INTEGER DEFAULT 0,
repair_version INTEGER DEFAULT 0,
preview_nsfw_level INTEGER DEFAULT 0,
loras_json TEXT,
checkpoint_json TEXT,
gen_params_json TEXT,
tags_json TEXT
)
"""
)
conn.execute("INSERT INTO recipes (recipe_id, title) VALUES ('legacy-1', 'Legacy')")
conn.commit()
conn.close()
cache = PersistentRecipeCache(db_path=temp_db_path)
loaded = cache.load_cache()
assert loaded is not None
assert loaded.raw_data[0]["id"] == "legacy-1"
assert loaded.raw_data[0]["has_workflow"] is False