mission_tables: restore write mode before unlink on replace failure and publish mode on Windows (MISSION-TABLES-STAGE-CLEANUP) #788

Merged
leonida/mandy
trigger337 merged 1 commit from fix/mission-tables-stage-cleanup into main 2026-11-28 11:06:23 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 13:50:18 +00:00

In tools/mission_tables.py, write_json creates a temporary 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_path, 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 (27/27 in test_mission_tables.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

In `tools/mission_tables.py`, `write_json` creates a temporary 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_path, 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 (27/27 in `test_mission_tables.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
tiguan26 approved these changes 2026-11-25 04:00:40 +00:00
tiguan26 left a comment

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).

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:25:23 +00:00

Reviewed 0bb217f: I ran the mission_tables suite on the PR tree (27 OK) and on a main worktree (25 OK, 27 with your test file). Only test_publish_applies_published_mode_on_windows fails on main; the cleanup test passes on origin/main too. Probes show why: write_json's os.open(destination, os.O_WRONLY) pre-check (line 565) refuses a read-only destination before any staging (0 replace_retry calls, no staged file), and msvcrt's open on Windows honors the read-only attribute the same way, so the stranded-read-only-stage scenario this PR guards cannot occur for this tool - the chmod 0o600 cleanup is unreachable in every normal environment. The unconditional published_mode chmod is fine and matches navmesh_index/bvh_index, but the cleanup half needs a test that actually reaches it (mock the pre-check) or should be dropped. AI-assisted review.

Recommendation: Fix first

Reviewed 0bb217f: I ran the mission_tables suite on the PR tree (27 OK) and on a main worktree (25 OK, 27 with your test file). Only test_publish_applies_published_mode_on_windows fails on main; the cleanup test passes on origin/main too. Probes show why: write_json's os.open(destination, os.O_WRONLY) pre-check (line 565) refuses a read-only destination before any staging (0 replace_retry calls, no staged file), and msvcrt's open on Windows honors the read-only attribute the same way, so the stranded-read-only-stage scenario this PR guards cannot occur for this tool - the chmod 0o600 cleanup is unreachable in every normal environment. The unconditional published_mode chmod is fine and matches navmesh_index/bvh_index, but the cleanup half needs a test that actually reaches it (mock the pre-check) or should be dropped. AI-assisted review. **Recommendation:** Fix first
tiguan26 commented 2026-11-26 06:58:58 +00:00

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).

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:06:18 +00:00

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)

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 description provided.