test: cover lifecycle init/post_upgrade argument validation#159
Merged
Conversation
Adds a tests module to lifecycle.rs exercising the previously-untested argument-validation and recovery branches: - init traps when given an Upgrade argument. - post_upgrade traps when the state snapshot is missing (pre_upgrade trapped or was skipped). - post_upgrade traps when given an Init argument. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a #[cfg(test)] unit test module to canister/src/lifecycle.rs to cover upgrade lifecycle argument validation and snapshot-missing failure behavior, addressing previously untested operator-critical paths during upgrades.
Changes:
- Add a test ensuring
initpanics when passed anUpgradeargument. - Add a test ensuring
post_upgradepanics when no state snapshot is available. - Add a test ensuring
post_upgradepanics when passed anInitargument (with a snapshot present so validation is reached).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Follow the repo convention: every module keeps its tests in a separate tests.rs wired via `mod tests;`, not an inline test module. Convert lifecycle.rs into lifecycle/mod.rs and move the argument-validation tests into lifecycle/tests.rs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
✅ No security or compliance issues detected. Reviewed everything up to c756abd. Security Overview
Detected Code Changes
|
gregorydemay
approved these changes
Jun 22, 2026
gregorydemay
left a comment
Contributor
There was a problem hiding this comment.
Thanks @mbjorkqvist !
Place `#[cfg(test)] mod tests;` right after the imports rather than at the end of the file, matching the convention used elsewhere (e.g. `order/queue/mod.rs`). Addresses review nit on #159. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes a test gap surfaced during the repo review:
lifecycle.rshad nomod tests, leaving the operator-facing init/upgrade arg-validation and snapshot-recovery branches — the code paths exercised at the worst possible time, during an upgrade — entirely untested.Adds a tests module covering:
inittraps when handed anUpgradeargument.post_upgradetraps when the state snapshot is missing (i.e.pre_upgradetrapped or was skipped).post_upgradetraps when handed anInitargument.Test-only; no production code changed.