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

Open
github-bot wants to merge 1 commit from github-bot/gh-775 into main AGit
Owner

@⁠trigger337 on GitHub · 2026-11-24 13:41 UTC · original
trigger337:fix/anim-skeleton-stage-cleanup → main · +51 −3 · 2 files · 1 commits · open

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

**@⁠trigger337** on GitHub · 2026-11-24 13:41 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/775) `trigger337:fix/anim-skeleton-stage-cleanup` → `main` · +51 −3 · 2 files · 1 commits · open 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:50 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-24 19:34 UTC · original

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.
**@⁠PierreEbele** on GitHub · 2026-11-24 19:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/775#issuecomment-7142295360) 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.
This pull request can be merged automatically.
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 '+refs/pull/775/head:github-bot/gh-775'
git switch 'github-bot/gh-775'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-775'
git switch 'github-bot/gh-775'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-775'
git switch 'github-bot/gh-775'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-775'
git switch 'main'
git merge --squash 'github-bot/gh-775'
git switch 'main'
git merge --ff-only 'github-bot/gh-775'
git switch 'main'
git merge 'github-bot/gh-775'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.