fix assert used
This commit is contained in:
+4
-2
@@ -71,7 +71,8 @@ class BaseAgent(Agent):
|
|||||||
"""Run a single interaction with the agent."""
|
"""Run a single interaction with the agent."""
|
||||||
if self.model is None:
|
if self.model is None:
|
||||||
await self.initialize()
|
await self.initialize()
|
||||||
assert self.model is not None
|
if self.model is None:
|
||||||
|
raise RuntimeError("Model initialization failed: model is None")
|
||||||
|
|
||||||
messages: list[dict[str, str]] = [
|
messages: list[dict[str, str]] = [
|
||||||
{"role": "system", "content": self.system_prompt},
|
{"role": "system", "content": self.system_prompt},
|
||||||
@@ -91,7 +92,8 @@ class BaseAgent(Agent):
|
|||||||
"""Run the agent with tool calling capability."""
|
"""Run the agent with tool calling capability."""
|
||||||
if self.model is None:
|
if self.model is None:
|
||||||
await self.initialize()
|
await self.initialize()
|
||||||
assert self.model is not None
|
if self.model is None:
|
||||||
|
raise RuntimeError("Model initialization failed: model is None")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
capture = _ActResponseCapture()
|
capture = _ActResponseCapture()
|
||||||
|
|||||||
+6
-3
@@ -489,7 +489,8 @@ class IssueTaskProcessor(TaskProcessor):
|
|||||||
return f"SKIP: Awaiting human reply on issue #{self.item.task_number} or PR."
|
return f"SKIP: Awaiting human reply on issue #{self.item.task_number} or PR."
|
||||||
|
|
||||||
issue_info = self.item.task_info
|
issue_info = self.item.task_info
|
||||||
assert isinstance(issue_info, IssueModel)
|
if not isinstance(issue_info, IssueModel):
|
||||||
|
raise TypeError("Expected task_info to be an IssueModel")
|
||||||
title = issue_info.title
|
title = issue_info.title
|
||||||
issue_body = issue_info.body or "No description provided."
|
issue_body = issue_info.body or "No description provided."
|
||||||
|
|
||||||
@@ -738,7 +739,8 @@ class AgentDispatcher:
|
|||||||
|
|
||||||
def _build_pr_mission(self, item: WorkItem) -> str:
|
def _build_pr_mission(self, item: WorkItem) -> str:
|
||||||
pr_info = item.task_info
|
pr_info = item.task_info
|
||||||
assert isinstance(pr_info, PullRequestModel)
|
if not isinstance(pr_info, PullRequestModel):
|
||||||
|
raise TypeError("Expected task_info to be a PullRequestModel")
|
||||||
processor = PRTaskProcessor(
|
processor = PRTaskProcessor(
|
||||||
client=self._client,
|
client=self._client,
|
||||||
tools=self._tools,
|
tools=self._tools,
|
||||||
@@ -751,7 +753,8 @@ class AgentDispatcher:
|
|||||||
|
|
||||||
def _build_issue_mission(self, item: WorkItem) -> str:
|
def _build_issue_mission(self, item: WorkItem) -> str:
|
||||||
issue_info = item.task_info
|
issue_info = item.task_info
|
||||||
assert isinstance(issue_info, IssueModel)
|
if not isinstance(issue_info, IssueModel):
|
||||||
|
raise TypeError("Expected task_info to be an IssueModel")
|
||||||
processor = IssueTaskProcessor(
|
processor = IssueTaskProcessor(
|
||||||
client=self._client,
|
client=self._client,
|
||||||
tools=self._tools,
|
tools=self._tools,
|
||||||
|
|||||||
@@ -542,3 +542,42 @@ async def test_dispatch_uses_coordinator_tool_calling(mock_coord_class: MagicMoc
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_dispatcher_raises_type_error_for_invalid_task_info() -> None:
|
||||||
|
mock_client: MagicMock = MagicMock(spec=GiteaClient)
|
||||||
|
mock_tools: MagicMock = MagicMock(spec=GiteaTools)
|
||||||
|
|
||||||
|
# Mock return values for methods called prior to the isinstance check
|
||||||
|
mock_client.list_repo_pull_requests.return_value = []
|
||||||
|
mock_client.get_issue_comments.return_value = []
|
||||||
|
mock_client.get_authenticated_user.return_value = UserModel(login="meeks-ai")
|
||||||
|
|
||||||
|
dispatcher = AgentDispatcher(client=mock_client, tools=mock_tools)
|
||||||
|
|
||||||
|
# 1. Test dispatch raises TypeError if task_info is not IssueModel for an issue task
|
||||||
|
work_item_invalid_issue = WorkItem(
|
||||||
|
repo_full_name="meeks/repo1",
|
||||||
|
task_type="issue",
|
||||||
|
task_number=42,
|
||||||
|
task_info=PullRequestModel(number=42), # Invalid model type
|
||||||
|
priority=0
|
||||||
|
)
|
||||||
|
with pytest.raises(TypeError, match="Expected task_info to be an IssueModel"):
|
||||||
|
await dispatcher.dispatch("meeks/repo1", [work_item_invalid_issue])
|
||||||
|
|
||||||
|
# 2. Test _build_pr_mission raises TypeError if task_info is not PullRequestModel
|
||||||
|
work_item_invalid_pr = WorkItem(
|
||||||
|
repo_full_name="meeks/repo1",
|
||||||
|
task_type="pr",
|
||||||
|
task_number=42,
|
||||||
|
task_info=IssueModel(number=42), # Invalid model type
|
||||||
|
priority=0
|
||||||
|
)
|
||||||
|
with pytest.raises(TypeError, match="Expected task_info to be a PullRequestModel"):
|
||||||
|
dispatcher._build_pr_mission(work_item_invalid_pr)
|
||||||
|
|
||||||
|
# 3. Test _build_issue_mission raises TypeError if task_info is not IssueModel
|
||||||
|
with pytest.raises(TypeError, match="Expected task_info to be an IssueModel"):
|
||||||
|
dispatcher._build_issue_mission(work_item_invalid_issue)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user