test_fix.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env python3
  2. """
  3. Test script to verify the autoprovides fix works end-to-end.
  4. """
  5. import sys
  6. import tempfile
  7. import json
  8. from pathlib import Path
  9. # Add the src directory to the path
  10. sys.path.insert(0, 'src')
  11. from autusm.download import DownloadManager
  12. from autusm.extractor import ArchiveExtractor
  13. from autusm.analyzer import SourceAnalyzer
  14. from autusm.metadata import MetadataExtractor
  15. from autusm.generator import ScriptGenerator
  16. from autusm.manifest import ManifestGenerator
  17. from autusm.usm_integration import USMIntegration
  18. from autusm.interaction import UserInteraction
  19. def test_full_workflow():
  20. """Test the full workflow with a simple package."""
  21. print("Testing full autusm workflow...")
  22. # Create a temporary directory for testing
  23. with tempfile.TemporaryDirectory() as temp_dir:
  24. temp_path = Path(temp_dir)
  25. # URL to a simple package
  26. url = "https://mirror.freedif.org/GNU/hello/hello-2.12.tar.gz"
  27. try:
  28. # Step 1: Download
  29. print("Downloading source archive...")
  30. download_manager = DownloadManager()
  31. archive_path = download_manager.download(url, temp_path)
  32. print(f"Downloaded to: {archive_path}")
  33. # Step 2: Extract
  34. print("Extracting archive...")
  35. extractor = ArchiveExtractor()
  36. source_dir = extractor.extract(archive_path, temp_path)
  37. print(f"Extracted to: {source_dir}")
  38. # Step 3: Analyze
  39. print("Analyzing source code...")
  40. analyzer = SourceAnalyzer()
  41. build_system = analyzer.detect_build_system(source_dir)
  42. print(f"Detected build system: {build_system.type.value}")
  43. # Step 4: Extract metadata
  44. print("Extracting metadata...")
  45. metadata_extractor = MetadataExtractor()
  46. package_info = metadata_extractor.extract(source_dir)
  47. package_info.name = "hello"
  48. package_info.version = "2.12"
  49. package_info.summary = "GNU Hello package, a classic example"
  50. package_info.url = url
  51. package_info.source_dir = str(source_dir)
  52. # Step 5: Generate scripts
  53. print("Generating scripts...")
  54. script_generator = ScriptGenerator()
  55. scripts_dir = source_dir / "scripts"
  56. scripts_dir.mkdir(parents=True, exist_ok=True)
  57. script_generator.generate_scripts(package_info, build_system, scripts_dir)
  58. # Step 6: Generate manifest
  59. print("Generating manifest...")
  60. manifest_generator = ManifestGenerator()
  61. manifest = manifest_generator.generate(package_info, build_system)
  62. # Write initial manifest
  63. manifest_path = source_dir / "MANIFEST.usm"
  64. with open(manifest_path, "w") as f:
  65. f.write(manifest.to_json())
  66. print(f"Initial manifest written to: {manifest_path}")
  67. # Also save to test_output for inspection
  68. test_output_path = Path("test_output") / "MANIFEST.usm"
  69. test_output_path.parent.mkdir(parents=True, exist_ok=True)
  70. with open(test_output_path, "w") as f:
  71. f.write(manifest.to_json())
  72. print(f"Also saved to: {test_output_path}")
  73. # Step 7: Test USM integration
  74. print("Testing USM integration...")
  75. usm_integration = USMIntegration()
  76. if usm_integration.is_available():
  77. print("USM is available, testing autoprovides...")
  78. autoprovides = usm_integration.get_autoprovides(source_dir)
  79. print(f"Got autoprovides: {autoprovides}")
  80. if autoprovides:
  81. print("Updating manifest with autoprovides...")
  82. updated_manifest = manifest_generator.update_with_autoprovides(manifest, autoprovides)
  83. # Rewrite the manifest
  84. with open(manifest_path, "w") as f:
  85. f.write(updated_manifest.to_json())
  86. print("Final manifest:")
  87. print(updated_manifest.to_json())
  88. else:
  89. print("No autoprovides returned from USM")
  90. else:
  91. print("USM is not available, skipping autoprovides")
  92. return True
  93. except Exception as e:
  94. print(f"Error: {e}")
  95. import traceback
  96. traceback.print_exc()
  97. return False
  98. if __name__ == "__main__":
  99. success = test_full_workflow()
  100. if success:
  101. print("\n✅ Full workflow test completed successfully!")
  102. else:
  103. print("\n❌ Full workflow test failed!")
  104. sys.exit(1)