tooling: validate section_probe --first and --last as section tags #641

Merged
louisdibiasi merged 2 commits from upstream-pr/647 into main 2026-11-22 18:31:10 +00:00
louisdibiasi commented 2026-11-22 17:28:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by louisdibiasi on 2026-11-22T17:28:44Z.


Change

tools/section_probe.py matches sections whose four-character tags satisfy [A-Z0-9_]{4}, but --first and --last accepted any string. A lowercase or wrong-length tag can never match, so the run exits 0 with "section_records": 0, which looks the same as an archive that has no such section. A tag outside ASCII raised UnicodeEncodeError. This validates both options with the same pattern through an argparse type, so a bad tag exits with status 2 and a usage message.

Independent problem, no linked issue.

Verification

Commit under test: b1faec8 on bcdce96, Windows 11, Python 3.12.10.

Synthetic archive: a zlib stream holding HEAD and FOOT sections. python -B tools/section_probe.py s.bin --first <F> --last FOOT:

--first Base This branch
head exit 0, "section_records": 0 exit 2, argument --first: 'head' is not a section tag: use four characters from A-Z, 0-9 and _
HEA exit 0, "section_records": 0 exit 2, same message form
HÉAD UnicodeEncodeError, exit 1 exit 2
HEAD 1 record 1 record

New test_section_probe_cli_validates_tags in tests/resource_ranges_check.py runs lowercase, short, long and non-ASCII values for both options, requires exit 2 and no traceback, then checks a valid pair still reports 1 section.

  • Base: AssertionError: 0 != 2.
  • This branch: python -B tests/resource_ranges_check.py -> Ran 20 tests ... OK.
    The documented usage (--first PSIN --last CHKS in docs/experiments.md) uses valid tags.

Evidence and follow-up

Synthetic data only. A missing archive path still raises FileNotFoundError; not changed here.

Checklist

  • One reviewable behavior.
  • Exact commands and results above.
  • Negative control: the new test fails on base.
  • No README/docs change needed.
  • No game files, dumps, links or secrets.

AI-assisted: I used Claude to find the bug and draft the change. I ran the reproductions and tests above myself.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6545455755 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/647). Originally posted by [louisdibiasi](https://github.com/louisdibiasi) on 2026-11-22T17:28:44Z. --- ## Change `tools/section_probe.py` matches sections whose four-character tags satisfy `[A-Z0-9_]{4}`, but `--first` and `--last` accepted any string. A lowercase or wrong-length tag can never match, so the run exits 0 with `"section_records": 0`, which looks the same as an archive that has no such section. A tag outside ASCII raised `UnicodeEncodeError`. This validates both options with the same pattern through an argparse `type`, so a bad tag exits with status 2 and a usage message. Independent problem, no linked issue. ## Verification Commit under test: b1faec8 on bcdce96, Windows 11, Python 3.12.10. Synthetic archive: a zlib stream holding `HEAD` and `FOOT` sections. `python -B tools/section_probe.py s.bin --first <F> --last FOOT`: | `--first` | Base | This branch | |---|---|---| | `head` | exit 0, `"section_records": 0` | exit 2, `argument --first: 'head' is not a section tag: use four characters from A-Z, 0-9 and _` | | `HEA` | exit 0, `"section_records": 0` | exit 2, same message form | | `HÉAD` | `UnicodeEncodeError`, exit 1 | exit 2 | | `HEAD` | 1 record | 1 record | New `test_section_probe_cli_validates_tags` in `tests/resource_ranges_check.py` runs lowercase, short, long and non-ASCII values for both options, requires exit 2 and no traceback, then checks a valid pair still reports 1 section. - Base: `AssertionError: 0 != 2`. - This branch: `python -B tests/resource_ranges_check.py` -> `Ran 20 tests ... OK`. The documented usage (`--first PSIN --last CHKS` in docs/experiments.md) uses valid tags. ## Evidence and follow-up Synthetic data only. A missing archive path still raises `FileNotFoundError`; not changed here. ## Checklist - [x] One reviewable behavior. - [x] Exact commands and results above. - [x] Negative control: the new test fails on base. - [x] No README/docs change needed. - [x] No game files, dumps, links or secrets. AI-assisted: I used Claude to find the bug and draft the change. I ran the reproductions and tests above myself.
upstream-sync closed this pull request 2026-11-24 06:44:08 +00:00
legacy-code-archaeologist commented 2026-11-24 06:48:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T18:27:14Z.


The description names b1faec8 as the commit under test. The current head is 39ee24a ("Use ASCII-safe diagnostics for invalid section tags", on 2bb9ee0). I re-ran the check at the head on Windows 11 26100.9168 with Python 3.12.10: python -B tests/resource_ranges_check.py reports OK. The head merges cleanly with main at 719552e.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7083613738 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/647#issuecomment-7083613738). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T18:27:14Z. --- The description names `b1faec8` as the commit under test. The current head is `39ee24a` ("Use ASCII-safe diagnostics for invalid section tags", on `2bb9ee0`). I re-ran the check at the head on Windows 11 26100.9168 with Python 3.12.10: `python -B tests/resource_ranges_check.py` reports `OK`. The head merges cleanly with `main` at `719552e`. AI-assisted (Claude Code).
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
R0Y00/Xbox2Windows!641
No description provided.