| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #!/usr/bin/env python3
- """
- Debug script to test USM autoprovides functionality.
- """
- import sys
- import tempfile
- from pathlib import Path
- # Add the src directory to the path
- sys.path.insert(0, 'src')
- from autusm.usm_integration import USMIntegration
- from autusm.manifest import ManifestGenerator
- from autusm.models import PackageInfo, BuildSystem, BuildSystemType, License, LicenseCategory
- def test_usm_integration():
- """Test USM integration directly."""
- print("Testing USM integration...")
-
- # Create USM integration instance
- usm_integration = USMIntegration()
-
- # Check if USM is available
- if not usm_integration.is_available():
- print("USM is not available on this system")
- return False
-
- # Create a temporary directory with a simple manifest
- with tempfile.TemporaryDirectory() as temp_dir:
- temp_path = Path(temp_dir)
-
- # Create a simple manifest file
- manifest_content = """{
- "name": "test",
- "version": "1.0.0",
- "summary": "Test package",
- "licences": [
- {
- "name": "MIT",
- "text": "LICENSE",
- "category": "open-source"
- }
- ],
- "provides": {
- "bin:test": "as-expected"
- },
- "depends": {
- "runtime": [],
- "build": [],
- "manage": []
- },
- "flags": [],
- "execs": {
- "build": "scripts/build"
- }
- }"""
-
- manifest_path = temp_path / "MANIFEST.usm"
- with open(manifest_path, "w") as f:
- f.write(manifest_content)
-
- print(f"Created test manifest at: {manifest_path}")
-
- # Try to get autoprovides
- try:
- autoprovides = usm_integration.get_autoprovides(temp_path)
- print(f"Got autoprovides: {autoprovides}")
- return True
- except Exception as e:
- print(f"Error getting autoprovides: {e}")
- import traceback
- traceback.print_exc()
- return False
- def test_parsing_with_garbage():
- """Test parsing with garbage output similar to what we're seeing."""
- print("\nTesting parsing with garbage output...")
-
- usm_integration = USMIntegration()
-
- # Test with the garbage pattern we're seeing
- garbage_output = '"provides": {\n "type": "reg",\n "path": "{",\n "pathBase": "source"\n }'
-
- print(f"Testing with garbage output: {repr(garbage_output)}")
-
- try:
- parsed = usm_integration._parse_autoprovides(garbage_output)
- print(f"Parsed result: {parsed}")
- return True
- except Exception as e:
- print(f"Error parsing garbage: {e}")
- import traceback
- traceback.print_exc()
- return False
- def test_manifest_update():
- """Test manifest update with problematic data."""
- print("\nTesting manifest update...")
-
- # Create test package info
- package_info = PackageInfo(
- name="test-package",
- version="1.0.0",
- summary="A test package",
- licenses=[License(name="MIT", text="LICENSE", category=LicenseCategory.OPEN_SOURCE)]
- )
-
- # Create test build system
- build_system = BuildSystem(type=BuildSystemType.MAKE)
-
- # Create manifest generator
- manifest_generator = ManifestGenerator()
-
- # Generate initial manifest
- manifest = manifest_generator.generate(package_info, build_system)
-
- print(f"Initial manifest provides: {manifest.provides}")
-
- # Try to update with garbage data
- garbage_autoprovides = {
- '"provides":': {
- "type": "reg",
- "path": "{",
- "pathBase": "source"
- }
- }
-
- try:
- updated_manifest = manifest_generator.update_with_autoprovides(manifest, garbage_autoprovides)
- print(f"Updated manifest provides: {updated_manifest.provides}")
-
- # Test JSON serialization
- json_str = updated_manifest.to_json()
- print("JSON serialization result:")
- print(json_str)
-
- return True
- except Exception as e:
- print(f"Error updating manifest: {e}")
- import traceback
- traceback.print_exc()
- return False
- if __name__ == "__main__":
- print("Running debug tests...\n")
-
- try:
- test_usm_integration()
- test_parsing_with_garbage()
- test_manifest_update()
-
- print("\n✅ All debug tests completed")
-
- except Exception as e:
- print(f"\n❌ Debug test failed: {e}")
- import traceback
- traceback.print_exc()
- sys.exit(1)
|