fix failed test cases

This commit is contained in:
Medyan
2026-01-30 12:43:15 -05:00
committed by Otto (AGPT)
parent 2891e5c48e
commit 21631a565b
3 changed files with 50 additions and 10 deletions

View File

@@ -385,13 +385,28 @@ async def get_library_agent_by_graph_id(
graph_id: str,
graph_version: Optional[int] = None,
) -> library_model.LibraryAgent | None:
filter: prisma.types.LibraryAgentWhereInput = {
"agentGraphId": graph_id,
"userId": user_id,
"isDeleted": False,
}
if graph_version is not None:
filter["agentGraphVersion"] = graph_version
"""
Retrieves a library agent by its graph ID for a given user.
Args:
user_id: The ID of the user who owns the library agent.
graph_id: The ID of the agent graph to look up.
graph_version: Optional specific version of the graph to retrieve.
Returns:
The LibraryAgent if found, otherwise None.
Raises:
DatabaseError: If there's an error during retrieval.
"""
try:
filter: prisma.types.LibraryAgentWhereInput = {
"agentGraphId": graph_id,
"userId": user_id,
"isDeleted": False,
}
if graph_version is not None:
filter["agentGraphVersion"] = graph_version
agent = await prisma.models.LibraryAgent.prisma().find_first(
where=filter,
@@ -772,6 +787,17 @@ async def update_library_agent(
async def delete_library_agent(
library_agent_id: str, user_id: str, soft_delete: bool = True
) -> None:
"""
Deletes a library agent and cleans up associated schedules and webhooks.
Args:
library_agent_id: The ID of the library agent to delete.
user_id: The ID of the user who owns the library agent.
soft_delete: If True, marks the agent as deleted; if False, permanently removes it.
Raises:
NotFoundError: If the library agent is not found or doesn't belong to the user.
"""
# First get the agent to find the graph_id for cleanup
library_agent = await prisma.models.LibraryAgent.prisma().find_unique(
where={"id": library_agent_id}, include={"AgentGraph": True}
@@ -1875,6 +1901,20 @@ async def update_preset(
async def set_preset_webhook(
user_id: str, preset_id: str, webhook_id: str | None
) -> library_model.LibraryAgentPreset:
"""
Sets or removes a webhook connection for a preset.
Args:
user_id: The ID of the user who owns the preset.
preset_id: The ID of the preset to update.
webhook_id: The ID of the webhook to connect, or None to disconnect.
Returns:
The updated LibraryAgentPreset.
Raises:
NotFoundError: If the preset is not found or doesn't belong to the user.
"""
current = await prisma.models.AgentPreset.prisma().find_unique(
where={"id": preset_id},
include=AGENT_PRESET_INCLUDE,

View File

@@ -110,7 +110,7 @@ async def test_get_library_agents_success(
mock_db_call.assert_called_once_with(
user_id=test_user_id,
search_term="test",
sort_by=library_model.LibraryAgentSort.UPDATED_AT,
sort_by=library_model.LibraryAgentSort.LAST_EXECUTED,
page=1,
page_size=15,
folder_id=None,

View File

@@ -3596,7 +3596,7 @@
"schema": {
"$ref": "#/components/schemas/LibraryAgentSort",
"description": "Criteria to sort results by",
"default": "updatedAt"
"default": "lastExecuted"
},
"description": "Criteria to sort results by"
},
@@ -10499,7 +10499,7 @@
},
"LibraryAgentSort": {
"type": "string",
"enum": ["createdAt", "updatedAt"],
"enum": ["createdAt", "updatedAt", "lastExecuted"],
"title": "LibraryAgentSort",
"description": "Possible sort options for sorting library agents."
},