Skip to content

Commit 379384f

Browse files
authored
Merge pull request #75 from nforro/tools
Clearly indicate a successful tool run
2 parents 4d28545 + 656bbbe commit 379384f

File tree

9 files changed

+38
-35
lines changed

9 files changed

+38
-35
lines changed

beeai/agents/tests/unit/test_tools.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def test_add_changelog_entry(minimal_spec):
104104
input=AddChangelogEntryToolInput(spec=minimal_spec, content=content, author=author, email=email)
105105
).middleware(GlobalTrajectoryMiddleware(pretty=True))
106106
result = output.result
107-
assert not result
107+
assert result.startswith("Successfully")
108108
assert minimal_spec.read_text().splitlines()[-7:-2] == [
109109
"%changelog",
110110
"* Tue Aug 05 2025 rhel-packaging-agent <[email protected]> - 0.1-2",
@@ -121,7 +121,7 @@ async def test_bump_release(minimal_spec):
121121
GlobalTrajectoryMiddleware(pretty=True)
122122
)
123123
result = output.result
124-
assert not result
124+
assert result.startswith("Successfully")
125125
assert minimal_spec.read_text().splitlines()[3] == "Release: 3%{?dist}"
126126

127127

@@ -157,7 +157,7 @@ async def test_set_zstream_release(autorelease_spec):
157157
input=SetZStreamReleaseToolInput(spec=autorelease_spec, latest_ystream_evr=latest_ystream_evr)
158158
).middleware(GlobalTrajectoryMiddleware(pretty=True))
159159
result = output.result
160-
assert not result
160+
assert result.startswith("Successfully")
161161
assert autorelease_spec.read_text().splitlines()[3] == "Release: 4%{?dist}.%{autorelease -n}"
162162

163163

@@ -170,7 +170,7 @@ async def test_create(tmp_path):
170170
GlobalTrajectoryMiddleware(pretty=True)
171171
)
172172
result = output.result
173-
assert not result
173+
assert result.startswith("Successfully")
174174
assert test_file.read_text() == content
175175

176176

@@ -255,7 +255,7 @@ async def test_insert(line, content, tmp_path):
255255
input=InsertToolInput(file=test_file, line=line, new_string="Inserted line")
256256
).middleware(GlobalTrajectoryMiddleware(pretty=True))
257257
result = output.result
258-
assert not result
258+
assert result.startswith("Successfully")
259259
assert test_file.read_text() == content
260260

261261

@@ -268,7 +268,7 @@ async def test_str_replace(tmp_path):
268268
input=StrReplaceToolInput(file=test_file, old_string="Line 2", new_string="LINE_2")
269269
).middleware(GlobalTrajectoryMiddleware(pretty=True))
270270
result = output.result
271-
assert not result
271+
assert result.startswith("Successfully")
272272
assert (
273273
test_file.read_text()
274274
== dedent(

beeai/agents/tools/specfile.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AddChangelogEntryToolInput(BaseModel):
3030
class AddChangelogEntryTool(Tool[AddChangelogEntryToolInput, ToolRunOptions, StringToolOutput]):
3131
name = "add_changelog_entry"
3232
description = """
33-
Adds a new changelog entry to the specified spec file. Returns error message on failure.
33+
Adds a new changelog entry to the specified spec file.
3434
"""
3535
input_schema = AddChangelogEntryToolInput
3636

@@ -48,7 +48,7 @@ async def _run(
4848
spec.add_changelog_entry(tool_input.content, author=tool_input.author, email=tool_input.email)
4949
except Exception as e:
5050
return StringToolOutput(result=f"Failed to add changelog entry: {e}")
51-
return StringToolOutput()
51+
return StringToolOutput(result=f"Successfully added a new changelog entry to {tool_input.spec}")
5252

5353

5454
class BumpReleaseToolInput(BaseModel):
@@ -59,7 +59,6 @@ class BumpReleaseTool(Tool[BumpReleaseToolInput, ToolRunOptions, StringToolOutpu
5959
name = "bump_release"
6060
description = """
6161
Bumps (increments) the value of `Release` in the specified spec file.
62-
Returns error message on failure.
6362
"""
6463
input_schema = BumpReleaseToolInput
6564

@@ -77,7 +76,7 @@ async def _run(
7776
spec.bump_release()
7877
except Exception as e:
7978
return StringToolOutput(result=f"Failed to bump release: {e}")
80-
return StringToolOutput()
79+
return StringToolOutput(result=f"Successfully bumped release in {tool_input.spec}")
8180

8281

8382
class SetZStreamReleaseToolInput(BaseModel):
@@ -90,7 +89,6 @@ class SetZStreamReleaseTool(Tool[SetZStreamReleaseToolInput, ToolRunOptions, Str
9089
description = """
9190
Sets the value of the `Release` field in the specified spec file to a Z-Stream release
9291
based on the release of the latest Y-Stream build.
93-
Returns error message on failure.
9492
"""
9593
input_schema = SetZStreamReleaseToolInput
9694

@@ -112,4 +110,4 @@ async def _run(
112110
spec.raw_release = base_raw_release + "%{?dist}.%{autorelease -n}"
113111
except Exception as e:
114112
return StringToolOutput(result=f"Failed to set Z-Stream release: {e}")
115-
return StringToolOutput()
113+
return StringToolOutput(result=f"Successfully set Z-Stream release in {tool_input.spec}")

beeai/agents/tools/text.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class CreateTool(Tool[CreateToolInput, ToolRunOptions, StringToolOutput]):
1717
name = "create"
1818
description = """
1919
Creates a new file with the specified content.
20-
Returns error message on failure.
2120
"""
2221
input_schema = CreateToolInput
2322

@@ -34,7 +33,7 @@ async def _run(
3433
await asyncio.to_thread(tool_input.file.write_text, tool_input.content)
3534
except Exception as e:
3635
return StringToolOutput(result=f"Failed to create file: {e}")
37-
return StringToolOutput()
36+
return StringToolOutput(result=f"Successfully created {tool_input.file} with the specified text")
3837

3938

4039
class ViewToolInput(BaseModel):
@@ -60,7 +59,7 @@ class ViewTool(Tool[ViewToolInput, ToolRunOptions, StringToolOutput]):
6059
name = "view"
6160
description = """
6261
Outputs the contents of a file or lists the contents of a directory. Can read an entire file
63-
or a specific range of lines. Returns error message on failure.
62+
or a specific range of lines.
6463
"""
6564
input_schema = ViewToolInput
6665

@@ -96,7 +95,6 @@ class InsertTool(Tool[InsertToolInput, ToolRunOptions, StringToolOutput]):
9695
name = "insert"
9796
description = """
9897
Inserts the specified text at a specific location in a file.
99-
Returns error message on failure.
10098
"""
10199
input_schema = InsertToolInput
102100

@@ -115,7 +113,7 @@ async def _run(
115113
await asyncio.to_thread(tool_input.file.write_text, "".join(lines))
116114
except Exception as e:
117115
return StringToolOutput(result=f"Failed to insert text: {e}")
118-
return StringToolOutput()
116+
return StringToolOutput(result=f"Successfully inserted the specified text into {tool_input.file}")
119117

120118

121119
class StrReplaceToolInput(BaseModel):
@@ -130,7 +128,6 @@ class StrReplaceTool(Tool[StrReplaceToolInput, ToolRunOptions, StringToolOutput]
130128
name = "str_replace"
131129
description = """
132130
Replaces a specific string in the specified file with a new string.
133-
Returns error message on failure.
134131
"""
135132
input_schema = StrReplaceToolInput
136133

@@ -150,4 +147,4 @@ async def _run(
150147
)
151148
except Exception as e:
152149
return StringToolOutput(result=f"Failed to replace text: {e}")
153-
return StringToolOutput()
150+
return StringToolOutput(result=f"Successfully replaced the specified text in {tool_input.file}")

beeai/mcp_server/gitlab_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ def push_to_remote_repository(
5151
clone_path: Annotated[Path, Field(description="Absolute path to local clone of the repository")],
5252
branch: Annotated[str, Field(description="Branch to push")],
5353
force: Annotated[bool, Field(description="Whether to overwrite the remote ref")] = False,
54-
) -> str | None:
54+
) -> str:
5555
"""
5656
Pushes the specified branch from a local clone to the specified remote repository.
57-
Returns error message on failure.
5857
"""
5958
url = urlparse(repository)
6059
token = os.getenv("GITLAB_TOKEN")
@@ -64,3 +63,4 @@ def push_to_remote_repository(
6463
command.append("--force")
6564
if subprocess.run(command, cwd=clone_path).returncode != 0:
6665
return "Failed to push to the specified repository"
66+
return f"Successfully pushed the specified branch to {repository}"

beeai/mcp_server/jira_tools.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ def set_jira_fields(
6464
preliminary_testing: Annotated[
6565
PreliminaryTesting | None, Field(description="Preliminary Testing value")
6666
] = None,
67-
) -> str | None:
67+
) -> str:
6868
"""
6969
Updates the specified Jira issue, setting the specified fields (if provided).
70-
Returns error message on failure.
7170
"""
7271
fields = {}
7372
if fix_versions is not None:
@@ -77,7 +76,7 @@ def set_jira_fields(
7776
if preliminary_testing is not None:
7877
fields["customfield_12321540"] = {"value": preliminary_testing.value}
7978
if not fields:
80-
return
79+
return "No fields to update have been specified, not doing anything"
8180
try:
8281
response = requests.put(
8382
urljoin(os.getenv("JIRA_URL"), f"rest/api/2/issue/{issue_key}"),
@@ -87,14 +86,15 @@ def set_jira_fields(
8786
response.raise_for_status()
8887
except requests.RequestException as e:
8988
return f"Failed to set the specified fields: {e}"
89+
return f"Successfully set the specified fields in {issue_key}"
9090

9191

9292
def add_jira_comment(
9393
issue_key: Annotated[str, Field(description="Jira issue key (e.g. RHEL-12345)")],
9494
comment: Annotated[str, Field(description="Comment text to add")],
95-
) -> str | None:
95+
) -> str:
9696
"""
97-
Adds a comment to the specified Jira issue. Returns error message on failure.
97+
Adds a comment to the specified Jira issue.
9898
"""
9999
try:
100100
response = requests.post(
@@ -105,3 +105,4 @@ def add_jira_comment(
105105
response.raise_for_status()
106106
except requests.RequestException as e:
107107
return f"Failed to add the specified comment: {e}"
108+
return f"Successfully added the specified comment to {issue_key}"

beeai/mcp_server/lookaside_tools.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@
1010
def download_sources(
1111
dist_git_path: Annotated[Path, Field(description="Path to cloned dist-git repository")],
1212
internal: Annotated[bool, Field(description="Whether to use internal RHEL dist-git instead of CentOS Stream one")] = False,
13-
) -> str | None:
13+
) -> str:
1414
"""
15-
Downloads sources from lookaside cache. Returns error message on failure.
15+
Downloads sources from lookaside cache.
1616
"""
1717
tool = "rhpkg" if internal else "centpkg"
1818
if subprocess.run([tool, "sources"], cwd=dist_git_path).returncode != 0:
1919
return "Failed to download sources"
20+
return "Successfully downloaded sources from lookaside cache"
2021

2122

2223
def upload_sources(
2324
dist_git_path: Annotated[Path, Field(description="Path to cloned dist-git repository")],
2425
new_sources: Annotated[list[str], Field(description="List of new sources (file names) to upload")],
2526
internal: Annotated[bool, Field(description="Whether to use internal RHEL dist-git instead of CentOS Stream one")] = False,
26-
) -> str | None:
27+
) -> str:
2728
"""
2829
Uploads the specified sources to lookaside cache. Also updates the `sources` and `.gitignore` files
29-
accordingly and adds them to git index. Returns error message on failure.
30+
accordingly and adds them to git index.
3031
"""
3132
tool = "rhpkg" if internal else "centpkg"
3233
if not init_kerberos_ticket():
3334
return "Failed to initialize Kerberos ticket"
3435
if subprocess.run([tool, "new-sources", *new_sources], cwd=dist_git_path).returncode != 0:
3536
return "Failed to upload sources"
37+
return "Successfully uploaded the specified new sources to lookaside cache"

beeai/mcp_server/tests/unit/test_gitlab_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ def run(cmd, **kwargs):
5353
return flexmock(returncode=0)
5454

5555
flexmock(subprocess).should_receive("run").replace_with(run)
56-
assert push_to_remote_repository(repository=repository, clone_path=clone_path, branch=branch) is None
56+
result = push_to_remote_repository(repository=repository, clone_path=clone_path, branch=branch)
57+
assert result.startswith("Successfully")

beeai/mcp_server/tests/unit/test_jira_tools.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def put(url, json, headers):
5757
return flexmock(raise_for_status=lambda: None)
5858

5959
flexmock(requests).should_receive("put").replace_with(put)
60-
assert set_jira_fields(issue_key, **args) is None
60+
result = set_jira_fields(issue_key, **args)
61+
assert result.startswith("Successfully")
6162

6263

6364
def test_add_jira_comment():
@@ -70,4 +71,5 @@ def post(url, json, headers):
7071
return flexmock(raise_for_status=lambda: None)
7172

7273
flexmock(requests).should_receive("post").replace_with(post)
73-
assert add_jira_comment(issue_key, comment) is None
74+
result = add_jira_comment(issue_key, comment)
75+
assert result.startswith("Successfully")

beeai/mcp_server/tests/unit/test_lookaside.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ def run(cmd, **kwargs):
1717
return flexmock(returncode=0)
1818

1919
flexmock(subprocess).should_receive("run").replace_with(run)
20-
assert download_sources(dist_git_path=".", internal=internal) is None
20+
result = download_sources(dist_git_path=".", internal=internal)
21+
assert result.startswith("Successfully")
2122

2223

2324
@pytest.mark.parametrize(
@@ -32,4 +33,5 @@ def run(cmd, **kwargs):
3233

3334
flexmock(lookaside_tools).should_receive("init_kerberos_ticket").and_return(True).once()
3435
flexmock(subprocess).should_receive("run").replace_with(run)
35-
assert upload_sources(dist_git_path=".", new_sources=new_sources, internal=internal) is None
36+
result = upload_sources(dist_git_path=".", new_sources=new_sources, internal=internal)
37+
assert result.startswith("Successfully")

0 commit comments

Comments
 (0)