Files
mandy/tools/conformance/native/scripts/run.ps1
diego a9447cae88 conformance run.ps1: check the renderer before deleting, and delete only a run's own output
run.ps1 ran `Remove-Item $Output -Recurse -Force` on whatever -Output named, before checking that
conform_native.exe was built: a mistyped -Output (a drive, the repository, a home folder) was
deleted, even when nothing could be rendered into it afterwards.

Now an unbuilt renderer exits 1 before -Output is touched, and an existing -Output is emptied
only when it holds nothing but <scene>.png and manifest.json, which is all a run writes. A file,
a link or junction (a recursive Remove-Item on one can empty its target), a drive root, or a
folder with anything else is refused with exit 2 and left as it was.

tests/test_conformance_run_script.py runs the script from a temporary copy of the tree, with
where.exe standing in for the renderer (Windows only). With main's run.ps1, 6 of its 7 tests
fail, and the junction case empties the junction's target.

Finding: https://github.com/ItsNotRexed/Leonida/issues/9401#issuecomment-7114404825

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 18:30:31 -03:00

42 lines
2.0 KiB
PowerShell

param(
[string]$Output = '',
[string[]]$Extra = @()
)
# Renders every scene into $Output (default: <repo>/tools/conformance/native/out/run1).
# A folder already at $Output is emptied first, so no PNG from an earlier run is left behind, but only when it holds
# nothing except what a run writes (<scene>.png and manifest.json). A mistyped -Output (a drive, the repository, a
# home folder, a folder of anything else) is refused with exit 2 instead of deleted, and nothing is touched at all
# when the renderer has not been built.
$ErrorActionPreference = 'Continue'
$root = Split-Path -Parent $PSScriptRoot
if ([string]::IsNullOrEmpty($Output)) { $Output = Join-Path $root 'out/run1' }
$exe = Join-Path $root 'build/Release/conform_native.exe'
if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) {
Write-Output "$exe does not exist; build first (scripts\build.ps1)"
Write-Output 'EXITCODE 1'
exit 1
}
function Refuse-Output([string]$Why) {
Write-Output "-Output $Output $Why; not deleting it. Pass an empty folder or a previous run's output folder."
Write-Output 'EXITCODE 2'
exit 2
}
if (Test-Path -LiteralPath $Output) {
$item = Get-Item -LiteralPath $Output -Force
if (-not $item.PSIsContainer) { Refuse-Output 'is a file' }
# A junction or symbolic link: a recursive Remove-Item on it can delete the contents of the folder it points to.
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) { Refuse-Output 'is a link or junction' }
if ($null -eq $item.Parent) { Refuse-Output 'is a drive root' }
$foreign = @(Get-ChildItem -LiteralPath $item.FullName -Force |
Where-Object { $_.PSIsContainer -or -not ($_.Name -eq 'manifest.json' -or $_.Extension -eq '.png') })
if ($foreign.Count -gt 0) {
$names = ($foreign | Select-Object -First 3 | ForEach-Object { $_.Name }) -join ', '
Refuse-Output "holds files a run does not write ($names)"
}
Remove-Item -LiteralPath $item.FullName -Recurse -Force
}
& $exe $Output @Extra
Write-Output "EXITCODE $LASTEXITCODE"