fix backend tests

This commit is contained in:
SwiftyOS
2025-01-30 10:35:41 +01:00
parent 644cff8155
commit f3319f23ba
5 changed files with 32 additions and 11 deletions

View File

@@ -71,6 +71,8 @@ class Pagination(pydantic.BaseModel):
page_size: int = pydantic.Field(
description="Number of items per page.", examples=[25]
)
class RequestTopUp(pydantic.BaseModel):
amount: int
"""Amount of credits to top up."""

View File

@@ -215,7 +215,7 @@ class AgentServer(backend.util.service.AppProcess):
graph_id: str,
graph_version: int,
preset_id: str,
node_input: dict[typing.Any, typing.Any],
node_input: dict[Any, Any],
user_id: str,
):
return await backend.server.v2.library.routes.presets.execute_preset(

View File

@@ -487,6 +487,7 @@ def execute_graph(
graph_version: Optional[int] = None,
) -> dict[str, Any]: # FIXME: add proper return type
try:
logger.info(f"Node input: {node_input}")
graph_exec = execution_manager_client().add_execution(
graph_id, node_input, user_id=user_id, graph_version=graph_version
)

View File

@@ -73,6 +73,10 @@ async def create_preset(
],
) -> backend.server.v2.library.model.LibraryAgentPreset:
try:
# Automatically correct node_input format.
if preset.inputs is not None and "node_input" not in preset.inputs:
preset.inputs["node_input"] = preset.inputs
return await backend.server.v2.library.db.create_or_update_preset(
user_id, preset
)
@@ -133,12 +137,20 @@ async def execute_preset(
raise fastapi.HTTPException(status_code=404, detail="Preset not found")
logger.info(f"Preset inputs: {preset.inputs}")
logger.info(f"Node input: {node_input}")
updated_node_input = node_input.copy()
# Merge in preset input values
for key, value in preset.inputs.items():
if key not in updated_node_input:
updated_node_input[key] = value
if "node_input" not in updated_node_input:
updated_node_input = preset.inputs
elif "node_input" in preset.inputs and "node_input" in updated_node_input:
# Merge in preset input values
for key, value in preset.inputs["node_input"].items():
# If there is a value to update, update it
if key not in updated_node_input["node_input"]:
updated_node_input["node_input"][key] = value
logger.info(f"Updated node input: {updated_node_input}")
execution = execution_manager_client().add_execution(
graph_id=graph_id,

View File

@@ -363,8 +363,10 @@ async def test_execute_preset(server: SpinTestServer):
agent_id=test_graph.id,
agent_version=test_graph.version,
inputs={
"dictionary": {"key1": "Hello", "key2": "World"},
"selected_value": "key2",
"node_input": {
"dictionary": {"key1": "Hello", "key2": "World"},
"selected_value": "key2",
}
},
is_active=True,
)
@@ -453,11 +455,14 @@ async def test_execute_preset_with_clash(server: SpinTestServer):
agent_id=test_graph.id,
agent_version=test_graph.version,
inputs={
"dictionary": {"key1": "Hello", "key2": "World"},
"selected_value": "key2",
"node_input": {
"dictionary": {"key1": "Hello", "key2": "World"},
"selected_value": "key2",
}
},
is_active=True,
)
created_preset = await server.agent_server.test_create_preset(preset, test_user.id)
# Execute preset with overriding values
@@ -465,16 +470,17 @@ async def test_execute_preset_with_clash(server: SpinTestServer):
graph_id=test_graph.id,
graph_version=test_graph.version,
preset_id=created_preset.id,
node_input={"selected_value": "key1"},
node_input={"node_input": {"selected_value": "key1"}},
user_id=test_user.id,
)
# Verify execution
assert result is not None
assert result is not None, f"Result should not be None: {result}"
graph_exec_id = result["id"]
# Wait for execution to complete
executions = await wait_execution(test_user.id, test_graph.id, graph_exec_id)
# assert executions == [], f"Executions: {executions}"
assert len(executions) == 4
# FindInDictionaryBlock should wait for the input pin to be provided,