Skip to content

Commit 05991a2

Browse files
authored
Merge pull request #10 from audiohacking/copilot/fix-comfyui-node-issues
Fix empty-string coercion for INT/FLOAT optional inputs in AcestepCPPGenerate
2 parents 325de0a + 6b4a848 commit 05991a2

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

nodes.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ def _coerce_float(value: Any, default: float) -> float:
8282
if isinstance(value, str):
8383
return float(value) if value.strip() else default
8484
return float(value)
85+
86+
87+
def _coerce_int(value: Any, default: int) -> int:
88+
"""Return *value* as an int, falling back to *default* for empty strings.
89+
90+
Older ComfyUI workflows may store optional INT widget values as ``""``
91+
instead of the numeric default when the field was not explicitly set.
92+
"""
93+
if isinstance(value, str):
94+
return int(value) if value.strip() else default
95+
return int(value)
8596
def _binary_in_build(build_dir: str, name: str) -> Optional[str]:
8697
"""Return the path to *name* if it exists in *build_dir* or *build_dir*/bin.
8798
@@ -1182,10 +1193,13 @@ def generate(
11821193
# Merge options dict (from AcestepCPPOptions) with defaults.
11831194
opts: Dict[str, Any] = options or {}
11841195

1185-
# Coerce optional FLOAT inputs that may arrive as empty strings from
1196+
# Coerce optional numeric inputs that may arrive as empty strings from
11861197
# workflows saved with an older version of the node schema.
11871198
lm_top_p = _coerce_float(lm_top_p, 0.9)
1199+
lm_top_k = _coerce_int(lm_top_k, 0)
11881200
audio_cover_strength = _coerce_float(audio_cover_strength, 0.5)
1201+
repainting_start = _coerce_float(repainting_start, -1.0)
1202+
repainting_end = _coerce_float(repainting_end, -1.0)
11891203

11901204
# Apply instrumental convenience toggle: overrides lyrics to [Instrumental]
11911205
# only when the lyrics field is empty (user-provided lyrics take priority).

tests/test_nodes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ def test_different_defaults(self):
3636
assert nodes._coerce_float("", 2.5) == pytest.approx(2.5)
3737

3838

39+
# ===========================================================================
40+
# _coerce_int
41+
# ===========================================================================
42+
43+
class TestCoerceInt:
44+
def test_int_passthrough(self):
45+
assert nodes._coerce_int(5, 0) == 5
46+
47+
def test_float_truncates(self):
48+
assert nodes._coerce_int(3.9, 0) == 3
49+
50+
def test_valid_string_converts(self):
51+
assert nodes._coerce_int("42", 0) == 42
52+
53+
def test_empty_string_uses_default(self):
54+
assert nodes._coerce_int("", 7) == 7
55+
56+
def test_whitespace_string_uses_default(self):
57+
assert nodes._coerce_int(" ", 10) == 10
58+
59+
def test_different_defaults(self):
60+
assert nodes._coerce_int("", 0) == 0
61+
assert nodes._coerce_int("", -1) == -1
62+
63+
3964
# ===========================================================================
4065
# scan_gguf_models / get_merged_model_folders / find_model_path
4166
# ===========================================================================

0 commit comments

Comments
 (0)