fix: three-strike route tests use unique keys for xdist isolation
Some checks failed
Tests / lint (pull_request) Failing after 13s
Tests / test (pull_request) Has been skipped

Tests used hardcoded keys that collided across parallel xdist workers
and repeated runs on the shared SQLite DB. Each test now generates a
uuid4-based key so state never leaks between tests.

Fixes 2 flaky failures on main: test_record_strike_first and
test_third_strike_returns_409.
This commit is contained in:
hermes
2026-03-23 19:48:34 -04:00
parent 35d2547a0b
commit fd4773acad

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