<# .SYNOPSIS Windows-executed gate for lmxopcua#980 / #1030: an OtOpcUaHost node whose ActorSystem terminates because it LEFT or was DOWNED from its cluster (manual failover, endpoint step-down, auto-down) must be RESTARTED by Windows SCM recovery (sc.exe failure), while an operator `sc stop` must stay stopped. .DESCRIPTION Background (docs/Redundancy.md "Recovery still depends on supervision"): ActorSystemTerminationWatchdog exits the process with code 1 on an unexpected termination, so SCM sees the service process die WITHOUT reporting SERVICE_STOPPED, logs System event 7031 ("terminated unexpectedly") and runs the configured recovery action. Before #980 the node ended in a clean stop (SERVICE_STOPPED, win32 exit 0) and SCM never restarted it. This script is the scripted form of the manual windev gate of 2026-12-03. It runs ON the Windows box that hosts the service under test, elevated, against an INSTALLED OtOpcUaHost (scripts\install\Install-Services.ps1). It never installs, uninstalls or reconfigures anything; it stops/starts only the named service and always leaves it Running (finally block). Legs (each prints PASS/FAIL lines; exit 0 = all passed, 1 = a check failed, 2 = cannot run here): 1. Recovery config sc.exe qfailure lists at least one RESTART action (what Install-Services.ps1 sets). 2. Cluster exit the trigger makes this node leave / be downed. Expected: the service process exits (exit code 1 when readable), SCM logs 7031 for the service, and the service is Running again under a NEW pid within the recovery delay + -TimeoutSeconds. 3. Clean stop (unless -SkipStopControl) Stop-Service: the service reports Stopped, NO new 7031 is logged and it is NOT restarted within the first recovery delay + 15 s; then the script starts it again. 4. Kill control (only with -KillControl) Stop-Process -Force: a crash is restarted (7031/7034). This proves the SCM recovery config, not the watchdog — use it to tell "recovery not configured" from "the node did not exit non-zero" when leg 2 fails. Triggers (-Trigger): Failover (default) with -FailoverUrl + a key (-FailoverApiKey or env OTOPCUA_FAILOVER_API_KEY) the script POSTs the headless failover endpoint (lmxopcua#1078, POST /api/cluster/failover on an admin node, key = Security:FailoverApiKey) - unattended. Without them the script pauses and asks the operator to press "Trigger failover" on the AdminUI cluster redundancy page (/clusters/{id}/redundancy). Manual failover asks the driver PRIMARY to leave, so run this on the box hosting the current Primary of a two-node pair. Needs an interactive console. Command runs -TriggerCommand (a PowerShell script block, as text) that makes THIS node leave or be downed, e.g. a local admin tool; the script does not interpret it. Do NOT run this on the wonder boxes (vd03 / vq03 / vq04) while remote access is on hold — it is meant for windev or a QA pair, run locally by an operator. It restarts the node it targets: a two-node pair fails over once (and again for -KillControl); a single-node cluster has an outage for each leg. Run once per PowerShell host if in doubt; it uses nothing host-specific: pwsh -NoProfile -File scripts\install\tests\Test-ScmRestartAfterClusterExit.Windows.ps1 powershell -NoProfile -ExecutionPolicy Bypass -File scripts\install\tests\Test-ScmRestartAfterClusterExit.Windows.ps1 -KillControl pwsh -NoProfile -File ...\Test-ScmRestartAfterClusterExit.Windows.ps1 -Trigger Command -TriggerCommand '