#requires -Version 7.0
param([Parameter(Mandatory)][string]$ServerPath, [string]$ReportDirectory, [string]$CompatibleBuildLabel)
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$ServerPath = [IO.Path]::GetFullPath($ServerPath)
if (-not (Test-Path -LiteralPath $ServerPath -PathType Leaf)) { throw 'Server executable not found.' }
if (-not $ReportDirectory) { $ReportDirectory = Join-Path $taskRoot ('artifacts/official-events-' + [DateTime]::Now.ToString('yyyyMMdd-HHmmss')) }
$ReportDirectory = [IO.Path]::GetFullPath($ReportDirectory)
if (Test-Path -LiteralPath $ReportDirectory) { throw 'Use a new report directory.' }
New-Item -ItemType Directory -Path $ReportDirectory | Out-Null
$taskRuntime = Join-Path $ReportDirectory 'isolated-runtime'
$taskListener = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0)
$taskListener.Start(); $taskPort = $taskListener.LocalEndpoint.Port; $taskListener.Stop()
$taskEndpoint = 'http://127.0.0.1:' + $taskPort
$taskStart = [Diagnostics.ProcessStartInfo]::new($ServerPath)
$taskStart.UseShellExecute = $false; $taskStart.CreateNoWindow = $true
$taskStart.RedirectStandardOutput = $true; $taskStart.RedirectStandardError = $true
$taskStart.ArgumentList.Add('--root=' + $taskRuntime)
$taskStart.ArgumentList.Add('--port=' + $taskPort)
$taskStart.ArgumentList.Add('--no-irc')
$taskProcess = [Diagnostics.Process]::Start($taskStart)
$taskOutput = $taskProcess.StandardOutput.ReadToEndAsync(); $taskErrors = $taskProcess.StandardError.ReadToEndAsync()
$taskClient = [Net.Http.HttpClient]::new(); $taskClient.Timeout = [TimeSpan]::FromSeconds(25)
$taskChecks = [Collections.Generic.List[object]]::new()
$taskAdmin = $null; $taskStatus = $null
function Test-Check([string]$Name, [bool]$Passed) {
$taskChecks.Add([ordered]@{ name=$Name; passed=$Passed })
if (-not $Passed) { throw ('Check failed: ' + $Name) }
}
function Send-TestRequest([string]$Path, [string]$Method = 'GET', [bool]$Admin = $false) {
$request = [Net.Http.HttpRequestMessage]::new([Net.Http.HttpMethod]::new($Method), $taskEndpoint + $Path)
try {
if ($Admin) { $request.Headers.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new('Bearer', $taskAdmin) }
if ($Method -eq 'POST') { $request.Content = [Net.Http.StringContent]::new('{}', [Text.Encoding]::UTF8, 'application/json') }
$response = $taskClient.SendAsync($request).GetAwaiter().GetResult()
try { return @{ status=[int]$response.StatusCode; body=$response.Content.ReadAsStringAsync().GetAwaiter().GetResult() } }
finally { $response.Dispose() }
} finally { $request.Dispose() }
}
function Test-DateMilliseconds($Token) {
if ($null -eq $Token) { return 0L }
if ($Token -is [Newtonsoft.Json.Linq.JObject]) { $Token = $Token['$date'] }
if ($Token -is [Newtonsoft.Json.Linq.JObject]) { $Token = $Token['$numberLong'] }
$parsed = 0L
if ($null -ne $Token -and [long]::TryParse($Token.ToString(), [ref]$parsed)) { return $parsed }
return 0L
}
try {
$taskReady = $false
for ($attempt = 0; $attempt -lt 40; $attempt++) {
if ($taskProcess.HasExited) { throw ('Isolated server exited: ' + $taskErrors.GetAwaiter().GetResult()) }
try { if ((Send-TestRequest '/health').status -eq 200) { $taskReady = $true; break } } catch { }
Start-Sleep -Milliseconds 200
}
Test-Check 'Isolated HTTP server is healthy' $taskReady
$taskAdmin = (Get-Content -LiteralPath (Join-Path $taskRuntime 'server.json') -Raw | ConvertFrom-Json).AdminToken
Test-Check 'Official synchronization API requires administrator authentication' ((Send-TestRequest '/control/v1/events').status -eq 401)
$taskSync = Send-TestRequest '/control/v1/events/sync' 'POST' $true
$taskSync.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'sync-response.json') -Encoding utf8
Test-Check 'Real official API fetch completes through the management endpoint' ($taskSync.status -eq 200)
$taskStatus = $taskSync.body | ConvertFrom-Json
Test-Check 'Public HTTPS source and a current snapshot are reported' ($taskStatus.source -eq 'https://api.warframe.com/cdn/worldState.php' -and $taskStatus.hasSnapshot -and -not $taskStatus.stale)
$taskStored = [Newtonsoft.Json.Linq.JObject]::Parse([IO.File]::ReadAllText((Join-Path $taskRuntime 'data/state.json')))
$taskSource = $taskStored['officialEvents']['world']
$taskBuild = [string]$taskSource['BuildLabel']
# Match ClientProtocol.Redirect: this ServerInteractive transport expects a literal slash in query build identities.
$taskReply = Send-TestRequest ('/dynamic/worldState.php?buildLabel=' + [Uri]::EscapeDataString($taskBuild).Replace('%2F', '/'))
$taskReply.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'world-response.json') -Encoding utf8
Test-Check 'Game world-state HTTP endpoint accepts the current official build' ($taskReply.status -eq 200)
$taskWorld = [Newtonsoft.Json.Linq.JObject]::Parse($taskReply.body)
$taskNow = [long]$taskWorld['Time'] * 1000
foreach ($field in @('Goals','Alerts','Events','GlobalUpgrades','FlashSales','NodeOverrides','HubEvents')) {
$equal = $true
foreach ($entry in $taskSource[$field]) {
$expired = $false
foreach ($dateField in @('Expiry','ExpiryDate','EndDate')) { $expiry = Test-DateMilliseconds $entry[$dateField]; if ($expiry -gt 0 -and $expiry -le $taskNow) { $expired = $true } }
if ($expired) { continue }
$found = $false
foreach ($candidate in $taskWorld[$field]) { if ([Newtonsoft.Json.Linq.JToken]::DeepEquals($entry, $candidate)) { $found = $true; break } }
if (-not $found) { $equal = $false }
}
Test-Check ("Official $field entries retain every phase, time and reward parameter") $equal
}
$taskSourceFlags = [Newtonsoft.Json.Linq.JObject]::Parse([string]$taskSource['Tmp'])
$taskLocalFlags = [Newtonsoft.Json.Linq.JObject]::Parse([string]$taskWorld['Tmp'])
$flagsEqual = $true
foreach ($property in $taskSourceFlags.Properties()) {
if ($property.Name -notin @('lqo','hqo','edg') -and -not [Newtonsoft.Json.Linq.JToken]::DeepEquals($property.Value, $taskLocalFlags[$property.Name])) { $flagsEqual = $false }
}
Test-Check 'Official event flags and schedules are preserved' $flagsEqual
if ($CompatibleBuildLabel) {
$compatible = Send-TestRequest ('/dynamic/worldState.php?buildLabel=' + [Uri]::EscapeDataString($CompatibleBuildLabel).Replace('%2F', '/'))
Test-Check 'Previous compatible client receives a valid world-state response' ($compatible.status -eq 200)
$compatibleWorld = [Newtonsoft.Json.Linq.JObject]::Parse($compatible.body)
$compatible.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'compatible-client-world.json') -Encoding utf8
$tauAlerts = @($taskSource['Alerts'] | Where-Object { $_['Tag'].ToString() -eq 'RoadToTauEvent' -and (Test-DateMilliseconds $_['Expiry']) -gt $taskNow })
Test-Check 'Official snapshot contains current Tau operation alerts for this validation' ($tauAlerts.Count -gt 0)
$compatibleAlertsEqual = $true
foreach ($entry in $tauAlerts) {
$found = $false
foreach ($candidate in $compatibleWorld['Alerts']) { if ([Newtonsoft.Json.Linq.JToken]::DeepEquals($entry, $candidate)) { $found = $true; break } }
if (-not $found) { $compatibleAlertsEqual = $false }
}
Test-Check 'Previous client retains every Tau alert ID, node, schedule and Moonflesh reward exactly' $compatibleAlertsEqual
}
Test-Check 'No test creates or mutates any player account' (@($taskStored['accounts'].Properties()).Count -eq 0)
$taskSource.ToString([Newtonsoft.Json.Formatting]::Indented) | Set-Content -LiteralPath (Join-Path $ReportDirectory 'official-snapshot.json') -Encoding utf8
} finally {
try { if (-not $taskProcess.HasExited -and $taskAdmin) { $null = Send-TestRequest '/control/v1/shutdown' 'POST' $true } } catch { }
if (-not $taskProcess.WaitForExit(5000)) { $taskProcess.Kill(); $taskProcess.WaitForExit() }
$taskOutput.GetAwaiter().GetResult() | Set-Content -LiteralPath (Join-Path $ReportDirectory 'server-output.log') -Encoding utf8
$taskErrors.GetAwaiter().GetResult() | Set-Content -LiteralPath (Join-Path $ReportDirectory 'server-error.log') -Encoding utf8
$taskClient.Dispose(); $taskProcess.Dispose()
[ordered]@{ passed=($taskChecks.Count -ge 14 -and @($taskChecks | Where-Object { -not $_.passed }).Count -eq 0); checks=$taskChecks; source=$taskStatus.source; sourceTime=$taskStatus.sourceTime; buildLabel=$taskStatus.buildLabel; compatibleBuildLabel=$CompatibleBuildLabel; counts=$taskStatus.counts; scope='Live public API, isolated HTTP server and game world-state response; no game launch or live-server restart' } | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Join-Path $ReportDirectory 'result.json') -Encoding utf8
}
Write-Output ('Official event HTTP validation: ' + (Join-Path $ReportDirectory 'result.json'))
#requires -Version 7.0
param([Parameter(Mandatory)][string]$ServerPath, [string]$ReportDirectory, [string]$CompatibleBuildLabel)
$ErrorActionPreference = 'Stop'
$taskRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$ServerPath = [IO.Path]::GetFullPath($ServerPath)
if (-not (Test-Path -LiteralPath $ServerPath -PathType Leaf)) { throw 'Server executable not found.' }
if (-not $ReportDirectory) { $ReportDirectory = Join-Path $taskRoot ('artifacts/official-events-' + [DateTime]::Now.ToString('yyyyMMdd-HHmmss')) }
$ReportDirectory = [IO.Path]::GetFullPath($ReportDirectory)
if (Test-Path -LiteralPath $ReportDirectory) { throw 'Use a new report directory.' }
New-Item -ItemType Directory -Path $ReportDirectory | Out-Null
$taskRuntime = Join-Path $ReportDirectory 'isolated-runtime'
$taskListener = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0)
$taskListener.Start(); $taskPort = $taskListener.LocalEndpoint.Port; $taskListener.Stop()
$taskEndpoint = 'http://127.0.0.1:' + $taskPort
$taskStart = [Diagnostics.ProcessStartInfo]::new($ServerPath)
$taskStart.UseShellExecute = $false; $taskStart.CreateNoWindow = $true
$taskStart.RedirectStandardOutput = $true; $taskStart.RedirectStandardError = $true
$taskStart.ArgumentList.Add('--root=' + $taskRuntime)
$taskStart.ArgumentList.Add('--port=' + $taskPort)
$taskStart.ArgumentList.Add('--no-irc')
$taskProcess = [Diagnostics.Process]::Start($taskStart)
$taskOutput = $taskProcess.StandardOutput.ReadToEndAsync(); $taskErrors = $taskProcess.StandardError.ReadToEndAsync()
$taskClient = [Net.Http.HttpClient]::new(); $taskClient.Timeout = [TimeSpan]::FromSeconds(25)
$taskChecks = [Collections.Generic.List[object]]::new()
$taskAdmin = $null; $taskStatus = $null
function Test-Check([string]$Name, [bool]$Passed) {
$taskChecks.Add([ordered]@{ name=$Name; passed=$Passed })
if (-not $Passed) { throw ('Check failed: ' + $Name) }
}
function Send-TestRequest([string]$Path, [string]$Method = 'GET', [bool]$Admin = $false) {
$request = [Net.Http.HttpRequestMessage]::new([Net.Http.HttpMethod]::new($Method), $taskEndpoint + $Path)
try {
if ($Admin) { $request.Headers.Authorization = [Net.Http.Headers.AuthenticationHeaderValue]::new('Bearer', $taskAdmin) }
if ($Method -eq 'POST') { $request.Content = [Net.Http.StringContent]::new('{}', [Text.Encoding]::UTF8, 'application/json') }
$response = $taskClient.SendAsync($request).GetAwaiter().GetResult()
try { return @{ status=[int]$response.StatusCode; body=$response.Content.ReadAsStringAsync().GetAwaiter().GetResult() } }
finally { $response.Dispose() }
} finally { $request.Dispose() }
}
function Test-DateMilliseconds($Token) {
if ($null -eq $Token) { return 0L }
if ($Token -is [Newtonsoft.Json.Linq.JObject]) { $Token = $Token['$date'] }
if ($Token -is [Newtonsoft.Json.Linq.JObject]) { $Token = $Token['$numberLong'] }
$parsed = 0L
if ($null -ne $Token -and [long]::TryParse($Token.ToString(), [ref]$parsed)) { return $parsed }
return 0L
}
try {
$taskReady = $false
for ($attempt = 0; $attempt -lt 40; $attempt++) {
if ($taskProcess.HasExited) { throw ('Isolated server exited: ' + $taskErrors.GetAwaiter().GetResult()) }
try { if ((Send-TestRequest '/health').status -eq 200) { $taskReady = $true; break } } catch { }
Start-Sleep -Milliseconds 200
}
Test-Check 'Isolated HTTP server is healthy' $taskReady
$taskAdmin = (Get-Content -LiteralPath (Join-Path $taskRuntime 'server.json') -Raw | ConvertFrom-Json).AdminToken
Test-Check 'Official synchronization API requires administrator authentication' ((Send-TestRequest '/control/v1/events').status -eq 401)
$taskSync = Send-TestRequest '/control/v1/events/sync' 'POST' $true
$taskSync.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'sync-response.json') -Encoding utf8
Test-Check 'Real official API fetch completes through the management endpoint' ($taskSync.status -eq 200)
$taskStatus = $taskSync.body | ConvertFrom-Json
Test-Check 'Public HTTPS source and a current snapshot are reported' ($taskStatus.source -eq 'https://api.warframe.com/cdn/worldState.php' -and $taskStatus.hasSnapshot -and -not $taskStatus.stale)
$taskStored = [Newtonsoft.Json.Linq.JObject]::Parse([IO.File]::ReadAllText((Join-Path $taskRuntime 'data/state.json')))
$taskSource = $taskStored['officialEvents']['world']
$taskBuild = [string]$taskSource['BuildLabel']
# Match ClientProtocol.Redirect: this ServerInteractive transport expects a literal slash in query build identities.
$taskReply = Send-TestRequest ('/dynamic/worldState.php?buildLabel=' + [Uri]::EscapeDataString($taskBuild).Replace('%2F', '/'))
$taskReply.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'world-response.json') -Encoding utf8
Test-Check 'Game world-state HTTP endpoint accepts the current official build' ($taskReply.status -eq 200)
$taskWorld = [Newtonsoft.Json.Linq.JObject]::Parse($taskReply.body)
$taskNow = [long]$taskWorld['Time'] * 1000
foreach ($field in @('Goals','Alerts','Events','GlobalUpgrades','FlashSales','NodeOverrides','HubEvents')) {
$equal = $true
foreach ($entry in $taskSource[$field]) {
$expired = $false
foreach ($dateField in @('Expiry','ExpiryDate','EndDate')) { $expiry = Test-DateMilliseconds $entry[$dateField]; if ($expiry -gt 0 -and $expiry -le $taskNow) { $expired = $true } }
if ($expired) { continue }
$found = $false
foreach ($candidate in $taskWorld[$field]) { if ([Newtonsoft.Json.Linq.JToken]::DeepEquals($entry, $candidate)) { $found = $true; break } }
if (-not $found) { $equal = $false }
}
Test-Check ("Official $field entries retain every phase, time and reward parameter") $equal
}
$taskSourceFlags = [Newtonsoft.Json.Linq.JObject]::Parse([string]$taskSource['Tmp'])
$taskLocalFlags = [Newtonsoft.Json.Linq.JObject]::Parse([string]$taskWorld['Tmp'])
$flagsEqual = $true
foreach ($property in $taskSourceFlags.Properties()) {
if ($property.Name -notin @('lqo','hqo','edg') -and -not [Newtonsoft.Json.Linq.JToken]::DeepEquals($property.Value, $taskLocalFlags[$property.Name])) { $flagsEqual = $false }
}
Test-Check 'Official event flags and schedules are preserved' $flagsEqual
if ($CompatibleBuildLabel) {
$compatible = Send-TestRequest ('/dynamic/worldState.php?buildLabel=' + [Uri]::EscapeDataString($CompatibleBuildLabel).Replace('%2F', '/'))
Test-Check 'Previous compatible client receives a valid world-state response' ($compatible.status -eq 200)
$compatibleWorld = [Newtonsoft.Json.Linq.JObject]::Parse($compatible.body)
$compatible.body | Set-Content -LiteralPath (Join-Path $ReportDirectory 'compatible-client-world.json') -Encoding utf8
$tauAlerts = @($taskSource['Alerts'] | Where-Object { $_['Tag'].ToString() -eq 'RoadToTauEvent' -and (Test-DateMilliseconds $_['Expiry']) -gt $taskNow })
Test-Check 'Official snapshot contains current Tau operation alerts for this validation' ($tauAlerts.Count -gt 0)
$compatibleAlertsEqual = $true
foreach ($entry in $tauAlerts) {
$found = $false
foreach ($candidate in $compatibleWorld['Alerts']) { if ([Newtonsoft.Json.Linq.JToken]::DeepEquals($entry, $candidate)) { $found = $true; break } }
if (-not $found) { $compatibleAlertsEqual = $false }
}
Test-Check 'Previous client retains every Tau alert ID, node, schedule and Moonflesh reward exactly' $compatibleAlertsEqual
}
Test-Check 'No test creates or mutates any player account' (@($taskStored['accounts'].Properties()).Count -eq 0)
$taskSource.ToString([Newtonsoft.Json.Formatting]::Indented) | Set-Content -LiteralPath (Join-Path $ReportDirectory 'official-snapshot.json') -Encoding utf8
} finally {
try { if (-not $taskProcess.HasExited -and $taskAdmin) { $null = Send-TestRequest '/control/v1/shutdown' 'POST' $true } } catch { }
if (-not $taskProcess.WaitForExit(5000)) { $taskProcess.Kill(); $taskProcess.WaitForExit() }
$taskOutput.GetAwaiter().GetResult() | Set-Content -LiteralPath (Join-Path $ReportDirectory 'server-output.log') -Encoding utf8
$taskErrors.GetAwaiter().GetResult() | Set-Content -LiteralPath (Join-Path $ReportDirectory 'server-error.log') -Encoding utf8
$taskClient.Dispose(); $taskProcess.Dispose()
[ordered]@{ passed=($taskChecks.Count -ge 14 -and @($taskChecks | Where-Object { -not $_.passed }).Count -eq 0); checks=$taskChecks; source=$taskStatus.source; sourceTime=$taskStatus.sourceTime; buildLabel=$taskStatus.buildLabel; compatibleBuildLabel=$CompatibleBuildLabel; counts=$taskStatus.counts; scope='Live public API, isolated HTTP server and game world-state response; no game launch or live-server restart' } | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Join-Path $ReportDirectory 'result.json') -Encoding utf8
}
Write-Output ('Official event HTTP validation: ' + (Join-Path $ReportDirectory 'result.json'))