import os
import sys
import unittest

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

class TestArchBoundaryPhase1(unittest.TestCase):
 def setUp(self) -> None:
  pass

 def tearDown(self) -> None:
  pass

 def test_unfettered_modules_constant_removed(self) -> None:
  """TEST 1: Check 'UNFETTERED_MODULES' string is removed from project_manager.py"""
  # We check the source directly to be sure it's not just hidden
  with open("src/project_manager.py", "r", encoding="utf-8") as f:
   content = f.read()
  self.assertNotIn("UNFETTERED_MODULES", content)

 def test_mcp_client_whitelist_enforcement(self) -> None:
   """TEST 2: mcp_client._is_allowed must return False for config.toml"""
   import tempfile
   from src import mcp_client
   from pathlib import Path

   tmp = Path(tempfile.mkdtemp())

   # Configure with some dummy file items (as dicts)
   file_items = [{"path": "src/gui_2.py"}]
   mcp_client.configure(file_items, [])

   # Should allow src files
   self.assertTrue(mcp_client._is_allowed(Path("src/gui_2.py")))
   # Should REJECT config files (using tmp_path versions; check is by basename)
   self.assertFalse(mcp_client._is_allowed(tmp / "config.toml"))
   self.assertFalse(mcp_client._is_allowed(tmp / "credentials.toml"))

 def test_mma_exec_no_hardcoded_path(self) -> None:
  """TEST 4: mma_exec.execute_agent must not contain hardcoded machine paths."""
  with open("scripts/mma_exec.py", "r", encoding="utf-8") as f:
   content = f.read()
  # Check for some common home directory patterns or user paths
  self.assertNotIn("C:\\Users\\Ed", content)
  self.assertNotIn("/Users/ed", content)

 def test_claude_mma_exec_no_hardcoded_path(self) -> None:
  """TEST 5: claude_mma_exec.execute_agent must not contain hardcoded machine paths."""
  with open("scripts/claude_mma_exec.py", "r", encoding="utf-8") as f:
   content = f.read()
  self.assertNotIn("C:\\Users\\Ed", content)
  self.assertNotIn("/Users/ed", content)