#!/usr/bin/env bash set -euo pipefail repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "${repo_root}" project_name="minerops-windows-package-test-$$" compose=( docker compose --project-name "${project_name}" --env-file .env.dev -f compose.dev.yaml ) cleanup() { status=$? "${compose[@]}" down --volumes --remove-orphans \ >/dev/null 2>&1 || true exit "${status}" } trap cleanup EXIT echo "=== BUILD BACKEND WITH CANONICAL AGENT SOURCE ===" "${compose[@]}" build backend echo echo "=== BACKEND PACKAGE TESTS ===" "${compose[@]}" run --rm --no-deps \ -v "${repo_root}/backend/tests:/app/tests:ro" \ backend python -m unittest -v \ tests.test_agent_windows_package echo echo "=== VERIFY CANONICAL SOURCE IS IN IMAGE ===" "${compose[@]}" run --rm --no-deps \ backend sh -ec ' test -f /app/agents/windows/Enroll-MinerOpsAgent.ps1 test -f /app/agents/windows/Upgrade-MinerOpsAgentCredential.ps1 test -f /app/agents/windows/install.ps1 test -f /app/agents/windows/MinerOpsAgentService.ps1 test -f /app/agents/windows/VERSION ' echo echo "=== OFFICIAL POWERSHELL VALIDATION ===" docker run --rm \ -v "${repo_root}/agents/windows:/work:ro" \ mcr.microsoft.com/powershell:7.4-debian-12 \ pwsh -NoLogo -NoProfile -Command ' $ErrorActionPreference = "Stop" foreach ($script in @( "/work/Enroll-MinerOpsAgent.ps1", "/work/Upgrade-MinerOpsAgentCredential.ps1", "/work/install.ps1", "/work/MinerOpsAgentGUI.ps1" )) { $tokens = $null $errors = $null [System.Management.Automation.Language.Parser]::ParseFile( $script, [ref]$tokens, [ref]$errors ) | Out-Null if ($errors.Count -gt 0) { throw "$script parser errors: $($errors.Message -join "; ")" } Write-Host "Parsed $script" } & /work/tests/Test-MinerOpsEnrollment.ps1 & /work/tests/Test-MinerOpsBootEventParser.ps1 & /work/tests/Test-MinerOpsCredentialTransition.ps1 & /work/tests/Test-MinerOpsInstaller.ps1 ' echo echo "Windows Agent package foundation tests passed."