"""Tests de estructura para comfyui_build_inpaint_workflow (funcion pura)."""

import os
import sys

sys.path.insert(0, os.path.dirname(__file__))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", ".."))

from ml.comfyui_build_inpaint_workflow import comfyui_build_inpaint_workflow
from _comfyui_wf_assert import assert_api_format, class_types, node_by_ct


def test_estructura_inpaint():
    wf = comfyui_build_inpaint_workflow("ck.safetensors", "img.png", "mask.png", "POS", "NEG")
    assert_api_format(wf)
    cts = class_types(wf)
    # Inpaint necesita la mascara y la codificacion para inpaint.
    assert "LoadImageMask" in cts
    assert "VAEEncodeForInpaint" in cts


def test_base_y_mascara_se_cargan():
    wf = comfyui_build_inpaint_workflow(
        "ck.safetensors", "base.png", "m.png", "POS", "NEG", seed=33, denoise=0.9
    )
    img = node_by_ct(wf, "LoadImage")["inputs"]["image"]
    mask = node_by_ct(wf, "LoadImageMask")["inputs"]["image"]
    assert img == "base.png"
    assert mask == "m.png"
    ks = node_by_ct(wf, "KSampler")["inputs"]
    assert ks["seed"] == 33 and ks["denoise"] == 0.9


def test_determinista():
    # Builder puro: misma entrada -> mismo dict (sin red, seed fijo, sin estado).
    args = ("ck.safetensors", "img.png", "mask.png", "POS", "NEG")
    a = comfyui_build_inpaint_workflow(*args, seed=33)
    b = comfyui_build_inpaint_workflow(*args, seed=33)
    assert a == b
