#!/usr/bin/env python3
"""
Test script for the Debian APT stage
"""

import json
import tempfile
import os
from apt_stage import AptStage

def test_apt_stage():
    """Test the APT stage with sample configuration"""
    
    # Test configuration
    options = {
        "packages": ["systemd", "bash", "apt"],
        "repos": [],
        "release": "trixie",
        "arch": "amd64",
        "exclude_packages": [],
        "install_weak_deps": True
    }
    
    print("Testing APT stage with options:")
    print(json.dumps(options, indent=2))
    print()
    
    # Create a mock context for testing
    class MockContext:
        def __init__(self, root):
            self.root = root
        
        def run(self, cmd, env=None):
            print(f"Mock run: {' '.join(cmd)}")
            if env:
                print(f"  Environment: {dict(env)}")
            return type('Result', (), {'returncode': 0, 'stdout': 'Success', 'stderr': ''})()
    
    # Create temporary directory for testing
    with tempfile.TemporaryDirectory() as temp_dir:
        print(f"Using temporary directory: {temp_dir}")
        
        # Create mock context
        context = MockContext(temp_dir)
        
        # Create and run the stage
        try:
            stage = AptStage(options)
            stage.run(context)
            print("✅ APT stage test completed successfully!")
        except Exception as e:
            print(f"❌ APT stage test failed: {e}")
            return False
    
    return True

if __name__ == "__main__":
    success = test_apt_stage()
    exit(0 if success else 1)
