debug_autoprovides.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #!/usr/bin/env python3
  2. """
  3. Debug script to test USM autoprovides functionality.
  4. """
  5. import sys
  6. import tempfile
  7. from pathlib import Path
  8. # Add the src directory to the path
  9. sys.path.insert(0, 'src')
  10. from autusm.usm_integration import USMIntegration
  11. from autusm.manifest import ManifestGenerator
  12. from autusm.models import PackageInfo, BuildSystem, BuildSystemType, License, LicenseCategory
  13. def test_usm_integration():
  14. """Test USM integration directly."""
  15. print("Testing USM integration...")
  16. # Create USM integration instance
  17. usm_integration = USMIntegration()
  18. # Check if USM is available
  19. if not usm_integration.is_available():
  20. print("USM is not available on this system")
  21. return False
  22. # Create a temporary directory with a simple manifest
  23. with tempfile.TemporaryDirectory() as temp_dir:
  24. temp_path = Path(temp_dir)
  25. # Create a simple manifest file
  26. manifest_content = """{
  27. "name": "test",
  28. "version": "1.0.0",
  29. "summary": "Test package",
  30. "licences": [
  31. {
  32. "name": "MIT",
  33. "text": "LICENSE",
  34. "category": "open-source"
  35. }
  36. ],
  37. "provides": {
  38. "bin:test": "as-expected"
  39. },
  40. "depends": {
  41. "runtime": [],
  42. "build": [],
  43. "manage": []
  44. },
  45. "flags": [],
  46. "execs": {
  47. "build": "scripts/build"
  48. }
  49. }"""
  50. manifest_path = temp_path / "MANIFEST.usm"
  51. with open(manifest_path, "w") as f:
  52. f.write(manifest_content)
  53. print(f"Created test manifest at: {manifest_path}")
  54. # Try to get autoprovides
  55. try:
  56. autoprovides = usm_integration.get_autoprovides(temp_path)
  57. print(f"Got autoprovides: {autoprovides}")
  58. return True
  59. except Exception as e:
  60. print(f"Error getting autoprovides: {e}")
  61. import traceback
  62. traceback.print_exc()
  63. return False
  64. def test_parsing_with_garbage():
  65. """Test parsing with garbage output similar to what we're seeing."""
  66. print("\nTesting parsing with garbage output...")
  67. usm_integration = USMIntegration()
  68. # Test with the garbage pattern we're seeing
  69. garbage_output = '"provides": {\n "type": "reg",\n "path": "{",\n "pathBase": "source"\n }'
  70. print(f"Testing with garbage output: {repr(garbage_output)}")
  71. try:
  72. parsed = usm_integration._parse_autoprovides(garbage_output)
  73. print(f"Parsed result: {parsed}")
  74. return True
  75. except Exception as e:
  76. print(f"Error parsing garbage: {e}")
  77. import traceback
  78. traceback.print_exc()
  79. return False
  80. def test_manifest_update():
  81. """Test manifest update with problematic data."""
  82. print("\nTesting manifest update...")
  83. # Create test package info
  84. package_info = PackageInfo(
  85. name="test-package",
  86. version="1.0.0",
  87. summary="A test package",
  88. licenses=[License(name="MIT", text="LICENSE", category=LicenseCategory.OPEN_SOURCE)]
  89. )
  90. # Create test build system
  91. build_system = BuildSystem(type=BuildSystemType.MAKE)
  92. # Create manifest generator
  93. manifest_generator = ManifestGenerator()
  94. # Generate initial manifest
  95. manifest = manifest_generator.generate(package_info, build_system)
  96. print(f"Initial manifest provides: {manifest.provides}")
  97. # Try to update with garbage data
  98. garbage_autoprovides = {
  99. '"provides":': {
  100. "type": "reg",
  101. "path": "{",
  102. "pathBase": "source"
  103. }
  104. }
  105. try:
  106. updated_manifest = manifest_generator.update_with_autoprovides(manifest, garbage_autoprovides)
  107. print(f"Updated manifest provides: {updated_manifest.provides}")
  108. # Test JSON serialization
  109. json_str = updated_manifest.to_json()
  110. print("JSON serialization result:")
  111. print(json_str)
  112. return True
  113. except Exception as e:
  114. print(f"Error updating manifest: {e}")
  115. import traceback
  116. traceback.print_exc()
  117. return False
  118. if __name__ == "__main__":
  119. print("Running debug tests...\n")
  120. try:
  121. test_usm_integration()
  122. test_parsing_with_garbage()
  123. test_manifest_update()
  124. print("\n✅ All debug tests completed")
  125. except Exception as e:
  126. print(f"\n❌ Debug test failed: {e}")
  127. import traceback
  128. traceback.print_exc()
  129. sys.exit(1)