awc_names: restore write mode before unlink on replace failure and publish mode on Windows (AWC-NAMES-STAGE-CLEANUP) #780

Merged
trigger337 merged 1 commit from upstream-pr/780 into main 2026-11-28 11:04:52 +00:00
trigger337 commented 2026-11-24 13:44:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T13:44:44Z.


In tools/awc_names.py, _publish_text creates a temporary staging file and previously skipped applying published_mode on Windows because os.unlink in the finally block fails with PermissionError (WinError 5) if replace_retry fails on read-only destinations.

Align with the repository standard:

  1. In finally, restore write permissions (try: os.chmod(staged.name, 0o600); except OSError: pass) before unlinking.
  2. Apply published_mode(destination) unconditionally so Windows outputs receive proper permissions instead of keeping NamedTemporaryFile's default 0o600 mode.
  3. Add synthetic regression tests verifying PermissionError handling and Windows published_mode application.

Tests pass (38/38 in test_awc_names.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473329691 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/780). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T13:44:44Z. --- In `tools/awc_names.py`, `_publish_text` creates a temporary staging file and previously skipped applying `published_mode` on Windows because `os.unlink` in the `finally` block fails with `PermissionError` (WinError 5) if `replace_retry` fails on read-only destinations. Align with the repository standard: 1. In `finally`, restore write permissions (`try: os.chmod(staged.name, 0o600); except OSError: pass`) before unlinking. 2. Apply `published_mode(destination)` unconditionally so Windows outputs receive proper permissions instead of keeping `NamedTemporaryFile`'s default `0o600` mode. 3. Add synthetic regression tests verifying `PermissionError` handling and Windows `published_mode` application. Tests pass (38/38 in `test_awc_names.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
tiguan26 commented 2026-11-25 04:00:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T04:00:57Z.

Review: APPROVED


Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed; and the published mode now also applies on Windows (the os.name guard is gone), using file_mode.published_mode. Only the staging/permission lines change.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051674440 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/780#pullrequestreview-6051674440). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T04:00:57Z. **Review:** APPROVED --- Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed; and the published mode now also applies on Windows (the os.name guard is gone), using file_mode.published_mode. Only the staging/permission lines change. AI-assisted (Claude).
PierreEbele commented 2026-11-25 20:13:17 +00:00 (Migrated from github.com)

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


Reviewed e006e1f: I ran tests/test_awc_names.py on this branch (38 pass, 1 pre-existing Windows skip), on main with your test file copied in, plus test_awc_manifest.py, test_joaat_agreement.py, py_compile and check_no_game_data.py (all clean), and probes against main on Linux. The fix is real when the staged file is read-only - main leaves .awc_names-*.tmp stranded and surfaces the unlink Access-Denied instead of the replace error, this branch cleans up and keeps the original error - but the new read-only test never reaches that path: its 0o444 report is refused at the os.open(destination, os.O_WRONLY) pre-check (awc_names.py:400) before anything is staged, so it passes on main too, and CI's non-root runner is vacuous the same way. Please make it reach the staged path (writable report + published_mode returning 0o444, or patch the pre-check open), and in the os.name="nt" test assert the staged file's mode: len(chmod_calls) > 0 is also met by the new finally chmod(0o600) after a successful replace, so it would not catch re-adding the nt guard. Consider suppress(OSError) around the cleanup chmod+unlink as navmesh_index/bvh_index/mask_channels do. AI-assisted review.

Recommendation: Fix first

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7173354654 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/780#issuecomment-7173354654). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T20:13:17Z. --- Reviewed e006e1f: I ran tests/test_awc_names.py on this branch (38 pass, 1 pre-existing Windows skip), on main with your test file copied in, plus test_awc_manifest.py, test_joaat_agreement.py, py_compile and check_no_game_data.py (all clean), and probes against main on Linux. The fix is real when the staged file is read-only - main leaves `.awc_names-*.tmp` stranded and surfaces the unlink Access-Denied instead of the replace error, this branch cleans up and keeps the original error - but the new read-only test never reaches that path: its 0o444 report is refused at the `os.open(destination, os.O_WRONLY)` pre-check (awc_names.py:400) before anything is staged, so it passes on main too, and CI's non-root runner is vacuous the same way. Please make it reach the staged path (writable report + `published_mode` returning 0o444, or patch the pre-check open), and in the `os.name="nt"` test assert the staged file's mode: `len(chmod_calls) > 0` is also met by the new `finally` chmod(0o600) after a successful replace, so it would not catch re-adding the nt guard. Consider `suppress(OSError)` around the cleanup chmod+unlink as navmesh_index/bvh_index/mask_channels do. AI-assisted review. **Recommendation:** Fix first
tiguan26 commented 2026-11-26 06:58:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-26T06:58:50Z.


Confirming @PierreEbele's finding, and why my approval missed it. I ran the PR's test file against main's tool, and the cleanup test (..._replace_fails_even_if_readonly) did fail there. But this workspace runs as root, and root opens a 0o444 file for writing anyway, so it gets past the pre-stage os.open(destination, os.O_WRONLY) check and into the staged-file cleanup. As a normal user on Linux, and on Windows where the read-only attribute is honoured, that check refuses the destination before anything is staged, so the test passes on main too and doesn't pin the fix. The code change is still right where it can be reached. The test needs a writable destination with the published mode forced to 0o444 (as the review suggests) to fail on main for everyone. AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7184972743 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/780#issuecomment-7184972743). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-26T06:58:50Z. --- Confirming @PierreEbele's finding, and why my approval missed it. I ran the PR's test file against main's tool, and the cleanup test (`..._replace_fails_even_if_readonly`) did fail there. But this workspace runs as root, and root opens a 0o444 file for writing anyway, so it gets past the pre-stage `os.open(destination, os.O_WRONLY)` check and into the staged-file cleanup. As a normal user on Linux, and on Windows where the read-only attribute is honoured, that check refuses the destination before anything is staged, so the test passes on main too and doesn't pin the fix. The code change is still right where it can be reached. The test needs a writable destination with the published mode forced to 0o444 (as the review suggests) to fail on main for everyone. AI-assisted (Claude).
MoonEyes commented 2026-11-28 11:04:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T11:04:43Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238312540 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/780#issuecomment-7238312540). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T11:04:43Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
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!780
No description provided.