refactor: tighten backend, flows, frontend, tests; push flows to Langflow
This commit is contained in:
parent
6688fb08c6
commit
06ab25fb47
31 changed files with 783 additions and 358 deletions
|
|
@ -278,3 +278,89 @@ def live_server():
|
|||
yield f"http://127.0.0.1:{port}"
|
||||
server.should_exit = True
|
||||
thread.join(timeout=15)
|
||||
|
||||
|
||||
# --- shared declutter helpers (single place, was copy-pasted across files) ---
|
||||
|
||||
FIXTURES_DIR = Path(__file__).parent / "fixtures" / "flows"
|
||||
|
||||
|
||||
def load_flow_fixture(name: str) -> dict:
|
||||
"""Load a fixture flow JSON (shared; was load_fixture() x3)."""
|
||||
import json
|
||||
|
||||
return json.loads((FIXTURES_DIR / name).read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def langflow_export_doc(name: str = "fake", flow_id: str = "fake-1") -> dict:
|
||||
"""Minimal Langflow export envelope (merges _export_doc/_langflow_doc)."""
|
||||
return {
|
||||
"id": flow_id,
|
||||
"name": name,
|
||||
"description": "",
|
||||
"data": {"nodes": [], "edges": []},
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def anon_client():
|
||||
"""Unauthenticated ASGI client (was 3x copy-pasted ASGITransport blocks)."""
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
async def _client():
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as c:
|
||||
yield c
|
||||
|
||||
return _client
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def flow_helpers(client, login):
|
||||
"""API flow factory: create flow/version/deploy/deployed_flow in one place.
|
||||
|
||||
Collapses _create_flow/_create_version/_deploy x4 files (~60 lines).
|
||||
"""
|
||||
|
||||
async def _create_flow(name: str = "regeltest") -> dict:
|
||||
response = await client.post("/api/flows", json={"name": name, "description": "t"})
|
||||
assert response.status_code == 201, response.text
|
||||
return response.json()
|
||||
|
||||
async def _create_version(flow_id: str, fixture: str = "simple_rule.json") -> dict:
|
||||
response = await client.post(
|
||||
f"/api/flows/{flow_id}/versions",
|
||||
json={"langflow_json": load_flow_fixture(fixture), "author": "test"},
|
||||
)
|
||||
assert response.status_code == 201, response.text
|
||||
return response.json()
|
||||
|
||||
async def _deploy(flow_id: str, version_no: int = 1) -> dict:
|
||||
response = await client.post(f"/api/flows/{flow_id}/versions/{version_no}/deploy")
|
||||
assert response.status_code == 200, response.text
|
||||
return response.json()
|
||||
|
||||
async def _deployed_flow(name: str = "regeltest", fixture: str = "simple_rule.json") -> tuple:
|
||||
await login()
|
||||
flow = await _create_flow(name)
|
||||
version = await _create_version(flow["id"], fixture)
|
||||
deployed = await _deploy(flow["id"], version["version_no"])
|
||||
return flow, deployed
|
||||
|
||||
return {
|
||||
"create_flow": _create_flow,
|
||||
"create_version": _create_version,
|
||||
"deploy": _deploy,
|
||||
"deployed_flow": _deployed_flow,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def lfx_client():
|
||||
"""LFX client pointed at the real test server (was _lfx() x2)."""
|
||||
from app.flows.lfx_client import LfxClient
|
||||
from app.settings import settings
|
||||
|
||||
return LfxClient(settings.lfx_url, api_key=settings.lfx_api_key or None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue