| | |
| | | #!/usr/bin/env python3 |
| | | """ |
| | | Integration test script for archbuild. |
| | | Integration test script for archrepobuild. |
| | | |
| | | This script creates a temporary repository, initializes it with a basic config, |
| | | adds test packages, and verifies they build and are added correctly. |
| | |
| | | # Add src to path for development |
| | | sys.path.insert(0, str(Path(__file__).parent.parent / "src")) |
| | | |
| | | from archbuild.aur import AURClient |
| | | from archbuild.builder import Builder, BuildStatus |
| | | from archbuild.config import Config, RepositoryConfig, BuildingConfig, SigningConfig, PackageOverride |
| | | from archbuild.logging import setup_logging, console |
| | | from archbuild.repo import RepoManager |
| | | from archrepobuild.aur import AURClient |
| | | from archrepobuild.builder import Builder, BuildStatus |
| | | from archrepobuild.config import Config, RepositoryConfig, BuildingConfig, SigningConfig, PackageOverride |
| | | from archrepobuild.logging import setup_logging, console |
| | | from archrepobuild.repo import RepoManager |
| | | |
| | | |
| | | # Test packages - real packages that exist in the AUR |
| | |
| | | class IntegrationTest: |
| | | """Integration test runner.""" |
| | | |
| | | def __init__(self, keep_temp: bool = False, use_cli: bool = False): |
| | | def __init__(self, keep_temp: bool = False, use_cli: bool = False, use_binary: bool = False): |
| | | self.keep_temp = keep_temp |
| | | self.use_cli = use_cli |
| | | self.use_binary = use_binary |
| | | self.temp_dir: Path | None = None |
| | | self.config: Config | None = None |
| | | self.config_path: Path | None = None |
| | |
| | | self.failed = 0 |
| | | |
| | | def _run_cli(self, command: str, *args: str) -> subprocess.CompletedProcess: |
| | | """Run archbuild CLI command via subprocess.""" |
| | | """Run archrepobuild CLI command via subprocess.""" |
| | | if not self.config_path: |
| | | raise RuntimeError("Config path not set") |
| | | |
| | | env = os.environ.copy() |
| | | # Add src to PYTHONPATH so the CLI can find the package |
| | | env["PYTHONPATH"] = str(Path(__file__).parent.parent / "src") |
| | | |
| | | cmd = [sys.executable, "-m", "archbuild.cli", "-c", str(self.config_path), command] + list(args) |
| | | if self.use_binary: |
| | | binary_path = Path(__file__).parent.parent / "dist" / "archrepobuild" |
| | | if not binary_path.exists(): |
| | | raise RuntimeError(f"Binary not found at {binary_path}. Run scripts/build_binary.py first.") |
| | | |
| | | cmd = [str(binary_path), "-c", str(self.config_path), command] + list(args) |
| | | # No PYTHONPATH needed for the standalone binary |
| | | else: |
| | | # Add src to PYTHONPATH so the CLI can find the package |
| | | env["PYTHONPATH"] = str(Path(__file__).parent.parent / "src") |
| | | cmd = [sys.executable, "-m", "archrepobuild.cli", "-c", str(self.config_path), command] + list(args) |
| | | |
| | | return subprocess.run(cmd, capture_output=True, text=True, env=env) |
| | | |
| | | def setup(self) -> None: |
| | |
| | | console.print("\n[bold blue]═══ Setting up test environment ═══[/]") |
| | | |
| | | # Create temp directory |
| | | self.temp_dir = Path(tempfile.mkdtemp(prefix="archbuild_test_")) |
| | | self.temp_dir = Path(tempfile.mkdtemp(prefix="archrepobuild_test_")) |
| | | console.print(f" Created temp directory: {self.temp_dir}") |
| | | |
| | | # Create subdirectories |
| | |
| | | ) |
| | | |
| | | # Save config to disk for CLI to use |
| | | from archbuild.config import save_config |
| | | from archrepobuild.config import save_config |
| | | self.config_path = self.temp_dir / "config.yaml" |
| | | save_config(self.config, self.config_path) |
| | | |
| | |
| | | |
| | | if artifacts: |
| | | # Create a mock build result for add_packages |
| | | from archbuild.builder import BuildResult |
| | | from archrepobuild.builder import BuildResult |
| | | mock_result = BuildResult( |
| | | package=pkg_name, |
| | | status=BuildStatus.SUCCESS, |
| | |
| | | |
| | | async def run(self) -> bool: |
| | | """Run all integration tests.""" |
| | | mode_str = " (CLI Mode)" if self.use_cli else " (Python Mode)" |
| | | mode_str = " (Python Mode)" |
| | | if self.use_binary: |
| | | mode_str = " (Binary Mode)" |
| | | elif self.use_cli: |
| | | mode_str = " (CLI Mode)" |
| | | |
| | | console.print("[bold magenta]╔════════════════════════════════════════════╗[/]") |
| | | console.print(f"[bold magenta]║ Archbuild Integration Test Suite{mode_str:<10}║[/]") |
| | | console.print("[bold magenta]╚════════════════════════════════════════════╝[/]") |
| | |
| | | """Main entry point.""" |
| | | keep_temp = "--keep-temp" in sys.argv |
| | | use_cli = "--use-cli" in sys.argv |
| | | use_binary = "--use-binary" in sys.argv |
| | | |
| | | if use_binary: |
| | | use_cli = True # Binary mode is a sub-mode of CLI mode |
| | | |
| | | # Check if running on Arch Linux |
| | | if not Path("/etc/arch-release").exists(): |
| | |
| | | console.print(f"[red]Required tool not found: {tool}[/]") |
| | | return 1 |
| | | |
| | | test = IntegrationTest(keep_temp=keep_temp, use_cli=use_cli) |
| | | test = IntegrationTest(keep_temp=keep_temp, use_cli=use_cli, use_binary=use_binary) |
| | | success = await test.run() |
| | | |
| | | return 0 if success else 1 |