[loop-cycle] fix: three-strike route test isolation for xdist (#1254)

This commit is contained in:
2026-03-23 23:49:00 +00:00
parent 35d2547a0b
commit 2240ddb632

View File

@@ -1,11 +1,21 @@
"""Integration tests for the three-strike dashboard routes.
Refs: #962
Uses unique keys per test (uuid4) so parallel xdist workers and repeated
runs never collide on shared SQLite state.
"""
import uuid
import pytest
def _uid() -> str:
"""Return a short unique suffix for test keys."""
return uuid.uuid4().hex[:8]
class TestThreeStrikeRoutes:
@pytest.mark.unit
def test_list_strikes_returns_200(self, client):
@@ -24,9 +34,10 @@ class TestThreeStrikeRoutes:
@pytest.mark.unit
def test_record_strike_first(self, client):
key = f"test_btn_{_uid()}"
response = client.post(
"/sovereignty/three-strike/record",
json={"category": "vlm_prompt_edit", "key": "test_btn"},
json={"category": "vlm_prompt_edit", "key": key},
)
assert response.status_code == 200
data = response.json()
@@ -43,14 +54,15 @@ class TestThreeStrikeRoutes:
@pytest.mark.unit
def test_third_strike_returns_409(self, client):
key = f"push_route_{_uid()}"
for _ in range(2):
client.post(
"/sovereignty/three-strike/record",
json={"category": "deployment_step", "key": "push_route_test"},
json={"category": "deployment_step", "key": key},
)
response = client.post(
"/sovereignty/three-strike/record",
json={"category": "deployment_step", "key": "push_route_test"},
json={"category": "deployment_step", "key": key},
)
assert response.status_code == 409
data = response.json()
@@ -60,7 +72,7 @@ class TestThreeStrikeRoutes:
@pytest.mark.unit
def test_register_automation_returns_success(self, client):
response = client.post(
"/sovereignty/three-strike/deployment_step/some_key/automation",
f"/sovereignty/three-strike/deployment_step/auto_{_uid()}/automation",
json={"artifact_path": "scripts/auto.sh"},
)
assert response.status_code == 200
@@ -68,13 +80,14 @@ class TestThreeStrikeRoutes:
@pytest.mark.unit
def test_get_events_returns_200(self, client):
key = f"events_{_uid()}"
client.post(
"/sovereignty/three-strike/record",
json={"category": "vlm_prompt_edit", "key": "events_test_key"},
json={"category": "vlm_prompt_edit", "key": key},
)
response = client.get("/sovereignty/three-strike/vlm_prompt_edit/events_test_key/events")
response = client.get(f"/sovereignty/three-strike/vlm_prompt_edit/{key}/events")
assert response.status_code == 200
data = response.json()
assert data["category"] == "vlm_prompt_edit"
assert data["key"] == "events_test_key"
assert data["key"] == key
assert len(data["events"]) >= 1