Skip to content

Comments

Refactoring storage and unifying unit tests#66

Merged
axelsrz merged 4 commits intomainfrom
users/robrandao/storage-tests
Jul 17, 2025
Merged

Refactoring storage and unifying unit tests#66
axelsrz merged 4 commits intomainfrom
users/robrandao/storage-tests

Conversation

@rodrigobr-msft
Copy link
Contributor

This pull request introduces significant refactoring and enhancements to the storage library, focusing on improved modularity, error handling, and test coverage. Key changes include the introduction of a new BlobStorageConfig class for configuration, the creation of a base class for asynchronous storage (AsyncStorageBase), enhanced error handling utilities, and updates to memory storage functionality. Additionally, comprehensive tests have been added to ensure robustness.

Refactoring and Modularization

  • Introduced BlobStorageConfig to encapsulate configuration settings for BlobStorage, replacing the previous BlobStorageSettings class. ([[1]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-da130280c6bf0eaf3149def4f772f961350aa71306930613070afe272f830909L1-R4), [[2]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-2a6302200acf3a2a75a861131b14e54bf9061b578120040f021d7bba81c34790R1-R28), [[3]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-a224ef42e2a15b06a12f8ef2842f38c73ac8ec2751f03754c90e686085f661ffL1-R97))
  • Refactored BlobStorage to inherit from the new AsyncStorageBase class, which provides shared logic for asynchronous storage operations like read, write, and delete. ([[1]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-e2b9bfabe0f61421ebdb756837c46cc904905df770dd1dd3a5831d10a79a6d35R16-R98), [[2]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-a224ef42e2a15b06a12f8ef2842f38c73ac8ec2751f03754c90e686085f661ffL1-R97))
  • Removed redundant methods and legacy code from BlobStorage, such as the connection string conversion logic, to streamline the implementation. ([libraries/Storage/microsoft-agents-blob/microsoft/agents/blob/blob_storage.pyL1-R97](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-a224ef42e2a15b06a12f8ef2842f38c73ac8ec2751f03754c90e686085f661ffL1-R97))

Error Handling Enhancements

  • Added ignore_error and is_status_code_error utilities to handle specific exceptions gracefully, such as ignoring 404 errors during blob operations. ([libraries/Storage/microsoft-agents-storage/microsoft/agents/storage/error_handling.pyR1-R31](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-9ee3c025fd3a28944e6cd26ab7b1fb4b88f94f0de4f18bed0007e1277d29c4a7R1-R31))
  • Updated BlobStorage methods (_read_item, _write_item, _delete_item) to use these error-handling utilities, ensuring better resilience. ([libraries/Storage/microsoft-agents-blob/microsoft/agents/blob/blob_storage.pyL1-R97](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-a224ef42e2a15b06a12f8ef2842f38c73ac8ec2751f03754c90e686085f661ffL1-R97))

Memory Storage Improvements

  • Added validation to MemoryStorage to prevent empty keys and ensure that required parameters are provided for read, write, and delete operations. ([[1]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-b33ecf4806c2605510d6635be8a5203db2c2c9b307ef367c5d363fed4f47681aR20-R30), [[2]](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-b33ecf4806c2605510d6635be8a5203db2c2c9b307ef367c5d363fed4f47681aR51-R62))
  • Enhanced the read method to raise errors for invalid inputs and handle missing keys more robustly. ([libraries/Storage/microsoft-agents-storage/microsoft/agents/storage/memory_storage.pyR20-R30](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-b33ecf4806c2605510d6635be8a5203db2c2c9b307ef367c5d363fed4f47681aR20-R30))

Test Coverage

  • Added unit tests for the new error-handling utilities (ignore_error, is_status_code_error) to verify their behavior under various scenarios. ([libraries/Storage/microsoft-agents-storage/tests/test_error_handling.pyR1-R58](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-14bbb4f6bae2d8e6951f33c84b305e2c3539e4ced0bb5e05175bbec5a88b1346R1-R58))
  • Implemented tests for MemoryStorage using a mock-based approach to validate CRUD operations. ([libraries/Storage/microsoft-agents-storage/tests/test_memory_storage.pyR1-R22](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-60ba7611f46e6f4fee8ba40fbae6b1a63ad9df734e5e19abe69b0f0c1ef74a19R1-R22))
  • Added utility tests for deep copying and subset generation to ensure correctness in helper functions. ([libraries/Storage/microsoft-agents-storage/tests/test_utils.pyR1-R93](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-7911a2ba7e6cf1ed63e718a9d6f6236071e34e763a7f821ae272c4b7eac9bf5bR1-R93))

Integration Updates

  • Updated the test_memory_storage_integration function to use the new target_cls parameter when reading from memory storage, aligning with the refactored interface. ([libraries/Builder/microsoft-agents-builder/tests/test_agent_state.pyL494-R494](https://github.com/microsoft/Agents-for-python/pull/66/files#diff-b47c6aca37e78ad0b03015b4d66f4f4e93e097b9a3c8cffa66fd0a9299b9163dL494-R494))

@rodrigobr-msft rodrigobr-msft requested a review from axelsrz July 17, 2025 21:59
@axelsrz axelsrz merged commit b367489 into main Jul 17, 2025
5 checks passed
kylerohnmsft added a commit that referenced this pull request Jul 21, 2025
Refactoring storage and unifying unit tests (#66)
@rodrigobr-msft rodrigobr-msft deleted the users/robrandao/storage-tests branch September 18, 2025 22:30
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