Files

65 lines
2.8 KiB
Python

from __future__ import annotations
import ast
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_one_visible_loader_node():
tree = ast.parse((ROOT / "__init__.py").read_text(encoding="utf-8"))
names = {
node.targets[0].id: node.value
for node in tree.body
if isinstance(node, ast.Assign)
and len(node.targets) == 1
and isinstance(node.targets[0], ast.Name)
}
mapping = names["NODE_CLASS_MAPPINGS"]
assert isinstance(mapping, ast.Dict)
assert [key.value for key in mapping.keys if isinstance(key, ast.Constant)] == ["MiniMaxH3TextEncoderLoader"]
def test_frontend_workflow_has_one_loader_and_a_real_clip_link():
workflow = json.loads(
(ROOT / "example_workflows" / "minimax_h3_recovered_8b_int8_convrot_t2v.json").read_text(encoding="utf-8")
)
assert isinstance(workflow["nodes"], list) # Frontend/canvas format, not API prompt format.
nodes = {node["id"]: node for node in workflow["nodes"]}
types = [node["type"] for node in workflow["nodes"]]
assert types.count("MiniMaxH3TextEncoderLoader") == 1
assert not {"MiniMaxH3SaveConditioning", "MiniMaxH3LoadConditioning", "MiniMaxH3LatentBarrier3"} & set(types)
loader = next(node for node in nodes.values() if node["type"] == "MiniMaxH3TextEncoderLoader")
h3 = next(node for node in nodes.values() if node["type"] == "MiniMaxH3ImageToVideo")
clip_slot = next(slot for slot in h3["inputs"] if slot["name"] == "clip")
assert clip_slot["type"] == "CLIP"
assert clip_slot["link"] is not None
links = {link[0]: link for link in workflow["links"]}
link = links[clip_slot["link"]]
assert link[1:5] == [loader["id"], 0, h3["id"], 0]
assert loader["outputs"][0]["type"] == "CLIP"
def test_api_prompt_is_separate_from_frontend_workflow():
api = json.loads(
(ROOT / "example_workflows" / "minimax_h3_recovered_8b_int8_convrot_t2v_api.json").read_text(encoding="utf-8")
)
assert api["5"]["class_type"] == "MiniMaxH3ImageToVideo"
assert api["5"]["inputs"]["clip"] == ["2", 0]
def test_pruned_manifest_variants_are_exposed_by_id():
source = (ROOT / "__init__.py").read_text(encoding="utf-8")
assert 'for variant_id in sorted(package["base_variants"])' in source
assert '_load_pruned24(directory, package, variant)' in source
tree = ast.parse(source)
loader = next(node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == "_load_pruned24")
load_clip = next(
node for node in ast.walk(loader)
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == "load_clip"
)
assert "model_options" not in {keyword.arg for keyword in load_clip.keywords}
assert 'BypassInjectionManager()' in source
assert 'set_injections("balanced_ara"' in source