From 7b87bbf5ec510e9127a62deb5127db4b495942cd Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 9 Jun 2026 16:40:18 -0400 Subject: [PATCH] feat(test): clean_baseline marker resets controller state before test --- pyproject.toml | 1 + tests/conftest.py | 15 +++++++++++++ tests/test_clean_baseline_marker.py | 34 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 tests/test_clean_baseline_marker.py diff --git a/pyproject.toml b/pyproject.toml index 838a587b..0dba8e49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ markers = [ "clean_install: clean install verification (opt-in via RUN_CLEAN_INSTALL_TEST=1)", "docker: docker build and run test (opt-in via RUN_DOCKER_TEST=1)", "live: marks tests as live visualization tests (not in CI by default)", + "clean_baseline: opt-in marker that resets controller state via /api/reset_session before the test starts (FR5, Phase 6 of test_infrastructure_hardening_20260609)", ] [tool.mypy] diff --git a/tests/conftest.py b/tests/conftest.py index 935584db..a31e89c9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -653,6 +653,21 @@ def _check_live_gui_health(request, live_gui) -> Generator[None, None, None]: handle.ensure_alive() yield +@pytest.fixture(autouse=True) +def _reset_clean_baseline(request, live_gui) -> Generator[None, None, None]: + """[SDM: tests/conftest.py:_reset_clean_baseline] [C: tests marked with @pytest.mark.clean_baseline]""" + if request.node.get_closest_marker("clean_baseline"): + try: + from src.api_hook_client import ApiHookClient + client = ApiHookClient() + if client.wait_for_server(timeout=5): + client.reset_session() + time.sleep(0.2) + except Exception: + pass + yield + + @pytest.fixture def live_gui_workspace(live_gui) -> Path: """[SDM: tests/conftest.py:live_gui_workspace] [C: tests/test_rag_phase4_*.py, tests/test_saved_presets_sim.py, etc.]""" diff --git a/tests/test_clean_baseline_marker.py b/tests/test_clean_baseline_marker.py new file mode 100644 index 00000000..2a6c2fcc --- /dev/null +++ b/tests/test_clean_baseline_marker.py @@ -0,0 +1,34 @@ +"""Tests for the clean_baseline marker (Phase 6, FR5).""" +import pytest +import time + + +def test_clean_baseline_marker_registered() -> None: + """The clean_baseline marker is registered in pyproject.toml.""" + # This test will fail if the marker is not registered. + # We use pytest.mark.clean_baseline as a sentinel. + @pytest.mark.clean_baseline + def dummy() -> None: + pass + assert hasattr(dummy, "pytestmark") + + +@pytest.mark.clean_baseline +def test_clean_baseline_ai_input_empty_at_start(live_gui) -> None: + """A test marked with clean_baseline starts with empty ai_input.""" + handle = live_gui + client = handle.api_client if hasattr(handle, "api_client") else None + if client is None: + # Fall back to creating a client + from src.api_hook_client import ApiHookClient + client = ApiHookClient() + assert client.wait_for_server(timeout=15) + value = client.get_value("ai_input") + assert value == "", f"Expected empty ai_input at start of clean_baseline test, got {value!r}" + + +@pytest.mark.clean_baseline +def test_clean_baseline_does_not_break_normal_tests(live_gui) -> None: + """A test marked with clean_baseline still runs normally.""" + handle = live_gui + assert handle.is_alive()