tools/psin_index: keep first LSNS section and match .bin case-insensitively #1820

Closed
github-bot wants to merge 1 commit from github-bot/gh-1820 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 12:32 UTC · original
kirigayakazima:fix/psin-index-lsns-and-case → main · +31 −5 · 2 files · 1 commits · closed without merging

Claimed in the coordination issue as: PSIN-INDEX-DUPLICATE-LSNS-AND-CASE-BIN (#1608)

What and why

  • Guard duplicate LSNS sections in tools/psin_index.py parse() (lsns_seen) so only the first LSNS section is decoded and later duplicate LSNS sections cannot overwrite either an earlier LSNS error or the first section's block/record counts, matching the existing LSCH and LENM first-section-only handling.
  • Make directory .bin discovery in input_paths() case-insensitive (name.lower().endswith(".bin")) so .BIN / .Bin files are indexed consistently across filesystems.
  • Accept optional argv=None in main(argv=None) (ap.parse_args(argv)) to support direct in-process CLI testing while preserving CLI invocation behavior.
  • Add regression tests in tests/test_psin_index.py (test_first_lsns_error_is_not_overwritten_by_duplicate_section, test_duplicate_valid_lsns_keeps_first_and_consistent_summary, and test_uppercase_bin_extension_is_indexed).

Tested

  • python -I tests/test_psin_index.py -v -> Ran 36 tests in 0.688s, OK.
  • Baseline upstream/main (0d80bc5d) detached worktree with updated tests/test_psin_index.py -> Ran 36 tests in 0.680s, FAILED (failures=3) (fails on all 3 new regression tests before the fix).
  • python -I tests/test_ci_registration.py -v -> Ran 16 tests in 4.691s, OK.
  • python -I tests/test_text_write_line_endings.py -v -> Ran 3 tests in 12.308s, OK.
  • python -I scripts/check_no_game_data.py tools/psin_index.py tests/test_psin_index.py -> exit 0.
  • python -I -m compileall -q tools/psin_index.py tests/test_psin_index.py and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

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. (n/a)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820) `kirigayakazima:fix/psin-index-lsns-and-case` → `main` · +31 −5 · 2 files · 1 commits · closed without merging Claimed in the coordination issue as: PSIN-INDEX-DUPLICATE-LSNS-AND-CASE-BIN (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Guard duplicate `LSNS` sections in `tools/psin_index.py` `parse()` (`lsns_seen`) so only the first `LSNS` section is decoded and later duplicate `LSNS` sections cannot overwrite either an earlier `LSNS` error or the first section's block/record counts, matching the existing `LSCH` and `LENM` first-section-only handling. - Make directory `.bin` discovery in `input_paths()` case-insensitive (`name.lower().endswith(".bin")`) so `.BIN` / `.Bin` files are indexed consistently across filesystems. - Accept optional `argv=None` in `main(argv=None)` (`ap.parse_args(argv)`) to support direct in-process CLI testing while preserving CLI invocation behavior. - Add regression tests in `tests/test_psin_index.py` (`test_first_lsns_error_is_not_overwritten_by_duplicate_section`, `test_duplicate_valid_lsns_keeps_first_and_consistent_summary`, and `test_uppercase_bin_extension_is_indexed`). ### Tested - `python -I tests/test_psin_index.py -v` -> `Ran 36 tests in 0.688s`, `OK`. - Baseline `upstream/main` (`0d80bc5d`) detached worktree with updated `tests/test_psin_index.py` -> `Ran 36 tests in 0.680s`, `FAILED (failures=3)` (fails on all 3 new regression tests before the fix). - `python -I tests/test_ci_registration.py -v` -> `Ran 16 tests in 4.691s`, `OK`. - `python -I tests/test_text_write_line_endings.py -v` -> `Ran 3 tests in 12.308s`, `OK`. - `python -I scripts/check_no_game_data.py tools/psin_index.py tests/test_psin_index.py` -> exit `0`. - `python -I -m compileall -q tools/psin_index.py tests/test_psin_index.py` and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) 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. (n/a)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:07:08 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-25 13:05 UTC · original · reviewed

Independent Windows 11 26H2 (26300.9711) check at f12a3f298 against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. All 55 tests passed across test_psin_index.py (36/36 in 0.774s), test_ci_registration.py (16/16 in 6.794s), and test_text_write_line_endings.py (3/3 in 14.023s), with check_no_game_data.py and compileall clean. Verified first-LSNS-only handling (lsns_seen matching lsch_seen/lenm_seen so duplicate sections do not overwrite errors or skew summary kinds/records) and case-insensitive .bin matching in input_paths(). LGTM.

**@⁠madvillain91** on GitHub · 2026-11-25 13:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820#pullrequestreview-6058136174) · **reviewed** Independent Windows 11 26H2 (26300.9711) check at f12a3f298 against main 98c2f7777 (PR base 0d80bc5df), using CPython 3.12.3 (python -I) and Git for Windows 2.56.0.windows.2. All 55 tests passed across test_psin_index.py (36/36 in 0.774s), test_ci_registration.py (16/16 in 6.794s), and test_text_write_line_endings.py (3/3 in 14.023s), with check_no_game_data.py and compileall clean. Verified first-LSNS-only handling (lsns_seen matching lsch_seen/lenm_seen so duplicate sections do not overwrite errors or skew summary kinds/records) and case-insensitive .bin matching in input_paths(). LGTM.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:54 UTC · original

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

python -m pytest -q tests/test_psin_index.py:

  • PR: 36 passed. main: 33 passed. The new tests pass on Windows.

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

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820#issuecomment-7167419318) Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_psin_index.py`: - PR: 36 passed. main: 33 passed. The new tests pass on Windows. (AI-assisted test run; output checked by hand.)
Author
Owner

@⁠MSedgeMC on GitHub · 2026-11-25 17:23 UTC · original · approved these changes

Verified on the PR branch: python3 -m unittest tests.test_psin_index -v -> 36 tests OK, including the new cases for keeping the first LSNS error, not overwriting it with a duplicate section, preserving consistent summaries, and indexing uppercase .BIN extensions. Both fixes prevent silent data loss in the index tool. Python-only, no game data.

**@⁠MSedgeMC** on GitHub · 2026-11-25 17:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820#pullrequestreview-6061996903) · **approved these changes** Verified on the PR branch: python3 -m unittest tests.test_psin_index -v -> 36 tests OK, including the new cases for keeping the first LSNS error, not overwriting it with a duplicate section, preserving consistent summaries, and indexing uppercase .BIN extensions. Both fixes prevent silent data loss in the index tool. Python-only, no game data.
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 17:27 UTC · original

Thanks. The new guards cover inputs the pipeline doesn't produce: the carver writes lowercase .bin names ({s:012x}.bin, rpf9_carve.py), and a duplicate LSNS section has never been measured.

Can you name a real input that hits them? Otherwise we'd rather not take the extra code.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 17:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820#issuecomment-7169533259) Thanks. The new guards cover inputs the pipeline doesn't produce: the carver writes lowercase `.bin` names (`{s:012x}.bin`, `rpf9_carve.py`), and a duplicate `LSNS` section has never been measured. Can you name a real input that hits them? Otherwise we'd rather not take the extra code. AI-assisted (Claude Code, Claude Opus 5.5).
github-bot closed this pull request 2026-11-27 12:03:58 +00:00
Author
Owner

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

Thanks @⁠aslan2142 — understood. Since rpf9_carve.py writes lowercase .bin names and duplicate LSNS sections have not been observed on real inputs, closing this PR rather than adding speculative guards.

**@⁠kirigayakazima** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1820#issuecomment-7217607755) Thanks @⁠aslan2142 — understood. Since `rpf9_carve.py` writes lowercase `.bin` names and duplicate `LSNS` sections have not been observed on real inputs, closing this PR rather than adding speculative guards.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.