rdna2spirv: restore write mode before unlink on replace failure and publish mode on Windows in write_index (RDNA2SPIRV-INDEX-STAGE-CLEANUP) #803

Merged
trigger337 merged 1 commit from upstream-pr/803 into main 2026-11-28 11:08:19 +00:00
trigger337 commented 2026-11-24 14:00:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:00:41Z.


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

Align with the repository standard:

  1. In except BaseException, restore write permissions (try: os.chmod(tmp, 0o600); except OSError: pass) before calling os.unlink.
  2. Apply published_mode(path) 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 (11/11 in test_rdna2spirv_index_write.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473597061 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/803). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:00:41Z. --- In `tools/rdna2spirv.py`, `write_index` creates a temporary file and previously skipped applying `published_mode` on Windows because `os.unlink` in the `except BaseException` block fails with `PermissionError` (WinError 5) if `replace_retry` fails on read-only destinations. Align with the repository standard: 1. In `except BaseException`, restore write permissions (`try: os.chmod(tmp, 0o600); except OSError: pass`) before calling `os.unlink`. 2. Apply `published_mode(path)` 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 (11/11 in `test_rdna2spirv_index_write.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
MoonEyes commented 2026-11-24 14:37:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-24T14:37:33Z.


Reviewed on native Windows 11 (Python 3.14.0) and on WSL (Python 3.14.4). The diff only touches write_index; translation is unaffected.

  • python -I tests/test_rdna2spirv_index_write.py: 11 OK on Windows (1 POSIX skip), 11 OK on Linux.
  • Red before green: dropping the chmod(tmp, 0o600) fails the read-only cleanup test; restoring the os.name guard fails the Windows publish test.
  • If both replace_retry and the cleanup chmod fail, the original exception still propagates and no staging file is left.

Two notes:

  1. On main, Windows cleanup already works: the staged file was never chmod'ed there, so it stayed writable. The new read-only cleanup test passes against main's rdna2spirv.py on Windows, and a real run with a 0o444 destination raises WinError 5 and leaves no staging file on both main and this branch. Also, NamedTemporaryFile reports 0o666 on Windows, not 0o600. So on Windows the change is effectively a no-op. It is fine for consistency with #775/#777/#780/#786/#791, but the description overstates it.
  2. test_publish_applies_published_mode_on_windows only asserts that some chmod happened. Asserting that the first call targets the .index-*.tmp file with published_mode(path) would pin the behavior. Likewise, assertRaises(OSError) in the cleanup test would also pass if an error from unlink or chmod surfaced instead of the replace error.

AI-assisted review (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7134681891 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/803#issuecomment-7134681891). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-24T14:37:33Z. --- Reviewed on native Windows 11 (Python 3.14.0) and on WSL (Python 3.14.4). The diff only touches write_index; translation is unaffected. - python -I tests/test_rdna2spirv_index_write.py: 11 OK on Windows (1 POSIX skip), 11 OK on Linux. - Red before green: dropping the chmod(tmp, 0o600) fails the read-only cleanup test; restoring the os.name guard fails the Windows publish test. - If both replace_retry and the cleanup chmod fail, the original exception still propagates and no staging file is left. Two notes: 1. On main, Windows cleanup already works: the staged file was never chmod'ed there, so it stayed writable. The new read-only cleanup test passes against main's rdna2spirv.py on Windows, and a real run with a 0o444 destination raises WinError 5 and leaves no staging file on both main and this branch. Also, NamedTemporaryFile reports 0o666 on Windows, not 0o600. So on Windows the change is effectively a no-op. It is fine for consistency with #775/#777/#780/#786/#791, but the description overstates it. 2. test_publish_applies_published_mode_on_windows only asserts that some chmod happened. Asserting that the first call targets the .index-*.tmp file with published_mode(path) would pin the behavior. Likewise, assertRaises(OSError) in the cleanup test would also pass if an error from unlink or chmod surfaced instead of the replace error. AI-assisted review (Claude Code).
tiguan26 commented 2026-11-25 19:31:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T19:31:46Z.

Review: APPROVED


Approving. Merged into current main (9f9a7c5) with no conflicts. tests/test_rdna2spirv_index_write.py passes (11 tests), and the full translator suite gives 491 files / 6,312 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13).

On Windows os.chmod only toggles the read-only bit, so applying published_mode there is harmless. On the failure path, making the temp file writable again before unlink is what lets a read-only temp be removed on Windows, and the OSError guard keeps cleanup best-effort.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6063765114 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/803#pullrequestreview-6063765114). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T19:31:46Z. **Review:** APPROVED --- Approving. Merged into current main (9f9a7c5) with no conflicts. `tests/test_rdna2spirv_index_write.py` passes (11 tests), and the full translator suite gives 491 files / 6,312 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). On Windows `os.chmod` only toggles the read-only bit, so applying `published_mode` there is harmless. On the failure path, making the temp file writable again before `unlink` is what lets a read-only temp be removed on Windows, and the `OSError` guard keeps cleanup best-effort. AI-assisted (Claude).
sodove commented 2026-11-28 10:45:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:45:50Z.


#803 | head 1003de325474f9f0fe774074fa996b79e4e2367e | python3 -I tests/test_rdna2spirv_index_write.py -v | red: 11 run, 2 failures (Linux), 11 run, 1 failure, 1 skipped (Windows) | green: 11 passed (Linux), 10 passed, 1 skipped (Windows) | Red → green

Also tested native Windows publication and failure cleanup. The POSIX-only permission-bits check ran on Linux and was skipped on Windows.

Additional commands

  • py -3.12 -I tests/test_rdna2spirv_index_write.py -v

Base 3bd936ecd98995bca3e1da83d5e28d2343001aef was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native runs used Windows 11, Python 3.12.10. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238106189 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/803#issuecomment-7238106189). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T10:45:50Z. --- #803 | head `1003de325474f9f0fe774074fa996b79e4e2367e` | `python3 -I tests/test_rdna2spirv_index_write.py -v` | red: 11 run, 2 failures (Linux), 11 run, 1 failure, 1 skipped (Windows) | green: 11 passed (Linux), 10 passed, 1 skipped (Windows) | **Red → green** Also tested native Windows publication and failure cleanup. The POSIX-only permission-bits check ran on Linux and was skipped on Windows. Additional commands - `py -3.12 -I tests/test_rdna2spirv_index_write.py -v` Base `3bd936ecd98995bca3e1da83d5e28d2343001aef` was merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native runs used Windows 11, Python 3.12.10. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7237873883).
MoonEyes commented 2026-11-28 11:08:15 +00:00 (Migrated from github.com)

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


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:7238351127 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/803#issuecomment-7238351127). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T11:08:15Z. --- 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!803
No description provided.