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

Open
github-bot wants to merge 1 commit from github-bot/gh-1769 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-25 11:45 UTC · original
kirigayakazima:fix/navmesh-index-error-handling-and-cleanup → main · +112 −19 · 2 files · 1 commits · open

Claimed in the coordination issue as: NAVMESH-INDEX-ERROR-HANDLING-AND-CLEANUP #1608

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 11:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1769) `kirigayakazima:fix/navmesh-index-error-handling-and-cleanup` → `main` · +112 −19 · 2 files · 1 commits · open Claimed in the coordination issue as: NAVMESH-INDEX-ERROR-HANDLING-AND-CLEANUP https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:18 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 18:44 UTC · original

Reviewed 6de3ecb: ran all of tests/test_navmesh_index.py on this branch (38 tests OK, 1 pre-existing environmental skip) and the same file against main - all four new tests fail there, each covering one of the fixes, while every existing test still passes on both trees. Also ran a 12-case end-to-end CLI matrix and a 110-case is_scanned_input pattern matrix (nested files, hard links, .. spellings) on both trees: no overwrite-guard regression (PR refusals are a strict superset of main's, scan sets identical), the temp-cleanup split behaves, and the unwritable-output cases exit 2 with ERROR: instead of a traceback. Windows-only paths were not run. One nit: ERROR: cannot write can name the staging temp path (e.filename) rather than the destination.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 18:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1769#issuecomment-7171333101) Reviewed 6de3ecb: ran all of tests/test_navmesh_index.py on this branch (38 tests OK, 1 pre-existing environmental skip) and the same file against main - all four new tests fail there, each covering one of the fixes, while every existing test still passes on both trees. Also ran a 12-case end-to-end CLI matrix and a 110-case is_scanned_input pattern matrix (nested files, hard links, `..` spellings) on both trees: no overwrite-guard regression (PR refusals are a strict superset of main's, scan sets identical), the temp-cleanup split behaves, and the unwritable-output cases exit 2 with `ERROR:` instead of a traceback. Windows-only paths were not run. One nit: `ERROR: cannot write` can name the staging temp path (`e.filename`) rather than the destination. AI-assisted review. **Recommendation:** Merge
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1769/head:github-bot/gh-1769'
git switch 'github-bot/gh-1769'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1769'
git switch 'github-bot/gh-1769'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1769'
git switch 'github-bot/gh-1769'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1769'
git switch 'main'
git merge --squash 'github-bot/gh-1769'
git switch 'main'
git merge --ff-only 'github-bot/gh-1769'
git switch 'main'
git merge 'github-bot/gh-1769'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.