inline_scan: support UTF-8 BOM, clean up dumpbin Popen on early close, and validate --base #2273

Open
github-bot wants to merge 1 commit from github-bot/gh-2273 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 11:59 UTC · original
kirigayakazima:fix/inline-scan-safety → main · +111 −8 · 2 files · 1 commits · open

Claimed in the coordination issue as: INLINE-SCAN-BOM-DUMPBIN-CLEANUP-AND-CLI-SAFETY (#1608)

What and why

tools/inline_scan.py previously:

  • Opened text listings with "utf-8" instead of "utf-8-sig", causing line 1 to miss LINE matching when a file started with a UTF-8 BOM.
  • Spawned dumpbin via subprocess.Popen without encoding="utf-8" or try/finally cleanup, risking locale-dependent decoding and leaking/leaving dumpbin running if iteration stopped early.
  • Defined main() with no argv parameter, accepted negative --base values (like -0x1000), and let OSError from reading listings crash unhandled instead of exiting 2.

This uses "utf-8-sig" for listings, adds encoding="utf-8" and try/finally pipe/process cleanup in read_lines(), adds _parse_base rejecting negative hex bases, accepts argv=None in main(), handles OSError cleanly, and adds unit/CLI tests in tests/test_inline_scan.py.

Tested

  • python -I tests/test_inline_scan.py -v (17 passed)
  • Detached upstream/main baseline negative control: failed with the new tests before the fix
  • python -I tests/test_ci_registration.py, python -I tests/test_text_write_line_endings.py, python -I scripts/check_no_game_data.py, python -I -m compileall -q, and git diff --cached --check

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 11:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2273) `kirigayakazima:fix/inline-scan-safety` → `main` · +111 −8 · 2 files · 1 commits · open Claimed in the coordination issue as: INLINE-SCAN-BOM-DUMPBIN-CLEANUP-AND-CLI-SAFETY (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `tools/inline_scan.py` previously: - Opened text listings with `"utf-8"` instead of `"utf-8-sig"`, causing line 1 to miss `LINE` matching when a file started with a UTF-8 BOM. - Spawned `dumpbin` via `subprocess.Popen` without `encoding="utf-8"` or `try/finally` cleanup, risking locale-dependent decoding and leaking/leaving `dumpbin` running if iteration stopped early. - Defined `main()` with no `argv` parameter, accepted negative `--base` values (like `-0x1000`), and let `OSError` from reading listings crash unhandled instead of exiting 2. This uses `"utf-8-sig"` for listings, adds `encoding="utf-8"` and `try/finally` pipe/process cleanup in `read_lines()`, adds `_parse_base` rejecting negative hex bases, accepts `argv=None` in `main()`, handles `OSError` cleanly, and adds unit/CLI tests in `tests/test_inline_scan.py`. ### Tested - `python -I tests/test_inline_scan.py -v` (17 passed) - Detached `upstream/main` baseline negative control: failed with the new tests before the fix - `python -I tests/test_ci_registration.py`, `python -I tests/test_text_write_line_endings.py`, `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q`, and `git diff --cached --check` 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 12:04:17 +00:00
Author
Owner

@⁠real-rusher on GitHub · 2026-11-26 12:23 UTC · original

Checked on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly, compileall clean, but one of the new tests fails with this PR:

python -I tests/test_inline_scan.py: 17 run, FAILED (failures=1), in test_negative_base_and_oserror_return_2:

AssertionError: 'non-negative' not found in 'usage: test_inline_scan.py [-h] [--base BASE] [--sites] source
test_inline_scan.py: error: argument --base: expected one argument'

argparse only treats decimal negatives like -1 as values, so "--base", "-0x1000" is parsed as a missing argument followed by an unknown option, and the new non-negative check in _parse_base is never reached. The same happens on the command line: python -I tools/inline_scan.py x.txt --base -0x1000 prints "argument --base: expected one argument". With the test changed to inline_scan.main([path, "--base=-0x1000"]), all 17 pass, and the new tests fail on main (1 failure, 2 errors) as they should. If negative bases should be caught as written in the usage line, the check may need the --base=... form documented or a different parser setup.

AI-assisted: yes (Claude Code)

**@⁠real-rusher** on GitHub · 2026-11-26 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2273#issuecomment-7191937401) Checked on main a73a57e1 (Ubuntu 24.04 x86-64, Python 3.13, no GPU). Merges cleanly, compileall clean, but **one of the new tests fails with this PR**: python -I tests/test_inline_scan.py: 17 run, FAILED (failures=1), in test_negative_base_and_oserror_return_2: AssertionError: 'non-negative' not found in 'usage: test_inline_scan.py [-h] [--base BASE] [--sites] source test_inline_scan.py: error: argument --base: expected one argument' argparse only treats decimal negatives like -1 as values, so "--base", "-0x1000" is parsed as a missing argument followed by an unknown option, and the new non-negative check in _parse_base is never reached. The same happens on the command line: python -I tools/inline_scan.py x.txt --base -0x1000 prints "argument --base: expected one argument". With the test changed to inline_scan.main([path, "--base=-0x1000"]), all 17 pass, and the new tests fail on main (1 failure, 2 errors) as they should. If negative bases should be caught as written in the usage line, the check may need the --base=... form documented or a different parser setup. AI-assisted: yes (Claude Code)
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-26 12:52 UTC · original

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_inline_scan.py: 1 failed, 16 passed.
  • Failing test: test_negative_base_and_oserror_return_2. inline_scan.main([path, "--base", "-0x1000"]) exits 2, but from argparse itself (argument --base: expected one argument), so "non-negative" is not in stderr.
  • Cause: on Python 3.12, argparse reads only decimal numbers like -1 as negative values. -0x1000 looks like an option, so --base gets no value. This is not Windows-specific. --base=-0x1000 in the test (or a decimal value such as -4096) would reach the tool's own check.

(AI-assisted test run; output checked by hand.)

**@⁠DeadlyChirp** on GitHub · 2026-11-26 12:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2273#issuecomment-7192573216) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_inline_scan.py`: 1 failed, 16 passed. - Failing test: `test_negative_base_and_oserror_return_2`. `inline_scan.main([path, "--base", "-0x1000"])` exits 2, but from argparse itself (`argument --base: expected one argument`), so `"non-negative"` is not in stderr. - Cause: on Python 3.12, argparse reads only decimal numbers like `-1` as negative values. `-0x1000` looks like an option, so `--base` gets no value. This is not Windows-specific. `--base=-0x1000` in the test (or a decimal value such as `-4096`) would reach the tool's own check. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:38 UTC · original · requested changes

Requesting one change in the new test; the code change itself looks right.

test_negative_base_and_oserror_return_2 calls inline_scan.main([path, "--base", "-0x1000"]) and fails on its own head (757ffc364) with Python 3.13: argparse only treats decimal negatives such as -5 as values, so -0x1000 is taken for an unknown option and the run stops with "argument --base: expected one argument" before _parse_base is called. The exit code is still 2, but the "non-negative" assertion fails:

AssertionError: 'non-negative' not found in 'usage: __main__.py [-h] [--base BASE] [--sites] source\n__main__.py: error: argument --base: expected one argument\n'

Writing it as "--base=-0x1000" passes the value on every Python and actually reaches the new check. The other tests pass (16 of 17 in tests/test_inline_scan.py, on main d1dff7949 plus this PR). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2273#pullrequestreview-6083551724) · **requested changes** Requesting one change in the new test; the code change itself looks right. `test_negative_base_and_oserror_return_2` calls `inline_scan.main([path, "--base", "-0x1000"])` and fails on its own head (757ffc364) with Python 3.13: argparse only treats decimal negatives such as `-5` as values, so `-0x1000` is taken for an unknown option and the run stops with "argument --base: expected one argument" before `_parse_base` is called. The exit code is still 2, but the "non-negative" assertion fails: ``` AssertionError: 'non-negative' not found in 'usage: __main__.py [-h] [--base BASE] [--sites] source\n__main__.py: error: argument --base: expected one argument\n' ``` Writing it as `"--base=-0x1000"` passes the value on every Python and actually reaches the new check. The other tests pass (16 of 17 in `tests/test_inline_scan.py`, on `main` `d1dff7949` plus this PR). AI-assisted (Claude Code, Claude Opus 5.5).
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/2273/head:github-bot/gh-2273'
git switch 'github-bot/gh-2273'

Merge

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