#!/usr/bin/env python3 """ Test setup scripts for correctness and path validation. Tests that bash scripts reference correct paths and are syntactically valid. """ import subprocess import re from pathlib import Path import pytest class TestSetupMCPScript: """Test setup_mcp.sh for path correctness and syntax""" @pytest.fixture def script_path(self): """Get path to setup_mcp.sh""" return Path("setup_mcp.sh") @pytest.fixture def script_content(self, script_path): """Read setup_mcp.sh content""" with open(script_path, 'r') as f: return f.read() def test_setup_mcp_exists(self, script_path): """Test that setup_mcp.sh exists""" assert script_path.exists(), "setup_mcp.sh should exist" assert script_path.is_file(), "setup_mcp.sh should be a file" def test_bash_syntax_valid(self, script_path): """Test that setup_mcp.sh has valid bash syntax""" result = subprocess.run( ["bash", "-n", str(script_path)], capture_output=True, text=True ) assert result.returncode == 0, f"Bash syntax error: {result.stderr}" def test_references_correct_mcp_directory(self, script_content): """Test that script references src/skill_seekers/mcp/ (v2.0.0 layout)""" # Should NOT reference old mcp/ or skill_seeker_mcp/ directories old_mcp_refs = re.findall(r'(?:^|[^a-z_])(?= 6, f"Expected at least 6 references to 'src/skill_seekers/mcp/', found {len(new_refs)}" def test_requirements_txt_path(self, script_content): """Test that script uses pip install -e . (v2.0.0 modern packaging)""" # v2.0.0 uses '-e .' (editable install) instead of requirements files # The actual command is "$PIP_INSTALL_CMD -e ." assert " -e ." in script_content or " -e." in script_content, \ "Should use '-e .' for editable install (modern packaging)" # Should NOT reference old requirements.txt paths import re old_skill_seeker_refs = re.findall(r'skill_seeker_mcp/requirements\.txt', script_content) old_mcp_refs = re.findall(r'(? 0: pytest.fail(f"README references old mcp/ directory: {old_mcp_refs}") def test_documentation_references_correct_paths(self): """Test that documentation files reference correct MCP paths""" doc_files = list(Path("docs/").glob("*.md")) if Path("docs/").exists() else [] for doc_file in doc_files: with open(doc_file, 'r') as f: content = f.read() # Check for old mcp/ directory paths (but allow mcp.json and "mcp" package name) old_mcp_refs = re.findall(r'(? 0: pytest.fail(f"{doc_file} references old mcp/ directory: {old_mcp_refs}") def test_mcp_directory_structure(): """Test that MCP directory structure is correct (new src/ layout)""" mcp_dir = Path("src/skill_seekers/mcp") assert mcp_dir.exists(), "src/skill_seekers/mcp/ directory should exist" assert mcp_dir.is_dir(), "src/skill_seekers/mcp should be a directory" assert (mcp_dir / "server.py").exists(), "src/skill_seekers/mcp/server.py should exist" assert (mcp_dir / "__init__.py").exists(), "src/skill_seekers/mcp/__init__.py should exist" # Old directories should NOT exist old_mcp = Path("mcp") old_skill_seeker_mcp = Path("skill_seeker_mcp") if old_mcp.exists(): # If it exists, it should not contain server.py (might be leftover empty dir) assert not (old_mcp / "server.py").exists(), \ "Old mcp/server.py should not exist - migrated to src/skill_seekers/mcp/" if old_skill_seeker_mcp.exists(): assert not (old_skill_seeker_mcp / "server.py").exists(), \ "Old skill_seeker_mcp/server.py should not exist - migrated to src/skill_seekers/mcp/" if __name__ == '__main__': print("=" * 60) print("Testing Setup Scripts") print("=" * 60) pytest.main([__file__, "-v"])