test_porting_workspace.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from __future__ import annotations
  2. import subprocess
  3. import sys
  4. import unittest
  5. from src.commands import PORTED_COMMANDS
  6. from src.parity_audit import run_parity_audit
  7. from src.port_manifest import build_port_manifest
  8. from src.query_engine import QueryEnginePort
  9. from src.tools import PORTED_TOOLS
  10. class PortingWorkspaceTests(unittest.TestCase):
  11. def test_manifest_counts_python_files(self) -> None:
  12. manifest = build_port_manifest()
  13. self.assertGreaterEqual(manifest.total_python_files, 20)
  14. self.assertTrue(manifest.top_level_modules)
  15. def test_query_engine_summary_mentions_workspace(self) -> None:
  16. summary = QueryEnginePort.from_workspace().render_summary()
  17. self.assertIn('Python Porting Workspace Summary', summary)
  18. self.assertIn('Command surface:', summary)
  19. self.assertIn('Tool surface:', summary)
  20. def test_cli_summary_runs(self) -> None:
  21. result = subprocess.run(
  22. [sys.executable, '-m', 'src.main', 'summary'],
  23. check=True,
  24. capture_output=True,
  25. text=True,
  26. )
  27. self.assertIn('Python Porting Workspace Summary', result.stdout)
  28. def test_parity_audit_runs(self) -> None:
  29. result = subprocess.run(
  30. [sys.executable, '-m', 'src.main', 'parity-audit'],
  31. check=True,
  32. capture_output=True,
  33. text=True,
  34. )
  35. self.assertIn('Parity Audit', result.stdout)
  36. def test_root_file_coverage_is_complete_when_local_archive_exists(self) -> None:
  37. audit = run_parity_audit()
  38. if audit.archive_present:
  39. self.assertEqual(audit.root_file_coverage[0], audit.root_file_coverage[1])
  40. self.assertGreaterEqual(audit.directory_coverage[0], 28)
  41. self.assertGreaterEqual(audit.command_entry_ratio[0], 150)
  42. self.assertGreaterEqual(audit.tool_entry_ratio[0], 100)
  43. def test_command_and_tool_snapshots_are_nontrivial(self) -> None:
  44. self.assertGreaterEqual(len(PORTED_COMMANDS), 150)
  45. self.assertGreaterEqual(len(PORTED_TOOLS), 100)
  46. def test_commands_and_tools_cli_run(self) -> None:
  47. commands_result = subprocess.run(
  48. [sys.executable, '-m', 'src.main', 'commands', '--limit', '5', '--query', 'review'],
  49. check=True,
  50. capture_output=True,
  51. text=True,
  52. )
  53. tools_result = subprocess.run(
  54. [sys.executable, '-m', 'src.main', 'tools', '--limit', '5', '--query', 'MCP'],
  55. check=True,
  56. capture_output=True,
  57. text=True,
  58. )
  59. self.assertIn('Command entries:', commands_result.stdout)
  60. self.assertIn('Tool entries:', tools_result.stdout)
  61. def test_subsystem_packages_expose_archive_metadata(self) -> None:
  62. from src import assistant, bridge, utils
  63. self.assertGreater(assistant.MODULE_COUNT, 0)
  64. self.assertGreater(bridge.MODULE_COUNT, 0)
  65. self.assertGreater(utils.MODULE_COUNT, 100)
  66. self.assertTrue(utils.SAMPLE_FILES)
  67. def test_route_and_show_entry_cli_run(self) -> None:
  68. route_result = subprocess.run(
  69. [sys.executable, '-m', 'src.main', 'route', 'review MCP tool', '--limit', '5'],
  70. check=True,
  71. capture_output=True,
  72. text=True,
  73. )
  74. show_command = subprocess.run(
  75. [sys.executable, '-m', 'src.main', 'show-command', 'review'],
  76. check=True,
  77. capture_output=True,
  78. text=True,
  79. )
  80. show_tool = subprocess.run(
  81. [sys.executable, '-m', 'src.main', 'show-tool', 'MCPTool'],
  82. check=True,
  83. capture_output=True,
  84. text=True,
  85. )
  86. self.assertIn('review', route_result.stdout.lower())
  87. self.assertIn('review', show_command.stdout.lower())
  88. self.assertIn('mcptool', show_tool.stdout.lower())
  89. if __name__ == '__main__':
  90. unittest.main()