$ErrorActionPreference = 'Continue' Set-Location $PSScriptRoot if (!(Test-Path -LiteralPath 'start-windows.cmd')) { throw 'Place this script in the extracted mtusi2026lab4 directory.' } New-Item -ItemType Directory -Force -Path evidence | Out-Null $log = Join-Path $PSScriptRoot ("evidence/windows-run-{0:yyyyMMdd-HHmmss-fff}.txt" -f (Get-Date)) $script:failed = $false function Write-Log([string]$Message) { $Message | Tee-Object -FilePath $log -Append } function Invoke-Check([string]$Name, [string]$Program, [string[]]$Arguments) { Write-Log ("--- {0} ---" -f $Name) $global:LASTEXITCODE = 1 & $Program @Arguments 2>&1 | ForEach-Object { "$_" } | Tee-Object -FilePath $log -Append $code = $LASTEXITCODE Write-Log ("{0} exit code = {1}" -f $Name, $code) $script:stepOK = $code -eq 0 if (!$script:stepOK) { $script:failed = $true } } $baseUrl = 'http://127.0.0.1:8080' Write-Log (Get-Date -Format o) try { Invoke-Check 'Docker Engine' docker @('info', '--format', '{{.OSType}}') if (!$script:stepOK) { exit 1 } Invoke-Check 'Python' py @('-3', '--version') if (!$script:stepOK) { exit 1 } Invoke-Check 'Startup and readiness' cmd.exe @('/d', '/c', 'start-windows.cmd') if (!$script:stepOK) { exit 1 } Invoke-Check 'Smoke' py @('-3', '-X', 'utf8', 'tests/smoke.py', '--base-url', $baseUrl) Invoke-Check 'Persistence' py @('-3', '-X', 'utf8', 'tests/resilience.py', '--mode', 'persistence', '--action-script', 'scripts/restart.cmd', '--base-url', $baseUrl) try { Invoke-Check 'Failover' py @('-3', '-X', 'utf8', 'tests/resilience.py', '--mode', 'failover', '--action-script', 'scripts/stop-one.cmd', '--base-url', $baseUrl) Invoke-Check 'State after failover' docker @('compose', '--env-file', '.env', 'ps', '-a') } finally { Invoke-Check 'Restore replicas' cmd.exe @('/d', '/c', 'scripts\restore-replicas.cmd') Invoke-Check 'Final state' docker @('compose', '--env-file', '.env', 'ps', '-a') } } finally { Write-Host "Evidence file: $log" } if ($script:failed) { exit 1 } exit 0