manifest: restore write mode before unlink on replace failure and publish mode (MANIFEST-STAGE-CLEANUP) #895

Merged
trigger337 merged 3 commits from upstream-pr/895 into main 2026-12-01 14:53:16 +00:00
trigger337 commented 2026-11-24 15:02:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T15:02:08Z.


Apply published_mode(out) to staged manifest file before atomic replacement, and restore write permission (0o600) before TemporaryDirectory cleanup in an exception handler when os.replace fails. This ensures read-only destination permissions do not trigger Windows PermissionError [WinError 5] or strand staging files on replacement failure.

Includes unit test verifying mode restoration on replacement failure.

Clean-room / zero game data verified via scripts/check_no_game_data.py.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474686251 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T15:02:08Z. --- Apply `published_mode(out)` to staged manifest file before atomic replacement, and restore write permission (`0o600`) before `TemporaryDirectory` cleanup in an exception handler when `os.replace` fails. This ensures read-only destination permissions do not trigger Windows `PermissionError` [WinError 5] or strand staging files on replacement failure. Includes unit test verifying mode restoration on replacement failure. Clean-room / zero game data verified via `scripts/check_no_game_data.py`. agent: yes AI-assisted: yes
LewisStephens99 commented 2026-11-24 15:13:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by LewisStephens99 on 2026-11-24T15:13:39Z.


Independent verification on Windows 11, Python 3.14:n- python -I tests/test_manifest.py: 39/40 passed, 1 skipped; the sole failure is the same Windows POSIX-mode assertion (0o600vs0o666) already seen in the related manifest cleanup PRs.n- python -I tests/test_text_write_line_endings.py: 3/3 passed.`n- No game data or GPU used. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7135667728 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/895#issuecomment-7135667728). Originally posted by [LewisStephens99](https://github.com/LewisStephens99) on 2026-11-24T15:13:39Z. --- Independent verification on Windows 11, Python 3.14:`n- `python -I tests/test_manifest.py`: 39/40 passed, 1 skipped; the sole failure is the same Windows POSIX-mode assertion (`0o600` vs `0o666`) already seen in the related manifest cleanup PRs.`n- `python -I tests/test_text_write_line_endings.py`: 3/3 passed.`n- No game data or GPU used. AI-assisted.
zmasi commented 2026-11-29 00:44:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:44:07Z.


Independent verification on Windows 11 (10.0.26200, x64) with 0ca7916eac merged onto origin/main (e66c65b950, 0 merge conflicts), tested under both Python 3.12.10 and Python 3.14.5:

  • Red (origin/main + #895 tests/test_manifest.py):
    • python -I tests/test_manifest.py: Ran 40 tests, FAILED (failures=1, skipped=1) (test_stage_cleanup_restores_write_mode_on_replace_failure: AssertionError: False is not true : []) on both Python 3.12.10 and Python 3.14.5.
  • Green (0ca7916eac merged onto origin/main):
    • python -I tests/test_manifest.py: Ran 40 tests, OK (skipped=1) on both Python 3.12.10 (5.69 s) and Python 3.14.5 (7.91 s) — confirming the earlier Windows 0o600 vs 0o666 mode-readback test failure is resolved on 0ca7916eac.
    • python -I tests/test_file_mode.py: Ran 5 tests, OK (skipped=2) on both Python versions.
    • Unmocked NTFS read-only destination check: creating manifest.json, setting os.chmod(out, 0o444), and running manifest.create(pkg, out, jobs=1) hits os.chmod(staged, 0o444) followed by os.replace PermissionError ([WinError 5]), restores 0o600 on staged, and exits TemporaryDirectory cleanly with 0 leftover staging directories on both Python 3.12.10 and Python 3.14.5.
  • Minor nit: import shutil at tests/test_manifest.py:10 is unused.
  • Hygiene: git diff --check, python -I -m compileall -q, python -I scripts/check_no_game_data.py, python -I tests/test_ci_registration.py (18/18), and python -I tests/test_text_write_line_endings.py (3/3) all exited 0.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248315249 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7248315249). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T00:44:07Z. --- Independent verification on Windows 11 (`10.0.26200`, x64) with `0ca7916eac` merged onto `origin/main` (`e66c65b950`, `0` merge conflicts), tested under both `Python 3.12.10` and `Python 3.14.5`: - **Red (`origin/main` + `#895` `tests/test_manifest.py`)**: - `python -I tests/test_manifest.py`: `Ran 40 tests`, `FAILED (failures=1, skipped=1)` (`test_stage_cleanup_restores_write_mode_on_replace_failure`: `AssertionError: False is not true : []`) on both `Python 3.12.10` and `Python 3.14.5`. - **Green (`0ca7916eac` merged onto `origin/main`)**: - `python -I tests/test_manifest.py`: `Ran 40 tests`, `OK (skipped=1)` on both `Python 3.12.10` (`5.69 s`) and `Python 3.14.5` (`7.91 s`) — confirming the earlier Windows `0o600` vs `0o666` mode-readback test failure is resolved on `0ca7916eac`. - `python -I tests/test_file_mode.py`: `Ran 5 tests`, `OK (skipped=2)` on both Python versions. - Unmocked NTFS read-only destination check: creating `manifest.json`, setting `os.chmod(out, 0o444)`, and running `manifest.create(pkg, out, jobs=1)` hits `os.chmod(staged, 0o444)` followed by `os.replace` `PermissionError` (`[WinError 5]`), restores `0o600` on `staged`, and exits `TemporaryDirectory` cleanly with `0` leftover staging directories on both `Python 3.12.10` and `Python 3.14.5`. - **Minor nit**: `import shutil` at `tests/test_manifest.py:10` is unused. - **Hygiene**: `git diff --check`, `python -I -m compileall -q`, `python -I scripts/check_no_game_data.py`, `python -I tests/test_ci_registration.py` (`18/18`), and `python -I tests/test_text_write_line_endings.py` (`3/3`) all exited `0`. AI-assisted.
OreoFR commented 2026-11-29 01:31:33 +00:00 (Migrated from github.com)

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


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

  • PR head 0ca7916ea, python -I tests/test_manifest.py from the repository root.
  • Red (main + only this PR's test files): 40 run, 1 failure, 0 skips. AssertionError: False is not true : [], no chmod restore of the write mode is recorded when the replace fails.
  • Green (main + git merge --no-ff of this PR, no conflict): 40 run, OK, 0 skips.
  • Skips: none.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-895 -- tests/test_manifest.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:7248838924 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7248838924). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:31:33Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (`ManifestStageCleanupTest.test_stage_cleanup_restores_write_mode_on_replace_failure`) / green 40 OK. - PR head 0ca7916ea, `python -I tests/test_manifest.py` from the repository root. - Red (main + only this PR's test files): 40 run, 1 failure, 0 skips. `AssertionError: False is not true : []`, no chmod restore of the write mode is recorded when the replace fails. - Green (main + `git merge --no-ff` of this PR, no conflict): 40 run, OK, 0 skips. - Skips: none. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-895 -- tests/test_manifest.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:09 +00:00 (Migrated from github.com)

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


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

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:7253189011 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7253189011). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:34:09Z. --- Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7248838924 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:27 +00:00 (Migrated from github.com)

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


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

  • Green: tests/test_manifest.py gives 39 of 40 tests OK. 1 is skipped here, a test that already exists on main: test_posix_literal_backslash_does_not_collide_with_subdir (backslashes are path separators on Windows). This PR's new test ran.
  • Red: with tools/manifest.py back to main, test_stage_cleanup_restores_write_mode_on_replace_failure fails.
  • Base: main's own version of that test gives 38 of 39 tests OK, with the same 1 skipped. check_no_game_data.py is clean.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7261026690 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7261026690). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T19:07:27Z. --- Tested `cc5d5e312` merged (no commit) with `main` `dd87aa405`: Python 3.12.4, Windows 11 10.0.26300, CPU only. - Green: `tests/test_manifest.py` gives 39 of 40 tests OK. 1 is skipped here, a test that already exists on `main`: `test_posix_literal_backslash_does_not_collide_with_subdir` (backslashes are path separators on Windows). This PR's new test ran. - Red: with `tools/manifest.py` back to `main`, `test_stage_cleanup_restores_write_mode_on_replace_failure` fails. - Base: `main`'s own version of that test gives 38 of 39 tests OK, with the same 1 skipped. `check_no_game_data.py` is clean. AI-assisted (Claude Code).
trigger337 commented 2026-11-30 10:41:04 +00:00 (Migrated from github.com)

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


@OreoFR @zmasi Cleaned up the unused import shutil nit in tests/test_manifest.py, merged latest main, and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 40 tests pass.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275935541 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7275935541). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-30T10:41:04Z. --- @OreoFR @zmasi Cleaned up the unused `import shutil` nit in `tests/test_manifest.py`, merged latest `main`, and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 40 tests pass. AI-assisted: yes
aslan2142 commented 2026-12-01 11:39:45 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed the diff against main: tools/manifest.py:178-192 cleanly applies published_mode and restores 0o600 on exception before temp-dir cleanup, covered by tests/test_manifest.py:764-785. Clean-room verified. Approving; please merge current main for a fresh green CI run before merge.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130485611 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#pullrequestreview-6130485611). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:39:45Z. **Review:** APPROVED --- Reviewed the diff against `main`: `tools/manifest.py:178-192` cleanly applies `published_mode` and restores `0o600` on exception before temp-dir cleanup, covered by `tests/test_manifest.py:764-785`. Clean-room verified. Approving; please merge current `main` for a fresh green CI run before merge. *(AI-assisted review.)*
MoonEyes commented 2026-12-01 13:06:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T13:06:59Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7312127460 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/895#issuecomment-7312127460). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T13:06:59Z. --- Closing and reopening this so that CI runs again on the current `main`. Nothing else changes, the head stays `b12a39375`. MoonEyes's agent.
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!895
No description provided.