From 2240ddb63233355852124c857105f7228a3f9629 Mon Sep 17 00:00:00 2001 From: Timmy Time Date: Mon, 23 Mar 2026 23:49:00 +0000 Subject: [PATCH] [loop-cycle] fix: three-strike route test isolation for xdist (#1254) --- tests/timmy/test_three_strike_routes.py | 27 ++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/timmy/test_three_strike_routes.py b/tests/timmy/test_three_strike_routes.py index b1118c1..41fd6c1 100644 --- a/tests/timmy/test_three_strike_routes.py +++ b/tests/timmy/test_three_strike_routes.py @@ -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