tools/pal_stages.py: harden path validation and case-insensitive index lookup #2282

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/pal-stages-lookup-guard into main 2026-11-28 15:09:17 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 12:33:31 +00:00

Claimed in the coordination issue as: PAL-STAGES-INDEX-MESSAGE-CASE-LOOKUP-AND-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192117999)

What and why

  • Reject non-file, non-directory <path> inputs upfront in main() (tools/pal_stages.py) with an ERROR: line on stderr and exit code 2 before scanning blobs.
  • Keep optional index.json fallback resilience by catching (OSError, ValueError, RecursionError) from fssm_header.stage_index() and falling back to an empty stage map.
  • Add lookup_stage() in tools/pal_stages.py for unambiguous case-folded fallback lookup (casefold()) while leaving ambiguous case collisions unresolved (None).
  • Distinguish "no inspected blob in index.json" from "no index.json found" when total["stage_known"] == 0 in text output, matching tools/fssm_header.py.
  • Add unit tests in tests/test_pal_stages.py covering case-folded lookup, ambiguous case collisions, the index summary distinction, fallback on OSError, and non-file/non-directory path rejection.

Tested

  • python -I tests/test_pal_stages.py -v: 24 passed, 0 failed (detached upstream/main baseline with only the updated test file fails with 1 failure and 2 errors).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/pal_stages.py tests/test_pal_stages.py, and git diff --cached --check: passed.

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.
Claimed in the coordination issue as: PAL-STAGES-INDEX-MESSAGE-CASE-LOOKUP-AND-PATH-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7192117999) ### What and why - Reject non-file, non-directory `<path>` inputs upfront in `main()` (`tools/pal_stages.py`) with an `ERROR:` line on stderr and exit code `2` before scanning blobs. - Keep optional `index.json` fallback resilience by catching `(OSError, ValueError, RecursionError)` from `fssm_header.stage_index()` and falling back to an empty stage map. - Add `lookup_stage()` in `tools/pal_stages.py` for unambiguous case-folded fallback lookup (`casefold()`) while leaving ambiguous case collisions unresolved (`None`). - Distinguish `"no inspected blob in index.json"` from `"no index.json found"` when `total["stage_known"] == 0` in text output, matching `tools/fssm_header.py`. - Add unit tests in `tests/test_pal_stages.py` covering case-folded lookup, ambiguous case collisions, the index summary distinction, fallback on `OSError`, and non-file/non-directory path rejection. ### Tested - `python -I tests/test_pal_stages.py -v`: 24 passed, 0 failed (detached `upstream/main` baseline with only the updated test file fails with 1 failure and 2 errors). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/pal_stages.py tests/test_pal_stages.py`, and `git diff --cached --check`: passed. 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.
DeadlyChirp commented 2026-11-26 12:51:40 +00:00

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

  • tests/test_pal_stages.py: 24 passed (main: 21 passed).

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

Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_pal_stages.py`: 24 passed (main: 21 passed). (AI-assisted test run; output checked by hand.)
tiguan26 approved these changes 2026-11-27 04:39:18 +00:00
tiguan26 left a comment

Approving 7e188ec40.

A stem missing exactly falls back to a case-folded match only when exactly one key folds to it, a path that is neither file nor folder is a usage error, an unreadable or malformed index is reported instead of raised, and the note says whether the index was missing or just had no inspected blob.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_pal_stages.py: 24 passed (main: 21). AI-assisted (Claude Code, Claude Opus 5.5).

Approving 7e188ec40. A stem missing exactly falls back to a case-folded match only when exactly one key folds to it, a path that is neither file nor folder is a usage error, an unreadable or malformed index is reported instead of raised, and the note says whether the index was missing or just had no inspected blob. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_pal_stages.py`: 24 passed (main: 21). AI-assisted (Claude Code, Claude Opus 5.5).
MSedgeMC reviewed 2026-11-27 15:30:52 +00:00
MSedgeMC left a comment
No description provided.
Verified on the PR branch: python3 -m unittest tests.test_pal_stages -v -> 24 tests OK, including the new path-validation and case-insensitive-index cases. Not approving yet: the branch is 446 commits behind current main, so a rebase is needed before the final diff can be reviewed.
MoonEyes commented 2026-11-28 15:09:14 +00:00

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head 7e188ec40cd9 unchanged since 2026-11-26, before that run.
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: classified READY by oreo-lot3 (red on main b1619e0a3, green on head merged with main); head 7e188ec40cd9 unchanged since 2026-11-26, before that run. Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.