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

Merged
trigger337 merged 1 commit from upstream-pr/775 into main 2026-11-28 11:03:17 +00:00
trigger337 commented 2026-11-24 13:41:21 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473273199 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/775). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T13:41:21Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-24T19:34:37Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142295360 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/775#issuecomment-7142295360). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-24T19:34:37Z. --- 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 (Migrated from github.com)

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


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