[PR #1240] [MERGED] Fix snapshot personaStats startup migration #4997

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1240
Author: @Xelvanis
Created: 5/26/2026
Status: ✅ Merged
Merged: 5/26/2026
Merged by: @Xelvanis

Base: refactor ← Head: fix/persona-stats-startup-migration


📝 Commits (1)

  • 07f8411 storage: accept snapshot persona stats arrays

📊 Changes

2 files changed (+191 additions, -3 deletions)

View changed files

📝 src-tauri/src/commands/storage/shared.rs (+65 -2)
📝 src-tauri/src/state.rs (+126 -1)

📄 Description

Linked issue

Closes #1239

Why this change

  • Existing refactor save data can contain game-state-snapshots.personaStats as an array, matching tracker snapshot readers/writers.
  • Startup storage migration was treating snapshot personaStats as object/null, so valid saves could fail app initialization with invalid_input.
  • A malformed old snapshot row should not brick startup when the frontend already treats non-array snapshot personaStats as null.

What changed

  • Normalize game-state-snapshots.personaStats as a nullable JSON array while keeping playerStats and metadata as nullable objects.
  • Add startup-only repair for malformed snapshot personaStats, coercing bad non-array values to null before strict storage normalization runs.
  • Add Rust coverage for valid array/null/empty snapshot values, strict API rejection of malformed snapshot values, and startup repair of malformed saved rows.

Refactor impact

Primary owner:

Rust storage startup migration and storage shape normalization.

Impact areas reviewed:

  • Tauri AppState startup storage migration
  • Shared Rust storage normalization contracts
  • Tracker snapshot storage writer/reader shape
  • Roleplay/Game world-state consumers that expect snapshot personaStats as array/null

Boundary notes:

  • Rust storage-only change; no React, Zustand, Tauri JS API, feature internals, or engine imports added.
  • Strict create/update validation stays in the shared storage normalizer; startup repair is limited to persisted old game-state-snapshots rows.

Pressure points touched:

  • src-tauri/src/state.rs startup migration
  • src-tauri/src/commands/storage/shared.rs typed JSON normalization

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

  • cargo test --manifest-path src-tauri\Cargo.toml persona_stats passed.
  • cargo check --manifest-path src-tauri\Cargo.toml passed.
  • git diff --check origin/refactor...HEAD passed.
  • rustfmt --edition 2021 --check src-tauri/src/state.rs passed.
  • Tauri desktop was launched with local test save data; the app opened and loaded existing roleplay/tracker data. QA process was closed afterward.
  • Known existing gap: cargo fmt --manifest-path src-tauri\Cargo.toml --check still fails repo-wide on unrelated pre-existing Rust formatting drift, so this PR avoids a broad formatting-only sweep.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

No docs changes needed: this is a storage migration compatibility fix with no user-facing settings or documented workflow changes.

UI evidence

No UI screenshots added. The relevant proof is startup/data migration behavior plus Rust storage tests.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced game state snapshot data handling with improved validation for player statistics and metadata. Malformed data values are now properly converted to null instead of potentially causing errors.
  • Tests

    • Added tests for game state snapshot data normalization and repair scenarios.

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/1240 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/26/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/persona-stats-startup-migration` --- ### 📝 Commits (1) - [`07f8411`](https://github.com/Pasta-Devs/Marinara-Engine/commit/07f8411d65322c4cac26fe34f839f55272c82766) storage: accept snapshot persona stats arrays ### 📊 Changes **2 files changed** (+191 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/shared.rs` (+65 -2) 📝 `src-tauri/src/state.rs` (+126 -1) </details> ### 📄 Description ## Linked issue Closes #1239 ## Why this change - Existing refactor save data can contain `game-state-snapshots.personaStats` as an array, matching tracker snapshot readers/writers. - Startup storage migration was treating snapshot `personaStats` as object/null, so valid saves could fail app initialization with `invalid_input`. - A malformed old snapshot row should not brick startup when the frontend already treats non-array snapshot `personaStats` as `null`. ## What changed - Normalize `game-state-snapshots.personaStats` as a nullable JSON array while keeping `playerStats` and `metadata` as nullable objects. - Add startup-only repair for malformed snapshot `personaStats`, coercing bad non-array values to `null` before strict storage normalization runs. - Add Rust coverage for valid array/null/empty snapshot values, strict API rejection of malformed snapshot values, and startup repair of malformed saved rows. ## Refactor impact Primary owner: Rust storage startup migration and storage shape normalization. Impact areas reviewed: - Tauri `AppState` startup storage migration - Shared Rust storage normalization contracts - Tracker snapshot storage writer/reader shape - Roleplay/Game world-state consumers that expect snapshot `personaStats` as array/null Boundary notes: - Rust storage-only change; no React, Zustand, Tauri JS API, feature internals, or engine imports added. - Strict create/update validation stays in the shared storage normalizer; startup repair is limited to persisted old `game-state-snapshots` rows. Pressure points touched: - `src-tauri/src/state.rs` startup migration - `src-tauri/src/commands/storage/shared.rs` typed JSON normalization ## Validation - [x] `pnpm check` passes locally - [x] `pnpm typecheck` passes locally - [x] `pnpm build` passes locally - [x] `pnpm check:architecture` passes locally - [x] `pnpm check:docs` passes locally - [x] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [x] Rust clippy/tests were run for Rust behavior changes - [x] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [x] Remote runtime smoke checked when relevant ### Manual verification notes - `cargo test --manifest-path src-tauri\Cargo.toml persona_stats` passed. - `cargo check --manifest-path src-tauri\Cargo.toml` passed. - `git diff --check origin/refactor...HEAD` passed. - `rustfmt --edition 2021 --check src-tauri/src/state.rs` passed. - Tauri desktop was launched with local test save data; the app opened and loaded existing roleplay/tracker data. QA process was closed afterward. - Known existing gap: `cargo fmt --manifest-path src-tauri\Cargo.toml --check` still fails repo-wide on unrelated pre-existing Rust formatting drift, so this PR avoids a broad formatting-only sweep. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims No docs changes needed: this is a storage migration compatibility fix with no user-facing settings or documented workflow changes. ## UI evidence No UI screenshots added. The relevant proof is startup/data migration behavior plus Rust storage tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced game state snapshot data handling with improved validation for player statistics and metadata. Malformed data values are now properly converted to null instead of potentially causing errors. * **Tests** * Added tests for game state snapshot data normalization and repair scenarios. <!-- 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/1240?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:12:20 +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#4997
No description provided.