Files
kunail0804-ComfyUI-Scene-Co…/tests/test_examples.py
T
02c3153359 docs(examples): add example workflow, scenes, and expected outputs (#30) (#74)
Ship ready-to-use examples (MASTER_SPEC §24, Phase 7).

- examples/workflows/scene_compiler_pipeline.json: a ComfyUI workflow wiring
  Configuration + Knowledge Base Loader + Analyzer -> Validator -> Resolver ->
  Category Splitter -> Prompt Builder.
- examples/scenes/*.scene.json: standalone example Scene JSON documents
  (single character; two characters with an interaction and an expansion).
- examples/scenes/*.prompts.json: the exact prompt outputs each scene compiles to
  with the shipped Knowledge Base and default config.
- examples/README.md: how to load the workflow and use the scene examples.

tests/test_examples.py asserts each example Scene JSON compiles to its documented
outputs, and that the workflow references only registered Scene Compiler nodes
and includes the full pipeline. The workflow JSON still wants a ComfyUI visual
check.

Co-authored-by: kunail0804 <kunail0804@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-09 13:54:08 +02:00

60 lines
2.1 KiB
Python

"""Tests that the shipped example scenes compile to their documented outputs (#30)."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from tests.regression.golden_scenes import (
compile_prompt_outputs,
load_reference_knowledge_base,
)
EXAMPLES_DIR = Path(__file__).resolve().parent.parent / "examples"
SCENES_DIR = EXAMPLES_DIR / "scenes"
WORKFLOW_FILE = EXAMPLES_DIR / "workflows" / "scene_compiler_pipeline.json"
SCENE_FILES = sorted(SCENES_DIR.glob("*.scene.json"))
@pytest.fixture(scope="module")
def knowledge_base():
return load_reference_knowledge_base()
def test_example_scenes_exist() -> None:
assert SCENE_FILES, "no example scenes found"
for scene_file in SCENE_FILES:
expected = scene_file.with_name(scene_file.name.replace(".scene.json", ".prompts.json"))
assert expected.is_file(), f"missing expected outputs for {scene_file.name}"
@pytest.mark.parametrize("scene_file", SCENE_FILES, ids=lambda p: p.stem)
def test_example_scene_compiles_to_documented_outputs(scene_file: Path, knowledge_base) -> None:
scene = json.loads(scene_file.read_text(encoding="utf-8"))
expected_file = scene_file.with_name(scene_file.name.replace(".scene.json", ".prompts.json"))
expected = json.loads(expected_file.read_text(encoding="utf-8"))
assert compile_prompt_outputs(scene, knowledge_base) == expected
def test_workflow_is_valid_json_referencing_registered_nodes() -> None:
import nodes
workflow = json.loads(WORKFLOW_FILE.read_text(encoding="utf-8"))
node_types = {node["type"] for node in workflow["nodes"]}
# Every node type in the example workflow is a registered Scene Compiler node.
assert node_types <= set(nodes.NODE_CLASS_MAPPINGS)
# The full pipeline is present.
for required in (
"SceneCompilerConfiguration",
"SceneCompilerKnowledgeBaseLoader",
"SceneCompilerAnalyzer",
"SceneCompilerValidator",
"SceneCompilerResolver",
"SceneCompilerCategorySplitter",
"SceneCompilerPromptBuilder",
):
assert required in node_types