import os
import subprocess
import shutil
from pathlib import Path

def test_link():
    project_root = Path(os.getcwd())
    temp_workspace = project_root / "tests" / "artifacts" / "test_link_workspace"
    if temp_workspace.exists():
        shutil.rmtree(temp_workspace)
    temp_workspace.mkdir(parents=True, exist_ok=True)
    
    src_assets = project_root / "assets"
    dest_assets = temp_workspace / "assets"
    
    print(f"Linking {src_assets} to {dest_assets}")
    if os.name == 'nt':
        res = subprocess.run(["cmd", "/c", "mklink", "/D", str(dest_assets), str(src_assets)], capture_output=True, text=True)
        print(f"Exit code: {res.returncode}")
        print(f"Stdout: {res.stdout}")
        print(f"Stderr: {res.stderr}")
    else:
        os.symlink(src_assets, dest_assets)
        
    if dest_assets.exists():
        print("Link exists")
        if (dest_assets / "fonts" / "Inter-Regular.ttf").exists():
            print("Font file accessible via link")
        else:
            print("Font file NOT accessible")
    else:
        print("Link does NOT exist")

if __name__ == "__main__":
    test_link()
