[PR #1633] [MERGED] Guard modern profile import against wiping absent collections #5165

Closed
opened 2026-10-22 04:13:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1633
Author: @Romuromylus
Created: 5/30/2026
Status: ✅ Merged
Merged: 5/30/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/profile-import-modern-skip-absent


📝 Commits (1)

  • 9c060c3 Guard modern profile import against wiping absent collections

📊 Changes

1 file changed (+92 additions, -3 deletions)

View changed files

📝 src-tauri/src/commands/storage/profile.rs (+92 -3)

📄 Description

Why this change

Follow-up to #1521. #1518 fixed the legacy table import path so a partial backup leaves collections it omits untouched instead of wiping them. The modern data.collections path (import_profile_collections_with_restored_assets) still rebuilt a replacement for every known collection, falling back to an empty array for any collection the file omitted. A partial or hand-built modern-format profile therefore wiped every collection it did not carry, the same data-loss shape #1512 described for the legacy path.

The refactor's own exports are always full backups, so a normal export/import round-trip never hit this. A hand-built or partial modern file did.

What changed

  • src-tauri/src/commands/storage/profile.rs: in the modern collections loop, skip collections absent from the file (leaving the user's existing data untouched) and reject a present-but-non-array collection instead of coercing it to an empty array. A present-but-empty array is still treated as a deliberate clear. This mirrors the #1518 legacy guard exactly.
  • Added three regression tests against the real storage layer: skip-absent leaves existing rows, present-but-empty clears, present-but-non-array is rejected with nothing replaced.

Verification

  • pnpm check passes locally (architecture + frontend tsc + cargo check + docs).
  • cargo clippy --workspace --all-targets -- -D warnings clean.
  • New unit tests exercise the exact data-loss path against the real storage engine and pass; full profile module suite (30 tests) green.

The end-user trigger (importing a hand-built/partial modern-format profile) is reached through the native file picker, which is not driven by the automated tiers; the storage-layer behavior it depends on is fully covered by the new tests.

Linked issue

Closes #1521.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Profile collection imports now preserve existing stored data when collections are absent from the import file, instead of clearing them
    • Non-array formatted collection data is validated and rejected during import before any changes take effect, safeguarding against data loss
  • Tests

    • Added tests verifying profile import behavior with absent collections, empty arrays, and invalid data formats

Review Change Stack


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/1633 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/30/2026 **Status:** ✅ Merged **Merged:** 5/30/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/profile-import-modern-skip-absent` --- ### 📝 Commits (1) - [`9c060c3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9c060c31a016aaef99a61862406de6eccd781be2) Guard modern profile import against wiping absent collections ### 📊 Changes **1 file changed** (+92 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/profile.rs` (+92 -3) </details> ### 📄 Description ## Why this change Follow-up to #1521. #1518 fixed the **legacy** table import path so a partial backup leaves collections it omits untouched instead of wiping them. The **modern** `data.collections` path (`import_profile_collections_with_restored_assets`) still rebuilt a replacement for every known collection, falling back to an empty array for any collection the file omitted. A partial or hand-built modern-format profile therefore wiped every collection it did not carry, the same data-loss shape #1512 described for the legacy path. The refactor's own exports are always full backups, so a normal export/import round-trip never hit this. A hand-built or partial modern file did. ## What changed - `src-tauri/src/commands/storage/profile.rs`: in the modern collections loop, skip collections absent from the file (leaving the user's existing data untouched) and reject a present-but-non-array collection instead of coercing it to an empty array. A present-but-empty array is still treated as a deliberate clear. This mirrors the #1518 legacy guard exactly. - Added three regression tests against the real storage layer: skip-absent leaves existing rows, present-but-empty clears, present-but-non-array is rejected with nothing replaced. ## Verification - `pnpm check` passes locally (architecture + frontend tsc + cargo check + docs). - `cargo clippy --workspace --all-targets -- -D warnings` clean. - New unit tests exercise the exact data-loss path against the real storage engine and pass; full `profile` module suite (30 tests) green. The end-user trigger (importing a hand-built/partial modern-format profile) is reached through the native file picker, which is not driven by the automated tiers; the storage-layer behavior it depends on is fully covered by the new tests. ## Linked issue Closes #1521. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Bug Fixes** * Profile collection imports now preserve existing stored data when collections are absent from the import file, instead of clearing them * Non-array formatted collection data is validated and rejected during import before any changes take effect, safeguarding against data loss * **Tests** * Added tests verifying profile import behavior with absent collections, empty arrays, and invalid data formats <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1633?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:13:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5165
No description provided.