import sys
import os
from unittest.mock import MagicMock

# Ensure project root is in path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))

from simulation.workflow_sim import WorkflowSimulator

def test_simulator_instantiation() -> None:
 client = MagicMock()
 sim = WorkflowSimulator(client)
 assert sim is not None

def test_setup_new_project() -> None:
 client = MagicMock()
 sim = WorkflowSimulator(client)
 # Mock responses for wait_for_server
 client.wait_for_server.return_value = True
 sim.setup_new_project("TestProject", "/tmp/test_git")
 # Verify hook calls
 client.click.assert_any_call("btn_project_new")
 client.set_value.assert_any_call("project_git_dir", "/tmp/test_git")
 client.click.assert_any_call("btn_project_save")

def test_discussion_switching() -> None:
 client = MagicMock()
 sim = WorkflowSimulator(client)
 sim.create_discussion("NewDisc")
 client.set_value.assert_called_with("disc_new_name_input", "NewDisc")
 client.click.assert_called_with("btn_disc_create")
 sim.switch_discussion("NewDisc")
 client.select_list_item.assert_called_with("disc_listbox", "NewDisc")

def test_history_truncation() -> None:
 client = MagicMock()
 sim = WorkflowSimulator(client)
 sim.truncate_history(3)
 client.set_value.assert_called_with("disc_truncate_pairs", 3)
 client.click.assert_called_with("btn_disc_truncate")
