fix(ts-oss): isolate entity store from memory store by default (#4829)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
Claude Opus 4.6
kartik-mem0
parent
d8d776636f
commit
9692726db4
@@ -286,8 +286,8 @@ def test_init_with_env_vars(monkeypatch):
|
||||
http_client=None,
|
||||
default_headers=None,
|
||||
)
|
||||
# Should default to "gpt-4.1-nano-2025-04-14" if model is None
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
# Should default to "gpt-5-mini" if model is None
|
||||
assert llm.config.model == "gpt-5-mini"
|
||||
|
||||
|
||||
def test_init_with_default_azure_credential(monkeypatch):
|
||||
|
||||
@@ -57,7 +57,7 @@ def test_init_with_default_credential(mock_credential, mock_token_provider, mock
|
||||
mock_token_provider.return_value = "token-provider"
|
||||
llm = AzureOpenAIStructuredLLM(config)
|
||||
# Should set default model if not provided
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
assert llm.config.model == "gpt-5-mini"
|
||||
mock_credential.assert_called_once()
|
||||
mock_token_provider.assert_called_once_with(mock_credential.return_value, SCOPE)
|
||||
mock_azure_openai.assert_called_once()
|
||||
@@ -92,7 +92,7 @@ def test_init_with_placeholder_api_key_uses_default_credential(
|
||||
config = DummyConfig(model=None, azure_kwargs=DummyAzureKwargs(api_key="your-api-key"))
|
||||
mock_token_provider.return_value = "token-provider"
|
||||
llm = AzureOpenAIStructuredLLM(config)
|
||||
assert llm.config.model == "gpt-4.1-nano-2025-04-14"
|
||||
assert llm.config.model == "gpt-5-mini"
|
||||
mock_credential.assert_called_once()
|
||||
mock_token_provider.assert_called_once_with(mock_credential.return_value, SCOPE)
|
||||
mock_azure_openai.assert_called_once()
|
||||
|
||||
@@ -359,3 +359,63 @@ class TestTelemetryEnvVar:
|
||||
def test_env_var_parsing(self, value, expected):
|
||||
result = value.lower() in ("true", "1", "yes")
|
||||
assert result == expected
|
||||
|
||||
|
||||
class TestTelemetryNullUserIdHandling:
|
||||
"""Verify telemetry doesn't crash when user_id is None.
|
||||
|
||||
This is a regression test for the bug where Memory.from_config() crashed
|
||||
with AssertionError because distinct_id was None in PostHog.capture().
|
||||
"""
|
||||
|
||||
def test_capture_event_skips_when_user_id_is_none(self):
|
||||
"""AnonymousTelemetry.capture_event should not crash when user_id is None."""
|
||||
with patch.object(telemetry_module, "MEM0_TELEMETRY", True):
|
||||
with patch("mem0.memory.telemetry.Posthog") as mock_posthog_cls:
|
||||
at = telemetry_module.AnonymousTelemetry()
|
||||
at.user_id = None # Simulate the bug condition
|
||||
|
||||
# This should not raise, even with user_id=None
|
||||
at.capture_event("test.event", {"key": "value"})
|
||||
|
||||
# PostHog.capture should NOT have been called since user_id is None
|
||||
mock_posthog_cls.return_value.capture.assert_not_called()
|
||||
|
||||
def test_capture_event_does_not_crash_on_posthog_error(self):
|
||||
"""AnonymousTelemetry.capture_event should catch PostHog exceptions."""
|
||||
with patch.object(telemetry_module, "MEM0_TELEMETRY", True):
|
||||
with patch("mem0.memory.telemetry.Posthog") as mock_posthog_cls:
|
||||
with patch("mem0.memory.telemetry.get_or_create_user_id", return_value="test-user"):
|
||||
at = telemetry_module.AnonymousTelemetry()
|
||||
mock_posthog_cls.return_value.capture.side_effect = Exception("PostHog error")
|
||||
|
||||
# This should not raise, even when PostHog.capture fails
|
||||
at.capture_event("test.event", {"key": "value"})
|
||||
|
||||
def test_oss_capture_event_does_not_crash_memory_init(self):
|
||||
"""capture_event() should never raise, even if everything inside fails."""
|
||||
with patch.object(telemetry_module, "MEM0_TELEMETRY", True):
|
||||
# Make _get_oss_telemetry return a broken telemetry object
|
||||
mock_at = MagicMock()
|
||||
mock_at.capture_event.side_effect = Exception("Telemetry is broken")
|
||||
|
||||
with patch.object(telemetry_module, "_oss_telemetry_instance", mock_at):
|
||||
mock_memory = MagicMock()
|
||||
mock_memory.config.graph_store.config = None
|
||||
mock_memory.api_version = "v1"
|
||||
|
||||
# This should not raise, even when telemetry fails
|
||||
telemetry_module.capture_event("mem0.init", mock_memory)
|
||||
|
||||
def test_client_capture_event_does_not_crash(self):
|
||||
"""capture_client_event() should never raise exceptions."""
|
||||
with patch.object(telemetry_module, "MEM0_TELEMETRY", True):
|
||||
mock_client_telemetry = MagicMock()
|
||||
mock_client_telemetry.capture_event.side_effect = Exception("Client telemetry broken")
|
||||
|
||||
with patch.object(telemetry_module, "client_telemetry", mock_client_telemetry):
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.user_email = "test@example.com"
|
||||
|
||||
# This should not raise
|
||||
telemetry_module.capture_client_event("test.event", mock_instance)
|
||||
|
||||
Reference in New Issue
Block a user