Data Migration: add UnsupportedVersion and ChecksumMismatch error-path tests for all import_from_* paths#746
Merged
Merged
Conversation
5 tasks
Contributor
|
rebased onto main and resolved a small additive conflict in data_migration. good error-path coverage on the UnsupportedVersion / ChecksumMismatch import paths - those were exactly the untested branches. merged 👍 |
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.
Summary
Add comprehensive error-path test coverage for all import_from_* migration entry points, ensuring imports correctly fail with UnsupportedVersion and ChecksumMismatch errors when encountering incompatible or corrupted data.
These tests validate that migration imports fail safely, consistently, and predictably across every supported import source.
Problem
Current migration tests primarily focus on successful import scenarios and do not fully verify failure handling:
Unsupported data versions may not be consistently rejected.
Corrupted imports with invalid checksums are not comprehensively tested.
Error handling behavior may differ across import_from_* implementations.
Future changes could accidentally bypass validation checks or alter error semantics.
Corrupted or incompatible data could lead to partial imports or inconsistent state.
Solution
Introduce a shared test suite that exercises UnsupportedVersion and ChecksumMismatch failure paths for every import_from_* implementation.
Covered Import Paths
Tests are added for all migration entry points, including:
import_from_file(...)
import_from_bytes(...)
import_from_json(...)
import_from_backup(...)
...all other import_from_* variants
Error Scenarios
Unsupported Version
Verify imports fail when the payload version is newer, older, or otherwise incompatible.
Import Payload
├── version = current → Accepted
├── version = unsupported → UnsupportedVersion
└── version = malformed → UnsupportedVersion
Checksum Mismatch
Verify imports fail when payload integrity validation fails.
Payload Data
├── Valid checksum → Imported successfully
├── Modified payload → ChecksumMismatch
└── Corrupted checksum → ChecksumMismatch
Implementation Details
Added tests that:
Generate fixtures with unsupported schema versions.
Generate corrupted payloads with invalid checksums.
Execute every import_from_* path using identical failure scenarios.
Assert that imports return the expected error variants.
Verify imports abort before any state mutation occurs.
Ensure behavior remains deterministic across repeated executions.
Example Assertions
assert_eq!(
result,
Err(MigrationError::UnsupportedVersion)
);
assert_eq!(
result,
Err(MigrationError::ChecksumMismatch)
);
State Integrity Verification
Tests additionally confirm that:
No partial data is imported.
Existing state remains unchanged after failures.
Temporary resources are cleaned up correctly.
Validation failures do not leave migration artifacts behind.
Edge Cases Covered
Version greater than supported maximum.
Version lower than minimum supported version.
Missing version metadata.
Corrupted checksum field.
Tampered payload contents.
Empty payloads with invalid checksums.
Large import payloads with integrity failures.
Multiple consecutive failed import attempts.
Testing Benefits
Ensures all import implementations enforce version compatibility.
Guarantees corrupted data is rejected consistently.
Prevents regressions in migration validation logic.
Protects application state from partial or unsafe imports.
Provides uniform error semantics across all import entry points.
Breaking Changes
None.
This PR adds automated test coverage only and does not modify migration runtime behavior.. Closed #730