Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bedrock_agentcore/memory/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class EventMetadataFilter(TypedDict):
"""

left: LeftExpression
operator: OperatorType
# Stored as the operator's string value (e.g. "EQUALS_TO"), not the enum itself,
# since this dict is serialized directly to the AgentCore service.
operator: str
right: Optional[RightExpression]

def build_expression(
Expand Down
45 changes: 45 additions & 0 deletions tests/bedrock_agentcore/memory/models/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
"""Unit tests for memory record metadata filter models."""

from datetime import datetime
from typing import get_type_hints

import pytest

from bedrock_agentcore.memory.models import (
EventMetadataFilter,
IndexedKey,
LeftExpression,
MemoryMetadataFilter,
MemoryRecordLeftExpression,
MemoryRecordOperatorType,
MemoryRecordRightExpression,
MetadataValueType,
OperatorType,
RightExpression,
)


class TestEventMetadataFilter:
"""Test cases for EventMetadataFilter."""

def test_operator_is_annotated_as_str(self):
"""The stored `operator` is the enum's string value, so the field is typed `str`.

Regression for #240: `build_expression` stores `operator.value` (a string),
but the field was annotated `OperatorType` (the enum), which mis-typed every
constructed filter. This mirrors the already-correct `MemoryMetadataFilter`.
"""
assert get_type_hints(EventMetadataFilter)["operator"] is str

def test_build_expression_equals_string(self):
"""build_expression stores the operator's string value, not the enum."""
result = EventMetadataFilter.build_expression(
LeftExpression.build("location"),
OperatorType.EQUALS_TO,
RightExpression.build("NYC"),
)

assert result == {
"left": {"metadataKey": "location"},
"operator": "EQUALS_TO",
"right": {"metadataValue": {"stringValue": "NYC"}},
}

def test_build_expression_exists_no_right_operand(self):
"""An EXISTS filter omits the right operand."""
result = EventMetadataFilter.build_expression(
LeftExpression.build("location"),
OperatorType.EXISTS,
)

assert result == {
"left": {"metadataKey": "location"},
"operator": "EXISTS",
}
assert "right" not in result


class TestMemoryRecordLeftExpression:
"""Test cases for MemoryRecordLeftExpression."""

Expand Down