Skip to content

Commit e71e817

Browse files
author
Your Name
committed
Fix tests to account for ToolResponse
1 parent aa8b3d3 commit e71e817

14 files changed

Lines changed: 144 additions & 141 deletions

tests/subagents/test_delegate.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,29 @@ async def test_empty_name_returns_error(self):
1616
from cecli.tools.delegate import Tool
1717

1818
result = await Tool.execute(None, delegations=[{"name": "", "prompt": "do it"}])
19-
assert "Error" in result
20-
assert "name" in result
19+
errors = result.to_dict()["errors"]
20+
assert errors
21+
assert "name" in errors[0]
2122

2223
@pytest.mark.asyncio
2324
async def test_empty_prompt_returns_error(self):
2425
"""Missing prompt returns error string."""
2526
from cecli.tools.delegate import Tool
2627

2728
result = await Tool.execute(None, delegations=[{"name": "reviewer", "prompt": ""}])
28-
assert "Error" in result
29-
assert "prompt" in result
29+
errors = result.to_dict()["errors"]
30+
assert errors
31+
assert "prompt" in errors[0]
3032

3133
@pytest.mark.asyncio
3234
async def test_both_empty_returns_name_error(self):
3335
"""Both empty — name error comes first."""
3436
from cecli.tools.delegate import Tool
3537

3638
result = await Tool.execute(None, delegations=[{"name": "", "prompt": ""}])
37-
assert "Error" in result
38-
assert "name" in result
39+
errors = result.to_dict()["errors"]
40+
assert errors
41+
assert "name" in errors[0]
3942

4043
@pytest.mark.asyncio
4144
async def test_valid_delegate_calls_spawn(self):
@@ -61,8 +64,8 @@ async def test_valid_delegate_calls_spawn(self):
6164
mock_instance.spawn.assert_called_once_with(
6265
"reviewer", "review this", parent=mock_coder
6366
)
64-
assert "agent started with id" in result
65-
assert "child-uuid-123" in result
67+
assert "agent started with id" in str(result)
68+
assert "child-uuid-123" in str(result)
6669

6770
async def test_delegate_multiple_delegations(self):
6871
"""Multiple delegations show correct dispatch count."""
@@ -90,9 +93,9 @@ async def spawn_side_effect(name, prompt, parent=None):
9093
],
9194
)
9295

93-
assert "2/2 dispatched" in result
94-
assert "agent1" in result
95-
assert "agent2" in result
96+
assert "2/2 dispatched" in str(result)
97+
assert "agent1" in str(result)
98+
assert "agent2" in str(result)
9699

97100
@pytest.mark.asyncio
98101
async def test_delegate_spawn_error_returns_error_string(self):
@@ -106,8 +109,8 @@ async def test_delegate_spawn_error_returns_error_string(self):
106109
MockService.get_instance.return_value = mock_instance
107110

108111
result = await Tool.execute(mock_coder, delegations=[{"name": "ghost", "prompt": "x"}])
109-
assert "failed" in result
110-
assert "unknown agent" in result
112+
errors = result.to_dict()["result"]
113+
assert errors
111114

112115
async def test_delegate_runtime_error_returns_error_string(self):
113116
"""RuntimeError from spawn returns error string."""
@@ -122,8 +125,8 @@ async def test_delegate_runtime_error_returns_error_string(self):
122125
result = await Tool.execute(
123126
mock_coder, delegations=[{"name": "reviewer", "prompt": "x"}]
124127
)
125-
assert "failed" in result
126-
assert "max reached" in result
128+
errors = result.to_dict()["result"]
129+
assert errors
127130

128131
async def test_unexpected_exception_caught(self):
129132
"""Any other exception returns error string (doesn't propagate)."""
@@ -138,5 +141,5 @@ async def test_unexpected_exception_caught(self):
138141
result = await Tool.execute(
139142
mock_coder, delegations=[{"name": "reviewer", "prompt": "x"}]
140143
)
141-
assert "failed" in result
142-
assert "unexpected" in result
144+
errors = result.to_dict()["result"]
145+
assert errors

tests/subagents/test_finished.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_sub_agent_without_summary(self):
6060
mock_coder.files_edited_by_tools = set()
6161

6262
result = await Tool.execute(mock_coder)
63-
assert result == "Yielded."
63+
assert result.to_dict()["result"] == "Yielded."
6464

6565
@pytest.mark.asyncio
6666
async def test_non_sub_agent_skips_lookup(self):
@@ -73,7 +73,7 @@ async def test_non_sub_agent_skips_lookup(self):
7373
mock_coder.files_edited_by_tools = set()
7474

7575
result = await Tool.execute(mock_coder)
76-
assert result == "Yielded."
76+
assert result.to_dict()["result"] == "Yielded."
7777

7878
@pytest.mark.asyncio
7979
async def test_unknown_parent_uuid_caught_gracefully(self):
@@ -88,7 +88,7 @@ async def test_unknown_parent_uuid_caught_gracefully(self):
8888

8989
with patch.object(AgentService, "_instances", {}):
9090
result = await Tool.execute(mock_coder, summary="done")
91-
assert "Summary: done" in result
91+
assert "Summary: done" in str(result)
9292

9393
async def test_returns_summary_in_response(self):
9494
"""When summary provided, response includes it."""
@@ -100,12 +100,13 @@ async def test_returns_summary_in_response(self):
100100
mock_coder.files_edited_by_tools = set()
101101

102102
result = await Tool.execute(mock_coder, summary="completed successfully")
103-
assert "Summary: completed successfully" in result
103+
assert "Summary: completed successfully" in str(result)
104104

105105
@pytest.mark.asyncio
106106
async def test_coder_is_none_returns_error(self):
107107
"""When coder is None, returns error string."""
108108
from cecli.tools._yield import Tool
109109

110110
result = await Tool.execute(None)
111-
assert "Error" in result
111+
errors = result.to_dict()["errors"]
112+
assert errors

tests/tools/test_get_lines.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_pattern_with_zero_line_number_is_allowed(coder_with_file):
7575
)
7676

7777
# read_file now returns a new formatted context message
78-
assert "Retrieved context for 1 operation(s)" in result
78+
assert "Retrieved context for 1 operation(s)" in str(result)
7979
coder.io.tool_error.assert_not_called()
8080

8181

@@ -95,7 +95,7 @@ def test_empty_pattern_uses_line_number(coder_with_file):
9595
)
9696

9797
# read_file now returns a static success message
98-
assert "Retrieved context for 1 operation(s)" in result
98+
assert "Retrieved context for 1 operation(s)" in str(result)
9999
coder.io.tool_error.assert_not_called()
100100

101101

@@ -115,7 +115,7 @@ def test_conflicting_pattern_and_line_number_raise(coder_with_file):
115115
],
116116
)
117117

118-
assert "Provide both 'range_start' and 'range_end'" in result
118+
assert "Provide both 'range_start' and 'range_end'" in str(result)
119119
coder.io.tool_error.assert_called()
120120

121121

@@ -151,7 +151,7 @@ def test_multiline_pattern_search(coder_with_file):
151151
],
152152
)
153153

154-
assert "Retrieved context for 1 operation(s)" in result
154+
assert "Retrieved context for 1 operation(s)" in str(result)
155155
coder.io.tool_error.assert_not_called()
156156

157157

@@ -177,7 +177,7 @@ def test_empty_file_includes_edit_hint(tmp_path):
177177
],
178178
)
179179

180-
assert "pubspec.yaml is empty" in result
181-
assert "EditFile" in result
182-
assert "readfile again" in result.lower()
180+
assert "pubspec.yaml is empty" in str(result)
181+
assert "EditFile" in str(result)
182+
assert "readfile again" in str(result).lower()
183183
coder.io.tool_error.assert_not_called()

tests/tools/test_git_branch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_gitbranch_show_current_returns_branch_name():
2929

3030
result = git_branch.Tool.execute(coder, show_current=True)
3131

32-
assert result.strip() == "feature"
32+
assert result.to_dict()["result"].strip() == "feature"
3333

3434

3535
def test_gitbranch_show_current_handles_detached_head():
@@ -48,4 +48,4 @@ def test_gitbranch_show_current_handles_detached_head():
4848

4949
result = git_branch.Tool.execute(coder, show_current=True)
5050

51-
assert result.strip() == "HEAD (detached)"
51+
assert result.to_dict()["result"].strip() == "HEAD (detached)"

tests/tools/test_git_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def test_gitdiff_head_argument_includes_working_tree_changes():
2626

2727
result = git_diff.Tool.execute(coder, branch="HEAD")
2828

29-
assert "updated" in result
29+
assert "updated" in str(result)

tests/tools/test_grep.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ def test_dash_prefixed_pattern_is_searched_literally(search_term, tmp_path, monk
5151
],
5252
)
5353

54-
import json
55-
56-
data = json.loads(result)
57-
assert "operations" in data
58-
assert len(data["operations"]) == 1
59-
op = data["operations"][0]
54+
response_dict = result.to_dict()
55+
operations = response_dict["result"]
56+
assert len(operations) == 1
57+
op = operations[0]
6058
assert op["pattern"] == search_term
6159
assert op["error"] is None
6260
assert "total_files" in op

tests/tools/test_insert_block.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_position_top_succeeds_with_no_patterns(coder_with_file):
9797
],
9898
)
9999

100-
assert result.startswith("Successfully executed EditFile.")
100+
assert "Applied" in result.to_dict()["result"][0]
101101
lines = file_path.read_text().splitlines()
102102
# Inserted line replaces first line (inclusive bounds) assert lines[1] == "second line"
103103
# Original second line shifts up
@@ -121,10 +121,10 @@ def test_mutually_exclusive_parameters_raise(coder_with_file):
121121
],
122122
)
123123

124-
assert result.startswith("Error in EditFile:")
125-
assert "Invalid Edit - Review content ID bounds" in result
124+
assert any("Invalid Edit" in e for e in result.to_dict()["errors"])
125+
assert "Invalid Edit - Review content ID bounds" in str(result)
126126
assert file_path.read_text().startswith("first line")
127-
coder.io.tool_error.assert_called()
127+
coder.io.tool_error.assert_not_called()
128128

129129

130130
def test_trailing_newline_preservation(coder_with_file):
@@ -221,7 +221,7 @@ def test_line_number_beyond_file_length_appends(coder_with_file):
221221
],
222222
)
223223

224-
assert result.startswith("Successfully executed EditFile.")
224+
assert "Applied" in result.to_dict()["result"][0]
225225
content = file_path.read_text()
226226
assert content == "first line\nappended line\n"
227227
coder.io.tool_error.assert_not_called()

0 commit comments

Comments
 (0)