param([Parameter(Mandatory)][string]$ExpectedVersion)
$ErrorActionPreference = 'Stop'
$actual = (Get-Content -LiteralPath 'C:\ProgramData\Workshopz\image-version.txt' -Raw).Trim()
$manifest = Get-Content -LiteralPath 'C:\ProgramData\Workshopz\build-manifest.json' -Raw | ConvertFrom-Json
$iis = Get-WindowsFeature Web-Server
$response = Invoke-WebRequest -Uri 'http://localhost/' -UseBasicParsing -TimeoutSec 20
$result = [ordered]@{
    ExpectedVersion = $ExpectedVersion
    ImageVersion = $actual
    VersionMatched = ($actual -eq $ExpectedVersion)
    IisInstalled = [bool]$iis.Installed
    LocalHttpStatus = [int]$response.StatusCode
    VersionedHealthPage = ($response.Content -match [regex]::Escape($ExpectedVersion))
    PatchInventoryPresent = ([int]$manifest.PatchInventoryCount -ge 0)
    BaselineRevision = [int]$manifest.BaselineRevision
    V2MarkerPresent = (Test-Path -LiteralPath 'C:\ProgramData\Workshopz\baseline-v2.marker')
}
$result.Passed = ($result.VersionMatched -and $result.IisInstalled -and $result.LocalHttpStatus -eq 200 -and $result.VersionedHealthPage)
Write-Output 'WORKSHOP_JSON_BEGIN'
$result | ConvertTo-Json -Compress
Write-Output 'WORKSHOP_JSON_END'
if (-not $result.Passed) { exit 2 }
