import os
import shutil
import subprocess
from pathlib import Path

base_lab = Path(os.path.expandvars(r"%LOCALAPPDATA%\OptimusRuntime\Labs\AR74\11_ar86_trust_closure"))
new_lab = Path(os.path.expandvars(r"%LOCALAPPDATA%\OptimusRuntime\Labs\AR74\12_ar88_authority_operational_closure"))

if new_lab.exists():
    shutil.rmtree(new_lab, ignore_errors=True)

# Copy base lab excluding temporary cache/runs
def _ignore(folder, names):
    return [n for n in names if n in ("__pycache__", ".pytest_cache", "test_venv")]

print(f"Copying from {base_lab} to {new_lab}...")
shutil.copytree(base_lab, new_lab, ignore=_ignore)

# Recreate test_venv junction pointing to 06_ar76_candidate_hardening/test_venv
shared_venv = Path(os.path.expandvars(r"%LOCALAPPDATA%\OptimusRuntime\Labs\AR74\06_ar76_candidate_hardening\test_venv"))
target_venv = new_lab / "test_venv"
cmd = ["cmd.exe", "/c", "mklink", "/J", str(target_venv), str(shared_venv)]
subprocess.run(cmd, check=True)

print("SUCCESS: 12_ar88_authority_operational_closure initialized with test_venv junction!")

