Files
InvokeAI/tests/test_docs_json_export.py
Alexander Eichhorn 70c852e896 fix(architectures): pin the latent space per base, and bound guidance from the node
The declaration this series exists to protect was itself checked for four of
sixteen bases: swapping FLUX_16 for SD3_16 in the FLUX declaration passed every
committed test and corrupted every FLUX preview at generation time. A 16-row
identity table now pins each base against the pre-refactor dispatch, and each of
the nine spaces has a hand-derived preview pixel. The smoothing-kernel test was
seeding after it drew its sample, so it had never been deterministic.

The guidance control's bounds now come from the architecture too, the way the
dimension grid already does. FLUX.2 accepts at most 20 and four architectures
reject below 1, while the input allowed 0 to 100 for every model -- so a value
the UI offered was rejected at enqueue. Pinned against the ge/le of the field
each denoise node actually validates.

Also: Ideal Size is no longer titled for SD, since it answers for every
architecture; the contributor docs describe the layout this branch created,
including the defs module whose absence refuses boot; and the docs-export test
no longer depends on pytest's working directory.
2026-09-12 05:17:14 +02:00

83 lines
3.0 KiB
Python

from __future__ import annotations
import importlib.util
import json
from pathlib import Path
# Absolute, like `test_check_pins.py` and `test_new_architecture_script.py`: a path relative to
# the process cwd only resolves when pytest is started from the repository root, and the four
# tests below fail with a FileNotFoundError from anywhere else.
REPO_ROOT = Path(__file__).resolve().parent.parent
def _load_module(module_path: Path, module_name: str):
spec = importlib.util.spec_from_file_location(module_name, module_path)
assert spec is not None
assert spec.loader is not None
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def test_docs_json_export_bundle_structure():
module = _load_module(REPO_ROOT / "scripts" / "generate_docs_json.py", "generate_docs_json")
bundle = module.build_docs_bundle()
assert set(bundle.keys()) == {"invocation_context", "settings"}
def test_docs_json_export_includes_images_interface_and_host_setting():
module = _load_module(REPO_ROOT / "scripts" / "generate_docs_json.py", "generate_docs_json")
bundle = module.build_docs_bundle()
interface_names = {interface["name"] for interface in bundle["invocation_context"]["interfaces"]}
assert "ImagesInterface" in interface_names
setting_names = {setting["name"] for setting in bundle["settings"]["settings"]}
assert "host" in setting_names
assert "schema_version" not in setting_names
def test_docs_json_export_includes_rendering_metadata():
module = _load_module(REPO_ROOT / "scripts" / "generate_docs_json.py", "generate_docs_json")
bundle = module.build_docs_bundle()
images_interface = next(
interface for interface in bundle["invocation_context"]["interfaces"] if interface["name"] == "ImagesInterface"
)
save_method = next(method for method in images_interface["methods"] if method["name"] == "save")
host_setting = next(setting for setting in bundle["settings"]["settings"] if setting["name"] == "host")
assert save_method["description"]
assert "parameters" in save_method
assert save_method["parameters"]
assert host_setting["env_var"] == "INVOKEAI_HOST"
assert host_setting["category"] == "WEB"
assert "validation" in host_setting
assert host_setting["validation"] == {}
def test_docs_json_export_writes_expected_files(tmp_path: Path):
module = _load_module(REPO_ROOT / "scripts" / "generate_docs_json.py", "generate_docs_json")
bundle = module.build_docs_bundle()
module.write_docs_bundle(bundle, tmp_path)
invocation_context_path = tmp_path / "invocation-context.json"
settings_path = tmp_path / "settings.json"
assert sorted(path.name for path in tmp_path.iterdir()) == [
"invocation-context.json",
"settings.json",
]
invocation_context_payload = json.loads(invocation_context_path.read_text())
settings_payload = json.loads(settings_path.read_text())
assert invocation_context_payload == bundle["invocation_context"]
assert settings_payload == bundle["settings"]