From e2ae630ec26ed1a1706232f5f605fd2255ee206a Mon Sep 17 00:00:00 2001 From: Z User Date: Sat, 26 Sep 2026 19:06:50 +0000 Subject: [PATCH] feat: lock Moxie loader to MiniMax H3 and drop model_loader bundle The Moxie model set is MiniMax H3-only, so no other model choices are exposed in the editor: - Moxie Multimedia Loader: removed the clip_type dropdown (which listed every CLIPType recipe in ComfyUI). The H3 Qwen3-VL text encoder is now always loaded with CLIPType.MINIMAX; older ComfyUI builds raise a clear error instead of silently loading the wrong encoder. - Moxie Multimedia Loader: outputs are now exactly model, clip, video_vae, audio_vae - the legacy FAST_MODEL_LOADER (model_loader) bundle output is removed. The model output keeps the attention backend and LoRA applied. - Moxie MultiTrack Project: takes model, clip, video_vae and audio_vae as required direct inputs instead of a bundled model_loader; the fallback plumbing is removed while EasyMultiTrackProject keeps its model_loader input for non-Moxie workflows. - Moxie Preview Override: dropped the model_loader pass-through slots and patches the model input directly. - Moxie-consolidated.json reference workflow updated to the new slots. - Added tests/test_moxie_nodes.py covering the schema contracts, the attention -> LoRA -> output chain, the MINIMAX lock and the project loader synthesis. --- CHANGELOG.md | 7 + Moxie-consolidated.json | 23 +- README.md | 24 +- moxie_loader.py | 53 ++-- moxie_preview.py | 35 +-- moxie_project.py | 29 +- tests/test_moxie_nodes.py | 595 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 653 insertions(+), 113 deletions(-) create mode 100644 tests/test_moxie_nodes.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dfe569..8b1e7df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ --- +## [Unreleased] + +### ⚡ Improvements + +- **Moxie Multimedia Loader**: Locked the loader to the MiniMax H3 model set. The `clip_type` dropdown (which previously exposed every CLIP recipe in ComfyUI) was removed; the H3 Qwen3-VL text encoder is now always loaded with the `minimax` CLIP recipe. Any older ComfyUI build without `CLIPType.MINIMAX` raises a clear startup error instead of silently loading the wrong encoder. +- **Moxie Multimedia Loader / Moxie MultiTrack Project**: Removed the legacy `FAST_MODEL_LOADER` (`model_loader`) bundle. The loader now outputs exactly `model`, `clip`, `video_vae`, and `audio_vae` (with the attention backend and LoRA already applied to the model), and the Moxie MultiTrack Project takes those four outputs as required direct inputs instead of a bundled loader. `Moxie Preview Override` likewise dropped its `model_loader` pass-through slots and now patches the `model` input directly. The generic `easy multitrackProject` node keeps its `model_loader` input for non-Moxie workflows. + ## [1.3.3] - 2026-09-25 ### ✨ New Features diff --git a/Moxie-consolidated.json b/Moxie-consolidated.json index c2f702e..ebef878 100644 --- a/Moxie-consolidated.json +++ b/Moxie-consolidated.json @@ -47,11 +47,6 @@ "links": [ 204 ] - }, - { - "name": "model_loader", - "type": "FAST_MODEL_LOADER", - "links": [] } ], "properties": { @@ -67,7 +62,6 @@ "minimax_h3_video_vae_int8_convrot.safetensors", "minimax_h3_audio_vae_fp32.safetensors", "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors", - "minimax", "cpu" ] }, @@ -90,11 +84,6 @@ "name": "model", "type": "MODEL", "link": 201 - }, - { - "name": "model_loader", - "type": "FAST_MODEL_LOADER", - "link": null } ], "outputs": [ @@ -104,11 +93,6 @@ "links": [ 205 ] - }, - { - "name": "model_loader", - "type": "FAST_MODEL_LOADER", - "links": [] } ], "properties": { @@ -162,11 +146,6 @@ "name": "audio_vae", "type": "VAE", "link": 204 - }, - { - "name": "model_loader", - "type": "FAST_MODEL_LOADER", - "link": null } ], "outputs": [ @@ -580,4 +559,4 @@ "VHS_KeepIntermediate": true, "links_added_by_ue": [] } -} \ No newline at end of file +} diff --git a/README.md b/README.md index 4495373..907f635 100644 --- a/README.md +++ b/README.md @@ -22,25 +22,25 @@ Moxie Multimedia Suite consolidates multi-node setups into a concise pipeline: ```text -[Moxie Multimedia Loader] ───────────────┬─────────► [Moxie Preview Override] (live preview) - │ │ - ▼ ▼ (FAST_MODEL_LOADER) -[easy multiTrackEditor] ── (TRACKS_INFO) ──► [Moxie MultiTrack Project] (controls: steps, seed) - │ (PROJECT_NAME) - ▼ - [Moxie Project Video Combine] - │ (images, audio, fps, prefix) - ▼ - [easy saveVideo] +[Moxie Multimedia Loader] ── model ──► [Moxie Preview Override] (live preview) + │ model, clip, │ + │ video_vae, audio_vae ▼ model + └──────────────► [easy multiTrackEditor] ── (TRACKS_INFO) ──► [Moxie MultiTrack Project] (controls: steps, seed) + │ (PROJECT_NAME) + ▼ + [Moxie Project Video Combine] + │ (images, audio, fps, prefix) + ▼ + [easy saveVideo] ``` ### Consolidated Core Nodes | Node | Description | |---|---| -| **Moxie Multimedia Loader** (`MoxieMultimediaLoader`) | Self-contained loader reading from local `models/` subdirectories (`diffusion`, `loras`, `vae`, `audio_vae`, `clip`). Chains **Diffusion Model → Attention Backend (`comfy_kitchen_int8`) → LoRA Loader** and outputs individual models as well as the bundled `FAST_MODEL_LOADER` object. | +| **Moxie Multimedia Loader** (`MoxieMultimediaLoader`) | Self-contained loader reading from local `models/` subdirectories (`diffusion`, `loras`, `vae`, `audio_vae`, `clip`). Chains **Diffusion Model → Attention Backend (`comfy_kitchen_int8`) → LoRA Loader** and outputs `model`, `clip`, `video_vae`, and `audio_vae` directly. The model set is MiniMax H3-only: the CLIP recipe is locked to the `minimax` (Qwen3-VL) text encoder with no model-type choices exposed. | | **Moxie Preview Override** (`MoxiePreviewOverride`) | Ported from ComfyUI-KJNodes' Model Preview Override. Intercepts outer-sampling iterations to stream full-resolution animated video/audio preview frames directly to the node canvas widget using `taeh3` / tiny VAE decoders. | -| **Moxie MultiTrack Project** (`MoxieProject`) | Consolidates `easy multitrackProject` + `KSamplerSelect` (euler) + `BasicScheduler` (beta scheduler) + `ManualSigmas`. Hardcodes tested single-pass settings while exposing only **`steps`**, **`seed`**, and **`project_name`**. | +| **Moxie MultiTrack Project** (`MoxieProject`) | Consolidates `easy multitrackProject` + `KSamplerSelect` (euler) + `BasicScheduler` (beta scheduler) + `ManualSigmas`. Takes `model`, `clip`, `video_vae`, and `audio_vae` directly from the Moxie Multimedia Loader. Hardcodes tested single-pass settings while exposing only **`steps`**, **`seed`**, and **`project_name`**. | | **Moxie Project Video Combine** (`MoxieCombine`) | Consolidates `easy multitrackProjectVideoCombine` + `GetVideoComponents`. Assembles rendered segments and outputs `images`, `audio`, `fps`, and `FILENAME_PREFIX` directly into `easy saveVideo`. | --- diff --git a/moxie_loader.py b/moxie_loader.py index f155e24..a43a377 100644 --- a/moxie_loader.py +++ b/moxie_loader.py @@ -53,21 +53,26 @@ def _resolve(subdir, name): return path -def _clip_type_options(): - """All CLIPType members from the running ComfyUI, lowercased like native CLIPLoader.""" - try: - return sorted( - m.lower() - for m in dir(comfy.sd.CLIPType) - if not m.startswith("_") and isinstance(getattr(comfy.sd.CLIPType, m), comfy.sd.CLIPType) +def _h3_clip_type(): + """MiniMax H3 CLIP recipe. The Moxie model set is H3-only, so the text + encoder type is intentionally NOT a user-facing choice.""" + clip_type_enum = getattr(comfy.sd.CLIPType, "MINIMAX", None) + if clip_type_enum is None: + raise RuntimeError( + "Moxie Multimedia Loader: this ComfyUI build does not expose " + "CLIPType.MINIMAX (required for MiniMax H3 Qwen3-VL text encoders). " + "Please update ComfyUI." ) - except Exception: - return ["stable_diffusion"] + return clip_type_enum class MoxieMultimediaLoader(io.ComfyNode): """All-in-one loader: diffusion model -> attention backend -> LoRA, plus - video VAE, audio VAE and CLIP, all read from the node pack's models/ folder.""" + video VAE, audio VAE and CLIP, all read from the node pack's models/ folder. + + The model set is MiniMax H3-only: the CLIP recipe is locked to + CLIPType.MINIMAX and outputs are exactly (model, clip, video_vae, audio_vae) + with the attention backend and LoRA already applied to the model.""" _loaded_lora = None # (path, sd, metadata) cache, mirrors native LoraLoader @@ -78,8 +83,9 @@ class MoxieMultimediaLoader(io.ComfyNode): node_id="MoxieMultimediaLoader", display_name="Moxie Multimedia Loader", category="loaders/moxie", - description="Loads the diffusion model, applies the attention backend and a LoRA, and loads a video VAE, " - "an audio VAE and CLIP - all from the models folder bundled with this custom node.", + description="Loads the MiniMax H3 diffusion model, applies the attention backend and a LoRA, and loads " + "a video VAE, an audio VAE and the H3 Qwen3-VL CLIP - all from the models folder bundled " + "with this custom node. Outputs model, clip, video_vae and audio_vae.", inputs=[ io.Combo.Input( "diffusion_model", @@ -123,13 +129,8 @@ class MoxieMultimediaLoader(io.ComfyNode): io.Combo.Input( "clip", options=_list_files("clip"), - tooltip="Text encoder file (inside models/clip).", - ), - io.Combo.Input( - "clip_type", - options=_clip_type_options(), - default="stable_diffusion", - tooltip="CLIP model type/recipe. E.g. wan: umt5 xxl, ltxv: t5 xxl, minimax: MiniMax H3 Qwen3-VL.", + tooltip="MiniMax H3 text encoder file (inside models/clip). Loaded with the locked " + "minimax CLIP recipe (Qwen3-VL).", ), io.Combo.Input( "clip_device", @@ -144,10 +145,6 @@ class MoxieMultimediaLoader(io.ComfyNode): io.Clip.Output(display_name="clip", tooltip="CLIP text encoder (with LoRA applied if present)."), io.Vae.Output(display_name="video_vae", tooltip="Loaded video/image VAE."), io.Vae.Output(display_name="audio_vae", tooltip="Loaded audio VAE."), - io.Custom(io_type="FAST_MODEL_LOADER").Output( - display_name="model_loader", - tooltip="Optional bundled {model, clip, vae, audio_vae} for legacy/subgraph nodes.", - ), ], ) @@ -223,8 +220,8 @@ class MoxieMultimediaLoader(io.ComfyNode): return vae @classmethod - def _load_clip(cls, clip_name, clip_type, device): - clip_type_enum = getattr(comfy.sd.CLIPType, clip_type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION) + def _load_clip(cls, clip_name, device): + clip_type_enum = _h3_clip_type() clip_path = _resolve("clip", clip_name) model_options = {} @@ -251,19 +248,17 @@ class MoxieMultimediaLoader(io.ComfyNode): video_vae, audio_vae, clip, - clip_type, clip_device, ) -> io.NodeOutput: # Chain: Load Diffusion Model -> Model Attention Backend -> Lora Loader (needs both model and clip) model = cls._load_diffusion_model(diffusion_model, weight_dtype) model = cls._apply_attention_backend(model, attention_backend) - clip_obj = cls._load_clip(clip, clip_type, clip_device) + clip_obj = cls._load_clip(clip, clip_device) model, clip_obj = cls._apply_lora(model, clip_obj, lora_name, lora_strength_model, lora_strength_clip) video_vae_obj = cls._load_vae(video_vae, "vae") audio_vae_obj = cls._load_vae(audio_vae, "audio_vae") - bundle = {"model": model, "clip": clip_obj, "vae": video_vae_obj, "audio_vae": audio_vae_obj} - return io.NodeOutput(model, clip_obj, video_vae_obj, audio_vae_obj, bundle) + return io.NodeOutput(model, clip_obj, video_vae_obj, audio_vae_obj) diff --git a/moxie_preview.py b/moxie_preview.py index d1d9a39..29f1f4b 100644 --- a/moxie_preview.py +++ b/moxie_preview.py @@ -978,8 +978,8 @@ class ModelPreviewOverrideKJ(io.ComfyNode): display_name="Moxie Preview Override", category="sampling/moxie", description=( - "Attaches the live-preview wrapper to the model inside a " - "FAST_MODEL_LOADER bundle produced by the Moxie Multimedia Loader. " + "Attaches the live-preview wrapper to the model produced by the " + "Moxie Multimedia Loader. " "Sends high-res preview frames (and audio) to the node while sampling." ), inputs=[ @@ -987,11 +987,6 @@ class ModelPreviewOverrideKJ(io.ComfyNode): "model", tooltip="Diffusion model (with attention backend and LoRA already applied).", ), - io.Custom(io_type="FAST_MODEL_LOADER").Input( - "model_loader", - optional=True, - tooltip="Optional FAST_MODEL_LOADER bundle from Moxie Multimedia Loader.", - ), io.Int.Input( "max_resolution", default=1024, @@ -1046,10 +1041,6 @@ class ModelPreviewOverrideKJ(io.ComfyNode): "model", tooltip="Model with preview wrapper attached.", ), - io.Custom(io_type="FAST_MODEL_LOADER").Output( - "model_loader", - tooltip="Bundle with preview wrapper attached to model (only when a bundle was passed in).", - ), ], hidden=[io.Hidden.unique_id], is_experimental=True, @@ -1059,7 +1050,6 @@ class ModelPreviewOverrideKJ(io.ComfyNode): def execute( cls, model=None, - model_loader=None, max_resolution=1024, jpeg_quality=80, suppress_default_preview=True, @@ -1067,18 +1057,10 @@ class ModelPreviewOverrideKJ(io.ComfyNode): preview_fps=24, tiny_vae="taeh3.safetensors", ) -> io.NodeOutput: - target_model = None - if model is not None: - target_model = model - elif isinstance(model_loader, dict) and model_loader.get("model") is not None: - target_model = model_loader.get("model") + if model is None: + raise TypeError("Moxie Preview Override: 'model' input is required.") - if target_model is None: - raise TypeError( - "Moxie Preview Override: Either 'model' or 'model_loader' must be provided." - ) - - patched_model = target_model.clone() + patched_model = model.clone() patched_model.add_wrapper_with_key( comfy.patcher_extension.WrappersMP.OUTER_SAMPLE, "moxie_preview_override", @@ -1088,12 +1070,7 @@ class ModelPreviewOverrideKJ(io.ComfyNode): ), ) - out_loader = None - if isinstance(model_loader, dict): - out_loader = dict(model_loader) - out_loader["model"] = patched_model - - return io.NodeOutput(patched_model, out_loader) + return io.NodeOutput(patched_model) class GetPreviewOverrideFramesKJ(io.ComfyNode): diff --git a/moxie_project.py b/moxie_project.py index c9b7d14..8541a19 100644 --- a/moxie_project.py +++ b/moxie_project.py @@ -8,7 +8,6 @@ from .nodes.project import ( TYPE_TRACKS_INFO, _first_input, ) -from .nodes.common import TYPE_FAST_MODEL_LOADER # Values baked from the reference workflow (Moxie-clean.json). End users only # control project_name, steps and seed on this node. @@ -45,7 +44,7 @@ class MoxieProject(EasyMultiTrackProject): category="EasyUse/MultiTrackEditor", description=( "Build and execute a multi-track MiniMax H3 project. " - "Takes direct model, clip, video_vae, and audio_vae inputs (or a bundled model_loader). " + "Takes model, clip, video_vae and audio_vae directly from the Moxie Multimedia Loader. " "Sampling is baked to a single pass with euler + beta sigmas; set only steps and seed." ), is_input_list=True, @@ -53,11 +52,10 @@ class MoxieProject(EasyMultiTrackProject): not_idempotent=True, inputs=[ TYPE_TRACKS_INFO.Input("tracks_info"), - io.Model.Input("model", tooltip="Diffusion model (with attention backend and LoRA already applied).", optional=True), - io.Clip.Input("clip", tooltip="CLIP text encoder (from Moxie Multimedia Loader).", optional=True), - io.Vae.Input("video_vae", tooltip="Video VAE (from Moxie Multimedia Loader).", optional=True), - io.Vae.Input("audio_vae", tooltip="Audio VAE (from Moxie Multimedia Loader).", optional=True), - TYPE_FAST_MODEL_LOADER.Input("model_loader", optional=True, tooltip="Optional bundled FAST_MODEL_LOADER from Moxie Multimedia Loader."), + io.Model.Input("model", tooltip="Diffusion model from Moxie Multimedia Loader (attention backend and LoRA already applied)."), + io.Clip.Input("clip", tooltip="CLIP text encoder from Moxie Multimedia Loader."), + io.Vae.Input("video_vae", tooltip="Video VAE from Moxie Multimedia Loader."), + io.Vae.Input("audio_vae", tooltip="Audio VAE from Moxie Multimedia Loader (required to decode MiniMax H3 audio)."), io.String.Input("project_name", default="", tooltip="Name of the project; used for output folders."), io.Int.Input( @@ -88,31 +86,20 @@ class MoxieProject(EasyMultiTrackProject): def execute(cls, **kwargs) -> io.NodeOutput: steps = int(_first_input(kwargs.get("steps"), 3)) - # Support both direct individual inputs and bundled model_loader model = _first_input(kwargs.get("model")) clip = _first_input(kwargs.get("clip")) video_vae = _first_input(kwargs.get("video_vae")) audio_vae = _first_input(kwargs.get("audio_vae")) - loader = _first_input(kwargs.get("model_loader")) - if isinstance(loader, dict): - if model is None: - model = loader.get("model") - if clip is None: - clip = loader.get("clip") - if video_vae is None: - video_vae = loader.get("vae") - if audio_vae is None: - audio_vae = loader.get("audio_vae") - if model is None or clip is None or video_vae is None or audio_vae is None: missing = [k for k, v in [("model", model), ("clip", clip), ("video_vae", video_vae), ("audio_vae", audio_vae)] if v is None] raise ValueError( "MoxieProject: Missing required model components: " + ", ".join(missing) + - ". Wire model, clip, video_vae, and audio_vae directly from Moxie Multimedia Loader, or provide model_loader." + ". Wire model, clip, video_vae, and audio_vae from Moxie Multimedia Loader." ) - # Build bundled loader dict for EasyMultiTrackProject.execute + # Pack the direct inputs into the loader dict consumed by + # EasyMultiTrackProject.execute (internal plumbing only). synthesized_loader = { "model": model, "clip": clip, diff --git a/tests/test_moxie_nodes.py b/tests/test_moxie_nodes.py new file mode 100644 index 0000000..0076ddf --- /dev/null +++ b/tests/test_moxie_nodes.py @@ -0,0 +1,595 @@ +"""Regression tests for the consolidated Moxie node contracts. + +These tests follow the self-contained stubbing pattern of +test_common_nodes.py so they run without a full ComfyUI installation. + +Verified contracts: +- MoxieMultimediaLoader: outputs exactly (model, clip, video_vae, audio_vae); + no legacy FAST_MODEL_LOADER bundle output; no clip_type choice (the CLIP + recipe is locked to CLIPType.MINIMAX); the model output has the attention + backend and LoRA applied. +- MoxieProject: takes model/clip/video_vae/audio_vae as required direct + inputs instead of a bundled model_loader, and packs them into the loader + dict consumed internally by EasyMultiTrackProject. +- MoxiePreviewOverride (ModelPreviewOverrideKJ): patches the model input + directly; no model_loader pass-through slots. +""" + +import enum +import importlib.util +import sys +import types +from pathlib import Path + +import pytest + + +REPO = Path(__file__).resolve().parents[1] + + +class _Port: + def __init__(self, name=None, **kwargs): + self.name = name + self.kwargs = kwargs + + +class _PortType: + @staticmethod + def Input(name, **kwargs): + return _Port(name, **kwargs) + + @staticmethod + def Output(name=None, **kwargs): + return _Port(name, **kwargs) + + +class _NodeOutput: + def __init__(self, *values): + self.values = values + + +class _Schema: + def __init__(self, **kwargs): + self.__dict__.update(kwargs) + + +def _build_io(): + io = types.SimpleNamespace() + io.AnyType = _PortType + io.Audio = _PortType + io.Boolean = _PortType + io.Clip = _PortType + io.Combo = _PortType + io.Float = _PortType + io.Image = _PortType + io.Int = _PortType + io.Model = _PortType + io.Sampler = _PortType + io.Sigmas = _PortType + io.String = _PortType + io.Vae = _PortType + io.Video = _PortType + io.Custom = lambda **kwargs: _PortType + io.NodeOutput = _NodeOutput + io.Schema = _Schema + io.Hidden = types.SimpleNamespace(prompt="prompt", unique_id="unique_id") + io.ControlAfterGenerate = types.SimpleNamespace(randomize="randomize") + io.InputImpl = type("InputImpl", (), {}) + + class _ComfyNode: + hidden = types.SimpleNamespace(unique_id="0", prompt={}) + + io.ComfyNode = _ComfyNode + return io + + +class _FakeModel: + """Minimal model stand-in recording attention/clone/wrapper calls.""" + + def __init__(self, label="model"): + self.label = label + self.attention_fn = None + self.wrappers = [] + + def clone(self): + clone = _FakeModel(self.label + ".clone") + clone.attention_fn = self.attention_fn + return clone + + def set_model_optimized_attention(self, attention_fn): + self.attention_fn = attention_fn + + def add_wrapper_with_key(self, key, *args): + self.wrappers.append((key,) + tuple(args)) + + def get_model_object(self, name): + return name + + +class _FakeVAE: + def __init__(self, sd=None, metadata=None): + self.sd = sd + self.metadata = metadata + + def throw_exception_if_invalid(self): + pass + + +class _StubState: + """Shared recorders/sentinels for the comfy.* stubs.""" + + def __init__(self): + self.calls = [] + self.attention_fn = lambda pixels, *a, **k: pixels + self.clip = object() + self.lora_model = None + self.lora_clip = None + + +def _register(state, io, monkeypatch=None): + """Build the ComfyUI stub modules and return {name: module} to install.""" + modules = {} + + comfy_api = types.ModuleType("comfy_api") + comfy_api_latest = types.ModuleType("comfy_api.latest") + comfy_api_latest.io = io + comfy_api_latest.InputImpl = io.InputImpl + comfy_api.latest = comfy_api_latest + modules["comfy_api"] = comfy_api + modules["comfy_api.latest"] = comfy_api_latest + + comfy = types.ModuleType("comfy") + comfy_sd = types.ModuleType("comfy.sd") + + class CLIPType(enum.Enum): + STABLE_DIFFUSION = "stable_diffusion" + WAN = "wan" + LTXV = "ltxv" + MINIMAX = "minimax" + + state.CLIPType = CLIPType + + def load_diffusion_model(path, model_options=None): + state.calls.append(("load_diffusion_model", path)) + return _FakeModel("diffusion") + + def load_clip(ckpt_paths, embedding_directory=None, clip_type=None, model_options=None): + state.calls.append(("load_clip", clip_type)) + return state.clip + + def load_lora_for_models(model, clip, lora_sd, strength_model, strength_clip, lora_metadata=None): + state.calls.append(("load_lora_for_models", strength_model, strength_clip)) + state.lora_model = model + state.lora_clip = clip + return model, clip + + comfy_sd.CLIPType = CLIPType + comfy_sd.load_diffusion_model = load_diffusion_model + comfy_sd.load_clip = load_clip + comfy_sd.load_lora_for_models = load_lora_for_models + comfy_sd.VAE = _FakeVAE + modules["comfy.sd"] = comfy_sd + + comfy_utils = types.ModuleType("comfy.utils") + + def load_torch_file(path, safe_load=False, return_metadata=False, device=None): + state.calls.append(("load_torch_file", str(path))) + if return_metadata: + return {}, {"source": str(path)} + return {} + + comfy_utils.load_torch_file = load_torch_file + comfy_utils.state_dict_prefix_replace = lambda sd, mapping, filter_keys=False: sd + comfy_utils.ProgressBar = type("ProgressBar", (), {"update_absolute": lambda *a, **k: None}) + modules["comfy.utils"] = comfy_utils + + comfy_ldm = types.ModuleType("comfy.ldm") + comfy_ldm_modules = types.ModuleType("comfy.ldm.modules") + comfy_attention = types.ModuleType("comfy.ldm.modules.attention") + + def get_attention_function(attention_name, extra_options=None): + state.calls.append(("get_attention_function", attention_name)) + return state.attention_fn + + comfy_attention.get_attention_function = get_attention_function + modules["comfy.ldm"] = comfy_ldm + modules["comfy.ldm.modules"] = comfy_ldm_modules + modules["comfy.ldm.modules.attention"] = comfy_attention + + comfy_samplers = types.ModuleType("comfy.samplers") + + def calculate_sigmas(model_sampling, scheduler, steps): + import torch + + state.calls.append(("calculate_sigmas", scheduler, steps)) + return torch.linspace(1.0, 0.0, steps + 1) + + comfy_samplers.calculate_sigmas = calculate_sigmas + comfy_samplers.sampler_object = lambda name: ("sampler", name) + modules["comfy.samplers"] = comfy_samplers + + comfy_patcher = types.ModuleType("comfy.patcher_extension") + comfy_patcher.WrappersMP = types.SimpleNamespace(OUTER_SAMPLE="OUTER_SAMPLE") + modules["comfy.patcher_extension"] = comfy_patcher + + modules["comfy.model_base"] = types.ModuleType("comfy.model_base") + modules["comfy.model_management"] = types.ModuleType("comfy.model_management") + + comfy_execution = types.ModuleType("comfy_execution") + graph_utils = types.ModuleType("comfy_execution.graph_utils") + graph_utils.GraphBuilder = type("GraphBuilder", (), {}) + graph_utils.ExecutionBlocker = type("ExecutionBlocker", (), {}) + graph_utils.is_link = lambda value: False + modules["comfy_execution"] = comfy_execution + modules["comfy_execution.graph_utils"] = graph_utils + + modules["latent_preview"] = types.ModuleType("latent_preview") + + folder_paths = types.ModuleType("folder_paths") + folder_paths.models_dir = "" + folder_paths.get_folder_paths = lambda *a, **k: [] + folder_paths.get_filename_list = lambda *a, **k: [] + modules["folder_paths"] = folder_paths + + nodes_stub = types.ModuleType("nodes") + nodes_stub.EXTENSION_WEB_DIRS = {} + modules["nodes"] = nodes_stub + + # Wire the comfy package attribute chain for `import comfy.x.y` statements. + comfy.sd = comfy_sd + comfy.utils = comfy_utils + comfy.samplers = comfy_samplers + comfy.patcher_extension = comfy_patcher + comfy.model_base = modules["comfy.model_base"] + comfy.model_management = modules["comfy.model_management"] + comfy_ldm.modules = comfy_ldm_modules + comfy_ldm_modules.attention = comfy_attention + comfy.ldm = comfy_ldm + modules["comfy"] = comfy + return modules + + +def _load(spec_name, path): + spec = importlib.util.spec_from_file_location(spec_name, path) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + sys.modules[spec_name] = module + spec.loader.exec_module(module) + return module + + +def _build_moxie(): + """Load the real Moxie modules against the stubbed ComfyUI runtime. + + Written as a plain generator (setup / yield / teardown) so it can back + the pytest fixture below and also be driven by a standalone runner in + environments where pytest's package-aware collection cannot be used. + """ + state = _StubState() + io = _build_io() + stubs = _register(state, io) + + added = {} + for name, module in stubs.items(): + added[name] = sys.modules.get(name) + sys.modules[name] = module + + mm_pkg = types.ModuleType("MMnode") + mm_pkg.__path__ = [str(REPO)] + added["MMnode"] = sys.modules.get("MMnode") + sys.modules["MMnode"] = mm_pkg + + try: + # Real utils package (torch/folder_paths only externals). + utils_spec = importlib.util.spec_from_file_location( + "MMnode.utils", + REPO / "utils" / "__init__.py", + submodule_search_locations=[str(REPO / "utils")], + ) + utils_pkg = importlib.util.module_from_spec(utils_spec) + added["MMnode.utils"] = sys.modules.get("MMnode.utils") + sys.modules["MMnode.utils"] = utils_pkg + utils_spec.loader.exec_module(utils_pkg) + + # nodes package without executing the full nodes/__init__ chain. + nodes_pkg = types.ModuleType("MMnode.nodes") + nodes_pkg.__path__ = [str(REPO / "nodes")] + added["MMnode.nodes"] = sys.modules.get("MMnode.nodes") + sys.modules["MMnode.nodes"] = nodes_pkg + common = _load("MMnode.nodes.common", REPO / "nodes" / "common.py") + nodes_pkg.common = common + project = _load("MMnode.nodes.project", REPO / "nodes" / "project.py") + nodes_pkg.project = project + + tiny_vae = types.ModuleType("MMnode.tiny_vae") + tiny_vae.load_tiny_vae_decoder = lambda *a, **k: None + added["MMnode.tiny_vae"] = sys.modules.get("MMnode.tiny_vae") + sys.modules["MMnode.tiny_vae"] = tiny_vae + + loader = _load("MMnode.moxie_loader", REPO / "moxie_loader.py") + preview = _load("MMnode.moxie_preview", REPO / "moxie_preview.py") + project_node = _load("MMnode.moxie_project", REPO / "moxie_project.py") + + yield types.SimpleNamespace( + state=state, + loader=loader, + preview=preview, + project_node=project_node, + base_project=project.EasyMultiTrackProject, + ) + finally: + for name, previous in added.items(): + if previous is None: + sys.modules.pop(name, None) + else: + sys.modules[name] = previous + + +@pytest.fixture(scope="module") +def moxie(): + yield from _build_moxie() + + +def _input_names(schema): + return [port.name for port in schema.inputs] + + +def _output_names(schema): + # V3 outputs may pass the label positionally or via display_name=. + return [port.name or port.kwargs.get("display_name") for port in schema.outputs] + + +def test_loader_schema_outputs_are_direct(moxie): + schema = moxie.loader.MoxieMultimediaLoader.define_schema() + + assert _output_names(schema) == ["model", "clip", "video_vae", "audio_vae"] + assert "model_loader" not in _output_names(schema) + assert "model_loader" not in _input_names(schema) + + +def test_loader_schema_locks_h3_clip_recipe(moxie): + schema = moxie.loader.MoxieMultimediaLoader.define_schema() + inputs = _input_names(schema) + + # The model set is MiniMax H3-only: no CLIP recipe choices are exposed. + assert "clip_type" not in inputs + assert "clip_device" in inputs + assert inputs.index("clip") == len(inputs) - 2 # clip, then clip_device + + +def test_loader_execute_applies_attention_then_lora(moxie, monkeypatch, tmp_path): + state = moxie.state + models = tmp_path / "models" + for subdir in ("diffusion", "vae", "audio_vae", "clip", "loras"): + (models / subdir).mkdir(parents=True, exist_ok=True) + for name in ("h3.safetensors", "video.safetensors", "audio.safetensors", "qwen.safetensors", "turbo.safetensors"): + subdir = { + "h3.safetensors": "diffusion", + "video.safetensors": "vae", + "audio.safetensors": "audio_vae", + "qwen.safetensors": "clip", + "turbo.safetensors": "loras", + }[name] + (models / subdir / name).write_bytes(b"stub") + monkeypatch.setattr(moxie.loader, "MODELS_DIR", models) + monkeypatch.setattr(moxie.loader.MoxieMultimediaLoader, "_loaded_lora", None) + state.calls.clear() + + result = moxie.loader.MoxieMultimediaLoader.execute( + diffusion_model="h3.safetensors", + weight_dtype="default", + attention_backend="comfy_kitchen_attention", + lora_name="turbo.safetensors", + lora_strength_model=1.0, + lora_strength_clip=1.0, + video_vae="video.safetensors", + audio_vae="audio.safetensors", + clip="qwen.safetensors", + clip_device="default", + ) + + sequence = [call[0] for call in state.calls] + assert sequence == [ + "load_diffusion_model", + "get_attention_function", + "load_clip", + "load_torch_file", + "load_lora_for_models", + "load_torch_file", + "load_torch_file", + ] + + # CLIP recipe is locked to MiniMax. + clip_calls = [call for call in state.calls if call[0] == "load_clip"] + assert clip_calls == [("load_clip", state.CLIPType.MINIMAX)] + + # LoRA applied on top of the attention-patched model, after the CLIP load. + assert state.calls.index(("get_attention_function", "comfy_kitchen_int8")) < state.calls.index( + ("load_clip", state.CLIPType.MINIMAX) + ) < state.calls.index(("load_lora_for_models", 1.0, 1.0)) + + # Exactly four direct outputs, model carrying attention + LoRA. + assert isinstance(result, _NodeOutput) + assert len(result.values) == 4 + model_out, clip_out, video_vae_out, audio_vae_out = result.values + assert model_out is state.lora_model + assert model_out.attention_fn is state.attention_fn + assert clip_out is state.clip + assert isinstance(video_vae_out, _FakeVAE) + assert isinstance(audio_vae_out, _FakeVAE) + + +def test_loader_execute_without_lora_skips_lora_loading(moxie, monkeypatch, tmp_path): + state = moxie.state + models = tmp_path / "models" + for subdir in ("diffusion", "vae", "audio_vae", "clip", "loras"): + (models / subdir).mkdir(parents=True, exist_ok=True) + for name in ("h3.safetensors", "video.safetensors", "audio.safetensors", "qwen.safetensors"): + subdir = { + "h3.safetensors": "diffusion", + "video.safetensors": "vae", + "audio.safetensors": "audio_vae", + "qwen.safetensors": "clip", + }[name] + (models / subdir / name).write_bytes(b"stub") + monkeypatch.setattr(moxie.loader, "MODELS_DIR", models) + state.calls.clear() + + result = moxie.loader.MoxieMultimediaLoader.execute( + diffusion_model="h3.safetensors", + weight_dtype="default", + attention_backend="pytorch_attention", + lora_name="", + lora_strength_model=1.0, + lora_strength_clip=1.0, + video_vae="video.safetensors", + audio_vae="audio.safetensors", + clip="qwen.safetensors", + clip_device="default", + ) + + assert "load_lora_for_models" not in [call[0] for call in state.calls] + assert result.values[0] is not state.clip # model output remains a model + assert result.values[0].attention_fn is state.attention_fn + assert result.values[1] is state.clip + + +def test_loader_requires_minimax_cliptype(moxie, monkeypatch, tmp_path): + state = moxie.state + models = tmp_path / "models" + for subdir in ("diffusion", "clip"): + (models / subdir).mkdir(parents=True, exist_ok=True) + (models / "diffusion" / "h3.safetensors").write_bytes(b"stub") + (models / "clip" / "qwen.safetensors").write_bytes(b"stub") + monkeypatch.setattr(moxie.loader, "MODELS_DIR", models) + + class CLIPTypeNoMinimax(enum.Enum): + STABLE_DIFFUSION = "stable_diffusion" + + monkeypatch.setattr(moxie.loader.comfy.sd, "CLIPType", CLIPTypeNoMinimax) + + with pytest.raises(RuntimeError, match="CLIPType.MINIMAX"): + moxie.loader.MoxieMultimediaLoader.execute( + diffusion_model="h3.safetensors", + weight_dtype="default", + attention_backend="pytorch_attention", + lora_name="", + lora_strength_model=1.0, + lora_strength_clip=1.0, + video_vae="video.safetensors", + audio_vae="audio.safetensors", + clip="qwen.safetensors", + clip_device="default", + ) + + +def test_project_schema_takes_direct_model_inputs(moxie): + schema = moxie.project_node.MoxieProject.define_schema() + inputs = {port.name: port for port in schema.inputs} + + assert list(inputs) == [ + "tracks_info", + "model", + "clip", + "video_vae", + "audio_vae", + "project_name", + "steps", + "seed", + ] + assert "model_loader" not in inputs + + # The four model components are required direct connections. + for name in ("model", "clip", "video_vae", "audio_vae"): + assert inputs[name].kwargs.get("optional") is not True + + +def test_project_execute_builds_loader_bundle_for_base_node(moxie, monkeypatch): + captured = {} + + def fake_base_execute(cls, **kwargs): + captured.update(kwargs) + return _NodeOutput("PROJECT", None) + + monkeypatch.setattr( + moxie.base_project, + "execute", + classmethod(fake_base_execute), + ) + + model = _FakeModel("h3") + clip = object() + video_vae = object() + audio_vae = object() + + moxie.project_node.MoxieProject.execute( + tracks_info=[{"width": 960, "height": 544, "frame_rate": 24, "tracks": []}], + model=[model], + clip=[clip], + video_vae=[video_vae], + audio_vae=[audio_vae], + project_name=["girl1-test"], + steps=[3], + seed=[42], + ) + + assert captured["model_loader"] == { + "model": model, + "clip": clip, + "vae": video_vae, + "audio_vae": audio_vae, + } + # Baked single-pass sampling settings survive the delegation. + assert captured["sampling_mode"] == "single" + assert captured["project_save"] == "override" + assert captured["sampler"] == ("sampler", "euler") + import torch + + assert captured["sigmas"].shape == (4,) # steps + 1 + assert captured["sigmas"].dtype == torch.float32 + + +def test_project_execute_missing_component_raises(moxie, monkeypatch): + def fake_base_execute(cls, **kwargs): # pragma: no cover - must not be reached + raise AssertionError("base execute must not run with missing components") + + monkeypatch.setattr(moxie.base_project, "execute", classmethod(fake_base_execute)) + + with pytest.raises(ValueError, match="MoxieProject: Missing required model components: clip"): + moxie.project_node.MoxieProject.execute( + tracks_info=[{}], + model=[_FakeModel("h3")], + clip=[None], + video_vae=[object()], + audio_vae=[object()], + project_name=["girl1-test"], + steps=[3], + seed=[42], + ) + + +def test_preview_override_has_no_model_loader_slots(moxie): + schema = moxie.preview.ModelPreviewOverrideKJ.define_schema() + + assert "model_loader" not in _input_names(schema) + assert _output_names(schema) == ["model"] + + +def test_preview_override_patches_model_directly(moxie): + model = _FakeModel("h3") + + result = moxie.preview.ModelPreviewOverrideKJ.execute(model=model) + + assert isinstance(result, _NodeOutput) + assert len(result.values) == 1 + patched = result.values[0] + assert patched is not model + assert any( + wrapper[0] == "OUTER_SAMPLE" and wrapper[1] == "moxie_preview_override" + for wrapper in patched.wrappers + ) + + +def test_preview_override_requires_model(moxie): + with pytest.raises(TypeError, match="'model' input is required"): + moxie.preview.ModelPreviewOverrideKJ.execute(model=None)