test_cli_paths.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/usr/bin/env python3
  2. """
  3. Test suite for modern CLI command patterns
  4. Tests that all CLI scripts use correct unified CLI commands in usage messages and print statements
  5. """
  6. import sys
  7. import os
  8. import unittest
  9. import subprocess
  10. from pathlib import Path
  11. # Add parent directory to path
  12. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  13. class TestModernCLICommands(unittest.TestCase):
  14. """Test that all CLI scripts use modern unified CLI commands"""
  15. def test_doc_scraper_uses_modern_commands(self):
  16. """Test doc_scraper.py uses skill-seekers commands"""
  17. script_path = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'doc_scraper.py'
  18. with open(script_path, 'r') as f:
  19. content = f.read()
  20. # Should use modern commands
  21. self.assertIn('skill-seekers scrape', content)
  22. # Should NOT use old python3 cli/ pattern
  23. self.assertNotIn('python3 cli/doc_scraper.py', content)
  24. def test_enhance_skill_local_uses_modern_commands(self):
  25. """Test enhance_skill_local.py uses skill-seekers commands"""
  26. script_path = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'enhance_skill_local.py'
  27. with open(script_path, 'r') as f:
  28. content = f.read()
  29. # Should use modern commands
  30. self.assertIn('skill-seekers', content)
  31. # Should NOT use old python3 cli/ pattern
  32. self.assertNotIn('python3 cli/enhance_skill_local.py', content)
  33. def test_estimate_pages_uses_modern_commands(self):
  34. """Test estimate_pages.py uses skill-seekers commands"""
  35. script_path = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'estimate_pages.py'
  36. with open(script_path, 'r') as f:
  37. content = f.read()
  38. # Should use modern commands
  39. self.assertIn('skill-seekers estimate', content)
  40. # Should NOT use old python3 cli/ pattern
  41. self.assertNotIn('python3 cli/estimate_pages.py', content)
  42. def test_package_skill_uses_modern_commands(self):
  43. """Test package_skill.py uses skill-seekers commands"""
  44. script_path = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'package_skill.py'
  45. with open(script_path, 'r') as f:
  46. content = f.read()
  47. # Should use modern commands
  48. self.assertIn('skill-seekers package', content)
  49. # Should NOT use old python3 cli/ pattern
  50. self.assertNotIn('python3 cli/package_skill.py', content)
  51. def test_github_scraper_uses_modern_commands(self):
  52. """Test github_scraper.py uses skill-seekers commands"""
  53. script_path = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'github_scraper.py'
  54. with open(script_path, 'r') as f:
  55. content = f.read()
  56. # Should use modern commands
  57. self.assertIn('skill-seekers', content)
  58. # Should NOT use old python3 cli/ pattern
  59. self.assertNotIn('python3 cli/github_scraper.py', content)
  60. class TestUnifiedCLIEntryPoints(unittest.TestCase):
  61. """Test that unified CLI entry points work correctly"""
  62. def test_main_cli_help_output(self):
  63. """Test skill-seekers --help works"""
  64. try:
  65. result = subprocess.run(
  66. ['skill-seekers', '--help'],
  67. capture_output=True,
  68. text=True,
  69. timeout=5
  70. )
  71. # Should return successfully
  72. self.assertIn(result.returncode, [0, 2],
  73. f"skill-seekers --help failed with code {result.returncode}")
  74. # Should show subcommands
  75. output = result.stdout + result.stderr
  76. self.assertIn('scrape', output)
  77. self.assertIn('github', output)
  78. self.assertIn('package', output)
  79. except FileNotFoundError:
  80. # If skill-seekers is not installed, skip this test
  81. self.skipTest("skill-seekers command not found - install package first")
  82. def test_main_cli_version_output(self):
  83. """Test skill-seekers --version works"""
  84. try:
  85. result = subprocess.run(
  86. ['skill-seekers', '--version'],
  87. capture_output=True,
  88. text=True,
  89. timeout=5
  90. )
  91. # Should return successfully
  92. self.assertEqual(result.returncode, 0,
  93. f"skill-seekers --version failed: {result.stderr}")
  94. # Should show version
  95. output = result.stdout + result.stderr
  96. self.assertIn('2.1.1', output)
  97. except FileNotFoundError:
  98. # If skill-seekers is not installed, skip this test
  99. self.skipTest("skill-seekers command not found - install package first")
  100. class TestNoHardcodedPaths(unittest.TestCase):
  101. """Test that no scripts have hardcoded absolute paths"""
  102. def test_no_hardcoded_paths_in_cli_scripts(self):
  103. """Test that CLI scripts don't have hardcoded paths"""
  104. cli_dir = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli'
  105. hardcoded_paths = [
  106. '/mnt/skills/examples/skill-creator/scripts/',
  107. '/home/',
  108. '/Users/',
  109. ]
  110. for script_path in cli_dir.glob('*.py'):
  111. with open(script_path, 'r') as f:
  112. content = f.read()
  113. for hardcoded_path in hardcoded_paths:
  114. self.assertNotIn(hardcoded_path, content,
  115. f"{script_path.name} contains hardcoded path: {hardcoded_path}")
  116. class TestPackageStructure(unittest.TestCase):
  117. """Test that package structure is correct"""
  118. def test_src_layout_exists(self):
  119. """Test that src/ layout directory exists"""
  120. src_dir = Path(__file__).parent.parent / 'src' / 'skill_seekers'
  121. self.assertTrue(src_dir.exists(), "src/skill_seekers/ directory should exist")
  122. def test_cli_package_exists(self):
  123. """Test that CLI package exists in src/"""
  124. cli_dir = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli'
  125. self.assertTrue(cli_dir.exists(), "src/skill_seekers/cli/ directory should exist")
  126. init_file = cli_dir / '__init__.py'
  127. self.assertTrue(init_file.exists(), "src/skill_seekers/cli/__init__.py should exist")
  128. def test_mcp_package_exists(self):
  129. """Test that MCP package exists in src/"""
  130. mcp_dir = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'mcp'
  131. self.assertTrue(mcp_dir.exists(), "src/skill_seekers/mcp/ directory should exist")
  132. init_file = mcp_dir / '__init__.py'
  133. self.assertTrue(init_file.exists(), "src/skill_seekers/mcp/__init__.py should exist")
  134. def test_main_cli_file_exists(self):
  135. """Test that main.py unified CLI exists"""
  136. main_file = Path(__file__).parent.parent / 'src' / 'skill_seekers' / 'cli' / 'main.py'
  137. self.assertTrue(main_file.exists(), "src/skill_seekers/cli/main.py should exist")
  138. if __name__ == '__main__':
  139. unittest.main()