Spaces:
Running
Running
File size: 1,952 Bytes
518d67a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import unittest
try:
from fastapi.testclient import TestClient
from app.main import app
except ModuleNotFoundError:
TestClient = None
app = None
@unittest.skipUnless(TestClient is not None, "FastAPI dependencies are not installed")
class ControlPlaneApiTests(unittest.TestCase):
def test_each_lane_is_reachable_and_pii_is_not_returned(self):
with TestClient(app) as client:
client.post("/api/demo/reset", json={"model_id": "claude-sonnet-3-5"})
fast = client.post("/api/execute", json={"prompt": "What are your store hours?", "use_case": "customer_support"})
verified = client.post("/api/execute", json={"prompt": "Will this product work for someone with sensitive skin?", "use_case": "customer_support"})
gated = client.post("/api/execute", json={"prompt": "Look up card number 4111-1111-1111-1111", "use_case": "customer_support"})
self.assertEqual(fast.json()["lane"], "FAST")
self.assertEqual(verified.json()["lane"], "VERIFIED")
self.assertEqual(gated.json()["lane"], "FULL GATE")
self.assertNotIn("4111-1111-1111-1111", gated.json()["final_response"])
def test_policy_update_rejects_malformed_thresholds(self):
with TestClient(app) as client:
response = client.post("/api/config/update", json={
"use_case": "customer_support",
"config_data": {
"use_case_id": "customer_support", "name": "x", "region": "EU",
"risk_category_overrides": {}, "latency_budget_ms": {"fast": 0},
"shadow_sample_rate": 1.2, "trust_thresholds": {"fast_lane_min_score": 0.8, "full_gate_max_score": 0.4},
"cold_start_default_lane": "full_gate", "blast_radius_cap": 0.03,
},
})
self.assertEqual(response.status_code, 422)
if __name__ == "__main__":
unittest.main() |