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

Closed
leonida/mandy
kirigayakazima wants to merge 0 commits from fix/psin-index-lsns-and-case into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

kirigayakazima commented 2026-11-25 12:32:33 +00:00

Claimed in the coordination issue as: PSIN-INDEX-DUPLICATE-LSNS-AND-CASE-BIN (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162455934)

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)
Claimed in the coordination issue as: PSIN-INDEX-DUPLICATE-LSNS-AND-CASE-BIN (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7162455934) ### 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)
madvillain91 reviewed 2026-11-25 13:05:18 +00:00
madvillain91 left a comment
No description provided.
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.
DeadlyChirp commented 2026-11-25 15:54:30 +00:00

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.)

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.)
MSedgeMC approved these changes 2026-11-25 17:23:16 +00:00
MSedgeMC left a comment

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.

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.
aslan2142 commented 2026-11-25 17:27:33 +00:00

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).

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).
kirigayakazima commented 2026-11-27 11:54:12 +00:00

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.

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.
Sign in to join this conversation.
No description provided.