test_execs_fix.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env python3
  2. """
  3. Test script to verify that the execs object in MANIFEST.usm correctly reflects
  4. which scripts are actually present in the package.
  5. This tests the fix for the issue where "acquire" was always included in execs
  6. even when not generating an acquire script for local directories.
  7. """
  8. import json
  9. import tempfile
  10. import shutil
  11. from pathlib import Path
  12. from src.autusm.models import PackageInfo, BuildSystem, BuildSystemType
  13. from src.autusm.manifest import ManifestGenerator
  14. def test_execs_for_url():
  15. """Test that acquire is included in execs when processing a URL."""
  16. print("Testing execs for URL...")
  17. # Create package info with a URL (simulating URL processing)
  18. package_info = PackageInfo(
  19. name="test-package",
  20. version="1.0.0",
  21. summary="Test package for URL",
  22. url="https://example.com/test-package.tar.gz"
  23. )
  24. # Create build system
  25. build_system = BuildSystem(type=BuildSystemType.MAKE)
  26. # Generate manifest
  27. manifest_generator = ManifestGenerator()
  28. manifest = manifest_generator.generate(package_info, build_system)
  29. # Convert to dict to check the execs section
  30. manifest_dict = manifest.to_dict()
  31. # Check that acquire is included in execs
  32. assert "acquire" in manifest_dict["execs"], "acquire should be in execs for URLs"
  33. assert manifest_dict["execs"]["acquire"] == "scripts/acquire", "acquire path should be scripts/acquire"
  34. print("✓ URL test passed: acquire is included in execs")
  35. return True
  36. def test_execs_for_local_directory():
  37. """Test that acquire is NOT included in execs when processing a local directory."""
  38. print("Testing execs for local directory...")
  39. # Create package info without a URL (simulating local directory processing)
  40. package_info = PackageInfo(
  41. name="test-package",
  42. version="1.0.0",
  43. summary="Test package for local directory",
  44. url="" # Empty URL indicates local directory
  45. )
  46. # Create build system
  47. build_system = BuildSystem(type=BuildSystemType.MAKE)
  48. # Generate manifest
  49. manifest_generator = ManifestGenerator()
  50. manifest = manifest_generator.generate(package_info, build_system)
  51. # Convert to dict to check the execs section
  52. manifest_dict = manifest.to_dict()
  53. # Check that acquire is NOT included in execs
  54. assert "acquire" not in manifest_dict["execs"], "acquire should NOT be in execs for local directories"
  55. print("✓ Local directory test passed: acquire is NOT included in execs")
  56. return True
  57. def test_manifest_json_output():
  58. """Test the actual JSON output to ensure it's correct."""
  59. print("Testing manifest JSON output...")
  60. # Create a temporary directory for testing
  61. with tempfile.TemporaryDirectory() as temp_dir:
  62. temp_path = Path(temp_dir)
  63. # Test 1: URL case
  64. print("\n1. Testing URL case JSON output:")
  65. url_package_info = PackageInfo(
  66. name="url-test",
  67. version="1.0.0",
  68. summary="Test URL package",
  69. url="https://example.com/url-test.tar.gz"
  70. )
  71. build_system = BuildSystem(type=BuildSystemType.CMAKE)
  72. manifest_generator = ManifestGenerator()
  73. url_manifest = manifest_generator.generate(url_package_info, build_system)
  74. url_manifest_dict = url_manifest.to_dict()
  75. print(json.dumps(url_manifest_dict["execs"], indent=2))
  76. assert "acquire" in url_manifest_dict["execs"]
  77. # Test 2: Local directory case
  78. print("\n2. Testing local directory case JSON output:")
  79. local_package_info = PackageInfo(
  80. name="local-test",
  81. version="1.0.0",
  82. summary="Test local package",
  83. url="" # Empty URL
  84. )
  85. local_manifest = manifest_generator.generate(local_package_info, build_system)
  86. local_manifest_dict = local_manifest.to_dict()
  87. print(json.dumps(local_manifest_dict["execs"], indent=2))
  88. assert "acquire" not in local_manifest_dict["execs"]
  89. print("✓ JSON output test passed")
  90. return True
  91. def main():
  92. """Run all tests."""
  93. print("Testing execs fix for manifest generation...\n")
  94. try:
  95. test_execs_for_url()
  96. test_execs_for_local_directory()
  97. test_manifest_json_output()
  98. print("\n✅ All tests passed! The fix is working correctly.")
  99. print("\nSummary:")
  100. print("- For URLs: acquire script is included in execs")
  101. print("- For local directories: acquire script is NOT included in execs")
  102. except AssertionError as e:
  103. print(f"\n❌ Test failed: {e}")
  104. return 1
  105. except Exception as e:
  106. print(f"\n❌ Unexpected error: {e}")
  107. import traceback
  108. traceback.print_exc()
  109. return 1
  110. return 0
  111. if __name__ == "__main__":
  112. exit(main())