"""Tests de estructura para comfyui_build_upscale_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_upscale_workflow import comfyui_build_upscale_workflow
from _comfyui_wf_assert import assert_api_format, class_types, node_by_ct


def test_method_model_usa_esrgan():
    wf = comfyui_build_upscale_workflow("img.png", model_name="4x-UltraSharp.pth", method="model")
    assert_api_format(wf)
    cts = class_types(wf)
    assert "UpscaleModelLoader" in cts
    assert "ImageUpscaleWithModel" in cts
    assert node_by_ct(wf, "UpscaleModelLoader")["inputs"]["model_name"] == "4x-UltraSharp.pth"


def test_method_latent_no_usa_modelo():
    wf = comfyui_build_upscale_workflow("img.png", method="latent")
    assert_api_format(wf)
    cts = class_types(wf)
    assert "ImageScaleBy" in cts
    assert "UpscaleModelLoader" not in cts
    assert node_by_ct(wf, "LoadImage")["inputs"]["image"] == "img.png"


def test_determinista():
    # Builder puro: misma entrada -> mismo dict (sin red ni estado).
    a = comfyui_build_upscale_workflow("img.png", model_name="4x-UltraSharp.pth", method="model")
    b = comfyui_build_upscale_workflow("img.png", model_name="4x-UltraSharp.pth", method="model")
    assert a == b
