Skip to content

Commit be0e93f

Browse files
ayaangazaliclaude
andcommitted
test(agent): revive the eight tests that have errored since 2025-10-21
`6f4803ef` (2025-10-21) deleted the `mocked_llm` fixture but left the two fixtures that request it, and the eight tests that request those. They have errored at setup ever since: fixture 'mocked_llm' not found Errors, not failures, so they read as infrastructure noise rather than missing coverage — and one of them is the only save/load round-trip test the repo has. The parent commit fixes an Agent.load() crash that this test reproduces on its first run. master 19 failed, 78 passed, 8 errors here 19 failed, 84 passed, 0 errors The 19 failures are unchanged and pre-existing (diffed, identical set). mocked_llm is restored as a stub with `run`/`arun`. The fixtures now also pin a tmp_path workspace and turn off autosave and persistent memory, so the revived tests touch no shared state. Three of the eight asserted an API the Agent has not had for years, which is why simply restoring the fixture turns them into failures rather than passes: - test_flow_initialization asserted `max_loops == 5` against a fixture that passes 1, plus `.feedback` and `.memory`. Rewritten to the attributes that exist. - test_provide_feedback called `.provide_feedback()` — deleted, the method is gone. - test_format_prompt called `.format_prompt()` — deleted, likewise. - test_save_and_load appended to a `.memory` list. Rewritten as a real scalar round trip (max_loops 9 -> 3, agent_name restored) through the Agent API. - test_flow_call asserted the call returned its own input, true only of the deleted mock. Comparing two live calls does not work either — the conversation grows between them — so it now pins the delegation: __call__ forwards to run(). The remaining three (bulk_run, and both run_* tests) needed nothing but the fixture back. Closes kyegomez#2010 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 27c47f1 commit be0e93f

1 file changed

Lines changed: 94 additions & 29 deletions

File tree

tests/structs/test_agent.py

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,58 @@
4040

4141

4242
@pytest.fixture
43-
def basic_flow(mocked_llm):
43+
def mocked_llm():
44+
"""Stand-in for the LLM, so these tests need no provider.
45+
46+
Restored: `6f4803ef` (2025-10-21) deleted this fixture but left the two
47+
fixtures that request it, so the eight tests below errored at setup with
48+
"fixture 'mocked_llm' not found" and have not executed since.
49+
50+
Echoes the task back. `Agent.__call__` returning its input is what
51+
test_flow_call asserts, and an echo keeps every other assertion about
52+
plumbing rather than about model output.
53+
"""
54+
55+
class MockedLLM:
56+
def run(self, task=None, *args, **kwargs):
57+
return task
58+
59+
async def arun(self, task=None, *args, **kwargs):
60+
return task
61+
62+
return MockedLLM()
63+
64+
65+
@pytest.fixture
66+
def basic_flow(mocked_llm, tmp_path):
4467
"""Basic agent flow for testing"""
45-
return Agent(llm=mocked_llm, max_loops=1)
68+
return Agent(
69+
agent_name="basic-flow",
70+
llm=mocked_llm,
71+
max_loops=1,
72+
print_on=False,
73+
verbose=False,
74+
persistent_memory=False,
75+
autosave=False,
76+
workspace_dir=str(tmp_path),
77+
)
4678

4779

4880
@pytest.fixture
49-
def flow_with_condition(mocked_llm):
81+
def flow_with_condition(mocked_llm, tmp_path):
5082
"""Agent flow with stopping condition"""
5183
from swarms.structs.agent import stop_when_repeats
5284

5385
return Agent(
86+
agent_name="flow-with-condition",
5487
llm=mocked_llm,
5588
max_loops=1,
5689
stopping_condition=stop_when_repeats,
90+
print_on=False,
91+
verbose=False,
92+
persistent_memory=False,
93+
autosave=False,
94+
workspace_dir=str(tmp_path),
5795
)
5896

5997

@@ -108,23 +146,20 @@ def test_stop_when_repeats(self):
108146
assert not stop_when_repeats("Continue the process")
109147

110148
def test_flow_initialization(self, basic_flow):
111-
"""Test agent initialization"""
112-
assert basic_flow.max_loops == 5
149+
"""The constructor arguments survive __init__.
150+
151+
Rewritten: this asserted `max_loops == 5` against a fixture that
152+
passes 1, plus `.feedback` and `.memory`, which the Agent has not
153+
had for a long time — it errored before ever running, so nothing
154+
caught the drift.
155+
"""
156+
assert basic_flow.max_loops == 1
113157
assert basic_flow.stopping_condition is None
114-
assert basic_flow.loop_interval == 1
115158
assert basic_flow.retry_attempts == 3
116-
assert basic_flow.feedback == []
117-
assert basic_flow.memory == []
118159
assert basic_flow.task is None
119160
assert basic_flow.stopping_token == "<DONE>"
120161
assert not basic_flow.interactive
121162

122-
def test_provide_feedback(self, basic_flow):
123-
"""Test feedback functionality"""
124-
feedback = "Test feedback"
125-
basic_flow.provide_feedback(feedback)
126-
assert feedback in basic_flow.feedback
127-
128163
@patch("time.sleep", return_value=None)
129164
def test_run_without_stopping_condition(
130165
self, mocked_sleep, basic_flow
@@ -147,27 +182,57 @@ def test_bulk_run(self, basic_flow):
147182
responses = basic_flow.bulk_run(inputs)
148183
assert responses is not None
149184

150-
def test_save_and_load(self, basic_flow, tmp_path):
151-
"""Test save and load functionality"""
152-
file_path = tmp_path / "memory.json"
153-
basic_flow.memory.append(["Test1", "Test2"])
185+
def test_save_and_load(self, basic_flow, mocked_llm, tmp_path):
186+
"""State written by save() comes back through load().
187+
188+
Rewritten against the current API: the original appended to a
189+
`.memory` list the Agent no longer has. This is the only round-trip
190+
test save()/load() has at the Agent level, and it has not executed
191+
since 2025-10-21 — which is how the load() crash fixed in the parent
192+
commit shipped unnoticed.
193+
194+
load() restores scalar configuration; it deliberately preserves live
195+
instances (the LLM, short_memory) rather than rehydrating them, so
196+
the conversation is not part of the round trip.
197+
"""
198+
file_path = str(tmp_path / "agent_state.json")
199+
basic_flow.max_loops = 3
154200
basic_flow.save(file_path)
155201

156-
new_flow = Agent(llm=basic_flow.llm, max_loops=5)
157-
new_flow.load(file_path)
158-
assert new_flow.memory == [["Test1", "Test2"]]
202+
assert os.path.exists(file_path)
203+
204+
restored = Agent(
205+
agent_name="basic-flow-restored",
206+
llm=mocked_llm,
207+
max_loops=9,
208+
print_on=False,
209+
verbose=False,
210+
persistent_memory=False,
211+
autosave=False,
212+
workspace_dir=str(tmp_path),
213+
)
214+
restored.load(file_path)
215+
216+
assert restored.max_loops == 3
217+
assert restored.agent_name == "basic-flow"
159218

160219
def test_flow_call(self, basic_flow):
161-
"""Test calling agent directly"""
162-
response = basic_flow("Test call")
163-
assert response == "Test call"
220+
"""__call__ forwards to run() rather than doing its own thing.
221+
222+
Rewritten: this asserted the call returned its own input, which was
223+
only ever true of the deleted mock. Comparing two live calls does not
224+
work either — the conversation grows between them, so the second
225+
returns something different. What is worth pinning is the delegation.
226+
"""
227+
with patch.object(
228+
basic_flow, "run", return_value="routed"
229+
) as run:
230+
assert basic_flow("Test call") == "routed"
164231

165-
def test_format_prompt(self, basic_flow):
166-
"""Test prompt formatting"""
167-
formatted_prompt = basic_flow.format_prompt(
168-
"Hello {name}", name="John"
232+
run.assert_called_once()
233+
assert "Test call" in run.call_args.args or (
234+
run.call_args.kwargs.get("task") == "Test call"
169235
)
170-
assert formatted_prompt == "Hello John"
171236

172237

173238
# ============================================================================

0 commit comments

Comments
 (0)