feat: add headless mode to replay-test script
Browse filesAdd -Headless flag to replay-test.ps1 that uses WA's /getlog mode for
pure-simulation replay testing. Compares output log byte-for-byte
against bots_expected.log to verify replay determinism.
Update replay-test skill docs to cover both modes.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- .claude/skills/replay-test/SKILL.md +33 -28
- replay-test.ps1 +77 -23
.claude/skills/replay-test/SKILL.md
CHANGED
|
@@ -1,52 +1,57 @@
|
|
| 1 |
---
|
| 2 |
name: replay-test
|
| 3 |
-
description: Run automated replay-based testing - builds,
|
| 4 |
---
|
| 5 |
|
| 6 |
# Replay Test
|
| 7 |
|
| 8 |
Run the replay-based automated testing pipeline.
|
| 9 |
|
| 10 |
-
##
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
```bash
|
| 15 |
powershell -ExecutionPolicy Bypass -File replay-test.ps1
|
| 16 |
```
|
| 17 |
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
2. Read the
|
| 29 |
|
| 30 |
-
|
| 31 |
-
-
|
| 32 |
-
-
|
| 33 |
-
-
|
| 34 |
-
-
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
## Environment Variables
|
| 39 |
|
| 40 |
-
- `OPENWA_VALIDATE=1` —
|
| 41 |
-
- `OPENWA_REPLAY_TEST=1` — Enables fast-forward mode
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
## Notes
|
| 46 |
|
| 47 |
-
-
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
-
|
| 51 |
-
-
|
| 52 |
-
- Occasional crashes may occur during fast-forward (null vtable calls from 50x speed processing); retry if this happens
|
|
|
|
| 1 |
---
|
| 2 |
name: replay-test
|
| 3 |
+
description: Run automated replay-based testing - builds, launches WA.exe with a replay file, captures validation logs, and presents results. Supports headful (graphics + validation) and headless (pure simulation + log diff) modes.
|
| 4 |
---
|
| 5 |
|
| 6 |
# Replay Test
|
| 7 |
|
| 8 |
Run the replay-based automated testing pipeline.
|
| 9 |
|
| 10 |
+
## Modes
|
| 11 |
|
| 12 |
+
### Headful (default) — graphics, sound, validation
|
| 13 |
+
Tests hooks, struct layouts, and game state with the full rendering pipeline active.
|
| 14 |
|
| 15 |
```bash
|
| 16 |
powershell -ExecutionPolicy Bypass -File replay-test.ps1
|
| 17 |
```
|
| 18 |
|
| 19 |
+
### Headless — pure simulation, log comparison
|
| 20 |
+
Uses WA's built-in `/getlog` mode: no window, no rendering, pure CPU simulation. Compares the output log byte-for-byte against an expected log to verify replay determinism. An order of magnitude faster than headful mode.
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
powershell -ExecutionPolicy Bypass -File replay-test.ps1 -Headless
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
## Steps
|
| 27 |
+
|
| 28 |
+
1. Run the replay test script (headful or headless as appropriate).
|
| 29 |
|
| 30 |
+
2. Read the output and present results:
|
| 31 |
|
| 32 |
+
**Headful mode:**
|
| 33 |
+
- Read `testdata/logs/validation_latest.log` and summarize total PASS/FAIL counts
|
| 34 |
+
- Quote any [FAIL] lines exactly
|
| 35 |
+
- Note whether validation completed or safety timeout triggered
|
| 36 |
+
- If `testdata/logs/openwa_latest.log` exists, check for errors or interesting hook activity
|
| 37 |
|
| 38 |
+
**Headless mode:**
|
| 39 |
+
- The script compares the output log to `testdata/replays/bots_expected.log`
|
| 40 |
+
- PASS means byte-identical output — replay is deterministic
|
| 41 |
+
- FAIL shows the diff lines between expected and actual
|
| 42 |
|
| 43 |
## Environment Variables
|
| 44 |
|
| 45 |
+
- `OPENWA_VALIDATE=1` — (headful) Enables validation module
|
| 46 |
+
- `OPENWA_REPLAY_TEST=1` — (headful) Enables fast-forward mode (50x speed)
|
| 47 |
+
- `OPENWA_HEADLESS=1` — (headless) Hooks MessageBoxA to auto-dismiss, enabling unattended /getlog
|
| 48 |
|
| 49 |
+
All are set automatically by `replay-test.ps1`.
|
| 50 |
|
| 51 |
## Notes
|
| 52 |
|
| 53 |
+
- Headful replay typically completes in ~15-30s; headless in ~5s
|
| 54 |
+
- Custom replay: `powershell -File replay-test.ps1 [-Headless] path\to\other.WAgame`
|
| 55 |
+
- Expected log convention: `<replay>_expected.log` next to `<replay>.WAgame`
|
| 56 |
+
- If no expected log exists, headless mode saves the first output as the expected log
|
| 57 |
+
- The launcher uses named event synchronization to ensure all hooks are installed before WA.exe's main thread runs
|
|
|
replay-test.ps1
CHANGED
|
@@ -1,7 +1,13 @@
|
|
| 1 |
# replay-test.ps1 - Automated replay-based testing
|
| 2 |
-
# Usage: powershell -File replay-test.ps1 [replay-file]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
param(
|
|
|
|
| 5 |
[string]$ReplayFile = "testdata\replays\bots.WAgame"
|
| 6 |
)
|
| 7 |
|
|
@@ -43,16 +49,29 @@ if (Test-Path "$gameDir\wkOpenWAValidator.dll") {
|
|
| 43 |
}
|
| 44 |
|
| 45 |
# 3. Launch via launcher with replay, env vars set
|
| 46 |
-
|
| 47 |
-
Write-Host " (Fast-forward mode: replay will be auto-advanced, game exits when done)" -ForegroundColor Yellow
|
| 48 |
|
| 49 |
-
$
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
# The launcher blocks until WA.exe exits, so run it as a background job for timeout support.
|
| 54 |
-
$proc = Start-Process -FilePath $launcher -ArgumentList "--minimized `"$waExe`" `"$ReplayFile`"" -PassThru
|
| 55 |
-
$timeout = 150 # seconds
|
| 56 |
if (-not $proc.WaitForExit($timeout * 1000)) {
|
| 57 |
Write-Host "WARNING: launcher did not exit within ${timeout}s, killing..." -ForegroundColor Red
|
| 58 |
$proc.Kill()
|
|
@@ -60,6 +79,7 @@ if (-not $proc.WaitForExit($timeout * 1000)) {
|
|
| 60 |
}
|
| 61 |
$env:OPENWA_VALIDATE = $null
|
| 62 |
$env:OPENWA_REPLAY_TEST = $null
|
|
|
|
| 63 |
$env:OPENWA_WA_PATH = $null
|
| 64 |
|
| 65 |
Write-Host "Launcher exited with code $($proc.ExitCode)" -ForegroundColor Cyan
|
|
@@ -87,20 +107,54 @@ if (Test-Path "$gameDir\OpenWA.log") {
|
|
| 87 |
|
| 88 |
# 5. Print summary
|
| 89 |
Write-Host ""
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
$
|
| 93 |
-
$
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
if (
|
| 99 |
-
Write-Host "
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
} else {
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
|
|
|
| 105 |
}
|
| 106 |
-
Write-Host " Logs: $logDir\" -ForegroundColor Gray
|
|
|
|
| 1 |
# replay-test.ps1 - Automated replay-based testing
|
| 2 |
+
# Usage: powershell -File replay-test.ps1 [-Headless] [replay-file]
|
| 3 |
+
#
|
| 4 |
+
# Modes:
|
| 5 |
+
# Default (headful): Fast-forward replay with validation, graphics & sound active.
|
| 6 |
+
# -Headless: Uses WA's /getlog mode -- no window, pure simulation.
|
| 7 |
+
# Compares output log to expected log for determinism checking.
|
| 8 |
|
| 9 |
param(
|
| 10 |
+
[switch]$Headless,
|
| 11 |
[string]$ReplayFile = "testdata\replays\bots.WAgame"
|
| 12 |
)
|
| 13 |
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
# 3. Launch via launcher with replay, env vars set
|
| 52 |
+
$env:OPENWA_WA_PATH = $waExe
|
|
|
|
| 53 |
|
| 54 |
+
if ($Headless) {
|
| 55 |
+
Write-Host "Launching WA.exe in HEADLESS mode: $ReplayFile" -ForegroundColor Cyan
|
| 56 |
+
Write-Host " (No window -- pure simulation via /getlog)" -ForegroundColor Yellow
|
| 57 |
+
|
| 58 |
+
# Remove any previous output log next to the replay file
|
| 59 |
+
$replayBase = [System.IO.Path]::ChangeExtension($ReplayFile, ".log")
|
| 60 |
+
Remove-Item $replayBase -ErrorAction SilentlyContinue
|
| 61 |
+
|
| 62 |
+
$env:OPENWA_HEADLESS = "1"
|
| 63 |
+
$proc = Start-Process -FilePath $launcher -ArgumentList "`"$waExe`" /getlog `"$ReplayFile`"" -PassThru
|
| 64 |
+
$timeout = 120
|
| 65 |
+
} else {
|
| 66 |
+
Write-Host "Launching WA.exe with replay: $ReplayFile" -ForegroundColor Cyan
|
| 67 |
+
Write-Host " (Fast-forward mode: replay will be auto-advanced, game exits when done)" -ForegroundColor Yellow
|
| 68 |
+
|
| 69 |
+
$env:OPENWA_VALIDATE = "1"
|
| 70 |
+
$env:OPENWA_REPLAY_TEST = "1"
|
| 71 |
+
$proc = Start-Process -FilePath $launcher -ArgumentList "--minimized `"$waExe`" `"$ReplayFile`"" -PassThru
|
| 72 |
+
$timeout = 150
|
| 73 |
+
}
|
| 74 |
|
|
|
|
|
|
|
|
|
|
| 75 |
if (-not $proc.WaitForExit($timeout * 1000)) {
|
| 76 |
Write-Host "WARNING: launcher did not exit within ${timeout}s, killing..." -ForegroundColor Red
|
| 77 |
$proc.Kill()
|
|
|
|
| 79 |
}
|
| 80 |
$env:OPENWA_VALIDATE = $null
|
| 81 |
$env:OPENWA_REPLAY_TEST = $null
|
| 82 |
+
$env:OPENWA_HEADLESS = $null
|
| 83 |
$env:OPENWA_WA_PATH = $null
|
| 84 |
|
| 85 |
Write-Host "Launcher exited with code $($proc.ExitCode)" -ForegroundColor Cyan
|
|
|
|
| 107 |
|
| 108 |
# 5. Print summary
|
| 109 |
Write-Host ""
|
| 110 |
+
if ($Headless) {
|
| 111 |
+
Write-Host "=== Headless Log Comparison ===" -ForegroundColor Cyan
|
| 112 |
+
$replayBase = [System.IO.Path]::ChangeExtension($ReplayFile, ".log")
|
| 113 |
+
$expectedLog = [System.IO.Path]::Combine(
|
| 114 |
+
[System.IO.Path]::GetDirectoryName($ReplayFile),
|
| 115 |
+
[System.IO.Path]::GetFileNameWithoutExtension($ReplayFile) + "_expected.log"
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
if (-not (Test-Path $replayBase)) {
|
| 119 |
+
Write-Host " FAIL: No output log generated at $replayBase" -ForegroundColor Red
|
| 120 |
+
exit 1
|
| 121 |
+
}
|
| 122 |
+
if (-not (Test-Path $expectedLog)) {
|
| 123 |
+
Write-Host " No expected log found -- saving output as expected: $expectedLog" -ForegroundColor Yellow
|
| 124 |
+
Copy-Item $replayBase $expectedLog
|
| 125 |
+
Write-Host " PASS (first run -- expected log created)" -ForegroundColor Green
|
| 126 |
} else {
|
| 127 |
+
$diff = Compare-Object (Get-Content $expectedLog) (Get-Content $replayBase)
|
| 128 |
+
if ($diff) {
|
| 129 |
+
Write-Host " FAIL: Output differs from expected log" -ForegroundColor Red
|
| 130 |
+
Write-Host ""
|
| 131 |
+
$diff | ForEach-Object {
|
| 132 |
+
$indicator = if ($_.SideIndicator -eq "<=") { "expected" } else { "actual " }
|
| 133 |
+
Write-Host " $indicator | $($_.InputObject)" -ForegroundColor $(if ($_.SideIndicator -eq "<=") { "Red" } else { "Yellow" })
|
| 134 |
+
}
|
| 135 |
+
exit 1
|
| 136 |
+
} else {
|
| 137 |
+
Write-Host " PASS: Output matches expected log" -ForegroundColor Green
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
# Clean up the generated log
|
| 141 |
+
Remove-Item $replayBase -ErrorAction SilentlyContinue
|
| 142 |
+
} else {
|
| 143 |
+
Write-Host "=== Validation Summary ===" -ForegroundColor Cyan
|
| 144 |
+
if (Test-Path "$logDir\validation_latest.log") {
|
| 145 |
+
$content = Get-Content "$logDir\validation_latest.log" -Raw
|
| 146 |
+
$passes = ([regex]::Matches($content, "\[PASS\]")).Count
|
| 147 |
+
$fails = ([regex]::Matches($content, "\[FAIL\]")).Count
|
| 148 |
+
Write-Host " PASS: $passes" -ForegroundColor Green
|
| 149 |
+
Write-Host " FAIL: $fails" -ForegroundColor $(if ($fails -gt 0) { "Red" } else { "Green" })
|
| 150 |
+
|
| 151 |
+
if ($content -match "Safety timeout reached") {
|
| 152 |
+
Write-Host " Replay: TIMEOUT (safety timeout triggered)" -ForegroundColor Red
|
| 153 |
+
} elseif ($content -match "deferred global validation") {
|
| 154 |
+
Write-Host " Validation: completed" -ForegroundColor Green
|
| 155 |
+
} else {
|
| 156 |
+
Write-Host " Validation: NOT found in log (may not have reached gameplay)" -ForegroundColor Yellow
|
| 157 |
+
}
|
| 158 |
}
|
| 159 |
+
Write-Host " Logs: $logDir\" -ForegroundColor Gray
|
| 160 |
}
|
|
|