From 8070103c1da82b0400608564cff6a83d25739993 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Sun, 29 Nov 2026 09:19:26 +0100 Subject: [PATCH] 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). --- 1.7/Assemblies/BlaxSlaves.dll | Bin 70656 -> 70656 bytes 1.7/Assemblies/BlaxSlaves.pdb | Bin 27412 -> 27412 bytes README.md | 2 +- Source/Art/README.md | 9 +- Tests/run-tests.ps1 | 167 +++++++++++++++++++++------------- 5 files changed, 109 insertions(+), 69 deletions(-) diff --git a/1.7/Assemblies/BlaxSlaves.dll b/1.7/Assemblies/BlaxSlaves.dll index 6755f71450d3e87278e5950a74b274a928a609b8..7fe8ec50054ab59e5386efd9bc535da5e140ce4c 100644 GIT binary patch delta 239 zcmZoz!P2mTWkLtb-z?Q78+$f95m0armJL)n>@n%d-TB8K^rUU}d0Hi*o@kk7WSVA@ zWRz-_k!os@XkwmfoNSn~`R(7&d@Os89h)%y2@hj{z?%H~ z2PSYFa@ZT@slooJHG8@XFQbJ5RJ6esDhgCDu(j@OlK{utq=fG;es7<{%NW7zo5*0v zkj7xdUmRsX)Q=v)8)f_3u4Cacge&d0Hi*ZkTG4m||vO zVr*n)nUrR1VrZI@Y-RxDo0}OWS|(WlNehEy%gt~9e&%CoVX=5W{Rt0afWRKkS<{Vt zJA8MCE>`9fb>W}x!pmr(02RIa8!8G?zw?W+(wd`l9$GHVe7AiLFJlC=uOUM!g9$?- zLkfc#g9VUf%wPm$Su!LsqygC`42BG*K)Ga~m;qGY9LP2T>Hw*+fU+%svdIjV+Z_cN H_cH+ibWli+ diff --git a/1.7/Assemblies/BlaxSlaves.pdb b/1.7/Assemblies/BlaxSlaves.pdb index 53e98bb5f5ce5ddff1135b837eaa6cea3c3eee86..8735409765dad219c587f805476a72df2ed16cca 100644 GIT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J{Oie+ITwzlZ{ARZwq2IY%rL zn~-D_>DC70oS zay@xYG>BMoS~x0y(ZN%_E9dE|g{NCDb&GHC_~I=uRgI|lCy2L^(EwKzb9|Zv1!-J! z1?jtE)Qfc`#X7&|XTBmF4w0app^Pxj6%$5DU9mA-?uurE(iP*3eOxgn%EJ|#OrEaz zB-$JC8imq*$|g1b0@a+Fq-2mSWmpm>D-ZsS%?_0Mm-9+_Mdnd`A;z2eC2-ClwzNg@d>tVp<4+uW};FQ|n1VYpAR zd|^oR^jq>h{->sS_whnPVOjFL1$}gL-Y=*xI=XmzvDTqUZR|SVUL1cR zazw$!VfKWd^EP)nZsd5IGrq0=GvRT@*~9_G_nXR(?OaiL#`-L?tU&j6Kfg)Mck_>T zesSFW$Br7|uWH|2wTDV$TWMtQ6HQie4)MUQbf=qhtJIRvcROOe@1?) zKWUV&TfHJ|Lr!%`y5Gj#fgZ9e(ZTVF0S~lyHq?(V6Ar0Ha={U&55H%Q*FF0(wX!6= z{HvmAch_CAZyBCBdqjSd>btcydi9xszLCvSmIO0OhR<+j4ed~S&SUJ08T)3&zJswB zGIobE+gi!GFJ?-X_Ea5CTVlB+$kll8DdX(hvmmxJ&QQiV&Ka7toaL~OBiAuCrT3mk zM~lS)wl<$$TcTL17tb1;+`_u|Y%E^F;S6|p8z+`}-KZi}&iM51>bdHb8Dr%C1C_(t AF#rGn diff --git a/README.md b/README.md index f4c859b..d4882b4 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/Source/Art/README.md b/Source/Art/README.md index c2924b5..4dc4b25 100644 --- a/Source/Art/README.md +++ b/Source/Art/README.md @@ -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 ``` diff --git a/Tests/run-tests.ps1 b/Tests/run-tests.ps1 index 02403b6..df4431c 100644 --- a/Tests/run-tests.ps1 +++ b/Tests/run-tests.ps1 @@ -3,17 +3,20 @@ Runs the in-game test suite. RimWorld 1.7 starts headless (no window, no focus c own save data folder, so your mod list, saves and settings stay untouched. Needs Steam running and the Harmony mod from the Workshop. Exit code: 0 all passed, 1 failures, 2 the run didn't finish. - .\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 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,77 +24,113 @@ $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.' +} -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" - if ($LASTEXITCODE -ne 0) { throw "build failed: $proj" } +# 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 -# packageId (lower case) -> About.xml, for every installed local and Workshop mod -$installed = @{} -foreach ($about in @(Get-ChildItem (Join-Path $RimWorldDir 'Mods\*\About\About.xml') -ErrorAction SilentlyContinue) + - @(Get-ChildItem (Join-Path $workshop '*\About\About.xml') -ErrorAction SilentlyContinue)) { - $x = [xml](Get-Content -LiteralPath $about.FullName -Raw -Encoding UTF8) - if ($x.ModMetaData.packageId) { $installed[$x.ModMetaData.packageId.Trim().ToLower()] = $x } -} -function Add-WithDependencies([string]$id, [System.Collections.ArrayList]$list) { - $id = $id.ToLower() - if ($list -contains $id -or $id -like 'ludeon.*') { return } - $x = $installed[$id] - if (-not $x) { Write-Warning "not installed, skipped: $id"; return } - foreach ($dep in @($x.ModMetaData.modDependencies.li)) { if ($dep.packageId) { Add-WithDependencies $dep.packageId $list } } - [void]$list.Add($id) -} - -$mods = New-Object System.Collections.ArrayList -$expansions = @() -[void]$mods.Add('brrainz.harmony') -[void]$mods.Add('ludeon.rimworld') -foreach ($dlc in 'Royalty', 'Ideology', 'Biotech', 'Anomaly', 'Odyssey') { - if (Test-Path (Join-Path $RimWorldDir "Data\$dlc")) { $id = 'ludeon.rimworld.' + $dlc.ToLower(); [void]$mods.Add($id); $expansions += $id } -} -if ($Compat) { - foreach ($id in 'unlimitedhugs.hugslib', 'orion.hospitality', 'smuffle.harvestorganspostmortem', - 'mersid.wce2updated.core', 'mlie.syrmoreslaves', 'bblkepling.everybodybuysslaves', - 'rhajiit.tradepurchasemode') { - Add-WithDependencies $id $mods - } -} -[void]$mods.Add('blax.slaves') -[void]$mods.Add('blax.slaves.tests') - -# fresh test data folder: mod list only, no old save, results or mod settings -New-Item -ItemType Directory -Force (Join-Path $DataDir 'Config') | Out-Null -Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $DataDir 'Saves\BlaxSlavesTest.rws'), (Join-Path $DataDir 'BlaxSlavesTestResults.txt'), (Join-Path $DataDir 'Config\Mod_blax.slaves_*.xml') -$li = { param($ids) ($ids | ForEach-Object { "
  • $_
  • " }) -join "`n" } -$modsConfig = "`n`n 1.7`n `n" + - (& $li $mods) + "`n `n `n" + (& $li $expansions) + "`n `n`n" -[IO.File]::WriteAllText((Join-Path $DataDir 'Config\ModsConfig.xml'), $modsConfig) -Write-Host ("Mods: " + ($mods -join ', ')) - -$createdLink = $false try { - if (-not (Test-Path $link)) { - New-Item -ItemType Junction -Path $link -Target $testMod | Out-Null - $createdLink = $true + 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" + if ($LASTEXITCODE -ne 0) { throw "build failed: $proj" } + } } - $gameArgs = "-headless -quicktest -blaxslavestests -NoFileLog -NoCrashDialog `"-savedatafolder=$DataDir`"" - $sw = [Diagnostics.Stopwatch]::StartNew() - $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 (-not $p.WaitForExit($TimeoutSeconds * 1000)) { - $p.Kill() - Write-Warning "timed out after $TimeoutSeconds s, game killed" + + # packageId (lower case) -> About.xml, for every installed local and Workshop mod + $installed = @{} + foreach ($about in @(Get-ChildItem (Join-Path $RimWorldDir 'Mods\*\About\About.xml') -ErrorAction SilentlyContinue) + + @(Get-ChildItem (Join-Path $workshop '*\About\About.xml') -ErrorAction SilentlyContinue)) { + $x = [xml](Get-Content -LiteralPath $about.FullName -Raw -Encoding UTF8) + if ($x.ModMetaData.packageId) { $installed[$x.ModMetaData.packageId.Trim().ToLower()] = $x } + } + function Add-WithDependencies([string]$id, [System.Collections.ArrayList]$list) { + $id = $id.ToLower() + if ($list -contains $id -or $id -like 'ludeon.*') { return } + $x = $installed[$id] + if (-not $x) { Write-Warning "not installed, skipped: $id"; return } + foreach ($dep in @($x.ModMetaData.modDependencies.li)) { if ($dep.packageId) { Add-WithDependencies $dep.packageId $list } } + [void]$list.Add($id) + } + + $mods = New-Object System.Collections.ArrayList + $expansions = @() + [void]$mods.Add('brrainz.harmony') + [void]$mods.Add('ludeon.rimworld') + foreach ($dlc in 'Royalty', 'Ideology', 'Biotech', 'Anomaly', 'Odyssey') { + if (Test-Path (Join-Path $RimWorldDir "Data\$dlc")) { $id = 'ludeon.rimworld.' + $dlc.ToLower(); [void]$mods.Add($id); $expansions += $id } + } + if ($Compat) { + foreach ($id in 'unlimitedhugs.hugslib', 'orion.hospitality', 'smuffle.harvestorganspostmortem', + 'mersid.wce2updated.core', 'mlie.syrmoreslaves', 'bblkepling.everybodybuysslaves', + 'rhajiit.tradepurchasemode') { + Add-WithDependencies $id $mods + } + } + [void]$mods.Add('blax.slaves') + [void]$mods.Add('blax.slaves.tests') + + # fresh test data folder: mod list only, no old save, results or mod settings + New-Item -ItemType Directory -Force (Join-Path $DataDir 'Config') | Out-Null + Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $DataDir 'Saves\BlaxSlavesTest.rws'), (Join-Path $DataDir 'BlaxSlavesTestResults.txt'), (Join-Path $DataDir 'Config\Mod_blax.slaves_*.xml') + $li = { param($ids) ($ids | ForEach-Object { "
  • $_
  • " }) -join "`n" } + $modsConfig = "`n`n 1.7`n `n" + + (& $li $mods) + "`n `n `n" + (& $li $expansions) + "`n `n`n" + [IO.File]::WriteAllText((Join-Path $DataDir 'Config\ModsConfig.xml'), $modsConfig) + Write-Host ("Mods: " + ($mods -join ', ')) + + $createdLink = $false + try { + if (-not (Test-Path $link)) { + New-Item -ItemType Junction -Path $link -Target $testMod | Out-Null + $createdLink = $true + } + $gameArgs = "-headless -quicktest -blaxslavestests -NoFileLog -NoCrashDialog `"-savedatafolder=$DataDir`"" + $sw = [Diagnostics.Stopwatch]::StartNew() + $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, 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 } } - 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 } + Remove-Item -LiteralPath $lockFile -Force -ErrorAction SilentlyContinue } $results = Join-Path $DataDir 'BlaxSlavesTestResults.txt'