Skip to content

test(foundation): add comprehensive unit tests for Memory storage implementations#1284

Open
ashum9 wants to merge 1 commit intomofa-org:mainfrom
ashum9:feat/foundation-memory-tests
Open

test(foundation): add comprehensive unit tests for Memory storage implementations#1284
ashum9 wants to merge 1 commit intomofa-org:mainfrom
ashum9:feat/foundation-memory-tests

Conversation

@ashum9
Copy link
Copy Markdown
Collaborator

@ashum9 ashum9 commented Mar 16, 2026

Summary

Adds comprehensive unit tests for FileBasedStorage — the disk-backed persistent memory implementation in mofa-foundation. This is the third PR in the incremental testing series for mofa-foundation's Memory component.

Part of the pre-GSoC testing series:

What it does

  1. test_file_based_persistence — Writes keys, history, long-term memory, and daily notes to disk in one FileBasedStorage scope, then re-opens the same directory in a new scope and verifies everything survived the drop (simulating an agent restart).

  2. test_file_based_clear — Stores data and history, calls clear(), then asserts the in-memory maps are empty, data.json has been removed from disk, and the sessions/ directory exists but is empty.

  3. 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 tests block with the three async FileBasedStorage tests; imports (TempDir, Arc, RwLock) are placed at the top of the test module.

cc @amosli @BH3GEI

Copilot AI review requested due to automatic review settings March 16, 2026 03:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 InMemoryStorage basic 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.

@ashum9 ashum9 force-pushed the feat/foundation-memory-tests branch from db397e8 to 70830b6 Compare March 17, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants