#!/usr/bin/env nu
# Test script to validate desktop taskserv configuration

def test_desktop_config [] {
    print "Testing desktop taskserv configuration..."
    
    # Check if required files exist
    let required_files = [
        "default/provisioning.toml",
        "default/env-desktop.j2", 
        "default/install-desktop.sh",
        "default/prepare",
        "kcl/desktop.k",
        "info.md"
    ]
    
    mut missing_files = []
    
    for file in $required_files {
        if not ($file | path exists) {
            $missing_files = ($missing_files | append $file)
        }
    }
    
    if ($missing_files | length) > 0 {
        print $"ERROR: Missing required files: ($missing_files)"
        return false
    }
    
    # Check if install script is executable
    let install_script = "default/install-desktop.sh"
    if not ($install_script | path exists) {
        print $"ERROR: Install script not found: ($install_script)"
        return false
    }
    
    # Validate provisioning.toml format
    let toml_content = (open "default/provisioning.toml")
    if ($toml_content.info == "desktop") and ($toml_content.release == "1.0") {
        print "✓ provisioning.toml is valid"
    } else {
        print "ERROR: provisioning.toml format is invalid"
        return false
    }
    
    # Check KCL file syntax (basic)
    let kcl_content = (open "kcl/desktop.k")
    if ($kcl_content | str contains "schema DesktopServer") {
        print "✓ KCL schema file is valid"
    } else {
        print "ERROR: KCL schema file is invalid"
        return false
    }
    
    print "✓ All desktop taskserv configuration files are present and valid"
    print ""
    print "Desktop taskserv features:"
    print "- Minimal desktop environments (XFCE, GNOME, KDE, LXDE, MATE)"
    print "- VNC remote access support"
    print "- Zed editor integration with configuration"
    print "- Essential development and productivity applications"
    print "- Multi-OS support (Ubuntu/Debian, CentOS/RHEL/Fedora)"
    print "- Graphics driver configuration"
    print "- Auto-login capability"
    
    return true
}

# Run the test
test_desktop_config