Files

101 lines
3.1 KiB
Python

"""Integration tests for the full pipeline CRUD + execution flow."""
import time
import uuid
import pytest
import requests
REQUEST_TIMEOUT = 5
def _unique_id():
return str(uuid.uuid4())
def test_full_pipeline_lifecycle(pipeline_server):
"""Create, list, get, run, poll, log, delete a pipeline end-to-end."""
base = pipeline_server.base_url
pipeline_id = _unique_id()
# --- Create pipeline ---
pipeline = {
"id": pipeline_id,
"name": "integration-test-pipeline",
"working_dir": "/tmp",
"prompts": [
{"id": _unique_id(), "text": "echo step1", "title": "Step 1", "order": 0},
{"id": _unique_id(), "text": "echo step2", "title": "Step 2", "order": 1},
{"id": _unique_id(), "text": "echo step3", "title": "Step 3", "order": 2},
],
}
resp = requests.post(
f"{base}/api/pipelines", json=pipeline, timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
created = resp.json()
assert created["id"] == pipeline_id
assert created["name"] == "integration-test-pipeline"
assert len(created["prompts"]) == 3
# --- List pipelines ---
resp = requests.get(f"{base}/api/pipelines", timeout=REQUEST_TIMEOUT)
assert resp.status_code == 200
pipelines = resp.json()
assert any(p["id"] == pipeline_id for p in pipelines)
# --- Get single pipeline ---
resp = requests.get(
f"{base}/api/pipelines/{pipeline_id}", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
fetched = resp.json()
assert fetched["id"] == pipeline_id
assert fetched["name"] == "integration-test-pipeline"
assert len(fetched["prompts"]) == 3
assert fetched["prompts"][0]["order"] == 0
# --- Start a run ---
resp = requests.post(
f"{base}/api/runs", json={"pipeline_id": pipeline_id}, timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
run_data = resp.json()
run_id = run_data["run_id"]
assert run_id
assert run_data["status"] == "running"
# --- Poll run status until completed ---
for _ in range(60):
resp = requests.get(
f"{base}/api/runs/{run_id}/status", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
status_data = resp.json()
if status_data["status"] in ("completed", "error"):
break
time.sleep(0.5)
else:
pytest.fail("Run did not complete within timeout")
assert status_data["status"] == "completed"
assert len(status_data["steps"]) == 3
# --- Get log ---
resp = requests.get(f"{base}/api/runs/{run_id}/log", timeout=REQUEST_TIMEOUT)
assert resp.status_code == 200
assert len(resp.text) > 0
# --- Delete pipeline ---
resp = requests.delete(
f"{base}/api/pipelines/{pipeline_id}", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 200
assert resp.json()["deleted"] == pipeline_id
# --- Verify deletion ---
resp = requests.get(
f"{base}/api/pipelines/{pipeline_id}", timeout=REQUEST_TIMEOUT
)
assert resp.status_code == 404