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

Open
opened 2026-11-26 21:20:41 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2282
Author: @kirigayakazima
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/pal-stages-lookup-guard


📝 Commits (1)

  • 7e188ec tools/pal_stages.py: guard path type, fold stem lookup safely, and clarify index message

📊 Changes

2 files changed (+75 additions, -3 deletions)

View changed files

📝 tests/test_pal_stages.py (+59 -0)
📝 tools/pal_stages.py (+16 -3)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2282 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/pal-stages-lookup-guard` --- ### 📝 Commits (1) - [`7e188ec`](https://github.com/ubiquitarianism/leonida/commit/7e188ec40cd9cd0c175672e655dd7a42ee02bf7b) tools/pal_stages.py: guard path type, fold stem lookup safely, and clarify index message ### 📊 Changes **2 files changed** (+75 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_pal_stages.py` (+59 -0) 📝 `tools/pal_stages.py` (+16 -3) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2287
No description provided.