test: run the suite next to an open game

run-tests.ps1 -AllowWhileRunning starts the headless test game even while
RimWorld is open, at below-normal priority, and a lock file keeps two runs
from overlapping. The art README's render commands now work as written
(escaped regex, separate Edge profile, waiting for each screenshot).
This commit is contained in:
Fabian @ Blax Software 2026-11-29 09:19:26 +01:00
parent a9f25f4b2e
commit 8070103c1d
5 changed files with 109 additions and 69 deletions

Binary file not shown.

Binary file not shown.

View File

@ -64,7 +64,7 @@ It stages only what players need (About, 1.7, Defs, Patches, Languages) in `%TEM
.\Tests\run-tests.ps1
```
`-Compat` also loads the installed mods Blax Slaves has compat code for (Hospitality, Harvest Organs Post Mortem, War Crimes Expanded 2, SYR More Slaves, Everybody Buys Slaves, Trade as Slave or Colonist); tests whose assumptions those mods change skip or relax only that assertion and say why. Exit code 0 means all passed, 1 failures, 2 the run didn't finish (see `game.log` in the data folder).
`-Compat` also loads the installed mods Blax Slaves has compat code for (Hospitality, Harvest Organs Post Mortem, War Crimes Expanded 2, SYR More Slaves, Everybody Buys Slaves, Trade as Slave or Colonist); tests whose assumptions those mods change skip or relax only that assertion and say why. `-AllowWhileRunning` runs it next to an open RimWorld, with the test game at below-normal priority; a lock file keeps two runs from overlapping. Exit code 0 means all passed, 1 failures, 2 the run didn't finish (see `game.log` in the data folder).
Tests are `public static void` methods marked `[BlaxTest("area: what", phase: 1)]`, using `T` for assertions and `Fixtures` for pawns, ticks and memories. Phase 2 runs after the save and reload; carry ThingIDs through `T.Carry`.

View File

@ -2,11 +2,12 @@
`preview.html` renders `About/Preview.png` (1280x720) and `icon.html` renders `About/ModIcon.png` (256x256), in the Blax CI from https://www.blax.at/ui-ci: Blax black `#050805`, Blax green `#19C63C`, logo gray `#CDCDCD`, Geist for headings, Inter for body, Rajdhani only for the "Blax Gaming" wordmark. Fonts are the woff2 files blax.at self-hosts (all SIL Open Font License); icons are lucide.
Render with Edge headless from this folder:
Render with Edge headless from this folder. The separate profile folder keeps the headless run away from an open Edge window, and `| Out-Null` waits for each screenshot.
```powershell
$edge = 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
$here = (Get-Location).Path -replace '\','/'
& $edge --headless=new --disable-gpu --hide-scrollbars --virtual-time-budget=3000 --window-size=1280,720 --screenshot="$PWD\preview.png" "file:///$here/preview.html"
& $edge --headless=new --disable-gpu --hide-scrollbars --virtual-time-budget=2000 --window-size=256,256 --default-background-color=00000000 --screenshot="$PWD\icon.png" "file:///$here/icon.html"
$here = (Get-Location).Path -replace '\\','/'
$edgeData = "$env:TEMP\blax-art-edge"
& $edge --headless=new --disable-gpu --hide-scrollbars --user-data-dir="$edgeData" --virtual-time-budget=3000 --window-size=1280,720 --screenshot="$PWD\..\..\About\Preview.png" "file:///$here/preview.html" | Out-Null
& $edge --headless=new --disable-gpu --hide-scrollbars --user-data-dir="$edgeData" --virtual-time-budget=2000 --window-size=256,256 --default-background-color=00000000 --screenshot="$PWD\..\..\About\ModIcon.png" "file:///$here/icon.html" | Out-Null
```

View File

@ -6,14 +6,17 @@ the Harmony mod from the Workshop. Exit code: 0 all passed, 1 failures, 2 the ru
.\Tests\run-tests.ps1 Harmony, the installed DLCs, Blax Slaves
.\Tests\run-tests.ps1 -Compat also the installed mods Blax Slaves has compat code for
.\Tests\run-tests.ps1 -NoBuild skip dotnet build
.\Tests\run-tests.ps1 -AllowWhileRunning run next to an open RimWorld (the test game runs at below-normal priority)
While it runs, the test mod is linked into the game's Mods folder; the link is removed afterwards.
Only one run at a time: a lock file in the data folder holds the running script's process id.
#>
param(
[string]$RimWorldDir = 'E:\SteamLibrary\steamapps\common\RimWorld',
[string]$DataDir = (Join-Path $env:TEMP 'BlaxSlavesTest'),
[switch]$Compat,
[switch]$NoBuild,
[switch]$AllowWhileRunning,
[int]$TimeoutSeconds = 900
)
$ErrorActionPreference = 'Stop'
@ -21,9 +24,38 @@ $repo = Split-Path -Parent $PSScriptRoot
$testMod = Join-Path $PSScriptRoot 'BlaxSlavesTests'
$link = Join-Path $RimWorldDir 'Mods\BlaxSlavesTests'
$workshop = Join-Path $RimWorldDir '..\..\workshop\content\294100'
$lockFile = Join-Path $DataDir 'run.lock'
if (Get-Process -Name RimWorld -ErrorAction SilentlyContinue) { throw 'RimWorld is running. Close it first.' }
if ((Get-Process -Name RimWorld -ErrorAction SilentlyContinue) -and -not $AllowWhileRunning) {
throw 'RimWorld is running. Close it first, or pass -AllowWhileRunning.'
}
# One run at a time. A lock whose process is gone is stale and taken over.
New-Item -ItemType Directory -Force $DataDir | Out-Null
function Enter-Lock {
for ($try = 0; $try -lt 2; $try++) {
try {
$stream = [IO.File]::Open($lockFile, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::Read)
$bytes = [Text.Encoding]::ASCII.GetBytes([string]$PID)
$stream.Write($bytes, 0, $bytes.Length)
$stream.Close()
return
}
catch [IO.IOException] {
$owner = (Get-Content -LiteralPath $lockFile -Raw -ErrorAction SilentlyContinue)
$ownerPid = 0
if ($owner -and [int]::TryParse($owner.Trim(), [ref]$ownerPid) -and $ownerPid -ne $PID -and (Get-Process -Id $ownerPid -ErrorAction SilentlyContinue)) {
throw "Another test run (process $ownerPid) is in progress. Lock: $lockFile"
}
Write-Warning "removing stale lock from process $owner"
Remove-Item -LiteralPath $lockFile -Force -ErrorAction SilentlyContinue
}
}
throw "Could not take the lock $lockFile"
}
Enter-Lock
try {
if (-not $NoBuild) {
foreach ($proj in (Join-Path $repo 'Source\BlaxSlaves\BlaxSlaves.csproj'), (Join-Path $testMod 'Source\BlaxSlavesTests.csproj')) {
& dotnet build $proj -c Release -nologo -v q "-p:RimWorldDir=$RimWorldDir"
@ -84,15 +116,22 @@ try {
$p = Start-Process -FilePath (Join-Path $RimWorldDir 'RimWorld.exe') -WorkingDirectory $RimWorldDir -ArgumentList $gameArgs `
-RedirectStandardOutput (Join-Path $DataDir 'game.log') -RedirectStandardError (Join-Path $DataDir 'game.err.log') `
-WindowStyle Hidden -PassThru
if ($AllowWhileRunning) {
try { $p.PriorityClass = [Diagnostics.ProcessPriorityClass]::BelowNormal } catch { Write-Warning "could not lower the test game's priority: $_" }
}
if (-not $p.WaitForExit($TimeoutSeconds * 1000)) {
$p.Kill()
Write-Warning "timed out after $TimeoutSeconds s, game killed"
Write-Warning "timed out after $TimeoutSeconds s, test game (process $($p.Id)) killed"
}
Write-Host ("Game ran {0:N0} s. Log: {1}" -f $sw.Elapsed.TotalSeconds, (Join-Path $DataDir 'game.log'))
}
finally {
if ($createdLink -and (Test-Path $link)) { cmd /c rmdir "$link" | Out-Null }
}
}
finally {
Remove-Item -LiteralPath $lockFile -Force -ErrorAction SilentlyContinue
}
$results = Join-Path $DataDir 'BlaxSlavesTestResults.txt'
if (-not (Test-Path $results)) { Write-Host 'No results file: the suite never started. See game.log.'; exit 2 }