param([Parameter(Mandatory=$true)][ValidatePattern('^[a-f0-9]{32}$')][string]$RunId)
# One UAC consent, a fixed service-validation sequence, then exit. No command queue,
# arbitrary command execution, permanent task, policy change or elevation endpoint.
$ErrorActionPreference='Stop'
. (Join-Path $PSScriptRoot 'Run-ServiceValidation.ps1') -Operation Snapshot -RunId $RunId -Library
$controlDirectory=Join-Path $repoDirectory '.BuildValidation/live-index-20261013-2119-release/control'
Assert-NoReparse $controlDirectory
if (-not [IO.Directory]::Exists($controlDirectory)) { throw 'Prepare the ordinary-user control directory first.' }
function Wait-ForMarker([string]$Name) {
$timer=[Diagnostics.Stopwatch]::StartNew()
while (-not [IO.File]::Exists((Join-Path $controlDirectory $Name))) {
if ($timer.Elapsed.TotalMinutes -gt 10) { throw 'Timed out waiting for the bounded ordinary-user validation phase.' }
Start-Sleep -Milliseconds 500
}
}
try {
Assert-ServicePath
New-ProtectedReportDirectory $reportRoot
New-ProtectedReportDirectory $reportDirectory
Write-NewJson 'coordinator-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); fixedSequence=$true}
# Preserve only fixed service-owned checkpoint files, without moving/deleting a directory.
Stop-Service -Name $serviceName
(Get-Service -Name $serviceName).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(60))
Export-Snapshot 'before-cold' @{stopped=$true}
Assert-NoReparse $dataDirectory
$backupDirectory=Join-Path $dataDirectory ('ValidationColdBackup-'+$RunId)
if ([IO.Directory]::Exists($backupDirectory)) { throw 'This validation backup already exists.' }
[IO.Directory]::CreateDirectory($backupDirectory) | Out-Null
$backedUp=0
foreach ($cacheFile in @(Get-ChildItem -LiteralPath $dataDirectory -Filter '*.ntfs.gz' -File)) {
if ($cacheFile.Name -notmatch '^[A-F0-9]{64}\.ntfs\.gz$' -or
$cacheFile.DirectoryName -ne $dataDirectory.Replace('/','\') -or
($cacheFile.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'Unexpected checkpoint target.' }
[IO.File]::Move($cacheFile.FullName,(Join-Path $backupDirectory $cacheFile.Name))
$backedUp++
}
if ($backedUp -ne 7) { throw 'Expected seven existing validation checkpoints.' }
Start-Service -Name $serviceName
Write-NewJson 'cold-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); backedUpCheckpoints=$backedUp}
Wait-ForReady 'cold-final'
Write-NewJson 'cold-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); ready=$true}
Wait-ForMarker 'stop-for-offline.marker'
Stop-Service -Name $serviceName
(Get-Service -Name $serviceName).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(60))
Export-Snapshot 'stopped-for-offline' @{stopped=$true}
Write-NewJson 'offline-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); serviceStopped=$true}
Wait-ForMarker 'offline-fixtures-ready.marker'
Start-Service -Name $serviceName
Write-NewJson 'restart-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o')}
Wait-ForReady 'restart-usn'
Write-NewJson 'restart-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); ready=$true}
Wait-ForMarker 'finish.marker'
Export-Snapshot 'final' @{leaveServiceRunning=$true}
Write-NewJson 'coordinator-completed.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); success=$true; leaveServiceRunning=$true}
exit 0
} catch {
if ([IO.Directory]::Exists($reportDirectory)) {
try { Write-NewJson 'coordinator-failed.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); success=$false; errorType=$_.Exception.GetType().Name; hresult=$_.Exception.HResult} } catch { }
}
exit 1
}
param([Parameter(Mandatory=$true)][ValidatePattern('^[a-f0-9]{32}$')][string]$RunId)
# One UAC consent, a fixed service-validation sequence, then exit. No command queue,
# arbitrary command execution, permanent task, policy change or elevation endpoint.
$ErrorActionPreference='Stop'
. (Join-Path $PSScriptRoot 'Run-ServiceValidation.ps1') -Operation Snapshot -RunId $RunId -Library
$controlDirectory=Join-Path $repoDirectory '.BuildValidation/live-index-20261013-2119-release/control'
Assert-NoReparse $controlDirectory
if (-not [IO.Directory]::Exists($controlDirectory)) { throw 'Prepare the ordinary-user control directory first.' }
function Wait-ForMarker([string]$Name) {
$timer=[Diagnostics.Stopwatch]::StartNew()
while (-not [IO.File]::Exists((Join-Path $controlDirectory $Name))) {
if ($timer.Elapsed.TotalMinutes -gt 10) { throw 'Timed out waiting for the bounded ordinary-user validation phase.' }
Start-Sleep -Milliseconds 500
}
}
try {
Assert-ServicePath
New-ProtectedReportDirectory $reportRoot
New-ProtectedReportDirectory $reportDirectory
Write-NewJson 'coordinator-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); fixedSequence=$true}
# Preserve only fixed service-owned checkpoint files, without moving/deleting a directory.
Stop-Service -Name $serviceName
(Get-Service -Name $serviceName).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(60))
Export-Snapshot 'before-cold' @{stopped=$true}
Assert-NoReparse $dataDirectory
$backupDirectory=Join-Path $dataDirectory ('ValidationColdBackup-'+$RunId)
if ([IO.Directory]::Exists($backupDirectory)) { throw 'This validation backup already exists.' }
[IO.Directory]::CreateDirectory($backupDirectory) | Out-Null
$backedUp=0
foreach ($cacheFile in @(Get-ChildItem -LiteralPath $dataDirectory -Filter '*.ntfs.gz' -File)) {
if ($cacheFile.Name -notmatch '^[A-F0-9]{64}\.ntfs\.gz$' -or
$cacheFile.DirectoryName -ne $dataDirectory.Replace('/','\') -or
($cacheFile.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) { throw 'Unexpected checkpoint target.' }
[IO.File]::Move($cacheFile.FullName,(Join-Path $backupDirectory $cacheFile.Name))
$backedUp++
}
if ($backedUp -ne 7) { throw 'Expected seven existing validation checkpoints.' }
Start-Service -Name $serviceName
Write-NewJson 'cold-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); backedUpCheckpoints=$backedUp}
Wait-ForReady 'cold-final'
Write-NewJson 'cold-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); ready=$true}
Wait-ForMarker 'stop-for-offline.marker'
Stop-Service -Name $serviceName
(Get-Service -Name $serviceName).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(60))
Export-Snapshot 'stopped-for-offline' @{stopped=$true}
Write-NewJson 'offline-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); serviceStopped=$true}
Wait-ForMarker 'offline-fixtures-ready.marker'
Start-Service -Name $serviceName
Write-NewJson 'restart-started.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o')}
Wait-ForReady 'restart-usn'
Write-NewJson 'restart-ready.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); ready=$true}
Wait-ForMarker 'finish.marker'
Export-Snapshot 'final' @{leaveServiceRunning=$true}
Write-NewJson 'coordinator-completed.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); success=$true; leaveServiceRunning=$true}
exit 0
} catch {
if ([IO.Directory]::Exists($reportDirectory)) {
try { Write-NewJson 'coordinator-failed.json' @{timestampUtc=[DateTime]::UtcNow.ToString('o'); success=$false; errorType=$_.Exception.GetType().Name; hresult=$_.Exception.HResult} } catch { }
}
exit 1
}