Skip to content

Commit 37a7b6a

Browse files
committed
test: florence2_hires — regression test for state_to_configs_json passthrough
1 parent 49b1406 commit 37a7b6a

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
"""Regression test: state_to_configs_json must preserve the florence2 sub-object
2+
on an upscale step when mode is 'florence2_hires'.
3+
4+
This is currently a passthrough (config_builder_node.py L838 does
5+
{**p, 'steps': active_steps}), but a future refactor could whitelist fields
6+
and silently drop our new keys. This test catches that.
7+
"""
8+
import json
9+
10+
import pytest
11+
12+
from config_builder_node import UltimateConfigBuilder
13+
14+
15+
def _base_state():
16+
return {
17+
"session_name": "test_session",
18+
"include_none": False,
19+
"global_positive_groups": [],
20+
"global_negative": "",
21+
"config_arrays": [{
22+
"name": "Config 1",
23+
"samplers": "euler",
24+
"schedulers": "simple",
25+
"steps": "20",
26+
"cfg": "7.0",
27+
"model": "ckpt.safetensors",
28+
"loras": ["None"],
29+
"lora_omit_triggers": [],
30+
"lora_triggerwords_append_settings": {},
31+
"combine": True,
32+
"positive_prompt_groups": [],
33+
"negative_prompt": "",
34+
"use_custom_prompts": False,
35+
"model_type": "checkpoint",
36+
}],
37+
"upscaling": {
38+
"enabled": True,
39+
"pipelines": [{
40+
"name": "Pipeline 1",
41+
"active": True,
42+
"steps": [{
43+
"active": True,
44+
"mode": "florence2_hires",
45+
"florence2": {
46+
"model": "microsoft/Florence-2-base",
47+
"text_input": "face",
48+
"target_megapixels": 1.0,
49+
"crop_padding": 64,
50+
"min_crop_resolution": 256,
51+
"max_crop_resolution": 1536,
52+
"grow_expand": 32,
53+
"feather_left": 128, "feather_top": 128,
54+
"feather_right": 128, "feather_bottom": 128,
55+
"output_mask_select": "",
56+
"model_source": "from_manifest",
57+
"on_no_detection": "skip",
58+
},
59+
"hires_denoise": "0.45",
60+
"hires_steps": 15,
61+
}]
62+
}]
63+
}
64+
}
65+
66+
67+
def test_florence2_block_round_trips():
68+
state = _base_state()
69+
out = UltimateConfigBuilder.state_to_configs_json(state)
70+
parsed = json.loads(out)
71+
session = parsed.get("_session_settings", {})
72+
upscaling = session.get("upscaling", {})
73+
pipelines = upscaling.get("pipelines", [])
74+
assert len(pipelines) == 1
75+
steps = pipelines[0]["steps"]
76+
assert len(steps) == 1
77+
step = steps[0]
78+
assert step["mode"] == "florence2_hires"
79+
f2 = step.get("florence2")
80+
assert f2 is not None
81+
assert f2["model"] == "microsoft/Florence-2-base"
82+
assert f2["text_input"] == "face"
83+
assert f2["target_megapixels"] == 1.0
84+
assert f2["model_source"] == "from_manifest"
85+
# Sampling fields are at step level, not inside florence2
86+
assert step["hires_denoise"] == "0.45"
87+
assert step["hires_steps"] == 15
88+
89+
90+
def test_florence2_step_with_active_false_filtered_out():
91+
"""Active=false step is dropped, just like other modes."""
92+
state = _base_state()
93+
state["upscaling"]["pipelines"][0]["steps"][0]["active"] = False
94+
out = UltimateConfigBuilder.state_to_configs_json(state)
95+
parsed = json.loads(out)
96+
upscaling = parsed.get("_session_settings", {}).get("upscaling", {})
97+
# When all steps are inactive, the entire pipeline is filtered
98+
assert upscaling == {} or upscaling.get("pipelines", []) == []
99+
100+
101+
def test_florence2_disabled_upscaling_omits_block():
102+
state = _base_state()
103+
state["upscaling"]["enabled"] = False
104+
out = UltimateConfigBuilder.state_to_configs_json(state)
105+
parsed = json.loads(out)
106+
assert "upscaling" not in parsed.get("_session_settings", {})

0 commit comments

Comments
 (0)