[PR #1769] navmesh_index: report missing input before mode checks, handle write OSError, separate cleanup guards, and align pattern matching (NAVMESH-INDEX-ERROR-HANDLING-AND-CLEANUP) #1781

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

📋 Pull Request Information

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

Base: main ← Head: fix/navmesh-index-error-handling-and-cleanup


📝 Commits (1)

  • 6de3ecb navmesh_index: report missing input before mode checks, handle write OSError, separate chmod/unlink cleanup, and align pattern matching

📊 Changes

2 files changed (+112 additions, -19 deletions)

View changed files

📝 tests/test_navmesh_index.py (+81 -0)
📝 tools/navmesh_index.py (+31 -19)

📄 Description

Claimed in the coordination issue as: NAVMESH-INDEX-ERROR-HANDLING-AND-CLEANUP https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161419600

What and why

Fixes four bugs in tools/navmesh_index.py (plus drops the duplicate sys.path.insert):

  1. Check os.path.exists(a.input) before archive/directory mode checks: Nonexistent paths with --pattern previously fell into not is_dir and exited with --pattern applies to a directory, not an archive instead of ERROR: <path>: does not exist. (--out/--csv equality and isdir checks remain first, preserving test_explicit_output_collision_before_scan.)
  2. Handle write_outputs OSError cleanly: Wrap write_outputs(...) in try/except OSError printing one ERROR: cannot write ... line and returning exit 2 without a Python traceback (keeping write_outputs's own OSError contract intact for unit callers).
  3. Separate os.chmod(temp, 0o600) and os.unlink(temp) cleanup guards in _publish: Use two separate with suppress(OSError): blocks so a failing chmod during exception cleanup does not skip unlinking temp.
  4. Align is_scanned_input pattern matching with scan_directory: Share _pattern_query (normalizing altsep and prepending ** only once) between scan_directory and is_scanned_input, and normalize altsep / leading **/ in is_scanned_input's fnmatch branch.

Adds 4 regression tests in tests/test_navmesh_index.py.

Tested

Windows 11 x64 (10.0.26100), Python 3.14.7, CPU only, synthetic 0DRP/RPF9 fixtures only (no game files). Commit 6de3ecb759c9bc180d2422aa646b283d86f677a2.

  • python -I tests/test_navmesh_index.py -v:
    • against main (bcaa13da) with all 38 tests: 4 failures, 1 skipped (existing POSIX permission test);
    • with the fix: 38 tests, OK (1 skipped) (only existing test_replaced_report_keeps_its_permission_bits skipped on Windows).
  • python -I tests/test_ci_registration.py: 16 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/navmesh_index.py tests/test_navmesh_index.py, python -m compileall -q tools tests, git diff --check: exit 0.

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. (n/a: no translator change)

🔄 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/1769 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/navmesh-index-error-handling-and-cleanup` --- ### 📝 Commits (1) - [`6de3ecb`](https://github.com/ubiquitarianism/leonida/commit/6de3ecb759c9bc180d2422aa646b283d86f677a2) navmesh_index: report missing input before mode checks, handle write OSError, separate chmod/unlink cleanup, and align pattern matching ### 📊 Changes **2 files changed** (+112 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_navmesh_index.py` (+81 -0) 📝 `tools/navmesh_index.py` (+31 -19) </details> ### 📄 Description Claimed in the coordination issue as: NAVMESH-INDEX-ERROR-HANDLING-AND-CLEANUP https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161419600 ### What and why Fixes four bugs in `tools/navmesh_index.py` (plus drops the duplicate `sys.path.insert`): 1. **Check `os.path.exists(a.input)` before archive/directory mode checks**: Nonexistent paths with `--pattern` previously fell into `not is_dir` and exited with `--pattern applies to a directory, not an archive` instead of `ERROR: <path>: does not exist`. (`--out`/`--csv` equality and `isdir` checks remain first, preserving `test_explicit_output_collision_before_scan`.) 2. **Handle `write_outputs` `OSError` cleanly**: Wrap `write_outputs(...)` in `try/except OSError` printing one `ERROR: cannot write ...` line and returning exit `2` without a Python traceback (keeping `write_outputs`'s own `OSError` contract intact for unit callers). 3. **Separate `os.chmod(temp, 0o600)` and `os.unlink(temp)` cleanup guards in `_publish`**: Use two separate `with suppress(OSError):` blocks so a failing `chmod` during exception cleanup does not skip unlinking `temp`. 4. **Align `is_scanned_input` pattern matching with `scan_directory`**: Share `_pattern_query` (normalizing `altsep` and prepending `**` only once) between `scan_directory` and `is_scanned_input`, and normalize `altsep` / leading `**/` in `is_scanned_input`'s `fnmatch` branch. Adds 4 regression tests in `tests/test_navmesh_index.py`. ### Tested Windows 11 x64 (`10.0.26100`), Python `3.14.7`, CPU only, synthetic `0DRP`/RPF9 fixtures only (no game files). Commit `6de3ecb759c9bc180d2422aa646b283d86f677a2`. - `python -I tests/test_navmesh_index.py -v`: - against `main` (`bcaa13da`) with all 38 tests: **4 failures, 1 skipped** (existing POSIX permission test); - with the fix: **38 tests, OK (1 skipped)** (only existing `test_replaced_report_keeps_its_permission_bits` skipped on Windows). - `python -I tests/test_ci_registration.py`: **16 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/navmesh_index.py tests/test_navmesh_index.py`, `python -m compileall -q tools tests`, `git diff --check`: exit `0`. 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. (n/a: no translator change) --- <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#1781
No description provided.