anim_skeleton_match: restore write mode before unlink on replace failure and publish mode on Windows (ANIM-SKELETON-STAGE-CLEANUP) #775

Merged
leonida/mandy
trigger337 merged 1 commit from fix/anim-skeleton-stage-cleanup into main 2026-11-28 11:03:17 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 13:41:21 +00:00

In tools/anim_skeleton_match.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 (5/5 in test_anim_skeleton_match.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

In `tools/anim_skeleton_match.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 (5/5 in `test_anim_skeleton_match.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
PierreEbele commented 2026-11-24 19:34:37 +00:00

Reviewed 8cee2f0d: ran python3 -I tests/test_anim_skeleton_match.py -v (5 passed vs 3 on main), py_compile, check_no_game_data.py, and a probe against origin/main. The staging cleanup fix works when published_mode returns 0o444 for a new file, but one new test doesn't exercise it and the other's assertion is weak:

  1. test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly sets report.json to 0o444, so os.open(destination, os.O_WRONLY) raises PermissionError before staging/replace/unlink ever execute (replace_called=False, unlink_called=False)—it passes on main too. Mock published_mode returning 0o444 (or use a new destination under a read-only mode) and assert replace_retry and os.unlink were called.
  2. test_publish_applies_published_mode_on_windows does fail on main (checked with this PR's test file on main's code), but it only asserts len(chmod_calls) > 0, which the new unconditional finally: os.chmod(staged.name, 0o600) also satisfies after a successful replace ([('0o664', True), ('0o600', False)]), so it would keep passing if the published-mode call were dropped again. Consider moving cleanup into except BaseException: (as in tools/bvh_index.py) and asserting the published mode was applied to the staged file before replace_retry. AI-assisted review.
Reviewed 8cee2f0d: ran `python3 -I tests/test_anim_skeleton_match.py -v` (5 passed vs 3 on `main`), `py_compile`, `check_no_game_data.py`, and a probe against `origin/main`. The staging cleanup fix works when `published_mode` returns `0o444` for a new file, but one new test doesn't exercise it and the other's assertion is weak: 1. `test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly` sets `report.json` to `0o444`, so `os.open(destination, os.O_WRONLY)` raises `PermissionError` before staging/replace/unlink ever execute (`replace_called=False`, `unlink_called=False`)—it passes on `main` too. Mock `published_mode` returning `0o444` (or use a new destination under a read-only mode) and assert `replace_retry` and `os.unlink` were called. 2. `test_publish_applies_published_mode_on_windows` does fail on `main` (checked with this PR's test file on `main`'s code), but it only asserts `len(chmod_calls) > 0`, which the new unconditional `finally:` `os.chmod(staged.name, 0o600)` also satisfies after a successful replace (`[('0o664', True), ('0o600', False)]`), so it would keep passing if the published-mode call were dropped again. Consider moving cleanup into `except BaseException:` (as in `tools/bvh_index.py`) and asserting the published mode was applied to the staged file before `replace_retry`. AI-assisted review.
MoonEyes commented 2026-11-28 11:03:13 +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.