Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Diffusion guard test: match the calibrated placement and ControlNet kwargs structurally (#17376)

Daniel Han9947de2162ae
diff --git a/studio/backend/tests/test_diffusion_calibrated_activation.py b/studio/backend/tests/test_diffusion_calibrated_activation.py
index d1c9ee79758..8c79c4d2ccc 100644
--- a/studio/backend/tests/test_diffusion_calibrated_activation.py
+++ b/studio/backend/tests/test_diffusion_calibrated_activation.py
@@ -574,13 +574,28 @@ def test_flat_tiers_ignore_the_controlnet_flag(free, kw):
def test_generate_passes_the_calibrated_placement_and_controlnet_to_the_guard():
+ import ast
import inspect
import core.inference.diffusion as d
- src = inspect.getsource(d)
- assert 'calibrated_placement = bool(getattr(state, "calibrated_placement", False)),' in src
- assert 'controlnet = workflow == "controlnet" and control_pil is not None,' in src
+ # Compare parsed keyword values, not source text, so a reflow of the call cannot fail this.
+ want = {
+ "calibrated_placement": ast.dump(
+ ast.parse('bool(getattr(state, "calibrated_placement", False))', mode = "eval").body
+ ),
+ "controlnet": ast.dump(
+ ast.parse('workflow == "controlnet" and control_pil is not None', mode = "eval").body
+ ),
+ }
+ calls = [
+ {kw.arg: ast.dump(kw.value) for kw in node.keywords if kw.arg in want}
+ for node in ast.walk(ast.parse(inspect.getsource(d)))
+ if isinstance(node, ast.Call)
+ ]
+ assert (
+ want in calls
+ ), "no guard call passes both the calibrated placement and the ControlNet flag"
# Real Tesla T4 load of stabilityai/stable-diffusion-xl-base-1.0 at fp16: the planner inputs it logged.