Co-authored-by: Claude (Opus 4.6) <claude@hermes.local> Co-committed-by: Claude (Opus 4.6) <claude@hermes.local>
83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""Integration tests for the three-strike dashboard routes.
|
|
|
|
Refs: #962
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
class TestThreeStrikeRoutes:
|
|
@pytest.mark.unit
|
|
def test_list_strikes_returns_200(self, client):
|
|
response = client.get("/sovereignty/three-strike")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "records" in data
|
|
assert "categories" in data
|
|
|
|
@pytest.mark.unit
|
|
def test_list_blocked_returns_200(self, client):
|
|
response = client.get("/sovereignty/three-strike/blocked")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "blocked" in data
|
|
|
|
@pytest.mark.unit
|
|
def test_record_strike_first(self, client):
|
|
response = client.post(
|
|
"/sovereignty/three-strike/record",
|
|
json={"category": "vlm_prompt_edit", "key": "test_btn"},
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["count"] == 1
|
|
assert data["blocked"] is False
|
|
|
|
@pytest.mark.unit
|
|
def test_record_invalid_category_returns_422(self, client):
|
|
response = client.post(
|
|
"/sovereignty/three-strike/record",
|
|
json={"category": "not_a_real_category", "key": "x"},
|
|
)
|
|
assert response.status_code == 422
|
|
|
|
@pytest.mark.unit
|
|
def test_third_strike_returns_409(self, client):
|
|
for _ in range(2):
|
|
client.post(
|
|
"/sovereignty/three-strike/record",
|
|
json={"category": "deployment_step", "key": "push_route_test"},
|
|
)
|
|
response = client.post(
|
|
"/sovereignty/three-strike/record",
|
|
json={"category": "deployment_step", "key": "push_route_test"},
|
|
)
|
|
assert response.status_code == 409
|
|
data = response.json()
|
|
assert data["detail"]["error"] == "three_strike_block"
|
|
assert data["detail"]["count"] == 3
|
|
|
|
@pytest.mark.unit
|
|
def test_register_automation_returns_success(self, client):
|
|
response = client.post(
|
|
"/sovereignty/three-strike/deployment_step/some_key/automation",
|
|
json={"artifact_path": "scripts/auto.sh"},
|
|
)
|
|
assert response.status_code == 200
|
|
assert response.json()["success"] is True
|
|
|
|
@pytest.mark.unit
|
|
def test_get_events_returns_200(self, client):
|
|
client.post(
|
|
"/sovereignty/three-strike/record",
|
|
json={"category": "vlm_prompt_edit", "key": "events_test_key"},
|
|
)
|
|
response = client.get(
|
|
"/sovereignty/three-strike/vlm_prompt_edit/events_test_key/events"
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["category"] == "vlm_prompt_edit"
|
|
assert data["key"] == "events_test_key"
|
|
assert len(data["events"]) >= 1
|