fix: persist MessagePack header after deletion - #69
Merged
Conversation
# Conflicts: # src/LocalPrefs.Tests/Editor/LocalPrefsCoreTest.cs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a persistence bug in the MessagePack-backed ILocalPrefs implementation where deleting a key updated the in-memory header but failed to write the updated header back to storage, causing a subsequent instance reopening the same path to read a stale header.
Changes:
- Fix
MessagePackLocalPrefs.DeleteAsyncto serialize the updated header directly into the writer (so it’s actually persisted). - Add a regression test that deletes the middle key (
a/b/c→ deleteb) and verifies correctness after reopening via a new instance. - Run the new regression scenario through both the .NET test suite and the Unity WebGL player test wrapper.
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/LocalPrefs.MessagePack/MessagePackLocalPrefs.cs | Fixes header persistence by serializing the updated header into _writer during deletion. |
| src/LocalPrefs.Tests/Runtime/LocalPrefsTest.cs | Adds a regression test verifying delete + reopen preserves remaining keys/values. |
| src/LocalPrefs.Tests/Editor/LocalPrefsCoreTest.cs | Wires the new regression test into the editor test suite across factories. |
| src/LocalPrefs.Unity/Assets/Tests/LSPrefsTest.cs | Wires the new regression test into Unity WebGL test execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
概要
MessagePack 実装でキーを削除した後、新しいインスタンスで同じ保存先を開くと、削除前の古いヘッダーを読み込んでしまう問題を修正します。公開 API は変更しません。
発生していた問題
削除処理は、メモリ上のヘッダー更新と値本体の削除までは行っていましたが、更新後ヘッダーの永続化に
MessagePackSerializer.Serialize(_header, options)を使用していました。この overload はシリアライズ済みバイト列を返しますが、戻り値が使用されていなかったため、_writerへ新しいヘッダーが書き込まれていませんでした。同一インスタンスでは更新済みのメモリ上ヘッダーを参照するため正常に見えますが、再オープンすると古いヘッダーが復元されます。その結果、削除したキーが残って見えたり、後続値の位置情報が不整合になる可能性がありました。
修正内容
_writerへ直接シリアライズする overload へ変更a / b / cの中央bを削除し、別インスタンスで再オープンする回帰テストを追加aとcが保持され、bが存在しないことを確認影響範囲
検証
dotnet formatを変更 C# ファイルへ実行dotnet test src/LocalPrefs.Tests/LocalPrefs.Tests.csproj --configuration Release --framework net9.0: 81 / 81 passedAll test(s) succeededを確認補足
このブランチは
mainから独立しており、他の修正PRを前提にしません。MessagePack 3.1.3 の既存 NU1902 / NU1903 警告は別PRの 3.1.8 更新で対応します。