Skip to content

armgit / ODS

Public Imported from GitHub
0

ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.

9.3 KB
Raw Blame
#!/usr/bin/env bash
# ============================================================================
# ODS Windows service-plan tests
# ============================================================================

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PLAN_LIB="$ROOT_DIR/installers/windows/lib/service-plan.ps1"
INSTALL_PS1="$ROOT_DIR/installers/windows/install-windows.ps1"

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
PASS=0
FAIL=0

pass() { echo -e "  ${GREEN}PASS${NC} $1"; PASS=$((PASS + 1)); }
fail() { echo -e "  ${RED}FAIL${NC} $1"; FAIL=$((FAIL + 1)); }

check() {
    local pattern="$1" file="$2" label="$3"
    if grep -Fq -- "$pattern" "$file"; then
        pass "$label"
    else
        fail "$label"
    fi
}

echo ""
echo "=== Windows service-plan tests ==="
echo ""

[[ -f "$PLAN_LIB" ]] && pass "service-plan library exists" || fail "service-plan library missing"
check 'service-plan.ps1' "$INSTALL_PS1" "Windows installer sources service-plan library"
check 'New-ODSWindowsServicePlan' "$PLAN_LIB" "service-plan constructor exists"
check 'Get-ODSWindowsServicePlanDecision' "$PLAN_LIB" "service-plan decision function exists"
check 'Test-ODSWindowsServiceEnabled' "$PLAN_LIB" "service-plan enabled helper exists"
check 'Set-ODSWindowsExtensionComposeState' "$PLAN_LIB" "service-plan compose-state helper exists"
if grep -qi 'openclaw' "$PLAN_LIB"; then
    fail "service plan still selects the removed legacy OpenClaw extension"
else
    pass "service plan no longer selects the removed legacy OpenClaw extension"
fi
check 'Pixel requires the ODS Linux installer in Ubuntu 24.04 WSL2' "$PLAN_LIB" "native Windows install explains the supported Pixel path"
check 'elseif ($currentBackend -eq "amd")' "$INSTALL_PS1" "Windows installer has AMD extension overlay branch"
check 'compose.amd.yaml' "$INSTALL_PS1" "Windows installer includes AMD extension overlays"
check 'function Test-ODSWindowsDockerCredentialHelperFailure' "$INSTALL_PS1" "Windows installer detects Docker credential-helper failures"
check '$text = $text.Replace([string][char]0, "")' "$INSTALL_PS1" "Windows installer normalizes null-separated Docker output"
check 'DOCKER_BUILDKIT=0' "$INSTALL_PS1" "Windows installer can retry builds with legacy Docker builder"
check 'Get-ODSWindowsUserDockerClientArgs' "$INSTALL_PS1" "Windows installer can retry builds with the preserved user Docker config"
check 'function Invoke-ODSWindowsPlainDockerBuildService' "$INSTALL_PS1" "Windows installer has plain docker build fallback"
check 'plain docker build and DOCKER_BUILDKIT=0' "$INSTALL_PS1" "Windows installer bypasses Compose build on credential-helper failure"
check "retrying \$_svc with user's Docker config" "$INSTALL_PS1" "Windows installer retries scoped Docker config build failures with the preserved user config"
check '$enableComfyui -and $currentBackend -eq "nvidia"' "$INSTALL_PS1" "Windows installer only locally builds ComfyUI on NVIDIA"
check 'ComfyUI disabled on Windows AMD' "$ROOT_DIR/installers/windows/phases/03-features.ps1" "Windows AMD disables Dockerized ComfyUI"
check '/dev/dri and /dev/kfd' "$ROOT_DIR/installers/windows/phases/03-features.ps1" "Windows AMD ComfyUI warning names unsupported ROCm devices"

if command -v pwsh >/dev/null 2>&1; then
    OUTPUT="$(PLAN_LIB="$PLAN_LIB" pwsh -NoProfile -Command '
        $ErrorActionPreference = "Stop"
        . $env:PLAN_LIB

        function Assert-Plan {
            param([bool]$Condition, [string]$Label)
            if ($Condition) { "PASS:$Label" } else { "FAIL:$Label" }
        }

        $core = New-ODSWindowsServicePlan `
            -EnableRecommended $false `
            -EnableVoice $false `
            -EnableWorkflows $false `
            -EnableRag $false `
            -EnableHermes $false `
            -EnableComfyui $false `
            -EnableDeepResearch $false `
            -EnablePrivacyShield $false

        $full = New-ODSWindowsServicePlan `
            -EnableRecommended $true `
            -EnableVoice $true `
            -EnableWorkflows $true `
            -EnableRag $true `
            -EnableHermes $true `
            -EnableComfyui $true `
            -EnableDeepResearch $true `
            -EnablePrivacyShield $true

        $unknownOptional = Get-ODSWindowsServicePlanDecision `
            -ServiceId "future-optional" `
            -Category "optional" `
            -Plan $core `
            -EnableRecommended $false

        $unknownRecommended = Get-ODSWindowsServicePlanDecision `
            -ServiceId "future-recommended" `
            -Category "recommended" `
            -Plan $core `
            -EnableRecommended $true

        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "hermes" -Plan $core)) "Core disables Hermes"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "searxng" -Plan $core)) "Core disables SearXNG"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "litellm" -Plan $core)) "Core disables LiteLLM"
        Assert-Plan (-not $core.ContainsKey("openclaw")) "Plan has no entry for the removed legacy OpenClaw extension"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "ape" -Plan $core)) "Core keeps APE off without an agent"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "pixel-edge" -Plan $core)) "Core does not launch a Pixel edge without a host runtime"
        Assert-Plan (-not (Get-ODSWindowsServicePlanDecision -ServiceId "pixel-model-relay" -Category "core" -Plan $core).Enabled) "Core does not launch a Pixel relay without a host runtime or bearer key"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "tailscale" -Plan $core)) "Core disables Tailscale"
        Assert-Plan (Test-ODSWindowsServiceEnabled -ServiceId "hermes" -Plan $full) "Full enables Hermes"
        Assert-Plan (Test-ODSWindowsServiceEnabled -ServiceId "searxng" -Plan $full) "Full enables SearXNG"
        Assert-Plan (Test-ODSWindowsServiceEnabled -ServiceId "ape" -Plan $full) "Full enables APE with agents"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "pixel-edge" -Plan $full)) "Full does not advertise unsupported native Windows Pixel"
        Assert-Plan (-not (Get-ODSWindowsServicePlanDecision -ServiceId "pixel-model-relay" -Category "core" -Plan $full).Enabled) "Full does not launch an unsupported native Windows Pixel relay"

        $deepResearchOnly = New-ODSWindowsServicePlan `
            -EnableRecommended $false `
            -EnableVoice $false `
            -EnableWorkflows $false `
            -EnableRag $false `
            -EnableHermes $false `
            -EnableComfyui $false `
            -EnableDeepResearch $true `
            -EnablePrivacyShield $false
        Assert-Plan (Test-ODSWindowsServiceEnabled -ServiceId "searxng" -Plan $deepResearchOnly) "Deep research without recommended still enables SearXNG"
        Assert-Plan (-not (Test-ODSWindowsServiceEnabled -ServiceId "litellm" -Plan $deepResearchOnly)) "Deep research without recommended leaves LiteLLM off"

        $hermesOnly = New-ODSWindowsServicePlan `
            -EnableRecommended $false `
            -EnableVoice $false `
            -EnableWorkflows $false `
            -EnableRag $false `
            -EnableHermes $true `
            -EnableComfyui $false `
            -EnableDeepResearch $false `
            -EnablePrivacyShield $false
        Assert-Plan (Test-ODSWindowsServiceEnabled -ServiceId "searxng" -Plan $hermesOnly) "Hermes without recommended still enables SearXNG"

        Assert-Plan (-not $unknownOptional.Enabled) "Unknown optional is disabled"
        Assert-Plan ($unknownRecommended.Enabled) "Unknown recommended follows recommended flag"

        $tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("ods-service-plan-" + [guid]::NewGuid())
        New-Item -ItemType Directory -Path $tempRoot -Force | Out-Null
        try {
            $composePath = Join-Path $tempRoot "compose.yaml"
            Set-Content -LiteralPath $composePath -Value "services: {}" -Encoding Ascii

            $disabledResult = Set-ODSWindowsExtensionComposeState `
                -ComposePath $composePath `
                -Enabled $false
            Assert-Plan (-not $disabledResult) "Disabled compose state reports unavailable"
            Assert-Plan (-not (Test-Path -LiteralPath $composePath)) "Disabled compose fragment is hidden"
            Assert-Plan (Test-Path -LiteralPath "$composePath.disabled") "Disabled compose marker is created"

            $enabledResult = Set-ODSWindowsExtensionComposeState `
                -ComposePath $composePath `
                -Enabled $true
            Assert-Plan $enabledResult "Enabled compose state reports available"
            Assert-Plan (Test-Path -LiteralPath $composePath) "Enabled compose fragment is restored"
            Assert-Plan (-not (Test-Path -LiteralPath "$composePath.disabled")) "Enabled compose marker is removed"
        } finally {
            Remove-Item -LiteralPath $tempRoot -Recurse -Force -ErrorAction SilentlyContinue
        }
    ')"

    while IFS= read -r line; do
        case "$line" in
            PASS:*) pass "${line#PASS:}" ;;
            FAIL:*) fail "${line#FAIL:}" ;;
        esac
    done <<< "$OUTPUT"
else
    pass "PowerShell runtime behavior skipped (pwsh unavailable)"
fi

echo ""
echo "Result: $PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]]