from fastapi.testclient import TestClient
from src.main import app
from src.linter.schemas import FlowInput, Node, Edge
client = TestClient(app)
def test_health():
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
def test_mcp_tools_list():
response = client.post("/mcp", json={
"jsonrpc": "2.0",
"method": "tools/list",
"id": 1
})
assert response.status_code == 200
data = response.json()
assert data["result"]["tools"][0]["name"] == "lint_flow"
def test_mcp_lint_flow():
# Valid flow
flow_data = {
"nodes": [
{"id": "s", "type": "Start"},
{"id": "e", "type": "End"}
],
"edges": [
{"from": "s", "to": "e"}
]
}
response = client.post("/mcp", json={
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": flow_data
},
"id": 2
})
assert response.status_code == 200
data = response.json()
result = data["result"]
# Check "data" part
assert "data" in result
lint_res = result["data"]
assert lint_res["score"] == 100
assert lint_res["errors"] == []
# Check "ui" part
assert "ui" in result
ui = result["ui"]
assert ui["type"] == "text/html+skybridge"
assert "<!DOCTYPE html>" in ui["html"]
assert "window.__IVR_LINT_RESULT__" in ui["html"]
def test_widget_endpoint():
response = client.get("/demo")
assert response.status_code == 200
assert "IVR Linter Demo (Hardened)" in response.text
def test_examples_endpoint():
"""Verify examples can be fetched"""
response = client.get("/examples/invalid_dead_end.json")
assert response.status_code == 200
data = response.json()
assert "nodes" in data
assert "edges" in data
def test_lint_demo_bad_flow():
"""Integration test: demo_bad_flow should return errors"""
# Load demo_bad_flow from file or use dict
import json
with open("examples/demo_bad_flow.json") as f:
bad_flow = json.load(f)
response = client.post("/mcp", json={
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": bad_flow
},
"id": "integration-test"
})
assert response.status_code == 200
result = response.json()["result"]
data = result["data"]
assert data["score"] < 100
assert len(data["errors"]) > 0
assert "window.__IVR_LINT_RESULT__" in result["ui"]["html"]