Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
290 changes: 21 additions & 269 deletions api.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/ci/api_line_budget.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
453
205
4 changes: 2 additions & 2 deletions tests/test_agent_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ def test_acknowledge_nonexistent_raises(self):
class TestAPIRouteRegistration(unittest.TestCase):

def test_api_module_imports_agent_discovery(self):
import api as api_mod
assert hasattr(api_mod, "agent_discovery")
import api_routers.agents as _r
assert hasattr(_r, "agent_discovery")

def test_discovery_routes_registered(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_behavioral_dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ def test_empty_agent_snapshot_ok(self):
class TestAPIRouteRegistration(unittest.TestCase):

def test_api_imports_behavioral_dna(self):
import api as api_mod
assert hasattr(api_mod, "behavioral_dna")
import api_routers.identity_surface as _r
assert hasattr(_r, "behavioral_dna")

def test_behavioral_routes_registered(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_compliance_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def test_audit_export_empty_agent_ok(self):
class TestAPIRouteRegistration(unittest.TestCase):

def test_api_imports_compliance_engine(self):
import api as api_mod
assert hasattr(api_mod, "compliance_engine")
import api_routers.compliance as _r
assert hasattr(_r, "compliance_engine")

def test_compliance_routes_registered(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_enforcement_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def test_decisions_logged_with_kill_switch_flag(self):
class TestAPIRouteRegistration(unittest.TestCase):

def test_api_imports_enforcement_plane(self):
import api as api_mod
assert hasattr(api_mod, "enforcement_plane")
import api_routers.enforcement as _r
assert hasattr(_r, "enforcement_plane")

def test_enforcement_routes_registered(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mcp_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ class TestAPIRouteRegistration(unittest.TestCase):
requiring a live FastAPI app instance."""

def test_api_module_imports_mcp_gateway(self):
import api as api_mod
assert hasattr(api_mod, "mcp_gateway"), "api.py should import mcp_gateway"
import api_routers.mcp as _r
assert hasattr(_r, "mcp_gateway"), "api.py should import mcp_gateway"

def test_gateway_routes_exist_in_api(self):
"""Confirm the expected route paths are registered on the FastAPI app."""
Expand Down
20 changes: 10 additions & 10 deletions tests/test_production_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_under_limit_does_not_raise(self):
with patch.object(_shared_mod, "increment_rate", return_value=1):
req = self._make_request()
# Should not raise
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))

def test_over_limit_raises_429(self):
from fastapi import HTTPException
Expand All @@ -306,7 +306,7 @@ def test_over_limit_raises_429(self):
with patch.object(_shared_mod, "increment_rate", return_value=9999):
req = self._make_request()
with pytest.raises(HTTPException) as exc_info:
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))
assert exc_info.value.status_code == 429
assert "Retry-After" in exc_info.value.headers

Expand All @@ -319,7 +319,7 @@ def test_exactly_at_limit_is_allowed(self):
with patch.object(_shared_mod, "increment_rate", return_value=30):
req = self._make_request()
# Should not raise — 30 == limit, not 30 > limit
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))

def test_one_over_limit_raises(self):
from fastapi import HTTPException
Expand All @@ -330,7 +330,7 @@ def test_one_over_limit_raises(self):
with patch.object(_shared_mod, "increment_rate", return_value=31):
req = self._make_request()
with pytest.raises(HTTPException) as exc_info:
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))
assert exc_info.value.status_code == 429

def test_uses_open_namespace(self):
Expand All @@ -347,7 +347,7 @@ def mock_increment(key, window_seconds, tenant_id):

with patch.object(_shared_mod, "increment_rate", side_effect=mock_increment):
req = self._make_request()
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))

assert captured["tenant_id"] == "_open_"

Expand All @@ -366,7 +366,7 @@ def mock_increment(key, window_seconds, tenant_id):
with patch.object(_shared_mod, "increment_rate", side_effect=mock_increment):
req = MagicMock()
req.client = None
asyncio.run(api_mod.check_rate_limit_open(req))
asyncio.run(_shared_mod.check_rate_limit_open(req))

assert "open_rate:unknown" in captured.get("key", "")

Expand Down Expand Up @@ -485,16 +485,16 @@ def test_api_imports_open_rate_limit_constant(self):
import api as api_mod
import api_routers._shared as _shared_mod

assert hasattr(api_mod, "RATE_LIMIT_OPEN_PER_MINUTE") or hasattr(
api_mod, "check_rate_limit_open"
), "api.py must import or define RATE_LIMIT_OPEN_PER_MINUTE or check_rate_limit_open"
assert hasattr(_shared_mod, "RATE_LIMIT_OPEN_PER_MINUTE") or hasattr(
_shared_mod, "check_rate_limit_open"
), "api_routers._shared must define check_rate_limit_open (T-1 decomposition)"

def test_check_rate_limit_open_is_async(self):
import asyncio
import api as api_mod
import api_routers._shared as _shared_mod

assert asyncio.iscoroutinefunction(api_mod.check_rate_limit_open)
assert asyncio.iscoroutinefunction(_shared_mod.check_rate_limit_open)


# =============================================================================
Expand Down
Loading