Skip to content

test(foundation): add examples and unit tests for InMemoryStorage search and history#1221

Open
ashum9 wants to merge 2 commits intomofa-org:mainfrom
ashum9:gsoc-test-in-memory-search-history
Open

test(foundation): add examples and unit tests for InMemoryStorage search and history#1221
ashum9 wants to merge 2 commits intomofa-org:mainfrom
ashum9:gsoc-test-in-memory-search-history

Conversation

@ashum9
Copy link
Copy Markdown
Collaborator

@ashum9 ashum9 commented Mar 13, 2026

Summary

Enhances the test coverage for the InMemoryStorage component by adding asynchronous unit tests for its search, history, and statistics capabilities. Additionally, this PR introduces a runnable example to demonstrate these features in practice.

Part of the pre-GSoC testing series:

Changes

  • Search tests (test_in_memory_search): verifies keyword searching across stored documents, correct handling of limits, and non-matching queries including key-level assertions.
  • History & stats tests (test_in_memory_history_and_stats): validates Message history tracking, stats accuracy (total messages, sessions, items), and correct clear() vs clear_history() semantics.
  • Runnable example (examples/memory_history_search.rs): complete demo showcasing how to initialize InMemoryStorage, interact with conversational history, store data, and execute keyword searches.

Motivation

Proper search and history tracking are essential features for building complex agent applications. These tests ensure the reliability of these advanced memory operations. The new example provides a practical reference for developers integrating InMemoryStorage into their own workflows.

cc @amosli @BH3GEI

Copilot AI review requested due to automatic review settings March 13, 2026 23:29
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

This PR improves the reliability and usability of InMemoryStorage in mofa-foundation by adding async unit tests for search/history/stats behavior and introducing a runnable example demonstrating those APIs.

Changes:

  • Added async unit tests for InMemoryStorage keyword search (including limit/non-match cases).
  • Added async unit tests for history tracking and stats reporting (including clear vs clear_history scenarios).
  • Added an example program demonstrating storing items, adding conversation history, and running keyword search.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
crates/mofa-foundation/src/agent/components/memory.rs Adds tokio::test coverage for InMemoryStorage search/history/stats behavior.
crates/mofa-foundation/examples/memory_history_search.rs Adds a runnable demo showcasing history + keyword search usage with InMemoryStorage.

You can also share your feedback on Copilot code review. Take the survey.

@ashum9 ashum9 force-pushed the gsoc-test-in-memory-search-history branch from 4bc8dcf to 8033d6c Compare March 17, 2026 08:08
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