* feat(nodes): add the Knowledge Base Loader ComfyUI node (#25) Add nodes/knowledge_base_loader_node.py: KnowledgeBaseLoaderNode, a thin adapter that delegates to load_knowledge_base (MASTER_SPEC §20). - Input path (STRING, default knowledge_base/) plus an optional reload (INT): bumping reload changes the inputs so ComfyUI re-executes the node -- an explicit manual reload with no automatic file watching. - Outputs (knowledge_base, warnings, errors): the KNOWLEDGE_BASE for the Resolver node, or None with the surfaced SC0004 message and findings on failure. No compiler logic in the node. - Registered as SceneCompilerKnowledgeBaseLoader ("Knowledge Base Loader"). Tests: metadata/inputs, successful load, SC0004 surfacing on an invalid KB, reload input accepted, and registration. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * ci: run push only on main and add concurrency guard Feature-branch CI now runs via the pull_request event only (push runs on main), eliminating duplicate runs per PR; a concurrency group cancels superseded runs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: kunail0804 <kunail0804@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.9 KiB
Python
52 lines
1.9 KiB
Python
"""Tests for the Knowledge Base Loader ComfyUI node (issue #25)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import nodes
|
|
from compiler.common.knowledge_base import KnowledgeBase
|
|
from nodes.knowledge_base_loader_node import KnowledgeBaseLoaderNode
|
|
|
|
|
|
def write_kb(directory, entries: list[dict]) -> str:
|
|
(directory / "hair.json").write_text(json.dumps(entries), encoding="utf-8")
|
|
return str(directory)
|
|
|
|
|
|
def test_node_metadata() -> None:
|
|
assert KnowledgeBaseLoaderNode.RETURN_TYPES == ("KNOWLEDGE_BASE", "STRING", "STRING")
|
|
assert KnowledgeBaseLoaderNode.RETURN_NAMES == ("knowledge_base", "warnings", "errors")
|
|
inputs = KnowledgeBaseLoaderNode.INPUT_TYPES()
|
|
assert "path" in inputs["required"]
|
|
assert "reload" in inputs["optional"]
|
|
|
|
|
|
def test_loads_knowledge_base(tmp_path) -> None:
|
|
path = write_kb(tmp_path, [{"id": "long_hair", "tags": ["long hair"], "category": "hair"}])
|
|
kb, warnings, errors = KnowledgeBaseLoaderNode().run(path)
|
|
assert isinstance(kb, KnowledgeBase)
|
|
assert kb.get("long_hair") is not None
|
|
assert (warnings, errors) == ("", "")
|
|
|
|
|
|
def test_invalid_knowledge_base_surfaces_sc0004(tmp_path) -> None:
|
|
path = write_kb(tmp_path, [{"id": "x", "tags": ["x"], "category": "nope"}])
|
|
kb, warnings, errors = KnowledgeBaseLoaderNode().run(path)
|
|
assert kb is None
|
|
assert "SC0004" in errors
|
|
|
|
|
|
def test_reload_input_is_accepted(tmp_path) -> None:
|
|
path = write_kb(tmp_path, [{"id": "long_hair", "tags": ["long hair"], "category": "hair"}])
|
|
kb, _, _ = KnowledgeBaseLoaderNode().run(path, reload=5)
|
|
assert isinstance(kb, KnowledgeBase)
|
|
|
|
|
|
def test_registered_for_comfyui() -> None:
|
|
assert nodes.NODE_CLASS_MAPPINGS["SceneCompilerKnowledgeBaseLoader"] is KnowledgeBaseLoaderNode
|
|
assert (
|
|
nodes.NODE_DISPLAY_NAME_MAPPINGS["SceneCompilerKnowledgeBaseLoader"]
|
|
== "Knowledge Base Loader"
|
|
)
|