1. .form-col border-box — 384px is the outer width (a6 spec) 2. import preview counts all analyzed inputs, matching inline/studio counts 3. SSRF guard also runs on endpoint save (create + patch) 4. schemeless/garbled URL is a 400 format error, not a DNS-classified probe failure 5. ComfyUI health probe timeout 120s → 5s (matches the test probe) 6. workflow delete refuses (409) while pending/running jobs use it; delete errors surfaced in the UI 7. agent_llm_assignments: per-role incremental merge server-side + single-role delta payloads 8. test_shell_tool now portable (interpreter on PATH; PYTHON+approval instead of ffprobe) 9. test_video_continue pauses the queue singleton via monkeypatch (no leak into test_workbench) Co-authored-by: multica-agent <github@multica.ai>
660 lines
23 KiB
Python
660 lines
23 KiB
Python
"""ComfyUI multi-connection endpoints (HEL-611): CRUD, masking, migration,
|
|
server-side connectivity test classification, workflow binding and job
|
|
endpoint snapshots."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import socket
|
|
import threading
|
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
|
|
import pytest
|
|
|
|
from calliope.config import settings
|
|
|
|
|
|
class _FakeComfyHandler(BaseHTTPRequestHandler):
|
|
server_version = "FakeComfy/1.0"
|
|
|
|
def do_GET(self):
|
|
self.server.requests.append({"path": self.path, "headers": dict(self.headers)})
|
|
if self.path == "/system_stats":
|
|
if self.server.require_auth and not self._auth_ok():
|
|
self._send(401, {"error": "unauthorized"})
|
|
return
|
|
if self.server.mode == "not_comfyui_json":
|
|
self._send(200, {"hello": "world"})
|
|
return
|
|
if self.server.mode == "html":
|
|
self._send_html(200, "<html><body>hi</body></html>")
|
|
return
|
|
self._send(
|
|
200,
|
|
{
|
|
"system": {"comfyui_version": "0.3.55-test", "os": "linux"},
|
|
"devices": [{"name": "FakeGPU RTX 5090", "type": "cuda"}],
|
|
},
|
|
)
|
|
return
|
|
if self.path == "/":
|
|
self._send_html(200, "<html></html>")
|
|
return
|
|
if self.server.mode == "system_stats_404":
|
|
# reverse-proxy style: /system_stats stripped
|
|
self._send_html(404, "<html>404</html>")
|
|
return
|
|
self._send(404, {"error": "not found"})
|
|
|
|
def _auth_ok(self) -> bool:
|
|
auth = self.headers.get("Authorization") or ""
|
|
if auth == f"Bearer {self.server.token}":
|
|
return True
|
|
if self.headers.get(self.server.header_name or "X-Api-Key") == self.server.token:
|
|
return True
|
|
return False
|
|
|
|
def _send(self, status: int, payload: dict) -> None:
|
|
data = json.dumps(payload).encode("utf-8")
|
|
self.send_response(status)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(data)))
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
|
|
def _send_html(self, status: int, text: str) -> None:
|
|
data = text.encode("utf-8")
|
|
self.send_response(status)
|
|
self.send_header("Content-Type", "text/html")
|
|
self.send_header("Content-Length", str(len(data)))
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
|
|
def log_message(self, format, *args):
|
|
pass
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_comfy():
|
|
server = ThreadingHTTPServer(("127.0.0.1", 0), _FakeComfyHandler)
|
|
server.requests = []
|
|
server.require_auth = False
|
|
server.token = "tok-1234"
|
|
server.header_name = "X-Api-Key"
|
|
server.mode = "ok"
|
|
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
|
thread.start()
|
|
try:
|
|
yield server
|
|
finally:
|
|
server.shutdown()
|
|
server.server_close()
|
|
|
|
|
|
def _url(server) -> str:
|
|
return f"http://127.0.0.1:{server.server_address[1]}"
|
|
|
|
|
|
def _snapshot_settings():
|
|
return {
|
|
"comfyui_endpoints": [dict(ep) for ep in (settings.comfyui_endpoints or [])],
|
|
"comfyui_active_id": settings.comfyui_active_id,
|
|
"comfyui_base_url": settings.comfyui_base_url,
|
|
}
|
|
|
|
|
|
def _clear_endpoints() -> None:
|
|
"""Start from an empty endpoint list (settings is a process singleton)."""
|
|
settings.comfyui_endpoints = []
|
|
settings.comfyui_active_id = None
|
|
|
|
|
|
def _reset_endpoints(**kw) -> dict:
|
|
"""Point settings at one fresh endpoint and return it."""
|
|
base = {
|
|
"id": "ep-11111111-1111-1111-1111-111111111111",
|
|
"name": "测试连接",
|
|
"base_url": "http://127.0.0.1:8188",
|
|
"auth_type": "none",
|
|
"auth_token": None,
|
|
"header_name": None,
|
|
"notes": None,
|
|
}
|
|
base.update(kw)
|
|
settings.comfyui_endpoints = [base]
|
|
settings.comfyui_active_id = base["id"]
|
|
settings.apply_active_comfyui()
|
|
return base
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# CRUD + masking
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def test_endpoints_crud_and_masking(client):
|
|
prev = _snapshot_settings()
|
|
try:
|
|
_clear_endpoints()
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={
|
|
"name": "本机",
|
|
"base_url": "http://127.0.0.1:8188",
|
|
"auth_type": "bearer",
|
|
"auth_token": "secret-tok-9999",
|
|
},
|
|
)
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert len(body["endpoints"]) == 1
|
|
ep = body["endpoints"][0]
|
|
assert ep["has_token"] is True
|
|
assert ep["token_tail"] == "9999"
|
|
assert "secret" not in r.text # token never echoed
|
|
eid = ep["id"]
|
|
|
|
# edit: blank token keeps the stored one
|
|
r = client.patch(
|
|
f"/api/comfyui/endpoints/{eid}",
|
|
json={"name": "本机改名", "base_url": "http://127.0.0.1:8189"},
|
|
)
|
|
assert r.status_code == 200
|
|
ep = r.json()["endpoints"][0]
|
|
assert ep["name"] == "本机改名"
|
|
assert ep["base_url"].endswith("8189")
|
|
assert ep["has_token"] is True
|
|
|
|
# comfyui_base_url mirrors the ACTIVE endpoint
|
|
assert settings.comfyui_base_url.endswith("8189")
|
|
|
|
# delete last endpoint is refused
|
|
r = client.delete(f"/api/comfyui/endpoints/{eid}")
|
|
assert r.status_code == 400
|
|
|
|
# add a second, delete the first: allowed, active falls back
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={"name": "局域网", "base_url": "http://192.168.200.15:8188"},
|
|
)
|
|
assert r.status_code == 200
|
|
second_id = r.json()["endpoints"][-1]["id"]
|
|
r = client.delete(f"/api/comfyui/endpoints/{eid}")
|
|
assert r.status_code == 200
|
|
assert r.json()["active_id"] == second_id
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_activate_endpoint(client):
|
|
prev = _snapshot_settings()
|
|
try:
|
|
_clear_endpoints()
|
|
r = client.post("/api/comfyui/endpoints", json={"name": "A", "base_url": "http://a.test:8188"})
|
|
assert r.status_code == 200
|
|
r = client.post("/api/comfyui/endpoints", json={"name": "B", "base_url": "http://b.test:8188"})
|
|
assert r.status_code == 200
|
|
id_b = r.json()["endpoints"][-1]["id"]
|
|
|
|
r = client.post(f"/api/comfyui/endpoints/{id_b}/activate")
|
|
assert r.status_code == 200
|
|
assert r.json()["active_id"] == id_b
|
|
assert settings.comfyui_base_url == "http://b.test:8188"
|
|
|
|
# legacy single-address PATCH writes onto the ACTIVE endpoint
|
|
r = client.post("/api/settings", json={"comfyui_base_url": "http://b2.test:8188"})
|
|
assert r.status_code == 200
|
|
assert settings.comfyui_base_url == "http://b2.test:8188"
|
|
stored_b = next(ep for ep in settings.comfyui_endpoints if ep["id"] == id_b)
|
|
assert stored_b["base_url"] == "http://b2.test:8188"
|
|
|
|
r = client.post("/api/comfyui/endpoints/does-not-exist/activate")
|
|
assert r.status_code == 404
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_legacy_base_url_migrates_into_endpoint():
|
|
prev = _snapshot_settings()
|
|
try:
|
|
settings.comfyui_endpoints = []
|
|
settings.comfyui_active_id = None
|
|
settings.comfyui_base_url = "http://192.168.200.15:8188"
|
|
migrated = settings.ensure_comfyui_endpoints()
|
|
assert migrated is True
|
|
assert len(settings.comfyui_endpoints) == 1
|
|
ep = settings.comfyui_endpoints[0]
|
|
assert ep["base_url"] == "http://192.168.200.15:8188"
|
|
assert settings.comfyui_active_id == ep["id"]
|
|
# idempotent
|
|
assert settings.ensure_comfyui_endpoints() is False
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# server-side connectivity test
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def test_comfy_test_success_with_version_and_latency(client, fake_comfy):
|
|
r = client.post("/api/comfyui/endpoints/test", json={"base_url": _url(fake_comfy)})
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["ok"] is True
|
|
assert body["comfyui_version"] == "0.3.55-test"
|
|
assert "FakeGPU" in body["device_name"]
|
|
assert isinstance(body["elapsed_ms"], int)
|
|
assert fake_comfy.requests[0]["path"] == "/system_stats"
|
|
|
|
|
|
def test_comfy_test_bearer_auth_from_stored_endpoint(client, fake_comfy):
|
|
prev = _snapshot_settings()
|
|
fake_comfy.require_auth = True
|
|
try:
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={
|
|
"name": "带鉴权",
|
|
"base_url": _url(fake_comfy),
|
|
"auth_type": "bearer",
|
|
"auth_token": "tok-1234",
|
|
},
|
|
)
|
|
eid = r.json()["endpoints"][-1]["id"]
|
|
# test by id: stored token used server-side, never needs echo
|
|
r = client.post("/api/comfyui/endpoints/test", json={"endpoint_id": eid})
|
|
assert r.json()["ok"] is True
|
|
assert fake_comfy.requests[-1]["headers"].get("Authorization") == "Bearer tok-1234"
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_comfy_test_header_auth(client, fake_comfy):
|
|
fake_comfy.require_auth = True
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test",
|
|
json={
|
|
"base_url": _url(fake_comfy),
|
|
"auth_type": "header",
|
|
"header_name": "X-Api-Key",
|
|
"auth_token": "tok-1234",
|
|
},
|
|
)
|
|
assert r.json()["ok"] is True
|
|
assert fake_comfy.requests[-1]["headers"].get("X-Api-Key") == "tok-1234"
|
|
|
|
|
|
def test_comfy_test_auth_rejected(client, fake_comfy):
|
|
fake_comfy.require_auth = True
|
|
r = client.post("/api/comfyui/endpoints/test", json={"base_url": _url(fake_comfy)})
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "auth"
|
|
assert "鉴权" in body["message"]
|
|
|
|
|
|
def test_comfy_test_connection_refused(client):
|
|
sock = socket.socket()
|
|
sock.bind(("127.0.0.1", 0))
|
|
port = sock.getsockname()[1]
|
|
sock.close()
|
|
r = client.post("/api/comfyui/endpoints/test", json={"base_url": f"http://127.0.0.1:{port}"})
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "refused"
|
|
assert "拒绝" in body["message"]
|
|
|
|
|
|
def test_comfy_test_timeout(client):
|
|
# 10.255.255.1 is unroutable on this LAN → connect timeout (2s floor)
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test",
|
|
json={"base_url": "http://10.255.255.1:8188", "timeout_sec": 2},
|
|
)
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "timeout"
|
|
assert "超时" in body["message"]
|
|
|
|
|
|
def test_comfy_test_dns_failure(client):
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test",
|
|
json={"base_url": "http://nonexistent-host-xyz.invalid:8188"},
|
|
)
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "dns"
|
|
assert "解析" in body["message"]
|
|
|
|
|
|
def test_comfy_test_reachable_but_not_comfyui(client, fake_comfy):
|
|
fake_comfy.mode = "not_comfyui_json"
|
|
r = client.post("/api/comfyui/endpoints/test", json={"base_url": _url(fake_comfy)})
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "not_comfyui"
|
|
assert "不是 ComfyUI" in body["message"] or "不像 ComfyUI" in body["message"]
|
|
|
|
|
|
def test_comfy_test_html_response_is_not_comfyui(client, fake_comfy):
|
|
fake_comfy.mode = "html"
|
|
r = client.post("/api/comfyui/endpoints/test", json={"base_url": _url(fake_comfy)})
|
|
body = r.json()
|
|
assert body["ok"] is False
|
|
assert body["error"] == "not_comfyui"
|
|
|
|
|
|
def test_comfy_test_ssrf_guard(client):
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test",
|
|
json={"base_url": "http://169.254.169.254/latest/meta-data"},
|
|
)
|
|
assert r.status_code == 400
|
|
assert "禁止" in r.json()["detail"]
|
|
# loopback IS allowed (local ComfyUI is a legitimate target)
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test",
|
|
json={"base_url": "http://127.0.0.1:1", "timeout_sec": 2},
|
|
)
|
|
assert r.status_code == 200 # runs the probe (refused), not blocked
|
|
|
|
|
|
def test_comfy_test_requires_url(client):
|
|
r = client.post("/api/comfyui/endpoints/test", json={})
|
|
assert r.status_code == 400
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test", json={"base_url": "ftp://x/", "timeout_sec": 2}
|
|
)
|
|
assert r.status_code == 400
|
|
|
|
|
|
def test_schemeless_url_is_format_error_everywhere(client):
|
|
"""HEL-619: a schemeless/garbled address is a 400 format error on every
|
|
entry point (probe + save), not a silent http:// prefix that later
|
|
surfaces as a DNS-classified probe failure."""
|
|
prev = _snapshot_settings()
|
|
try:
|
|
for url in ("192.168.0.1:8188", "http:192.168.0.1", "ht!tp://x", "http://a b.test/"):
|
|
r = client.post(
|
|
"/api/comfyui/endpoints/test", json={"base_url": url, "timeout_sec": 2}
|
|
)
|
|
assert r.status_code == 400, url
|
|
assert "http://" in r.json()["detail"] or "https://" in r.json()["detail"]
|
|
r = client.post(
|
|
"/api/comfyui/endpoints", json={"name": "无协议", "base_url": url}
|
|
)
|
|
assert r.status_code == 400, url
|
|
assert "无协议" not in [ep.get("name") for ep in settings.comfyui_endpoints or []]
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_save_endpoint_runs_ssrf_guard(client):
|
|
"""HEL-619: the SSRF guard applies on save (create + edit), not only on
|
|
the connectivity probe; loopback stays allowed."""
|
|
prev = _snapshot_settings()
|
|
try:
|
|
_clear_endpoints()
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={"name": "元数据", "base_url": "http://169.254.169.254/latest"},
|
|
)
|
|
assert r.status_code == 400
|
|
assert "禁止" in r.json()["detail"]
|
|
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={"name": "本机", "base_url": "http://127.0.0.1:8188"},
|
|
)
|
|
assert r.status_code == 200
|
|
eid = r.json()["endpoints"][-1]["id"]
|
|
|
|
r = client.patch(
|
|
f"/api/comfyui/endpoints/{eid}",
|
|
json={"base_url": "http://169.254.169.254/latest"},
|
|
)
|
|
assert r.status_code == 400
|
|
# the stored endpoint is untouched
|
|
stored = next(ep for ep in settings.comfyui_endpoints if ep["id"] == eid)
|
|
assert stored["base_url"] == "http://127.0.0.1:8188"
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
# workflow binding + job snapshots
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
def _import_workflow(client, name="H3 视频", kind="video", endpoint_id=None):
|
|
wf_json = {
|
|
"4": {
|
|
"class_type": "CheckpointLoaderSimple",
|
|
"inputs": {"ckpt_name": "model.safetensors"},
|
|
},
|
|
"6": {
|
|
"class_type": "CLIPTextEncode",
|
|
"inputs": {"text": "placeholder prompt", "clip": ["4", 1]},
|
|
},
|
|
# HEL-636: a workflow needs a recognizable output node to classify a
|
|
# usage and stay enabled; without it generation is refused.
|
|
"9": {
|
|
"class_type": "VHS_VideoCombine",
|
|
"inputs": {"images": ["6", 0]},
|
|
"_meta": {"title": "Video Output (Output:video)"},
|
|
},
|
|
}
|
|
payload = {"name": name, "kind": kind, "workflow_json": wf_json}
|
|
if endpoint_id is not None:
|
|
payload["endpoint_id"] = endpoint_id
|
|
return client.post("/api/workflows", json=payload)
|
|
|
|
|
|
def test_workflow_endpoint_binding_roundtrip(client):
|
|
prev = _snapshot_settings()
|
|
try:
|
|
r = client.post(
|
|
"/api/comfyui/endpoints", json={"name": "局域网机", "base_url": "http://192.168.200.15:8188"}
|
|
)
|
|
eid = r.json()["endpoints"][-1]["id"]
|
|
|
|
r = _import_workflow(client, endpoint_id=eid)
|
|
assert r.status_code == 200
|
|
wf = r.json()
|
|
assert wf["endpoint_id"] == eid
|
|
|
|
# clear binding with explicit null
|
|
r = client.patch(f"/api/workflows/{wf['id']}", json={"endpoint_id": None})
|
|
assert r.json()["endpoint_id"] is None
|
|
|
|
# rebind
|
|
r = client.patch(f"/api/workflows/{wf['id']}", json={"endpoint_id": eid})
|
|
assert r.json()["endpoint_id"] == eid
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_playground_generate_stamps_endpoint_snapshot(client):
|
|
prev = _snapshot_settings()
|
|
try:
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={"name": "目标A", "base_url": "http://192.168.200.15:8188"},
|
|
)
|
|
target = r.json()["endpoints"][-1]
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={"name": "默认B", "base_url": "http://192.168.200.16:8188"},
|
|
)
|
|
default_ep = r.json()["endpoints"][-1]
|
|
client.post(f"/api/comfyui/endpoints/{default_ep['id']}/activate")
|
|
|
|
wf = _import_workflow(client).json()
|
|
|
|
# explicit endpoint_id wins
|
|
r = client.post(
|
|
"/api/playground/generate",
|
|
json={"workflow_id": wf["id"], "endpoint_id": target["id"]},
|
|
)
|
|
assert r.status_code == 200
|
|
snap = r.json()["job"]["payload"]["endpoint"]
|
|
assert snap["id"] == target["id"]
|
|
assert snap["name"] == "目标A"
|
|
assert snap["base_url"] == "http://192.168.200.15:8188"
|
|
assert "auth_token" not in snap # token never snapshots into payloads
|
|
|
|
# no explicit id + no binding → active endpoint
|
|
r = client.post("/api/playground/generate", json={"workflow_id": wf["id"]})
|
|
snap = r.json()["job"]["payload"]["endpoint"]
|
|
assert snap["id"] == default_ep["id"]
|
|
|
|
# workflow binding wins when no explicit id
|
|
r = client.patch(f"/api/workflows/{wf['id']}", json={"endpoint_id": target["id"]})
|
|
r = client.post("/api/playground/generate", json={"workflow_id": wf["id"]})
|
|
snap = r.json()["job"]["payload"]["endpoint"]
|
|
assert snap["id"] == target["id"]
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_worker_resolves_endpoint_from_snapshot():
|
|
from calliope.queue.worker import QueueWorker
|
|
|
|
prev = _snapshot_settings()
|
|
try:
|
|
ep = _reset_endpoints(
|
|
id="ep-22222222-2222-2222-2222-222222222222",
|
|
name="快照机",
|
|
base_url="http://192.168.200.15:8188",
|
|
)
|
|
# snapshot id still configured → current values (fresh URL/token)
|
|
url, headers, label = QueueWorker._resolve_endpoint(
|
|
{"endpoint": {"id": ep["id"], "name": "旧名", "base_url": "http://old:1"}}
|
|
)
|
|
assert url == "http://192.168.200.15:8188"
|
|
assert "快照机" in label
|
|
|
|
# dangling id → snapshot URL without token
|
|
url, headers, label = QueueWorker._resolve_endpoint(
|
|
{"endpoint": {"id": "gone-id", "name": "已删", "base_url": "http://kept:8188"}}
|
|
)
|
|
assert url == "http://kept:8188"
|
|
assert headers == {}
|
|
assert "已删" in label
|
|
|
|
# no snapshot → active endpoint
|
|
url, _h, label = QueueWorker._resolve_endpoint({})
|
|
assert url == "http://192.168.200.15:8188"
|
|
|
|
# bearer headers built for the active endpoint
|
|
_reset_endpoints(
|
|
id="ep-33333333-3333-3333-3333-333333333333",
|
|
base_url="http://auth.test:8188",
|
|
auth_type="bearer",
|
|
auth_token="tok-xyz",
|
|
)
|
|
_url2, headers, _label = QueueWorker._resolve_endpoint({})
|
|
assert headers == {"Authorization": "Bearer tok-xyz"}
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_queue_enqueue_stamps_all_paths(client):
|
|
"""Flow-internal video enqueue also carries the snapshot (same path)."""
|
|
prev = _snapshot_settings()
|
|
try:
|
|
r = client.post(
|
|
"/api/comfyui/endpoints", json={"name": "流程机", "base_url": "http://192.168.200.15:8188"}
|
|
)
|
|
eid = r.json()["endpoints"][-1]["id"]
|
|
wf = _import_workflow(client, endpoint_id=eid).json()
|
|
|
|
# enqueue via queue_manager directly (what enqueue_video_jobs calls)
|
|
from calliope.queue.manager import queue_manager
|
|
|
|
project = client.post(
|
|
"/api/projects", json={"title": "连接快照测试", "idea": "x"}
|
|
).json()
|
|
job = queue_manager.enqueue(
|
|
project_id=project["id"], kind="video", workflow_id=wf["id"], payload={}
|
|
)
|
|
payload = json.loads(job["payload_json"])
|
|
assert payload["endpoint"]["id"] == eid
|
|
assert payload["endpoint"]["base_url"] == "http://192.168.200.15:8188"
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|
|
|
|
|
|
def test_workflow_delete_blocked_while_jobs_pending(client):
|
|
"""HEL-619: deleting a workflow with pending/running jobs is refused
|
|
with 409 instead of silently nulling the jobs' workflow_id."""
|
|
from calliope.db import get_db
|
|
from calliope.queue.manager import queue_manager
|
|
|
|
wf = _import_workflow(client).json()
|
|
project = client.post(
|
|
"/api/projects", json={"title": "删除保护测试", "idea": "x"}
|
|
).json()
|
|
# Pause the lifespan-started worker so the pending job STAYS pending.
|
|
queue_manager.paused = True
|
|
try:
|
|
queue_manager.enqueue(
|
|
project_id=project["id"], kind="video", workflow_id=wf["id"], payload={}
|
|
)
|
|
|
|
r = client.delete(f"/api/workflows/{wf['id']}")
|
|
assert r.status_code == 409
|
|
assert "排队" in r.json()["detail"]
|
|
finally:
|
|
queue_manager.paused = False
|
|
|
|
# job finished → deletion allowed again
|
|
conn = get_db(settings.db_path)
|
|
try:
|
|
conn.execute("UPDATE jobs SET status = 'done' WHERE project_id = ?", (project["id"],))
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
r = client.delete(f"/api/workflows/{wf['id']}")
|
|
assert r.status_code == 200
|
|
assert r.json() == {"ok": True}
|
|
|
|
|
|
def test_settings_public_dict_masks_endpoint_tokens(client):
|
|
prev = _snapshot_settings()
|
|
try:
|
|
r = client.post(
|
|
"/api/comfyui/endpoints",
|
|
json={
|
|
"name": "云端",
|
|
"base_url": "https://comfy.example.com",
|
|
"auth_type": "header",
|
|
"header_name": "X-Key",
|
|
"auth_token": "cloud-secret-7777",
|
|
},
|
|
)
|
|
assert r.status_code == 200
|
|
r = client.get("/api/settings")
|
|
text = r.text
|
|
assert "cloud-secret" not in text
|
|
ep = next(
|
|
ep for ep in r.json()["comfyui_endpoints"] if ep["name"] == "云端"
|
|
)
|
|
assert ep["has_token"] is True
|
|
assert ep["token_tail"] == "7777"
|
|
finally:
|
|
for key, value in prev.items():
|
|
setattr(settings, key, value)
|