fix(nodes): resolve KB path against the package and add raw debug outputs (#78)

Two ComfyUI issues found while testing.

1. Empty output with no error: the Knowledge Base Loader resolved a relative
   `path` against ComfyUI's working directory, not this package, so the default
   `knowledge_base/` loaded 0 entries (an empty KB is valid) and every concept
   became unknown -> empty prompts. Relative paths now resolve against the
   package root, and the loader warns when the Knowledge Base is empty.

2. Add a `raw` string output (a JSON dump of the node's data) to the Scene
   Analyzer, Scene Validator, Resolver, Category Splitter, and Prompt Builder
   nodes, plus a summary `raw` on the Knowledge Base Loader, for inspecting the
   pipeline in the graph. Adds a shared to_raw_json helper.

Tests: package-relative path resolution (independent of cwd), empty-KB warning,
raw output content, and updated node metadata/return-arity expectations.

Co-authored-by: kunail0804 <kunail0804@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Crespin Alexandre
2026-07-09 18:54:40 +02:00
committed by GitHub
co-authored by kunail0804 Claude Opus 4.8
parent c967327e8f
commit de5edd7064
15 changed files with 160 additions and 63 deletions
+22 -5
View File
@@ -15,8 +15,8 @@ def write_kb(directory, entries: list[dict]) -> str:
def test_node_metadata() -> None:
assert KnowledgeBaseLoaderNode.RETURN_TYPES == ("KNOWLEDGE_BASE", "STRING", "STRING")
assert KnowledgeBaseLoaderNode.RETURN_NAMES == ("knowledge_base", "warnings", "errors")
assert KnowledgeBaseLoaderNode.RETURN_TYPES == ("KNOWLEDGE_BASE", "STRING", "STRING", "STRING")
assert KnowledgeBaseLoaderNode.RETURN_NAMES == ("knowledge_base", "warnings", "errors", "raw")
inputs = KnowledgeBaseLoaderNode.INPUT_TYPES()
assert "path" in inputs["required"]
assert "reload" in inputs["optional"]
@@ -24,7 +24,7 @@ def test_node_metadata() -> None:
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)
kb, warnings, errors, *_ = KnowledgeBaseLoaderNode().run(path)
assert isinstance(kb, KnowledgeBase)
assert kb.get("long_hair") is not None
assert (warnings, errors) == ("", "")
@@ -32,14 +32,31 @@ def test_loads_knowledge_base(tmp_path) -> None:
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)
kb, warnings, errors, *_ = KnowledgeBaseLoaderNode().run(path)
assert kb is None
assert "SC0004" in errors
def test_relative_path_resolves_against_package(monkeypatch, tmp_path) -> None:
# Even with an unrelated working directory (as under ComfyUI), the default
# relative path must load the shipped Knowledge Base, not an empty one.
monkeypatch.chdir(tmp_path)
kb, warnings, errors, raw = KnowledgeBaseLoaderNode().run("knowledge_base/")
assert isinstance(kb, KnowledgeBase)
assert len(kb) > 100
assert (warnings, errors) == ("", "")
assert "entries" in raw
def test_empty_knowledge_base_warns(tmp_path) -> None:
kb, warnings, errors, raw = KnowledgeBaseLoaderNode().run(str(tmp_path))
assert len(kb) == 0
assert "empty" in warnings.lower()
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)
kb, _, _, _ = KnowledgeBaseLoaderNode().run(path, reload=5)
assert isinstance(kb, KnowledgeBase)