NAVMESH-TILE-STAGE-CLEANUP: harden staged OBJ output and cleanup #906

Merged
fitzypopper merged 1 commit from upstream-pr/906 into main 2026-11-28 07:45:08 +00:00
fitzypopper commented 2026-11-24 15:09:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fitzypopper on 2026-11-24T15:09:08Z.


Claimed in the coordination issue as: NAVMESH-TILE-STAGE-CLEANUP (claim comment).

tools/navmesh_tile_obj.py wrote its staged OBJ with NamedTemporaryFile's mode and, on a failed os.replace, deleted the staged file in finally without making it writable first. On Windows a staged file carrying a read-only destination's mode cannot be unlinked, so the cleanup error masks the real ERROR: line. This publishes the staged file with published_mode(out) and, on failure, chmods it to 0o600 before unlinking, with both cleanup failures suppressed so the original error survives.

New tests/test_navmesh_tile_stage_cleanup.py patches os.replace to fail and asserts the staged file is made writable, removed, and the previous output is left intact. Verified red on origin/main and green with this change.

No game data: synthetic navmesh archive only. python3 -I scripts/check_no_game_data.py passes; line-ending test passes.

AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474811354 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/906). Originally posted by [fitzypopper](https://github.com/fitzypopper) on 2026-11-24T15:09:08Z. --- Claimed in the coordination issue as: `NAVMESH-TILE-STAGE-CLEANUP` ([claim comment](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135525133)). `tools/navmesh_tile_obj.py` wrote its staged OBJ with `NamedTemporaryFile`'s mode and, on a failed `os.replace`, deleted the staged file in `finally` without making it writable first. On Windows a staged file carrying a read-only destination's mode cannot be unlinked, so the cleanup error masks the real `ERROR:` line. This publishes the staged file with `published_mode(out)` and, on failure, chmods it to `0o600` before unlinking, with both cleanup failures suppressed so the original error survives. New `tests/test_navmesh_tile_stage_cleanup.py` patches `os.replace` to fail and asserts the staged file is made writable, removed, and the previous output is left intact. Verified red on `origin/main` and green with this change. No game data: synthetic navmesh archive only. `python3 -I scripts/check_no_game_data.py` passes; line-ending test passes. AI-assisted: yes.
PierreEbele commented 2026-11-25 21:13:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T21:13:47Z.


Reviewed d4019e4: navmesh_tile_obj now publishes with the destination's mode (file_mode.published_mode, like the ~20 tools already on main) and its failed-replace cleanup chmods the staged file 0o600 before unlink. I ran this on Linux with a synthetic archive only: the new test passes here and fails on main (no chmod recorded), test_navmesh_tile_obj.py and test_navmesh_decode.py pass on both, and an unmocked probe shows an existing 0o444 OBJ keeping its bits after export (main silently rewrote it to 0600) while a new OBJ gets the umask bits; failed replaces stay rc 2 with the real error, destination untouched, no leftovers on either tree. The Windows unlink-of-read-only claim is covered by the mocked call-order test only. No findings. AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174787038 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/906#issuecomment-7174787038). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T21:13:47Z. --- Reviewed d4019e4: navmesh_tile_obj now publishes with the destination's mode (file_mode.published_mode, like the ~20 tools already on main) and its failed-replace cleanup chmods the staged file 0o600 before unlink. I ran this on Linux with a synthetic archive only: the new test passes here and fails on main (no chmod recorded), test_navmesh_tile_obj.py and test_navmesh_decode.py pass on both, and an unmocked probe shows an existing 0o444 OBJ keeping its bits after export (main silently rewrote it to 0600) while a new OBJ gets the umask bits; failed replaces stay rc 2 with the real error, destination untouched, no leftovers on either tree. The Windows unlink-of-read-only claim is covered by the mocked call-order test only. No findings. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-28 07:45:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T07:45:03Z.


Red/green: the new test fails on main and passes with this PR (1 passed).
Full suite with this PR merged together with seven others in one batch matches main (pytest, translator suite, ctest without the game) on Windows 11 with an RTX 4060, except xmem_write_watch, a test that depends on free host memory and has also failed on plain main.
AI-assisted (Claude Code, Claude Opus 5.5). Thank you!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236138812 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/906#issuecomment-7236138812). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T07:45:03Z. --- Red/green: the new test fails on main and passes with this PR (1 passed). Full suite with this PR merged together with seven others in one batch matches main (pytest, translator suite, ctest without the game) on Windows 11 with an RTX 4060, except xmem_write_watch, a test that depends on free host memory and has also failed on plain main. AI-assisted (Claude Code, Claude Opus 5.5). Thank you!
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!906
No description provided.