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

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/navmesh-index-error-handling-and-cleanup into main 2026-11-28 13:27:20 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-25 11:45:34 +00:00

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)
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)
PierreEbele commented 2026-11-25 18:44:38 +00:00

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

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
MoonEyes commented 2026-11-28 13:27:23 +00:00

Merged after local re-verification: this PR merged onto main 7ce011205 without conflict, and its test file(s) (tests/test_navmesh_index.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

Merged after local re-verification: this PR merged onto `main` 7ce011205 without conflict, and its test file(s) (`tests/test_navmesh_index.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No description provided.