import pytest
import time
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from src.api_hook_client import ApiHookClient
import src.gui_2 as gui_2

@pytest.mark.integration
def test_selectable_label_stability(live_gui) -> None:
 """
   Verifies that the application starts correctly with --enable-test-hooks
   and that the selectable label infrastructure is present and stable.
 """
 client = ApiHookClient()
 assert client.wait_for_server(timeout=20), "Hook server failed to start"

 diag = client.get_gui_diagnostics()
 assert diag.get("prior") is False, "Initial state should not be viewing prior session"

 assert hasattr(gui_2, 'render_selectable_label'), "gui_2 module must have render_selectable_label function"

 client.set_value("ai_response", "Test selectable text stability")
 time.sleep(1)
 val = client.get_value("ai_response")
 assert val == "Test selectable text stability", f"Expected 'Test selectable text stability', got '{val}'"

 prior_val = client.get_value("prior_session_indicator")
 assert prior_val is False, "prior_session_indicator field should be False initially"
