rpf_probe: restore write mode before unlink on replace failure and publish mode on Windows (RPF-PROBE-STAGE-CLEANUP) #792

Open
trigger337 wants to merge 4 commits from upstream-pr/792 into main
trigger337 commented 2026-11-24 13:52:23 +00:00 (Migrated from github.com)

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


In tools/rpf_probe.py, _write_json_report 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.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 (32/32 in test_rpf_probe.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473454564 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T13:52:23Z. --- In `tools/rpf_probe.py`, `_write_json_report` 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.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 (32/32 in `test_rpf_probe.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
tiguan26 commented 2026-11-25 03:59:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:59:58Z.

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:6051667902 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#pullrequestreview-6051667902). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:59:58Z. **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:33:29 +00:00 (Migrated from github.com)

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


Reviewed ee50881: I ran python -I tests/test_rpf_probe.py on the PR (32/32) and on main (30/30), and reran the PR's test file on main (only test_publish_applies_published_mode_on_windows fails there); check_no_game_data.py is clean. The fix works: a probe with a writable destination, published mode forced to 0o444 and a mocked replace failure strands a read-only .rpf_probe-*.tmp on main and re-raises the unlink PermissionError naming the temp file instead of the replace error (Windows unlink simulated); the PR deletes the staged file and raises the original error. One issue: the new cleanup test is vacuous in any unprivileged run, including CI - the read-only report it sets up is refused by the pre-flight open() (tools/rpf_probe.py:50) before staging, so nothing is staged and it passes on main too (probe: 0 staged files on both trees). Please force the path: keep the destination writable and patch published_mode to return 0o444. AI-assisted review.

Recommendation: Fix first

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7173848570 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/792#issuecomment-7173848570). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T20:33:29Z. --- Reviewed ee50881: I ran `python -I tests/test_rpf_probe.py` on the PR (32/32) and on main (30/30), and reran the PR's test file on main (only `test_publish_applies_published_mode_on_windows` fails there); `check_no_game_data.py` is clean. The fix works: a probe with a writable destination, published mode forced to 0o444 and a mocked replace failure strands a read-only `.rpf_probe-*.tmp` on main and re-raises the unlink `PermissionError` naming the temp file instead of the replace error (Windows unlink simulated); the PR deletes the staged file and raises the original error. One issue: the new cleanup test is vacuous in any unprivileged run, including CI - the read-only report it sets up is refused by the pre-flight open() (tools/rpf_probe.py:50) before staging, so nothing is staged and it passes on main too (probe: 0 staged files on both trees). Please force the path: keep the destination writable and patch `published_mode` to return 0o444. AI-assisted review. **Recommendation:** Fix first
tiguan26 commented 2026-11-26 06:59:03 +00:00 (Migrated from github.com)

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


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:7184976255 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/792#issuecomment-7184976255). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-26T06:59:03Z. --- 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).
zmasi commented 2026-11-28 22:00:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:00:44Z.


Native Windows 11 NTFS Verification (2baf41b399)

Verified 2baf41b399f615945341264b3e045a368d652ec5 merged cleanly onto origin/main (c7753ed98a56677f10e34078b37eab0540e190ec, git merge-tree --write-tree rc=0) on native Windows 11 (26200) + NTFS:

  • Red (origin/main c7753ed98a): python -I tests/test_rpf_probe.py failed (FAILED (failures=1, skipped=5) — os.chmod(staged.name, published_mode(destination)) was skipped under os.name == "nt").
  • Green (origin/main + 2baf41b399):
    • python -I tests/test_rpf_probe.py: 35 ran, OK (skipped=5).
    • Live unmocked Windows 11 NTFS stat.S_IREAD probe: Created a read-only report.json (stat.S_IREAD) on NTFS and invoked rpf_probe._write_json_report(report, ...): os.chmod(staged.name, 0o444) + replace_retry raised the expected PermissionError cleanly without any secondary PermissionError from finally: os.unlink(staged.name) (os.chmod(staged.name, 0o600) cleared FILE_ATTRIBUTE_READONLY first), left 0 .rpf_probe-* staged files, and preserved the existing read-only report.json byte-for-byte.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246432602 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7246432602). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:00:44Z. --- ### Native Windows 11 NTFS Verification (`2baf41b399`) Verified `2baf41b399f615945341264b3e045a368d652ec5` merged cleanly onto `origin/main` (`c7753ed98a56677f10e34078b37eab0540e190ec`, `git merge-tree --write-tree` `rc=0`) on native **Windows 11 (`26200`) + NTFS**: - **Red (`origin/main` `c7753ed98a`)**: `python -I tests/test_rpf_probe.py` failed (`FAILED (failures=1, skipped=5)` — `os.chmod(staged.name, published_mode(destination))` was skipped under `os.name == "nt"`). - **Green (`origin/main + 2baf41b399`)**: - `python -I tests/test_rpf_probe.py`: **`35 ran, OK (skipped=5)`**. - **Live unmocked Windows 11 NTFS `stat.S_IREAD` probe**: Created a read-only `report.json` (`stat.S_IREAD`) on NTFS and invoked `rpf_probe._write_json_report(report, ...)`: `os.chmod(staged.name, 0o444)` + `replace_retry` raised the expected `PermissionError` cleanly without any secondary `PermissionError` from `finally: os.unlink(staged.name)` (`os.chmod(staged.name, 0o600)` cleared `FILE_ATTRIBUTE_READONLY` first), left **`0` `.rpf_probe-*` staged files**, and preserved the existing read-only `report.json` byte-for-byte. AI-assisted.
OreoFR commented 2026-11-29 01:31:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:31:44Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (MainTests.test_publish_applies_published_mode_on_windows) / green 35 OK.

  • PR head 2baf41b39, python -I tests/test_rpf_probe.py from the repository root.
  • Red (main + only this PR's test files): 35 run, 1 failure, 0 skips. AssertionError: False is not true, the published mode is not applied.
  • Green (main + git merge --no-ff of this PR, no conflict): 35 run, OK, 0 skips.
  • Skips: none.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-792 -- tests/test_rpf_probe.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.

AI-assisted: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248841187 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7248841187). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:31:44Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (`MainTests.test_publish_applies_published_mode_on_windows`) / green 35 OK. - PR head 2baf41b39, `python -I tests/test_rpf_probe.py` from the repository root. - Red (main + only this PR's test files): 35 run, 1 failure, 0 skips. `AssertionError: False is not true`, the published mode is not applied. - Green (main + `git merge --no-ff` of this PR, no conflict): 35 run, OK, 0 skips. - Skips: none. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-792 -- tests/test_rpf_probe.py`); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched. AI-assisted: Claude Code (Claude Opus 5.5).
OreoFR commented 2026-11-29 08:34:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T08:34:23Z.


Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7248841187

The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253191600 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7253191600). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:34:23Z. --- Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7248841187 The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up. AI-assisted: Claude Code
TheGeogeo commented 2026-11-29 19:07:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T19:07:13Z.


Tested f36871d6e merged (no commit) with main dd87aa405: Python 3.12.4, Windows 11 10.0.26300, CPU only.

  • Green: tests/test_rpf_probe.py gives 33 of 35 tests OK. 2 are skipped here, both tests that already exist on main: test_failed_write_preserves_the_existing_report ("requires a POSIX file size limit") and test_refresh_preserves_private_report_permissions ("POSIX permission bits"). This PR's new tests ran.
  • Red: with tools/rpf_probe.py back to main, test_publish_applies_published_mode_on_windows fails.
  • Base: main's own version of that test gives 31 of 33 tests OK, with the same 2 skipped. check_no_game_data.py is clean.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7261023612 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7261023612). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T19:07:13Z. --- Tested `f36871d6e` merged (no commit) with `main` `dd87aa405`: Python 3.12.4, Windows 11 10.0.26300, CPU only. - Green: `tests/test_rpf_probe.py` gives 33 of 35 tests OK. 2 are skipped here, both tests that already exist on `main`: `test_failed_write_preserves_the_existing_report` ("requires a POSIX file size limit") and `test_refresh_preserves_private_report_permissions` ("POSIX permission bits"). This PR's new tests ran. - Red: with `tools/rpf_probe.py` back to `main`, `test_publish_applies_published_mode_on_windows` fails. - Base: `main`'s own version of that test gives 31 of 33 tests OK, with the same 2 skipped. `check_no_game_data.py` is clean. AI-assisted (Claude Code).
trigger337 commented 2026-11-30 10:41:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-30T10:41:10Z.


@OreoFR Merged latest main and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 35 tests pass.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275937542 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7275937542). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-30T10:41:10Z. --- @OreoFR Merged latest `main` and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 35 tests pass. AI-assisted: yes
aslan2142 commented 2026-12-01 11:38:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:38:45Z.

Review: CHANGES_REQUESTED


Reviewed the diff against main: the production fix in tools/rpf_probe.py:64-73 is sound, but there are two issues to address before merge:

  • Weak test assertion (tests/test_rpf_probe.py:420-431): Because _write_json_report's finally: block unconditionally calls os.chmod(staged.name, 0o600), track_chmod records that call even if published_mode were skipped under os.name == "nt". Please assert that the published mode (e.g., patching published_mode to 0o640, as in #779) is applied to the staged file.
  • Stale CI failure: Please merge/rebase current main so CI re-runs cleanly without the old main failure.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130469534 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#pullrequestreview-6130469534). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:38:45Z. **Review:** CHANGES_REQUESTED --- Reviewed the diff against `main`: the production fix in `tools/rpf_probe.py:64-73` is sound, but there are two issues to address before merge: - **Weak test assertion (`tests/test_rpf_probe.py:420-431`):** Because `_write_json_report`'s `finally:` block unconditionally calls `os.chmod(staged.name, 0o600)`, `track_chmod` records that call even if `published_mode` were skipped under `os.name == "nt"`. Please assert that the published mode (e.g., patching `published_mode` to `0o640`, as in `#779`) is applied to the staged file. - **Stale CI failure:** Please merge/rebase current `main` so CI re-runs cleanly without the old `main` failure. *(AI-assisted review.)*
enlight3d commented 2026-12-02 10:17:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-02T10:17:47Z.


RUN (independent run on Windows, #792 head 18d871a99, merged locally into main a917c54d6 with git merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) This run looks at what changes on Windows with real files.

  • python -I tests/test_rpf_probe.py -v: main 33 tests OK (2 skipped, POSIX only); merge 35 tests OK (the same 2 skipped).
  • python -m pytest on tests/test_rpf_probe.py tests/test_report_paths.py (the files that name rpf_probe): main 57 passed / 2 skipped; merge 59 passed / 2 skipped.
  • Red on Windows: main's tools/rpf_probe.py with this pull request's test file gives 35 tests (2 skipped) and 1 failure, test_publish_applies_published_mode_on_windows ("expected published_mode 0o640 to be applied, got []"). This red comes from an assertion on the os.chmod calls, with published_mode mocked. test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly passes on main too.
  • Native probes on NTFS, calling rpf_probe._write_json_report directly, with no mocks unless stated:
    • Read-only existing report. This is the setup of the new cleanup test, with replace_retry mocked to fail as in that test. main and the merge both raise PermissionError at os.close(os.open(destination, os.O_WRONLY)), the permission check that runs before staging. replace_retry is called 0 times and no staged file is created. So the new cleanup test never reaches the staged-file path it is named for. On POSIX, a run that is not root hits the same EACCES at that line. The check has been in main since 23 November, before this pull request.
    • New report: the file the tool writes and a file made with plain open() in the same folder have the same mode (0o666) and the same ACL (icacls, 4 entries, identical). On Windows, NamedTemporaryFile's 0600 only leaves the read-only attribute clear, and the staged file is not private. So the body's point that Windows outputs "retained NamedTemporaryFile's private 0600 permissions" does not hold here. Applying published_mode on Windows can only set or clear the read-only attribute, and the check above refuses a read-only destination. So it has no visible effect on a write that succeeds.
    • Staged path forced: a writable report, published_mode mocked to 0o444, replace_retry mocked to fail, and the real os.unlink. main leaves 0 staged files, because it never runs the chmod on Windows. The merge also leaves 0, because the new os.chmod(staged.name, 0o600) before the unlink works.
  • Mutations of the merge's tools/rpf_probe.py, each run with the whole test file and the forced probe, and restored afterwards (git status clean):
    • if os.name != "nt": put back around the chmod, which is main's behaviour: killed (1 failure, the published-mode test).
    • The new os.chmod(staged.name, 0o600) in finally removed: survives the test file (all OK). With the forced probe it raises PermissionError: [WinError 5] from os.unlink(staged.name) in finally, which hides the replace error, and leaves 1 staged .rpf_probe-*.tmp behind. So the restore is needed once the chmod runs on Windows, but no test pins it.
  • Suggestion: make the cleanup test reach the staged path. Use a writable report, patch published_mode to 0o444 and replace_retry to fail, and keep the strict-unlink emulation for POSIX. On Windows, the real unlink already refuses a read-only file.

Not covered here: Linux and macOS (the POSIX permission paths run in CI), and the whole standalone suite.

Verdict: PARTIAL. The change is correct and safe: the chmod now runs on Windows as on POSIX, the published-mode test is red on main and green on the merge, and nothing regresses natively. But the new cleanup test is vacuous: it stops at the permission check, before any staged file exists, and removing the restore it is meant to cover survives the suite. On Windows the change also has no visible effect on real files (same mode, same ACL), which is not what the body describes.

Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests and synthetic inputs only, no GPU or game files used.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342258486 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7342258486). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-02T10:17:47Z. --- RUN (independent run on Windows, #792 head 18d871a99, merged locally into `main` a917c54d6 with `git merge --no-ff`, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) This run looks at what changes on Windows with real files. - `python -I tests/test_rpf_probe.py -v`: main 33 tests OK (2 skipped, POSIX only); merge 35 tests OK (the same 2 skipped). - `python -m pytest` on `tests/test_rpf_probe.py tests/test_report_paths.py` (the files that name `rpf_probe`): main 57 passed / 2 skipped; merge 59 passed / 2 skipped. - Red on Windows: `main`'s `tools/rpf_probe.py` with this pull request's test file gives 35 tests (2 skipped) and 1 failure, `test_publish_applies_published_mode_on_windows` ("expected published_mode 0o640 to be applied, got []"). This red comes from an assertion on the `os.chmod` calls, with `published_mode` mocked. `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly` passes on `main` too. - Native probes on NTFS, calling `rpf_probe._write_json_report` directly, with no mocks unless stated: - Read-only existing report. This is the setup of the new cleanup test, with `replace_retry` mocked to fail as in that test. `main` and the merge both raise `PermissionError` at `os.close(os.open(destination, os.O_WRONLY))`, the permission check that runs before staging. `replace_retry` is called 0 times and no staged file is created. So the new cleanup test never reaches the staged-file path it is named for. On POSIX, a run that is not root hits the same EACCES at that line. The check has been in `main` since 23 November, before this pull request. - New report: the file the tool writes and a file made with plain `open()` in the same folder have the same mode (0o666) and the same ACL (`icacls`, 4 entries, identical). On Windows, `NamedTemporaryFile`'s 0600 only leaves the read-only attribute clear, and the staged file is not private. So the body's point that Windows outputs "retained NamedTemporaryFile's private 0600 permissions" does not hold here. Applying `published_mode` on Windows can only set or clear the read-only attribute, and the check above refuses a read-only destination. So it has no visible effect on a write that succeeds. - Staged path forced: a writable report, `published_mode` mocked to 0o444, `replace_retry` mocked to fail, and the real `os.unlink`. `main` leaves 0 staged files, because it never runs the chmod on Windows. The merge also leaves 0, because the new `os.chmod(staged.name, 0o600)` before the unlink works. - Mutations of the merge's `tools/rpf_probe.py`, each run with the whole test file and the forced probe, and restored afterwards (`git status` clean): - `if os.name != "nt":` put back around the chmod, which is `main`'s behaviour: killed (1 failure, the published-mode test). - The new `os.chmod(staged.name, 0o600)` in `finally` removed: survives the test file (all OK). With the forced probe it raises `PermissionError: [WinError 5]` from `os.unlink(staged.name)` in `finally`, which hides the replace error, and leaves 1 staged `.rpf_probe-*.tmp` behind. So the restore is needed once the chmod runs on Windows, but no test pins it. - Suggestion: make the cleanup test reach the staged path. Use a writable report, patch `published_mode` to 0o444 and `replace_retry` to fail, and keep the strict-unlink emulation for POSIX. On Windows, the real unlink already refuses a read-only file. Not covered here: Linux and macOS (the POSIX permission paths run in CI), and the whole standalone suite. Verdict: PARTIAL. The change is correct and safe: the chmod now runs on Windows as on POSIX, the published-mode test is red on `main` and green on the merge, and nothing regresses natively. But the new cleanup test is vacuous: it stops at the permission check, before any staged file exists, and removing the restore it is meant to cover survives the suite. On Windows the change also has no visible effect on real files (same mode, same ACL), which is not what the body describes. Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests and synthetic inputs only, no GPU or game files used.
MoonEyes commented 2026-12-02 18:03:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:03:35Z.


Verified on Linux (CPython 3.13.18), as root and as an unprivileged user. Correct change, but one of the two new tests only goes red under root.

  • Head: 18d871a99, merge base 1a52f5b63, merged with --no-ff into current main 45dc41f95 (332 behind, merges clean). CI on the head is green.
  • python3 -I tests/test_rpf_probe.py: 35 tests OK.
  • python3 -I scripts/check_no_game_data.py tools/rpf_probe.py tests/test_rpf_probe.py: exit 0.

Red/green (source revert, git checkout origin/main -- tools/rpf_probe.py):

  • As root (uid 0): 2 failures, both new tests.
  • As uid 65534 (setpriv --reuid=65534 --regid=65534 --clear-groups), which is how a non-root CI runner sees it: 1 failure, test_publish_applies_published_mode_on_windows. test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly passes on main.

Mutation: I removed only the new os.chmod(staged.name, 0o600) restore in finally (tools/rpf_probe.py, the finally: block of _write_json_report).

  • As root: killed (1 failure, the cleanup test).
  • As uid 65534: survives (35 OK).

Defect: tests/test_rpf_probe.py, test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly. The report is made 0o444, so for any non-root user the existing pre-staging check os.close(os.open(destination, os.O_WRONLY)) raises EACCES before a staged file exists. The test then passes without ever reaching the code it is named for. Only root, which ignores the mode bit, reaches the staged path. This matches enlight3d's Windows finding. The fix enlight3d suggested would make it pin the restore for every user: keep the report writable, patch published_mode to return 0o444, patch replace_retry to fail, and keep the strict-unlink emulation.

The source change itself is sound. Running the chmod on Windows too means the read-only restore before os.unlink is needed, and the PR adds it.

Verdict: defects. The fix is right, but the cleanup regression test needs to reach the staged path for a non-root user.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353902452 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7353902452). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:03:35Z. --- **Verified on Linux (CPython 3.13.18), as root and as an unprivileged user. Correct change, but one of the two new tests only goes red under root.** - Head: `18d871a99`, merge base `1a52f5b63`, merged with `--no-ff` into current `main` `45dc41f95` (332 behind, merges clean). CI on the head is green. - `python3 -I tests/test_rpf_probe.py`: 35 tests OK. - `python3 -I scripts/check_no_game_data.py tools/rpf_probe.py tests/test_rpf_probe.py`: exit 0. **Red/green (source revert, `git checkout origin/main -- tools/rpf_probe.py`):** - As root (uid 0): 2 failures, both new tests. - As uid 65534 (`setpriv --reuid=65534 --regid=65534 --clear-groups`), which is how a non-root CI runner sees it: 1 failure, `test_publish_applies_published_mode_on_windows`. `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly` passes on `main`. **Mutation:** I removed only the new `os.chmod(staged.name, 0o600)` restore in `finally` (`tools/rpf_probe.py`, the `finally:` block of `_write_json_report`). - As root: killed (1 failure, the cleanup test). - As uid 65534: survives (35 OK). **Defect:** `tests/test_rpf_probe.py`, `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly`. The report is made `0o444`, so for any non-root user the existing pre-staging check `os.close(os.open(destination, os.O_WRONLY))` raises `EACCES` before a staged file exists. The test then passes without ever reaching the code it is named for. Only root, which ignores the mode bit, reaches the staged path. This matches enlight3d's Windows finding. The fix enlight3d suggested would make it pin the restore for every user: keep the report writable, patch `published_mode` to return `0o444`, patch `replace_retry` to fail, and keep the strict-unlink emulation. The source change itself is sound. Running the chmod on Windows too means the read-only restore before `os.unlink` is needed, and the PR adds it. Verdict: **defects**. The fix is right, but the cleanup regression test needs to reach the staged path for a non-root user. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
fiestorra commented 2026-12-03 03:30:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T03:30:34Z.


VERIFY-792 — la misma familia que #752, con dos tests saltados y un chmod que también toca Windows

Un fichero y su test, 45 líneas, nueve días abierto:

pytest tests/test_rpf_probe.py -q     33 passed, 2 skipped, 6 subtests passed   (0.82 s)

Y el cambio es el hermano del de #752 — mismo título, mismo patrón: "restore write mode before unlink on replace failure and publish mode…" — y el diff quita el if os.name != "nt": del chmod, restaura 0o600 antes del unlink y amplía el except a OSError.

Los dos skipped: no los abrí — y en una suite de 35 casos, dos saltados pueden ser los que cubren el caso de Windows. Si lo son, este PR tiene la misma propiedad que #752: el caso que arregla sólo se ejerce en la plataforma que lo sufre, que es correcto y deja el arreglo sin cubrir aquí.

Lo que sí verifiqué: el resto de la suite no se rompe con el cambio — 33 pasan en 0,8 s, y rpf_probe es una herramienta de sondeo, no un camino del runtime.

Y la razón de mirarlos juntos: #752 y #792 son el mismo patrón aplicado a dos herramientas, con el mismo autor. Si uno entra, el otro debería entrar en el mismo merge — o el arreglo vive en un sitio compartido y no en dos chmod copiados. Es la pregunta que le haría al autor antes de aprobar los dos por separado.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7366642029 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7366642029). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T03:30:34Z. --- ## VERIFY-792 — la misma familia que `#752`, con dos tests saltados y un `chmod` que también toca Windows **Un fichero y su test, 45 líneas, nueve días abierto**: ``` pytest tests/test_rpf_probe.py -q 33 passed, 2 skipped, 6 subtests passed (0.82 s) ``` **Y el cambio es el hermano del de `#752`** — **mismo título, mismo patrón**: *"restore write mode before unlink on replace failure and publish mode…"* — **y el diff quita el `if os.name != "nt":` del `chmod`, restaura `0o600` antes del unlink y amplía el `except` a `OSError`.** **Los dos `skipped`**: **no los abrí** — **y en una suite de 35 casos, dos saltados pueden ser los que cubren el caso de Windows.** **Si lo son, este PR tiene la misma propiedad que `#752`: el caso que arregla sólo se ejerce en la plataforma que lo sufre**, **que es correcto y deja el arreglo sin cubrir aquí.** **Lo que sí verifiqué**: **el resto de la suite no se rompe con el cambio** — **33 pasan en 0,8 s, y `rpf_probe` es una herramienta de sondeo, no un camino del runtime.** **Y la razón de mirarlos juntos**: **`#752` y `#792` son el mismo patrón aplicado a dos herramientas**, **con el mismo autor**. **Si uno entra, el otro debería entrar en el mismo merge** — **o el arreglo vive en un sitio compartido y no en dos `chmod` copiados.** **Es la pregunta que le haría al autor antes de aprobar los dos por separado.**
merzleckeier commented 2026-12-03 03:34:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-03T03:34:20Z.

Review: COMMENTED


I combined this head (18d871a99) with #752 (99ef7a875) on 516c9eaa without conflicts. The two tool suites had 55 passes on Linux and 53 passes with two skips in Windows Python under Wine 11.22. The Linux report-path suite also had 25 passes and one skip.

For the cleanup test gap mentioned above, a fixture that reaches the intended path on both platforms is to keep the existing report writable, mock published_mode to 0o444, and have the replacement stub assert that it received a read-only staged file before raising a distinct sentinel error. I verified that both writers reach the stub once, preserve the old report and original error, and remove the staged file. Removing just os.chmod(staged.name, 0o600) leaves one staged file in each writer, with strict unlink emulation on Linux and with ordinary os.unlink in Windows Python under Wine.

[P3] Preserve the replacement error if deleting the staged file also fails. I let the chmod succeed and injected a separate error on unlink. _write_json_report() surfaced the cleanup error in place of the earlier replacement error because its unlink handler only catches FileNotFoundError. The caller consequently reports the wrong cause. #752 already preserves the original error in the same fixture. Please keep the original error in the diagnostic when cleanup also fails.

All inputs and faults were synthetic. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6163271079 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/792#pullrequestreview-6163271079). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-03T03:34:20Z. **Review:** COMMENTED --- I combined this head (`18d871a99`) with #752 (`99ef7a875`) on `516c9eaa` without conflicts. The two tool suites had 55 passes on Linux and 53 passes with two skips in Windows Python under Wine 11.22. The Linux report-path suite also had 25 passes and one skip. For the cleanup test gap mentioned above, a fixture that reaches the intended path on both platforms is to keep the existing report writable, mock `published_mode` to `0o444`, and have the replacement stub assert that it received a read-only staged file before raising a distinct sentinel error. I verified that both writers reach the stub once, preserve the old report and original error, and remove the staged file. Removing just `os.chmod(staged.name, 0o600)` leaves one staged file in each writer, with strict unlink emulation on Linux and with ordinary `os.unlink` in Windows Python under Wine. **[P3] Preserve the replacement error if deleting the staged file also fails.** I let the chmod succeed and injected a separate error on unlink. `_write_json_report()` surfaced the cleanup error in place of the earlier replacement error because its unlink handler only catches `FileNotFoundError`. The caller consequently reports the wrong cause. #752 already preserves the original error in the same fixture. Please keep the original error in the diagnostic when cleanup also fails. All inputs and faults were synthetic. AI-assisted with OpenAI Codex.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/792:upstream-pr/792'
git switch 'upstream-pr/792'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/792'
git switch 'upstream-pr/792'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/792'
git switch 'upstream-pr/792'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/792'
git switch 'main'
git merge --squash 'upstream-pr/792'
git switch 'main'
git merge --ff-only 'upstream-pr/792'
git switch 'main'
git merge 'upstream-pr/792'
git push origin 'main'
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!792
No description provided.