test(foundation): add comprehensive unit tests for Memory storage implementations#1284
Open
ashum9 wants to merge 1 commit intomofa-org:mainfrom
Open
test(foundation): add comprehensive unit tests for Memory storage implementations#1284ashum9 wants to merge 1 commit intomofa-org:mainfrom
ashum9 wants to merge 1 commit intomofa-org:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds unit tests to validate the behavior of mofa-foundation’s Memory storage implementations (in-memory and file-based), focusing on CRUD operations, history handling, and persistence semantics.
Changes:
- Add async unit tests for
InMemoryStoragebasic operations plus search/history behavior. - Add file-based storage tests covering persistence across re-initialization, clearing behavior, and a concurrency scenario.
- Introduce temp-dir-backed test setup via
tempfile.
You can also share your feedback on Copilot code review. Take the survey.
50e4fbf to
db397e8
Compare
db397e8 to
70830b6
Compare
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
Adds comprehensive unit tests for
FileBasedStorage— the disk-backed persistent memory implementation inmofa-foundation. This is the third PR in the incremental testing series formofa-foundation'sMemorycomponent.What it does
test_file_based_persistence— Writes keys, history, long-term memory, and daily notes to disk in oneFileBasedStoragescope, then re-opens the same directory in a new scope and verifies everything survived the drop (simulating an agent restart).test_file_based_clear— Stores data and history, callsclear(), then asserts the in-memory maps are empty,data.jsonhas been removed from disk, and thesessions/directory exists but is empty.test_file_based_concurrency— Spawns 10 concurrent Tokio tasks each acquiring a write lock (Arc<RwLock<FileBasedStorage>>), stores a unique key and appends a history message per task, then verifies all 10 values and 10 history entries are present after join.Changes
crates/mofa-foundation/src/agent/components/memory.rs— adds#[cfg(test)] mod testsblock with the three asyncFileBasedStoragetests; imports (TempDir,Arc,RwLock) are placed at the top of the test module.cc @amosli @BH3GEI