import urllib.request
import os
import sys

# Test against production Hub
BASE_URL = "https://ai.jerxie.com/api/v1"
NODE_ID = "test-win-manual"
TOKEN = "win-test-token-123"

def test_provisioning_script_paths():
    print(f"Verifying Windows paths at {BASE_URL}/nodes/provision/ps1/{NODE_ID}...")
    
    url = f"{BASE_URL}/nodes/provision/ps1/{NODE_ID}?token={TOKEN}"
    
    try:
        with urllib.request.urlopen(url) as response:
            if response.getcode() != 200:
                print(f"❌ Failed to fetch script: {response.getcode()}")
                return False
            
            script = response.read().decode("utf-8")
            
            found_sync = "sync_root: C:\\CortexAgent\\sync" in script
            found_fs = "fs_root: C:\\" in script
            
            if found_sync and found_fs:
                print("✅ PASSED: Windows-style paths (C:\CortexAgent\sync and C:\) are present in the provisioning script.")
                return True
            else:
                print("❌ FAILED: Windows-style paths NOT found.")
                if not found_sync: print("   Missing: sync_root: C:\\CortexAgent\\sync")
                if not found_fs: print("   Missing: fs_root: C:\\")
                
                # Debug: Print full script to see what we got
                print("\n--- Full Script ---")
                print(script)
                print("-------------------------------")

                
                return False
                
    except Exception as e:
        print(f"❌ Error: {e}")
        return False

if __name__ == "__main__":
    success = test_provisioning_script_paths()
    sys.exit(0 if success else 1)
