FIRST-LOOK-PS1-GAMEDIR-VALIDATION-HANDLE-CLEANUP-AND-REPORT-CHECK #2345

Merged
kirigayakazima merged 2 commits from upstream-pr/2345 into main 2026-11-29 00:59:10 +00:00
kirigayakazima commented 2026-11-26 14:19:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T14:19:11Z.


Claimed in the coordination issue as: FIRST-LOOK-PS1-GAMEDIR-VALIDATION-HANDLE-CLEANUP-AND-REPORT-CHECK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194523743)

What and why

  • Resolve explicit -GameDir arguments via GetUnresolvedProviderPathFromPSPath in scripts/first_look.ps1 and validate -PathType Container before creating the report directory under reports\exe.
  • Guard $out with Test-Path -LiteralPath $out -PathType Leaf and create it via [IO.Directory]::CreateDirectory($out) so wildcard-metacharacter exe names and file-occupied report paths fail cleanly.
  • Dispose the [IO.File]::OpenRead($Exe) stream in try/finally and verify a 2-byte read before checking the "MZ" header so non-MZ or 0-byte inputs do not leak open handles.
  • Reset $global:LASTEXITCODE = 0 before invoking build_runtime.ps1 and throw when $LASTEXITCODE -ne 0; check $reportPath exists with -PathType Leaf before Get-Content | ConvertFrom-Json.
  • Add standard-library tests in tests/test_first_look_safety.py.

Tested

  • python -I tests/test_first_look_safety.py -v: 2 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 2 failures).
  • python -I tests/test_first_look_exit.py -v: 1 passed (11 subtests).
  • python -I tests/test_first_look_paths.py -v: 1 passed.
  • python -I tests/test_first_look_rebuild.py -v: 5 passed.
  • python -I tests/test_first_look_shim_report.py -v: 1 passed.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tests/test_first_look_safety.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511691544 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T14:19:11Z. --- Claimed in the coordination issue as: FIRST-LOOK-PS1-GAMEDIR-VALIDATION-HANDLE-CLEANUP-AND-REPORT-CHECK (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194523743) ### What and why - Resolve explicit `-GameDir` arguments via `GetUnresolvedProviderPathFromPSPath` in `scripts/first_look.ps1` and validate `-PathType Container` before creating the report directory under `reports\exe`. - Guard `$out` with `Test-Path -LiteralPath $out -PathType Leaf` and create it via `[IO.Directory]::CreateDirectory($out)` so wildcard-metacharacter exe names and file-occupied report paths fail cleanly. - Dispose the `[IO.File]::OpenRead($Exe)` stream in `try`/`finally` and verify a 2-byte read before checking the `"MZ"` header so non-MZ or 0-byte inputs do not leak open handles. - Reset `$global:LASTEXITCODE = 0` before invoking `build_runtime.ps1` and throw when `$LASTEXITCODE -ne 0`; check `$reportPath` exists with `-PathType Leaf` before `Get-Content | ConvertFrom-Json`. - Add standard-library tests in `tests/test_first_look_safety.py`. ### Tested - `python -I tests/test_first_look_safety.py -v`: 2 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 2 failures). - `python -I tests/test_first_look_exit.py -v`: 1 passed (11 subtests). - `python -I tests/test_first_look_paths.py -v`: 1 passed. - `python -I tests/test_first_look_rebuild.py -v`: 5 passed. - `python -I tests/test_first_look_shim_report.py -v`: 1 passed. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tests/test_first_look_safety.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
lixonik commented 2026-11-26 20:50:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T20:50:19Z.

Code review location: scripts/first_look.ps1; line 120

@@ -102,7 +116,9 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
 $dryRunExitCode = $LASTEXITCODE
 
 # Shim to-do list, grouped by DLL, most functions first.
-$report = Get-Content -LiteralPath (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json
+$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json"
+if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" }

[P3] A second invocation can satisfy this existence check with the previous report. I kept game.exe.json from the first invocation, put a distinctive DLL name in it, and ran the PR's LEONIDA_SKIP_PE_REPORT=1 fixture. The wrapper exited 0 and listed that old DLL. The committed test deletes the earlier report, so it covers a clean output directory only. Could this invocation use a fresh report path or otherwise verify that its inspector produced the JSON before deriving shim-todo.txt?

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4713258153 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2345#discussion_r4713258153). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T20:50:19Z. **Code review location:** `scripts/first_look.ps1`; line 120 ~~~~diff @@ -102,7 +116,9 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)" $dryRunExitCode = $LASTEXITCODE # Shim to-do list, grouped by DLL, most functions first. -$report = Get-Content -LiteralPath (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json +$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json" +if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" } ~~~~ --- [P3] A second invocation can satisfy this existence check with the previous report. I kept `game.exe.json` from the first invocation, put a distinctive DLL name in it, and ran the PR's `LEONIDA_SKIP_PE_REPORT=1` fixture. The wrapper exited 0 and listed that old DLL. The committed test deletes the earlier report, so it covers a clean output directory only. Could this invocation use a fresh report path or otherwise verify that its inspector produced the JSON before deriving `shim-todo.txt`?
lixonik commented 2026-11-26 20:50:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T20:50:19Z.

Review: COMMENTED


On the merge with main at fac8b4bb9, all 10 test_first_look_*.py tests passed on Windows 11 with the standard Windows PowerShell module path. I also ran the missing-report fixture a second way, retaining the previous JSON as happens when the command is rerun. The wrapper returned success and printed a shim from the previous report. Details inline.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6080354131 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345#pullrequestreview-6080354131). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T20:50:19Z. **Review:** COMMENTED --- On the merge with `main` at `fac8b4bb9`, all 10 `test_first_look_*.py` tests passed on Windows 11 with the standard Windows PowerShell module path. I also ran the missing-report fixture a second way, retaining the previous JSON as happens when the command is rerun. The wrapper returned success and printed a shim from the previous report. Details inline. AI-assisted.
kirigayakazima commented 2026-11-27 12:02:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:02:48Z.

Code review location: scripts/first_look.ps1; line 120

@@ -102,7 +116,9 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
 $dryRunExitCode = $LASTEXITCODE
 
 # Shim to-do list, grouped by DLL, most functions first.
-$report = Get-Content -LiteralPath (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json
+$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json"
+if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" }

Fixed: first_look.ps1 now removes any existing $reportPath before invoking pe_inspect.py, so a failed or skipped report cannot silently reuse an earlier run's JSON. Updated tests/test_first_look_safety.py to keep a stale game.exe.json and verify it fails cleanly. All 5 test_first_look_*.py suites + 5 repo checks pass.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4719130616 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2345#discussion_r4719130616). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-27T12:02:48Z. **Code review location:** `scripts/first_look.ps1`; line 120 ~~~~diff @@ -102,7 +116,9 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)" $dryRunExitCode = $LASTEXITCODE # Shim to-do list, grouped by DLL, most functions first. -$report = Get-Content -LiteralPath (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json +$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json" +if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" } ~~~~ --- Fixed: `first_look.ps1` now removes any existing `$reportPath` before invoking `pe_inspect.py`, so a failed or skipped report cannot silently reuse an earlier run's JSON. Updated `tests/test_first_look_safety.py` to keep a stale `game.exe.json` and verify it fails cleanly. All 5 `test_first_look_*.py` suites + 5 repo checks pass.
lixonik commented 2026-11-27 14:23:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T14:23:21Z.

Review: COMMENTED


Re-checked at f43076b07 (merged onto main ec91d695c).

Clearing `` before invoking pe_inspect.py and testing with a pre-existing stale JSON in tests/test_first_look_safety.py cleanly address the stale-report issue.

Verified locally on Windows 11 (PowerShell + Python 3):

  • tests/test_first_look_exit.py, test_first_look_paths.py, test_first_look_rebuild.py, test_first_look_safety.py, test_first_look_shim_report.py: 10/10 passed
  • PowerShell AST parse of tools/first_look.ps1: clean
  • scripts/check_no_game_data.py and git diff --check: clean

No remaining findings.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6089570199 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345#pullrequestreview-6089570199). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T14:23:21Z. **Review:** COMMENTED --- Re-checked at `f43076b07` (merged onto `main` `ec91d695c`). Clearing `` before invoking `pe_inspect.py` and testing with a pre-existing stale JSON in `tests/test_first_look_safety.py` cleanly address the stale-report issue. Verified locally on Windows 11 (PowerShell + Python 3): - `tests/test_first_look_exit.py`, `test_first_look_paths.py`, `test_first_look_rebuild.py`, `test_first_look_safety.py`, `test_first_look_shim_report.py`: 10/10 passed - PowerShell AST parse of `tools/first_look.ps1`: clean - `scripts/check_no_game_data.py` and `git diff --check`: clean No remaining findings. AI-assisted.
zmasi commented 2026-11-28 20:31:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T20:31:08Z.


#2345 | head f43076b07f (merged cleanly with main 1bc055e6c2) | python -I tests/test_first_look_safety.py | red on main: FAILED (failures=2) (accepted missing/file -GameDir and created reports/exe before failing, leaked open file handle on 0-byte non-MZ exe, ignored non-zero build_runtime.ps1 exit code, and read stale game.exe.json when pe_inspect.py produced no output) | green on PR+main: 2 tests OK (all 7 runtime guard cases + static checks) | Windows 11 (10.0.26200.9974, powershell.exe 5.1.26100.9818), Python 3.12.10 | AI-assisted: yes

Audited scripts/first_look.ps1 and tests/test_first_look_safety.py on Windows 11 PowerShell 5.1, verifying literal provider-path resolution and -PathType Container validation on -GameDir (including bracketed data [1]), try / finally $fs.Dispose() + $read -ne 2 guard on short/non-MZ files so Windows file handles never leak, leaf-blocker check on $out, $global:LASTEXITCODE = 0 + exit-code check around build_runtime.ps1, and stale $reportPath removal + existence verification around pe_inspect.py. Also verified tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245344148 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345#issuecomment-7245344148). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T20:31:08Z. --- #2345 | head f43076b07f1d792616cf68ad1d1940ced13e9c54 (merged cleanly with main 1bc055e6c2) | `python -I tests/test_first_look_safety.py` | red on main: `FAILED (failures=2)` (accepted missing/file `-GameDir` and created `reports/exe` before failing, leaked open file handle on 0-byte non-MZ exe, ignored non-zero `build_runtime.ps1` exit code, and read stale `game.exe.json` when `pe_inspect.py` produced no output) | green on PR+main: `2 tests OK` (all 7 runtime guard cases + static checks) | Windows 11 (`10.0.26200.9974`, `powershell.exe` `5.1.26100.9818`), Python 3.12.10 | AI-assisted: yes Audited `scripts/first_look.ps1` and `tests/test_first_look_safety.py` on Windows 11 PowerShell 5.1, verifying literal provider-path resolution and `-PathType Container` validation on `-GameDir` (including bracketed `data [1]`), `try / finally` `$fs.Dispose()` + `$read -ne 2` guard on short/non-MZ files so Windows file handles never leak, leaf-blocker check on `$out`, `$global:LASTEXITCODE = 0` + exit-code check around `build_runtime.ps1`, and stale `$reportPath` removal + existence verification around `pe_inspect.py`. Also verified `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
TheGeogeo commented 2026-11-28 23:38:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:38:06Z.


Tested f43076b07 merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_first_look_safety.py, 2 tests pass.
  • Red: with scripts/first_look.ps1 back to main, it fails: GetUnresolvedProviderPathFromPSPath($GameDir) is not found.
  • Note: that check matches the script's text rather than running it.

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247561847 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345#issuecomment-7247561847). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:38:06Z. --- Tested `f43076b07` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_first_look_safety.py`, 2 tests pass. - Red: with `scripts/first_look.ps1` back to `main`, it fails: `GetUnresolvedProviderPathFromPSPath($GameDir)` is not found. - Note: that check matches the script's text rather than running it. No blocker from my side. AI-assisted (Claude Code).
DadaCap commented 2026-11-29 00:59:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T00:59:22Z.


Merged, thank you! Its own tests failed on main without the change and passed with it, and a batch test with eight other tool PRs (main's Python suite plus a game run on an RTX 5080) showed no regression.

AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248485277 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2345#issuecomment-7248485277). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-29T00:59:22Z. --- Merged, thank you! Its own tests failed on main without the change and passed with it, and a batch test with eight other tool PRs (main's Python suite plus a game run on an RTX 5080) showed no regression. AI-assisted (Claude Code, Claude Opus 5.5), on behalf of DadaCap.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2345
No description provided.