import sys
from pathlib import Path
from praisonai.recipe.registry import LocalRegistry, RegistryError

def test_pull(registry_dir, output_dir, log_path):
    reg = LocalRegistry(registry_dir)
    try:
        result = reg.pull("testrecipe", "1.0.0", output_dir=output_dir, verify_checksum=False)
        with open(log_path, "w") as f:
            f.write(f"RESULT: no_exception\n")
            f.write(f"PATH: {result['path']}\n")
    except RegistryError as e:
        with open(log_path, "w") as f:
            f.write(f"RESULT: registry_error\n")
            f.write(f"ERROR: {e}\n")
    except Exception as e:
        with open(log_path, "w") as f:
            f.write(f"RESULT: other_error\n")
            f.write(f"ERROR: {type(e).__name__}: {e}\n")

if __name__ == "__main__":
    registry_dir = Path(sys.argv[1])
    output_dir = Path(sys.argv[2])
    log_path = Path(sys.argv[3])
    output_dir.mkdir(parents=True, exist_ok=True)
    test_pull(registry_dir, output_dir, log_path)
