Enhance SwarmUI integration and GPU environment verification
- Updated CLI documentation to reflect the new handling of `CIVITAI_API_TOKEN`, which is now automatically passed to SwarmUI user settings during startup. - Improved the `render_access_panel` function to include additional warnings for idle-killer failures and stack errors, enhancing user feedback. - Introduced a new function `seed_swarmui_api_keys` to manage API key injection into SwarmUI, ensuring seamless integration with the Model Downloader. - Enhanced GPU environment verification logic to include fail-fast checks for critical components like CUDA, improving error handling and user notifications. - Updated tests to validate the new API key handling and access panel behavior, ensuring robustness in the integration process.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""Tests for remote swarmui_set_api_keys."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
REMOTE = ROOT / "src" / "gpu_rent" / "remote" / "swarmui_set_api_keys.py"
|
||||
|
||||
|
||||
def _load():
|
||||
spec = importlib.util.spec_from_file_location("swarmui_set_api_keys", REMOTE)
|
||||
assert spec and spec.loader
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
def test_set_civitai_key(tmp_path, monkeypatch):
|
||||
mod = _load()
|
||||
keys = tmp_path / "keys.json"
|
||||
keys.write_text(json.dumps({"civitai_api": "tok-123"}), encoding="utf-8")
|
||||
monkeypatch.setattr(mod, "KEYS_PATH", keys)
|
||||
|
||||
calls = []
|
||||
|
||||
def fake_post(path, payload, timeout=15.0):
|
||||
calls.append((path, payload))
|
||||
if path == "/API/GetNewSession":
|
||||
return {"session_id": "sid-1"}
|
||||
if path == "/API/SetAPIKey":
|
||||
assert payload["session_id"] == "sid-1"
|
||||
assert payload["keyType"] == "civitai_api"
|
||||
assert payload["key"] == "tok-123"
|
||||
return {"success": True}
|
||||
raise AssertionError(path)
|
||||
|
||||
monkeypatch.setattr(mod, "post", fake_post)
|
||||
monkeypatch.setattr(mod, "wait_session", lambda _d: "sid-1")
|
||||
assert mod.main() == 0
|
||||
assert not keys.exists()
|
||||
assert any(c[0] == "/API/SetAPIKey" for c in calls)
|
||||
|
||||
|
||||
def test_skip_empty_keys(tmp_path, monkeypatch):
|
||||
mod = _load()
|
||||
keys = tmp_path / "keys.json"
|
||||
keys.write_text("{}", encoding="utf-8")
|
||||
monkeypatch.setattr(mod, "KEYS_PATH", keys)
|
||||
assert mod.main() == 0
|
||||
Reference in New Issue
Block a user