Repository navigation
fix(wpm): keep two rollback copies after an update, and pin the #1206/#1208 acceptance in tests - #1226
Conversation
…1208 acceptance in tests The prune #1210 added runs before an update writes its own copy, so keeping two there left three images in .wpm/backup after every update - against the two-copy bound #1208 accepts and the guide documents. Keep one earlier rollback instead: the fresh copy then brings the directory to exactly two, and a swap that fails halfway still has a usable image to restore from. Three acceptance tests that were still missing: - an apply-update moves a command link left on the previous image onto the new one (#1206) instead of leaving it stale until a manual rebuild; - repeated updates leave at most two backups, the survivor chosen by write time, and the fresh copy holds the replaced image (#1208); - a swap that cannot land (the image held without FILE_SHARE_WRITE or FILE_SHARE_DELETE) fails loudly, leaves the previous image running, and keeps the rollback copy (#1208). Test: wpm.apply_update_relinks_a_stale_command_link, wpm.apply_update_keeps_two_rollback_backups, wpm.apply_update_failed_swap_keeps_a_usable_backup. Full suite 2975 tests, 2973 pass (the two machine-local locale_hint i18n failures are pre-existing).
caomengxuan666
left a comment
There was a problem hiding this comment.
Independent code review of PR #1226 (verification run)
Verified on cr-1226 (4b92712) against base 3c42903. Verdict: APPROVE.
1. Off-by-one claim — confirmed, fix is correct.
- Pre-PR
prune_update_backups(root, 2)ran before the run wrote its own copy (src/commands/wpm.cpp:4236 area), so steady state after every update was 3 images in.wpm/backup— contradictingdocs/en/wpm_guide.md:281("the newest two are kept") and #1208's "at most two" bound. - The fix to
keep = 1(src/commands/wpm.cpp:4236) lands before the fresh backup write (line 4240), so steady state is exactly 2. Edge cases check out: first update with 0 backups deletes nothing (backups.size() <= keepearly-return, wpm.cpp:4167); both failure paths — rename-fail restore (wpm.cpp:4272) and in-place-fail restore (wpm.cpp:4295) — execute after the fresh backup exists, so a usable rollback is always present. If the backup copy itself fails, the run exits loudly before touching the image.
2. Tests are genuine pins, not tautologies. All three drive the real built binary (run_command(build_winuxcmd_path(), {"wpm", "--", "__apply-update", ...})) and assert on filesystem/inode state, exit codes and stderr — none assert on the function under test's own return values. Mutation check performed: flipping wpm.cpp:4236 back to keep = 2, rebuilding and rerunning turns wpm.wpm_apply_update_keeps_two_rollback_backups red (3 backups ≠ 2) while the other three apply_update tests stay green; source restored and re-verified green afterwards.
3. Diff discipline — clean. Only src/commands/wpm.cpp (1 call change + explanatory comment) and pure test additions in tests/unit/wpm/wpm_unit_test.cpp. No user-visible strings touched, so no i18n sync needed (and the code now matches the already-documented "newest two" wording).
4. Build/test evidence reproduced.
python scripts/build.py --build-dir build-dbg --target winuxcmd-tests --skip-configure: OK.- Lifecycle subset
--gtest_filter=wpm.wpm_links*:wpm.wpm_apply_update*:wpm.wpm_clean_backup*: 11/11 passed (reproduces the PR's claimed targeted number). - Full
ctest: 2975/2975 passed on this machine (the twolocale_hintfailures in the PR body are machine-local; they pass here). Total count 2975 matches. - clang-format (VS 22.1.3, repo style): violation-line set on
wpm.cppidentical to base (64 lines, purely shifted +4 by the new comment); the test file's one violation is pre-existing code outside the added hunks. Zero new violations.
5. Interaction with #1209 park-and-replace / self-heal — no conflict. prune_update_backups has exactly one call site (apply_update start, before the backup write); finish_update/rebuild_links/links verify never prune; parked names (kReplacedMarker) live beside their targets, not in .wpm/backup; .wpm/logs pruning is a separate helper. Nothing prunes during the swap-failure retry window, so a usable rollback cannot be cut mid-retry.
Non-blocking notes (no action required):
- wpm.cpp:4236/4240: if the prune succeeds but the fresh backup copy then fails, the machine is left with 1 backup instead of 2 until the next update. Loud failure, self-correcting — acceptable.
- Prune-then-write race between two concurrent apply-update helpers can in principle prune the other's just-written backup. Same shape existed with
keep = 2from #1210; in practice serialized by the parent-wait at wpm.cpp:4223-4228.
Follow-up to the merged #1206/#1208 fixes (#1209, #1210): the code paths are in, but the issues' acceptance criteria were not fully pinned, and one retention bound was off by one against its own documentation.
What was already merged (no code duplicated here)
payload_source_forinstead of the extraction tree, the PATH entry links are recorded in the receipt and rebuilt by install/update/uninstall, and.wpm/staging/<pkg>is pruned after a successful install. Verified live per the 1.1.13 changelog (usr\bin\git.exeandbin\git.exeshare the payload inode, staging pruned). No gap found..wpm\logs, verified the family after the swap and retried once, and addedwpm links verify.prune_update_backupsandwpm clean backup/clean all.What this PR fixes
The retention bound was three, not two.
apply_updatepruned tokeep = 2before writing its own copy, so every update left three images in.wpm/backup— against the acceptance criterion "ten forced updates leave at most two backup files" and the guide's "the newest two are kept". Now it keeps one earlier rollback before the write, so the fresh copy brings the directory to exactly two, while a failed swap still has the image it needs to restore.Acceptance tests added
wpm.apply_update_relinks_a_stale_command_link— an__apply-updatewith one name left on a previous image moves it onto the new one; after the update every name inusr/binthat links towinuxcmd.exeshares its inode (wpm update winuxcmd can leave command links on the previous image, silently #1206).wpm.apply_update_keeps_two_rollback_backups— four stale backups with staggered write times plus an update leave exactly two: the newest earlier copy and the fresh rollback, whose content is the replaced image (self-update backups accumulate without bound (.wpm/backup = 61.8 MB) #1208).wpm.apply_update_failed_swap_keeps_a_usable_backup— with the image held open withoutFILE_SHARE_WRITE/FILE_SHARE_DELETE(neither unlink nor in-place replace can land), the update exits non-zero, names the failure, leaves the previous image intact, and keeps a rollback copy holding the old bytes (self-update backups accumulate without bound (.wpm/backup = 61.8 MB) #1208).Test evidence
wpm.*targeted run: 11/11 passed (incl. the three new cases).ctest: 2975 tests, 2973 passed; the two failures (locale_hint_suggests_install_when_catalog_missing,locale_hint_resolves_through_lang_environment) are the machine-local i18n-catalog failures already documented as pre-existing in d50f8f2's commit message, untouched by this change.Closes #1206, closes #1208, closes #1188 (the last with no code change needed — merged in #1192/#1194; this PR is where all three acceptance states got verified).