pe_inspect: reject missing --game-dir before scanning images #492

Merged
kotekompotek merged 1 commit from upstream-pr/492 into main 2026-11-28 14:48:32 +00:00
kotekompotek commented 2026-11-24 06:21:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kotekompotek on 2026-11-24T06:21:05Z.


Claimed in the coordination issue as: TOOL-PE-INSPECT-GAMEDIR (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140050149)

What and why

  • Rebased onto current main and squashed into one clean commit.
  • Validated --game-dir in tools/pe_inspect.py before scanning images and added regression tests in tests/test_pe_inspect_game_dir.py.

Tested

  • python -I tests/test_pe_inspect_game_dir.py (2/2 OK) on commit 17d5b5134.
  • All 12 tests/test_docs_*.py (OK) on commit 17d5b5134.

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:5467203491 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/492). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-24T06:21:05Z. --- Claimed in the coordination issue as: TOOL-PE-INSPECT-GAMEDIR (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140050149) ### What and why - Rebased onto current `main` and squashed into one clean commit. - Validated `--game-dir` in `tools/pe_inspect.py` before scanning images and added regression tests in `tests/test_pe_inspect_game_dir.py`. ### Tested - `python -I tests/test_pe_inspect_game_dir.py` (`2/2 OK`) on commit `17d5b5134`. - All 12 `tests/test_docs_*.py` (`OK`) on commit `17d5b5134`. 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.
Len1k commented 2026-11-24 07:34:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Len1k on 2026-11-24T07:34:03Z.


Heads-up on the test this adds, from running it both ways.

I swapped tools/pe_inspect.py back to this branch's base commit, kept tests/test_pe_inspect_game_dir.py as it is, and ran it: Ran 1 test ... OK. The test passes without the change.

Why: it asserts rc == 2 and "does not exist" in stderr. Without your check, main() falls through to the missing-image branch, which prints ERROR: {img}: does not exist and returns the same 2 — both assertions are satisfied by the older code path.

Two ways to pin it:

  • assert on the wording only your branch produces, e.g. "--game-dir" and the path in the message;
  • or pass an --image that exists (an empty file is enough, since the validation should fire before the image is read), so the missing-image branch cannot return 2.

Rest of the branch is fine — the check itself is a good addition, it just is not covered yet. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7125130934 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/492#issuecomment-7125130934). Originally posted by [Len1k](https://github.com/Len1k) on 2026-11-24T07:34:03Z. --- Heads-up on the test this adds, from running it both ways. I swapped `tools/pe_inspect.py` back to this branch's base commit, kept `tests/test_pe_inspect_game_dir.py` as it is, and ran it: **`Ran 1 test ... OK`**. The test passes without the change. Why: it asserts `rc == 2` and `"does not exist"` in stderr. Without your check, `main()` falls through to the missing-image branch, which prints `ERROR: {img}: does not exist` and returns the same `2` — both assertions are satisfied by the older code path. Two ways to pin it: - assert on the wording only your branch produces, e.g. `"--game-dir"` and the path in the message; - or pass an `--image` that exists (an empty file is enough, since the validation should fire before the image is read), so the missing-image branch cannot return 2. Rest of the branch is fine — the check itself is a good addition, it just is not covered yet. *AI-assisted.*
kotekompotek commented 2026-11-24 18:30:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kotekompotek on 2026-11-24T18:30:31Z.


@Len1k Fixed in commit 17d5b5134: updated tests/test_pe_inspect_game_dir.py so img.exe is created as a real existing file before testing a missing --game-dir and a regular-file --game-dir, asserting exit code 2 and that out_dir is not created. Re-verified python -I tests/test_pe_inspect_game_dir.py (2/2 OK) and all 12 tests/test_docs_*.py (OK).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140742915 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/492#issuecomment-7140742915). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-24T18:30:31Z. --- @Len1k Fixed in commit `17d5b5134`: updated `tests/test_pe_inspect_game_dir.py` so `img.exe` is created as a real existing file before testing a missing `--game-dir` and a regular-file `--game-dir`, asserting exit code `2` and that `out_dir` is not created. Re-verified `python -I tests/test_pe_inspect_game_dir.py` (2/2 OK) and all 12 `tests/test_docs_*.py` (OK).
NinsonD commented 2026-11-25 08:58:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by NinsonD on 2026-11-25T08:58:22Z.


I independently checked the updated regression tests at 17d5b5134 on Windows using synthetic files.

  • With the PR’s --game-dir validation present: 2 tests passed.
  • With only that validation removed from an isolated copy: both tests failed, returning 1 instead of the expected 2.

This supports that the updated tests catch the behavior discussed in the earlier review. I tested the two relevant files only, not the full repository suite.

AI-assisted review and testing.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7157706957 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/492#issuecomment-7157706957). Originally posted by [NinsonD](https://github.com/NinsonD) on 2026-11-25T08:58:22Z. --- I independently checked the updated regression tests at `17d5b5134` on Windows using synthetic files. - With the PR’s `--game-dir` validation present: 2 tests passed. - With only that validation removed from an isolated copy: both tests failed, returning 1 instead of the expected 2. This supports that the updated tests catch the behavior discussed in the earlier review. I tested the two relevant files only, not the full repository suite. AI-assisted review and testing.
kotekompotek commented 2026-11-25 09:40:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kotekompotek on 2026-11-25T09:40:30Z.


Rebased onto current main (a104a898c) — the macos-python/check/label runs on the old head had been cancelled before finishing, so this push also re-triggers a full check set. test_pe_inspect_game_dir.py: 2/2 OK locally after the rebase.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7158648965 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/492#issuecomment-7158648965). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T09:40:30Z. --- Rebased onto current main (`a104a898c`) — the macos-python/check/label runs on the old head had been cancelled before finishing, so this push also re-triggers a full check set. `test_pe_inspect_game_dir.py`: 2/2 OK locally after the rebase.
MoonEyes commented 2026-11-28 14:48:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:48:29Z.


Red/green: test_pe_inspect_game_dir.py failed 2 assertions on main because a missing or non-directory --game-dir was not rejected, and both pass with the early rc 2 check.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 4f9199d09 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240945839 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/492#issuecomment-7240945839). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:48:29Z. --- Red/green: test_pe_inspect_game_dir.py failed 2 assertions on main because a missing or non-directory --game-dir was not rejected, and both pass with the early rc 2 check. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 4f9199d09 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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!492
No description provided.