docs(HEL-892): bind scoped SCAIL2 workflow reference
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
"Foreground local browser check; stop every owned service before returning."
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
OUT = ROOT / (".local-evidence/scail-document/browser")
|
||||
|
||||
|
||||
def main():
|
||||
# Require successful rebuilt and packaged current resources before any service starts.
|
||||
evidence = ROOT / "docs/hel-892/scail-document-evidence"
|
||||
for record in json.loads((evidence / "package-check.json").read_bytes()):
|
||||
product = ROOT / "calliope-backend/src/calliope/comfyui" / record["file"]
|
||||
assert hashlib.sha256(product.read_bytes()).hexdigest() == record["sha256"]
|
||||
assert record["wheel"] and record["sdist"] and record["definitions"] == 140
|
||||
protection = json.loads((evidence / "import-protection.json").read_bytes())
|
||||
assert protection["upgrade"] == {"updated": 1, "skipped": 154, "user_excluded": 1}
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
# Refuse to reuse another operator's service or port.
|
||||
import socket
|
||||
|
||||
for port in (8247, 5173):
|
||||
with socket.socket() as sock:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(("127.0.0.1", port))
|
||||
processes = []
|
||||
logs = []
|
||||
try:
|
||||
commands = [
|
||||
([sys.executable, str(ROOT / "e2e/scail-document-server.py")], ROOT),
|
||||
(
|
||||
["node", "node_modules/vite/bin/vite.js", "--host", "127.0.0.1"],
|
||||
ROOT / "calliope-web",
|
||||
),
|
||||
]
|
||||
for i, (command, cwd) in enumerate(commands):
|
||||
log = (OUT / f"service-{i}.log").open("w")
|
||||
logs.append(log)
|
||||
processes.append(
|
||||
subprocess.Popen(command, cwd=cwd, stdout=log, stderr=log, start_new_session=True)
|
||||
)
|
||||
for url in (
|
||||
"http://127.0.0.1:8247/api/workflows",
|
||||
"http://127.0.0.1:5173/connections",
|
||||
):
|
||||
parsed = urlsplit(url)
|
||||
if (
|
||||
parsed.scheme != "http"
|
||||
or parsed.hostname not in {"127.0.0.1", "localhost"}
|
||||
or parsed.port not in {8247, 5173}
|
||||
or parsed.username
|
||||
or parsed.password
|
||||
):
|
||||
raise ValueError("Refused before readiness request: " + url)
|
||||
deadline = time.monotonic() + 30
|
||||
while True:
|
||||
if any(p.poll() is not None for p in processes):
|
||||
raise RuntimeError("Local service exited; inspect service logs")
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=1) as response:
|
||||
if response.status == 200:
|
||||
break
|
||||
except (urllib.error.URLError, TimeoutError):
|
||||
pass
|
||||
if time.monotonic() > deadline:
|
||||
raise TimeoutError(url)
|
||||
time.sleep(0.2)
|
||||
names = ["scail-document"]
|
||||
for name in names:
|
||||
subprocess.run(["node", f"e2e/{name}.mjs"], cwd=ROOT, check=True)
|
||||
finally:
|
||||
for p in processes:
|
||||
if p.poll() is None:
|
||||
os.killpg(p.pid, signal.SIGTERM)
|
||||
try:
|
||||
p.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
os.killpg(p.pid, signal.SIGKILL)
|
||||
p.wait(timeout=5)
|
||||
for log in logs:
|
||||
log.close()
|
||||
released = []
|
||||
for port in (8247, 5173):
|
||||
with socket.socket() as sock:
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.bind(("127.0.0.1", port))
|
||||
released.append(port)
|
||||
with socket.socket() as probe:
|
||||
probe.settimeout(1)
|
||||
assert probe.connect_ex(("127.0.0.1", port)) != 0
|
||||
|
||||
(OUT / "service-stop.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"ports_released": released,
|
||||
"independent_connection_refused": released,
|
||||
"child_exit_codes": [p.returncode for p in processes],
|
||||
}
|
||||
)
|
||||
+ "\n"
|
||||
)
|
||||
print(("All owned browser services stopped; ports released."))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,82 @@
|
||||
"""HEL-892 isolated browser host: production workflow router, no execution worker.
|
||||
|
||||
From repo root: calliope-backend/.venv/bin/python e2e/scail-document-server.py
|
||||
Run Vite on 5173 alongside it. No remote ComfyUI endpoint is configured.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
import uvicorn
|
||||
from calliope.comfyui.companions import load_companions
|
||||
from calliope.comfyui.library import import_library
|
||||
from calliope.config import settings
|
||||
from calliope.db import get_db, migrate_db
|
||||
from calliope.routers import workflows
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DATA = ROOT / ".local-evidence" / "scail-document-server"
|
||||
settings.data_dir = DATA
|
||||
settings.db_name = "library.db"
|
||||
settings.assets_dir = DATA / "assets"
|
||||
settings.comfyui_endpoints = []
|
||||
settings.comfyui_base_url = "http://127.0.0.1:1"
|
||||
app = FastAPI()
|
||||
app.include_router(workflows.router, prefix="/api/workflows")
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def read_only(request, call_next):
|
||||
if request.method != "GET":
|
||||
return JSONResponse({"detail": "隔离说明服务仅允许GET"}, status_code=405)
|
||||
return await call_next(request)
|
||||
|
||||
|
||||
@app.get("/api/settings")
|
||||
def get_settings():
|
||||
return {"comfyui_endpoints": [], "comfyui_active_id": None}
|
||||
|
||||
|
||||
def prepare():
|
||||
DATA.mkdir(parents=True, exist_ok=True)
|
||||
asyncio.run(migrate_db(settings.db_path))
|
||||
conn = get_db(settings.db_path)
|
||||
try:
|
||||
report = import_library(
|
||||
conn,
|
||||
ROOT / "example_ComfyUI_workflows",
|
||||
source_commit="ui-browser",
|
||||
companions=load_companions(ROOT / "docs/hel-892/supplied-api/manifest.json"),
|
||||
)
|
||||
print({"counts": report["counts"], "states": report["states"]})
|
||||
for name, document in [
|
||||
("旧工作流回退(隔离测试夹具)", None),
|
||||
("空说明回退(隔离测试夹具)", "{}"),
|
||||
]:
|
||||
if conn.execute("SELECT id FROM workflows WHERE name=?", (name,)).fetchone():
|
||||
continue
|
||||
conn.execute(
|
||||
"INSERT INTO workflows(name,kind,workflow_json,input_schema,description,"
|
||||
"is_enabled,doc_json) VALUES (?,?,?,?,?,?,?)",
|
||||
(
|
||||
name,
|
||||
"image",
|
||||
"{}",
|
||||
"[]",
|
||||
"隔离库旧条目回退测试;不代表真实工作流。",
|
||||
0,
|
||||
document,
|
||||
),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
prepare()
|
||||
uvicorn.run(app, host="127.0.0.1", port=8247)
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user