| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #!/usr/bin/env python3
- """
- Test script to verify the autoprovides fix works end-to-end.
- """
- import sys
- import tempfile
- import json
- from pathlib import Path
- # Add the src directory to the path
- sys.path.insert(0, 'src')
- from autusm.download import DownloadManager
- from autusm.extractor import ArchiveExtractor
- from autusm.analyzer import SourceAnalyzer
- from autusm.metadata import MetadataExtractor
- from autusm.generator import ScriptGenerator
- from autusm.manifest import ManifestGenerator
- from autusm.usm_integration import USMIntegration
- from autusm.interaction import UserInteraction
- def test_full_workflow():
- """Test the full workflow with a simple package."""
- print("Testing full autusm workflow...")
-
- # Create a temporary directory for testing
- with tempfile.TemporaryDirectory() as temp_dir:
- temp_path = Path(temp_dir)
-
- # URL to a simple package
- url = "https://mirror.freedif.org/GNU/hello/hello-2.12.tar.gz"
-
- try:
- # Step 1: Download
- print("Downloading source archive...")
- download_manager = DownloadManager()
- archive_path = download_manager.download(url, temp_path)
- print(f"Downloaded to: {archive_path}")
-
- # Step 2: Extract
- print("Extracting archive...")
- extractor = ArchiveExtractor()
- source_dir = extractor.extract(archive_path, temp_path)
- print(f"Extracted to: {source_dir}")
-
- # Step 3: Analyze
- print("Analyzing source code...")
- analyzer = SourceAnalyzer()
- build_system = analyzer.detect_build_system(source_dir)
- print(f"Detected build system: {build_system.type.value}")
-
- # Step 4: Extract metadata
- print("Extracting metadata...")
- metadata_extractor = MetadataExtractor()
- package_info = metadata_extractor.extract(source_dir)
- package_info.name = "hello"
- package_info.version = "2.12"
- package_info.summary = "GNU Hello package, a classic example"
- package_info.url = url
- package_info.source_dir = str(source_dir)
-
- # Step 5: Generate scripts
- print("Generating scripts...")
- script_generator = ScriptGenerator()
- scripts_dir = source_dir / "scripts"
- scripts_dir.mkdir(parents=True, exist_ok=True)
- script_generator.generate_scripts(package_info, build_system, scripts_dir)
-
- # Step 6: Generate manifest
- print("Generating manifest...")
- manifest_generator = ManifestGenerator()
- manifest = manifest_generator.generate(package_info, build_system)
-
- # Write initial manifest
- manifest_path = source_dir / "MANIFEST.usm"
- with open(manifest_path, "w") as f:
- f.write(manifest.to_json())
- print(f"Initial manifest written to: {manifest_path}")
-
- # Also save to test_output for inspection
- test_output_path = Path("test_output") / "MANIFEST.usm"
- test_output_path.parent.mkdir(parents=True, exist_ok=True)
- with open(test_output_path, "w") as f:
- f.write(manifest.to_json())
- print(f"Also saved to: {test_output_path}")
-
- # Step 7: Test USM integration
- print("Testing USM integration...")
- usm_integration = USMIntegration()
-
- if usm_integration.is_available():
- print("USM is available, testing autoprovides...")
- autoprovides = usm_integration.get_autoprovides(source_dir)
- print(f"Got autoprovides: {autoprovides}")
-
- if autoprovides:
- print("Updating manifest with autoprovides...")
- updated_manifest = manifest_generator.update_with_autoprovides(manifest, autoprovides)
-
- # Rewrite the manifest
- with open(manifest_path, "w") as f:
- f.write(updated_manifest.to_json())
-
- print("Final manifest:")
- print(updated_manifest.to_json())
- else:
- print("No autoprovides returned from USM")
- else:
- print("USM is not available, skipping autoprovides")
-
- return True
-
- except Exception as e:
- print(f"Error: {e}")
- import traceback
- traceback.print_exc()
- return False
- if __name__ == "__main__":
- success = test_full_workflow()
- if success:
- print("\n✅ Full workflow test completed successfully!")
- else:
- print("\n❌ Full workflow test failed!")
- sys.exit(1)
|