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

Merged
leonida/mandy
trigger337 merged 3 commits from fix/manifest-stage-cleanup into main 2026-12-01 14:53:16 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 15:02:08 +00:00

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

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

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.

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

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.

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

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).

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

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

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

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).

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

@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

@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 approved these changes 2026-12-01 11:39:45 +00:00
aslan2142 left a comment

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.)

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

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

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 description provided.