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

Open
github-bot wants to merge 2 commits from github-bot/gh-2345 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 14:19 UTC · original
kirigayakazima:fix/first-look-ps1-safety → main · +183 −5 · 2 files · 2 commits · open

Claimed in the coordination issue as: FIRST-LOOK-PS1-GAMEDIR-VALIDATION-HANDLE-CLEANUP-AND-REPORT-CHECK (#1608)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 14:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2345) `kirigayakazima:fix/first-look-ps1-safety` → `main` · +183 −5 · 2 files · 2 commits · open Claimed in the coordination issue as: FIRST-LOOK-PS1-GAMEDIR-VALIDATION-HANDLE-CLEANUP-AND-REPORT-CHECK (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:23:46 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 20:50 UTC · original · reviewed

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.

**@⁠lixonik** on GitHub · 2026-11-26 20:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2345#pullrequestreview-6080354131) · **reviewed** 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.
@ -104,2 +118,3 @@
# 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" }
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 20:50 UTC · original

[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** on GitHub · 2026-11-26 20:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2345#discussion_r4713258153) [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`?
@ -103,3 +119,3 @@
# 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
if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" }
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-27 12:02 UTC · original

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.

**@⁠kirigayakazima** on GitHub · 2026-11-27 12:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2345#discussion_r4719130616) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2345/head:github-bot/gh-2345'
git switch 'github-bot/gh-2345'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2345'
git switch 'github-bot/gh-2345'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2345'
git switch 'github-bot/gh-2345'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2345'
git switch 'main'
git merge --squash 'github-bot/gh-2345'
git switch 'main'
git merge --ff-only 'github-bot/gh-2345'
git switch 'main'
git merge 'github-bot/gh-2345'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.