$projectRoot = $PSScriptRoot $exePath = Join-Path $projectRoot "dist\aza_desktop\aza_desktop.exe" $tokenPath = Join-Path $projectRoot "backend_token.txt" function Test-PortOpen { param( [string]$HostName = "127.0.0.1", [int]$Port = 8000 ) try { $client = New-Object System.Net.Sockets.TcpClient $iar = $client.BeginConnect($HostName, $Port, $null, $null) $ok = $iar.AsyncWaitHandle.WaitOne(500) if (-not $ok) { $client.Close() return $false } $client.EndConnect($iar) $client.Close() return $true } catch { return $false } } if (-not (Test-Path $exePath)) { Write-Error "EXE nicht gefunden: $exePath" Write-Host "Bitte zuerst build_exe.ps1 oder build_and_test_desktop.ps1 ausfuehren." exit 1 } if (-not (Test-Path $tokenPath)) { Write-Error "backend_token.txt nicht gefunden: $tokenPath" exit 1 } if (Test-PortOpen -HostName "127.0.0.1" -Port 8000) { Write-Error "Port 8000 ist bereits belegt. Bitte zuerst bereits laufende AZA-/Backend-Instanzen schliessen." exit 1 } Write-Host "Starte AZA Desktop Smoke Test..." Write-Host "EXE: $exePath" $process = $null $testPassed = $false try { $process = Start-Process -FilePath $exePath -PassThru $maxWait = 30 $waited = 0 while ($waited -lt $maxWait) { Start-Sleep -Seconds 2 $waited += 2 if (Test-PortOpen -HostName "127.0.0.1" -Port 8000) { Write-Host "Backend erreichbar nach $waited Sekunden." break } Write-Host "Warte auf Backend... ($waited/$maxWait s)" } if (-not (Test-PortOpen -HostName "127.0.0.1" -Port 8000)) { Write-Error "Backend nach $maxWait Sekunden nicht erreichbar." throw "Backend-Timeout" } $token = (Get-Content $tokenPath -Raw).Trim() $response = Invoke-RestMethod -Uri "http://127.0.0.1:8000/license/status" -Headers @{ "X-API-Token" = $token "X-Device-Id" = "desktop-smoke-test" } Write-Host "" Write-Host ("valid: " + $response.valid) Write-Host ("valid_until: " + $response.valid_until) if (-not $response.valid) { Write-Error "Smoke Test fehlgeschlagen: Lizenzstatus ist valid=false." throw "License-Check-Failed" } Write-Host "" Write-Host "=== Runtime Config Check ===" $runtimeConfigDir = Join-Path (Split-Path $exePath -Parent) "config" $runtimeConfigFile = Join-Path $runtimeConfigDir "aza_runtime.env" if (Test-Path $runtimeConfigFile) { Write-Host "Runtime config present: yes" $envContent = Get-Content $runtimeConfigFile -Raw -Encoding UTF8 if ($envContent -match 'OPENAI_API_KEY\s*=\s*\S+') { Write-Host "OpenAI configured: yes" } else { Write-Host "OpenAI configured: no (template only)" } } else { Write-Host "Runtime config present: no" Write-Host "OpenAI configured: no" } $testPassed = $true } catch { Write-Error "Desktop Smoke Test fehlgeschlagen." Write-Host $_ } finally { if ($process) { try { if (-not $process.HasExited) { Stop-Process -Id $process.Id -Force Write-Host "Test-EXE wurde nach dem Smoke Test beendet." } } catch { Write-Warning "Test-EXE konnte nicht automatisch beendet werden." } } } if ($testPassed) { Write-Host "" Write-Host "Desktop Smoke Test erfolgreich." exit 0 } else { exit 1 }