Skip to content

Commit b042397

Browse files
RichmondAlakeclaude
andcommitted
test(internet): guard that save/load restores internet access
An automation runs MemAgent.load(agent_id, provider) then agent.run(...), so the loaded agent must regain its internet provider + the internet_search tool. Add regression tests (fake provider, create_internet_access_provider patched — no network) for tool (un)registration and load-restoration. Verified end to end during this work: an automation actually searches the web (Tavily) on all three surfaces — programmatic, the CLI /automation command, and the web UI run-now (driven by Playwright) — with the tool log confirming internet_search fired each time. Firecrawl wires + restores identically (real searches need FIRECRAWL_API_KEY). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ab3b1c9 commit b042397

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2024 Richmond Alake. All rights reserved.
2+
# Licensed under the PolyForm Noncommercial License 1.0.0.
3+
# See LICENSE file in the project root for full license information.
4+
5+
"""Internet access survives save/load — the capability automations depend on.
6+
7+
An automation runs ``MemAgent.load(agent_id, provider)`` then ``agent.run(...)``,
8+
so the loaded agent must regain its internet provider + the ``internet_search``
9+
tool. No network: the provider is a fake and create_internet_access_provider is
10+
patched for the load path.
11+
"""
12+
13+
from unittest.mock import patch
14+
15+
import pytest
16+
17+
from memorizz.internet_access import InternetAccessProvider
18+
from memorizz.llms.llm_factory import create_llm_provider
19+
from memorizz.memagent import MemAgent
20+
from memorizz.memagent.builders import MemAgentBuilder
21+
from memorizz.memory_provider.filesystem import FileSystemConfig, FileSystemProvider
22+
23+
24+
class _FakeInternet(InternetAccessProvider):
25+
provider_name = "tavily"
26+
27+
def search(self, query, **kwargs):
28+
return {"query": query, "results": []}
29+
30+
def fetch_url(self, url, **kwargs):
31+
return {"url": url, "content": ""}
32+
33+
def get_provider_name(self):
34+
return "tavily"
35+
36+
def is_enabled(self):
37+
return True
38+
39+
40+
def _agent(tmp_path, internet=True):
41+
prov = FileSystemProvider(FileSystemConfig(root_path=str(tmp_path)))
42+
model = create_llm_provider({"provider": "ollama", "model": "qwen2.5:7b"})
43+
builder = (
44+
MemAgentBuilder()
45+
.with_model(model)
46+
.with_memory_provider(prov)
47+
.with_automations_enabled(False)
48+
)
49+
if internet:
50+
builder = builder.with_internet_access_provider(_FakeInternet())
51+
return prov, builder.build()
52+
53+
54+
@pytest.mark.unit
55+
def test_internet_tools_register_and_unregister(tmp_path):
56+
_, agent = _agent(tmp_path, internet=True)
57+
assert agent.has_internet_access()
58+
assert "internet_search" in agent.tool_manager.tools
59+
agent.with_internet_access_provider(None)
60+
assert "internet_search" not in agent.tool_manager.tools
61+
62+
63+
@pytest.mark.unit
64+
def test_load_restores_internet_access(tmp_path):
65+
prov, agent = _agent(tmp_path, internet=True)
66+
agent.save()
67+
with patch(
68+
"memorizz.internet_access.create_internet_access_provider",
69+
return_value=_FakeInternet(),
70+
):
71+
loaded = MemAgent.load(agent.agent_id, memory_provider=prov)
72+
assert loaded.has_internet_access()
73+
assert loaded.get_internet_access_provider_name() == "tavily"
74+
assert "internet_search" in loaded.tool_manager.tools

0 commit comments

Comments
 (0)