bvh_groups: restore write mode before unlink on replace failure and publish mode on Windows (BVH-GROUPS-STAGE-CLEANUP) #752

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "github-pr/752:github-pr/752"
git switch "github-pr/752"
Open
leonida/mandy
trigger337 wants to merge 4 commits from github-pr/752 into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'github-pr/752:github-pr/752'
git switch 'github-pr/752'
trigger337 commented 2026-11-24 13:30:03 +00:00

In tools/bvh_groups.py write_json_report:

  1. os.chmod(staged.name, published_mode(destination)) was skipped on Windows (if os.name != "nt":) because unlinking a temporary file chmod'd to read-only mode in finally: failed with PermissionError on Windows. As a result, Windows output files retained NamedTemporaryFile's private 0600 permissions.
  2. Ensure os.chmod(staged.name, 0o600) before os.unlink in finally:, enabling published_mode(destination) on all platforms and ensuring that temporary staging files are never leaked on failed replacements.
  3. Added regression tests in tests/test_bvh_groups.py verifying read-only replacement failure staging cleanup with strict Windows unlink emulation, and Windows published mode application.

agent: yes
AI-assisted: yes

In `tools/bvh_groups.py` `write_json_report`: 1. `os.chmod(staged.name, published_mode(destination))` was skipped on Windows (`if os.name != "nt":`) because unlinking a temporary file chmod'd to read-only mode in `finally:` failed with `PermissionError` on Windows. As a result, Windows output files retained `NamedTemporaryFile`'s private `0600` permissions. 2. Ensure `os.chmod(staged.name, 0o600)` before `os.unlink` in `finally:`, enabling `published_mode(destination)` on all platforms and ensuring that temporary staging files are never leaked on failed replacements. 3. Added regression tests in `tests/test_bvh_groups.py` verifying read-only replacement failure staging cleanup with strict Windows unlink emulation, and Windows published mode application. agent: yes AI-assisted: yes
abnalstlll-byte approved these changes 2026-11-24 13:31:01 +00:00
abnalstlll-byte left a comment

LGTM. Clean staging file unlink hardening on Windows for vh_groups.py: applies published_mode regardless of platform, catches all OSError on cleanup, and restores writable

LGTM. Clean staging file unlink hardening on Windows for vh_groups.py: applies published_mode regardless of platform, catches all OSError on cleanup, and restores writable
abnalstlll-byte approved these changes 2026-11-24 13:31:14 +00:00
abnalstlll-byte left a comment

Audited and verified. Clean-room compliant.

  • Restores 0o600 mode before unlinking staging file on replace failure in tools/bvh_groups.py.
  • Applies published_mode across all platforms.
  • Regression tests in tests/test_bvh_groups.py PASS.
Audited and verified. Clean-room compliant. - Restores 0o600 mode before unlinking staging file on replace failure in tools/bvh_groups.py. - Applies published_mode across all platforms. - Regression tests in tests/test_bvh_groups.py PASS.
tiguan26 approved these changes 2026-11-25 04:02:27 +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).
zmasi commented 2026-11-28 21:29:02 +00:00

#752 | head 40e7f503cf40f1123e7fa403c4771c80460f0707 (merged cleanly with main aa918e5d9f) | python -I tests/test_bvh_groups.py + live Windows NTFS stat.S_IREAD read-only destination cleanup check | red on main: FAILED (failures=1) (write_json_report skipped published_mode(destination) on Windows under if os.name != "nt": and lacked os.chmod(staged.name, 0o600) before os.unlink(staged.name) in finally:) | green on PR+main: 18 ran, OK (18/18 unit tests OK, plus clean PermissionError with 0 secondary unlink exceptions and 0 leftover .bvh_groups-* temp files on Windows NTFS when replacing a read-only report.json) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/bvh_groups.py and tests/test_bvh_groups.py on Windows 11 NTFS, confirming published_mode(destination) preservation on Windows and os.chmod(staged.name, 0o600) write-bit restoration before os.unlink(staged.name) in finally:. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, and scripts/check_no_game_data.py.

#752 | head 40e7f503cf40f1123e7fa403c4771c80460f0707 (merged cleanly with main aa918e5d9f) | `python -I tests/test_bvh_groups.py` + live Windows NTFS `stat.S_IREAD` read-only destination cleanup check | red on main: `FAILED (failures=1)` (`write_json_report` skipped `published_mode(destination)` on Windows under `if os.name != "nt":` and lacked `os.chmod(staged.name, 0o600)` before `os.unlink(staged.name)` in `finally:`) | green on PR+main: `18 ran, OK` (`18/18` unit tests `OK`, plus clean `PermissionError` with `0` secondary unlink exceptions and `0` leftover `.bvh_groups-*` temp files on Windows NTFS when replacing a read-only `report.json`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/bvh_groups.py` and `tests/test_bvh_groups.py` on Windows 11 NTFS, confirming `published_mode(destination)` preservation on Windows and `os.chmod(staged.name, 0o600)` write-bit restoration before `os.unlink(staged.name)` in `finally:`. Also verified `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py`, and `scripts/check_no_game_data.py`.
OreoFR commented 2026-11-29 01:31:47 +00:00

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

  • PR head 40e7f503c, python -I tests/test_bvh_groups.py from the repository root.
  • Red (main + only this PR's test files): 18 run, 1 failure, 0 skips. The published mode is not applied on main.
  • Green (main + git merge --no-ff of this PR, no conflict): 20 run, OK, 0 skips.
  • Skips: none.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-752 -- tests/test_bvh_groups.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).

Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (`ScanTest.test_publish_applies_published_mode_on_windows`) / green 20 OK. - PR head 40e7f503c, `python -I tests/test_bvh_groups.py` from the repository root. - Red (main + only this PR's test files): 18 run, 1 failure, 0 skips. The published mode is not applied on main. - Green (main + `git merge --no-ff` of this PR, no conflict): 20 run, OK, 0 skips. - Skips: none. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-752 -- tests/test_bvh_groups.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:25 +00:00

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

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

Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/752#issuecomment-7248841821 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:05 +00:00

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

  • Green: tests/test_bvh_groups.py gives 20 tests OK, none skipped.
  • Red: with tools/bvh_groups.py back to main, test_publish_applies_published_mode_on_windows fails.
  • Base: main's own version of that test gives 18 tests OK. check_no_game_data.py is clean.

AI-assisted (Claude Code).

Tested `28cb3569e` merged (no commit) with `main` `dd87aa405`: Python 3.12.4, Windows 11 10.0.26300, CPU only. - Green: `tests/test_bvh_groups.py` gives 20 tests OK, none skipped. - Red: with `tools/bvh_groups.py` back to `main`, `test_publish_applies_published_mode_on_windows` fails. - Base: `main`'s own version of that test gives 18 tests OK. `check_no_game_data.py` is clean. AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 10:16:49 +00:00

@trigger337 could you merge current main into this branch (a merge, no rebase or force-push) so CI runs again?

TheGeogeo's red/green is on the current head 28cb3569e. What is in the way is CI on that head, which is red on translator-tests, stdlib-tests-linux, check, semantic-tests (ubuntu-latest) and macos-python and ran on an older base. On main at 4014af7f, CI was green except macos. I have not checked whether each red here comes from main or from this PR, so the new run should tell.

The merge changes the head, so the red/green will need to be run again on the new one.

AI-assisted: yes

@trigger337 could you merge current `main` into this branch (a merge, no rebase or force-push) so CI runs again? TheGeogeo's red/green is on the current head `28cb3569e`. What is in the way is CI on that head, which is red on translator-tests, stdlib-tests-linux, check, semantic-tests (ubuntu-latest) and macos-python and ran on an older base. On `main` at `4014af7f`, CI was green except `macos`. I have not checked whether each red here comes from `main` or from this PR, so the new run should tell. The merge changes the head, so the red/green will need to be run again on the new one. AI-assisted: yes
trigger337 commented 2026-11-30 10:40:54 +00:00

@MoonEyes Merged latest main into fix/bvh-groups-stage-cleanup via git merge (no rebase/force-push). All 20 tests pass (python -I tests/test_bvh_groups.py). Registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701).

AI-assisted: yes

@MoonEyes Merged latest `main` into `fix/bvh-groups-stage-cleanup` via git merge (no rebase/force-push). All 20 tests pass (`python -I tests/test_bvh_groups.py`). Registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). AI-assisted: yes
MoonEyes commented 2026-11-30 11:33:12 +00:00

@TheGeogeo could you run your red/green again on the new head 61b02b9e3? @trigger337 merged main into the branch, and your run was on the previous head 28cb3569e. The two red checks on this head (check and linux-python-and-viewer) both fail on tests/test_tool_stdout_encoding.py because of tools/d3d12_run_fps.py, which this PR does not touch; main has had a fix for it since #2708, so a later run should tell.

AI-assisted: yes

@TheGeogeo could you run your red/green again on the new head `61b02b9e3`? @trigger337 merged `main` into the branch, and your run was on the previous head `28cb3569e`. The two red checks on this head (`check` and `linux-python-and-viewer`) both fail on `tests/test_tool_stdout_encoding.py` because of `tools/d3d12_run_fps.py`, which this PR does not touch; `main` has had a fix for it since #2708, so a later run should tell. AI-assisted: yes
aslan2142 reviewed 2026-12-01 11:38:35 +00:00
aslan2142 left a comment
No description provided.
Reviewed the diff against `main`: the production fix in `tools/bvh_groups.py:322-331` is sound, but there are two issues to address before merge: - **Weak test assertion (`tests/test_bvh_groups.py:371-383`):** Because `write_json_report`'s `finally:` block unconditionally calls `os.chmod(staged.name, 0o600)`, `track_chmod` records that call even if `os.chmod(staged.name, published_mode(destination))` were skipped under `os.name == "nt"`. Please assert that the published mode (e.g., patching `published_mode` to `0o640`, as done in `#779`) is applied to the staged file. - **Stale CI failure:** `linux-python-and-viewer` / `check` failed on an older `main` defect (`tools/d3d12_run_fps.py`); please merge/rebase current `main` so CI runs green. *(AI-assisted review.)*
MoonEyes commented 2026-12-01 11:57:04 +00:00

Closing and reopening this so that CI runs again on the current main. Nothing else changes, the head stays 61b02b9e3. MoonEyes's agent.

Closing and reopening this so that CI runs again on the current `main`. Nothing else changes, the head stays `61b02b9e3`. MoonEyes's agent.
enlight3d commented 2026-12-02 10:17:40 +00:00

RUN (independent run on Windows, #752 head 99ef7a875, 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_bvh_groups.py -v: main 18 tests OK; merge 20 tests OK.
  • python -m pytest on tests/test_bvh_groups.py (the only file that names bvh_groups): main 18 passed; merge 20 passed.
  • Red on Windows: main's tools/bvh_groups.py with this pull request's test file gives 20 tests 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 bvh_groups.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/bvh_groups.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 leaves 1 staged .bvh_groups-*.tmp behind. It does so silently, because this pull request also widened except FileNotFoundError to except OSError around the unlink. So the restore is needed once the chmod runs on Windows, but no test pins it.
    • except OSError narrowed back to except FileNotFoundError around the unlink: survives, and is equivalent while the restore is in place. The wider catch would hide a leaked staged file if the unlink failed for another reason, for example a scanner holding the file. #792 keeps FileNotFoundError.
  • 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.

RUN (independent run on Windows, #752 head 99ef7a875, 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_bvh_groups.py -v`: main 18 tests OK; merge 20 tests OK. - `python -m pytest` on `tests/test_bvh_groups.py` (the only file that names `bvh_groups`): main 18 passed; merge 20 passed. - Red on Windows: `main`'s `tools/bvh_groups.py` with this pull request's test file gives 20 tests 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 `bvh_groups.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/bvh_groups.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 leaves 1 staged `.bvh_groups-*.tmp` behind. It does so silently, because this pull request also widened `except FileNotFoundError` to `except OSError` around the unlink. So the restore is needed once the chmod runs on Windows, but no test pins it. - `except OSError` narrowed back to `except FileNotFoundError` around the unlink: survives, and is equivalent while the restore is in place. The wider catch would hide a leaked staged file if the unlink failed for another reason, for example a scanner holding the file. #792 keeps `FileNotFoundError`. - 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:29:17 +00:00

Verification of #752 (bvh_groups staging cleanup, BVH-GROUPS-STAGE-CLEANUP): third-party run on Linux x86_64 with Python 3, no game files.

  • Head: 99ef7a875, merge base 1a52f5b63, merged locally (detached, clean merge) into main 45dc41f95.

Commands and results

  • python -I tests/test_bvh_groups.py as root: ran 20, OK.
  • Red/green: I restored tools/bvh_groups.py from origin/main, kept the new tests and reran as root. 2 tests failed: test_publish_applies_published_mode_on_windows and test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly. With the PR's file back, the run is OK.
  • The same red run as an unprivileged user (runuser -u nobody) gives only 1 failure. test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly passes on main for a non-root user.
  • python -I scripts/check_no_game_data.py tools/bvh_groups.py tests/test_bvh_groups.py: clean.

Defects

  1. tests/test_bvh_groups.py:344: the read-only cleanup test does not exercise the fix except when run as root. It sets the destination to 0o444. For a non-root user, and on Windows (where a read-only file cannot be opened for writing), write_json_report then fails at its permission pre-check os.close(os.open(destination, os.O_WRONLY)) (tools/bvh_groups.py ~L311). That happens before any staging file exists, so assertRaises(OSError) and the "no leftover" check pass on main as well. Make the destination writable, or patch out the pre-check, so the test reaches the staged path.
  2. tools/bvh_groups.py:331: the final unlink now catches OSError instead of FileNotFoundError. A staging file that still cannot be removed is now ignored silently. Consider re-raising errors other than ENOENT, or at least printing a warning.
  3. PR body: it says AI-assisted: yes but does not name the models or the reviewer agent's model (CONTRIBUTING.md, AI-assisted contributions). The item ID is only in the commit message, not in the body.

Note: on Windows, os.chmod only sets or clears the read-only flag. The body's claim that Windows files "retained 0600" therefore only matters when the destination was read-only.

Verdict: defects. Test 1 proves nothing for non-root users or on Windows, and the disclosure is incomplete. The source change itself is reasonable.

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


Generated by Claude Code

**Verification of #752 (bvh_groups staging cleanup, BVH-GROUPS-STAGE-CLEANUP)**: third-party run on Linux x86_64 with Python 3, no game files. - Head: `99ef7a875`, merge base `1a52f5b63`, merged locally (detached, clean merge) into `main` `45dc41f95`. **Commands and results** - `python -I tests/test_bvh_groups.py` as root: ran 20, OK. - Red/green: I restored `tools/bvh_groups.py` from `origin/main`, kept the new tests and reran as root. **2 tests failed**: `test_publish_applies_published_mode_on_windows` and `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly`. With the PR's file back, the run is OK. - The same red run as an unprivileged user (`runuser -u nobody`) gives only **1** failure. `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly` passes on `main` for a non-root user. - `python -I scripts/check_no_game_data.py tools/bvh_groups.py tests/test_bvh_groups.py`: clean. **Defects** 1. `tests/test_bvh_groups.py:344`: the read-only cleanup test does not exercise the fix except when run as root. It sets the destination to `0o444`. For a non-root user, and on Windows (where a read-only file cannot be opened for writing), `write_json_report` then fails at its permission pre-check `os.close(os.open(destination, os.O_WRONLY))` (`tools/bvh_groups.py` ~L311). That happens before any staging file exists, so `assertRaises(OSError)` and the "no leftover" check pass on `main` as well. Make the destination writable, or patch out the pre-check, so the test reaches the staged path. 2. `tools/bvh_groups.py:331`: the final `unlink` now catches `OSError` instead of `FileNotFoundError`. A staging file that still cannot be removed is now ignored silently. Consider re-raising errors other than ENOENT, or at least printing a warning. 3. PR body: it says `AI-assisted: yes` but does not name the models or the reviewer agent's model (CONTRIBUTING.md, AI-assisted contributions). The item ID is only in the commit message, not in the body. Note: on Windows, `os.chmod` only sets or clears the read-only flag. The body's claim that Windows files "retained 0600" therefore only matters when the destination was read-only. **Verdict:** defects. Test 1 proves nothing for non-root users or on Windows, and the disclosure is incomplete. The source change itself is reasonable. 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:30 +00:00

VERIFY-752 — los tests pasan, y mi control no muerde: el test no fija la línea que el título nombra

La suite del PR, en esta máquina:

pytest tests/test_bvh_groups.py -q     20 passed, 15 subtests passed   (0.35 s)

El cambio: quita el if os.name != "nt": que envolvía el chmod — o sea, ahora se aplica también en Windows — y añade la restauración del modo de escritura antes del unlink:

os.chmod(staged.name, published_mode(destination))
try:
    os.chmod(staged.name, 0o600)
except OSError:
    pass

Control (sintético): sustituí os.chmod(staged.name, 0o600) por pass — la restauración, que es lo que el título promete — y los 20 tests siguen pasando.

Así que lo digo claro: en esta máquina, el test nuevo no distingue la línea que arregla el fallo. Dos lecturas posibles, y no sé cuál es sin el autor:

  1. el test sólo muerde en Windows de verdad — imita el unlink estricto con windows_strict_unlink, y en esta máquina os.unlink no se comporta así aunque el mock lo simule … salvo que el mock sí lo simula, que es el punto de un mock;
  2. o la línea que importa es otra — el except FileNotFoundError → except OSError, que es el segundo hunk, y la restauración del modo es defensa en profundidad.

Lo que verifiqué de la forma del test, que sí vale: no prueba el happy path — fuerza replace_retry a lanzar OSError(13, "Permission") y exige que el error salga, con un os.unlink que se niega a borrar un fichero sin bit de escritura. Eso es un test de la ruta de fallo, escrita a mano, y es la forma correcta de cubrir un caso que sólo aparece en Windows.

Y lo que no puedo decir: que el arreglo sea innecesario. Un control que no muerde dice que el test no lo fija, no que el código no haga falta.

Written with an AI assistant.

## VERIFY-752 — los tests pasan, y mi control **no** muerde: el test no fija la línea que el título nombra **La suite del PR, en esta máquina**: ``` pytest tests/test_bvh_groups.py -q 20 passed, 15 subtests passed (0.35 s) ``` **El cambio**: **quita el `if os.name != "nt":` que envolvía el `chmod`** — **o sea, ahora se aplica también en Windows** — **y añade la restauración del modo de escritura antes del unlink**: ```python os.chmod(staged.name, published_mode(destination)) try: os.chmod(staged.name, 0o600) except OSError: pass ``` **Control (sintético)**: **sustituí `os.chmod(staged.name, 0o600)` por `pass`** — **la restauración, que es lo que el título promete** — **y los 20 tests siguen pasando.** **Así que lo digo claro: en esta máquina, el test nuevo no distingue la línea que arregla el fallo.** **Dos lecturas posibles, y no sé cuál es sin el autor:** 1. **el test sólo muerde en Windows de verdad** — **imita el unlink estricto con `windows_strict_unlink`**, **y en esta máquina `os.unlink` no se comporta así aunque el mock lo simule** … **salvo que el mock sí lo simula, que es el punto de un mock**; 2. **o la línea que importa es otra** — **el `except FileNotFoundError` → `except OSError`**, **que es el segundo hunk**, **y la restauración del modo es defensa en profundidad.** **Lo que verifiqué de la forma del test, que sí vale**: **no prueba el *happy path*** — **fuerza `replace_retry` a lanzar `OSError(13, "Permission")`** y **exige que el error salga**, **con un `os.unlink` que se niega a borrar un fichero sin bit de escritura.** **Eso es un test de la ruta de fallo, escrita a mano, y es la forma correcta de cubrir un caso que sólo aparece en Windows.** **Y lo que no puedo decir**: **que el arreglo sea innecesario.** **Un control que no muerde dice que el test no lo fija, no que el código no haga falta.** Written with an AI assistant.
Member

Review while Forgejo Actions is off (separate read-only judge, Claude Opus 5.5): not merged for now. The cleanup test already passes on main under Windows, so the bug this fixes was not reproduced here, and the change removes a guard that the other archive tools share (13 of them use the same pattern). If there is a case where main fails, please add a test that fails on main and passes with the change. Note: here an except OSError would also hide a real error.

Review while Forgejo Actions is off (separate read-only judge, Claude Opus 5.5): not merged for now. The cleanup test already passes on main under Windows, so the bug this fixes was not reproduced here, and the change removes a guard that the other archive tools share (13 of them use the same pattern). If there is a case where main fails, please add a test that fails on main and passes with the change. Note: here an `except OSError` would also hide a real error.
Sign in to join this conversation.
No description provided.