Skip to content

fix(wpm): keep two rollback copies after an update, and pin the #1206/#1208 acceptance in tests - #1226

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/wpm-lifecycle-acceptance-tests
Oct 18, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/wpm-lifecycle-acceptance-tests

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

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)

What this PR fixes

The retention bound was three, not two. apply_update pruned to keep = 2 before 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

Test evidence

  • wpm.* targeted run: 11/11 passed (incl. the three new cases).
  • Full 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).

…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 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — contradicting docs/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() <= keep early-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 two locale_hint failures 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.cpp identical 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 = 2 from #1210; in practice serialized by the parent-wait at wpm.cpp:4223-4228.

@caomengxuan666
caomengxuan666 merged commit b4f7834 into main Oct 18, 2026
5 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/wpm-lifecycle-acceptance-tests branch October 18, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant