Enhance backend recovery and diagnostics in installation and tuning scripts

- Improved the `install_swarm_comfy` function to handle empty backend states more effectively, introducing recovery mechanisms and enhanced logging for better visibility.
- Updated the `tune_swarm_perf` function to always sanitize backend FDS corruption, ensuring consistent performance tuning.
- Added new tests to validate the functionality of backend recovery and FDS sanitization, ensuring robustness in backend management.
This commit is contained in:
Leonid Pershin
2026-08-21 10:54:02 +03:00
parent ef743a6e6d
commit f8bbde8ac0
4 changed files with 40 additions and 13 deletions
+19 -8
View File
@@ -154,14 +154,25 @@ def test_pip_install_uses_python_dash_m(tmp_path, monkeypatch):
assert seen and seen[0][:4] == [str(py), "-m", "pip", "install"]
def test_pip_install_oserror_returns_false(tmp_path, monkeypatch):
def test_patch_extra_args_fds_empty_x(tmp_path, monkeypatch):
"""FDS empty ExtraArgs is '\\x' — must replace, not append."""
mod = _load()
py = tmp_path / "python"
py.write_text("", encoding="utf-8")
backends = tmp_path / "Backends.fds"
backends.write_text("0:\n\ttype: comfyui_selfstart\n\tExtraArgs: \\x\n", encoding="utf-8")
monkeypatch.setattr(mod, "BACKENDS", backends)
assert mod.patch_backends_extra_args("--use-sage-attention") is True
text = backends.read_text(encoding="utf-8")
assert "ExtraArgs: --use-sage-attention" in text
assert "\\x --use-sage" not in text
def boom(*_a, **_k):
raise OSError(8, "Exec format error", str(py))
monkeypatch.setattr(mod, "sage_already_importable", lambda _p: False)
monkeypatch.setattr(mod.subprocess, "check_call", boom)
assert mod.pip_install_sage(py) is False
def test_sanitize_backends_fds_corruption(tmp_path, monkeypatch):
mod = _load()
backends = tmp_path / "Backends.fds"
backends.write_text(
"ExtraArgs: \\x --use-sage-attention\n",
encoding="utf-8",
)
monkeypatch.setattr(mod, "BACKENDS", backends)
assert mod.sanitize_backends_fds() is True
assert backends.read_text(encoding="utf-8") == "ExtraArgs: --use-sage-attention\n"