From 11b1077c8aac6476f82261093a02145135754fcc Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Mon, 9 Jun 2025 16:18:26 +0800 Subject: [PATCH] test(api): fix broken tests --- .../app/workflow_draft_variables_test.py | 22 ++++++++++++++----- api/models/workflow.py | 3 ++- .../test_workflow_draft_variable_service.py | 8 +++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/api/controllers/console/app/workflow_draft_variables_test.py b/api/controllers/console/app/workflow_draft_variables_test.py index c196ef8d9d..52c52f8a61 100644 --- a/api/controllers/console/app/workflow_draft_variables_test.py +++ b/api/controllers/console/app/workflow_draft_variables_test.py @@ -1,7 +1,7 @@ import datetime import uuid from collections import OrderedDict -from typing import NamedTuple +from typing import Any, NamedTuple from flask_restful import marshal @@ -18,6 +18,7 @@ from .workflow_draft_variable import ( ) _TEST_APP_ID = "test_app_id" +_TEST_NODE_EXEC_ID = str(uuid.uuid4()) class TestWorkflowDraftVariableFields: @@ -29,7 +30,7 @@ class TestWorkflowDraftVariableFields: conv_var.id = str(uuid.uuid4()) conv_var.visible = True - expected_without_value = OrderedDict( + expected_without_value: OrderedDict[str, Any] = OrderedDict( { "id": str(conv_var.id), "type": conv_var.get_variable_type().value, @@ -53,6 +54,7 @@ class TestWorkflowDraftVariableFields: name="sys_var", value=build_segment("a"), editable=True, + node_execution_id=_TEST_NODE_EXEC_ID, ) sys_var.id = str(uuid.uuid4()) @@ -83,12 +85,13 @@ class TestWorkflowDraftVariableFields: name="node_var", value=build_segment([1, "a"]), visible=False, + node_execution_id=_TEST_NODE_EXEC_ID, ) node_var.id = str(uuid.uuid4()) node_var.last_edited_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None) - expected_without_value = OrderedDict( + expected_without_value: OrderedDict[str, Any] = OrderedDict( { "id": str(node_var.id), "type": node_var.get_variable_type().value, @@ -120,6 +123,7 @@ class TestWorkflowDraftVariableList: name="test_var", value=build_segment("a"), visible=True, + node_execution_id=_TEST_NODE_EXEC_ID, ) node_var.id = str(uuid.uuid4()) node_var_dict = OrderedDict( @@ -216,7 +220,11 @@ def test_workflow_file_variable_with_signed_url(): # Create a WorkflowDraftVariable with the File file_var = WorkflowDraftVariable.new_node_variable( - app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file) + app_id=_TEST_APP_ID, + node_id="test_node", + name="file_var", + value=build_segment(test_file), + node_execution_id=_TEST_NODE_EXEC_ID, ) # Marshal the variable using the API fields @@ -270,7 +278,11 @@ def test_workflow_file_variable_remote_url(): # Create a WorkflowDraftVariable with the File file_var = WorkflowDraftVariable.new_node_variable( - app_id=_TEST_APP_ID, node_id="test_node", name="file_var", value=build_segment(test_file) + app_id=_TEST_APP_ID, + node_id="test_node", + name="file_var", + value=build_segment(test_file), + node_execution_id=_TEST_NODE_EXEC_ID, ) # Marshal the variable using the API fields diff --git a/api/models/workflow.py b/api/models/workflow.py index bdabc14da6..9c02d0dcb2 100644 --- a/api/models/workflow.py +++ b/api/models/workflow.py @@ -1107,7 +1107,7 @@ class WorkflowDraftVariable(Base): node_id: str, name: str, value: Segment, - node_execution_id: str | None = None, + node_execution_id: str | None, description: str = "", ) -> "WorkflowDraftVariable": variable = WorkflowDraftVariable() @@ -1137,6 +1137,7 @@ class WorkflowDraftVariable(Base): name=name, value=value, description=description, + node_execution_id=None, ) return variable diff --git a/api/tests/integration_tests/services/test_workflow_draft_variable_service.py b/api/tests/integration_tests/services/test_workflow_draft_variable_service.py index 466c390155..a7e5599098 100644 --- a/api/tests/integration_tests/services/test_workflow_draft_variable_service.py +++ b/api/tests/integration_tests/services/test_workflow_draft_variable_service.py @@ -17,6 +17,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase): _session: Session _node1_id = "test_node_1" _node2_id = "test_node_2" + _node_exec_id = str(uuid.uuid4()) def setUp(self): self._test_app_id = str(uuid.uuid4()) @@ -25,6 +26,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase): app_id=self._test_app_id, name="sys_var", value=build_segment("sys_value"), + node_execution_id=self._node_exec_id, ) conv_var = WorkflowDraftVariable.new_conversation_variable( app_id=self._test_app_id, @@ -38,6 +40,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase): name="int_var", value=build_segment(1), visible=False, + node_execution_id=self._node_exec_id, ), WorkflowDraftVariable.new_node_variable( app_id=self._test_app_id, @@ -45,6 +48,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase): name="str_var", value=build_segment("str_value"), visible=True, + node_execution_id=self._node_exec_id, ), ] node1_var = WorkflowDraftVariable.new_node_variable( @@ -53,6 +57,7 @@ class TestWorkflowDraftVariableService(unittest.TestCase): name="str_var", value=build_segment("str_value"), visible=True, + node_execution_id=self._node_exec_id, ) _variables = list(node2_vars) _variables.extend( @@ -163,6 +168,7 @@ class TestDraftVariableLoader(unittest.TestCase): _test_app_id: str _node1_id = "test_loader_node_1" + _node_exec_id = str(uuid.uuid4()) def setUp(self): self._test_app_id = str(uuid.uuid4()) @@ -170,6 +176,7 @@ class TestDraftVariableLoader(unittest.TestCase): app_id=self._test_app_id, name="sys_var", value=build_segment("sys_value"), + node_execution_id=self._node_exec_id, ) conv_var = WorkflowDraftVariable.new_conversation_variable( app_id=self._test_app_id, @@ -182,6 +189,7 @@ class TestDraftVariableLoader(unittest.TestCase): name="str_var", value=build_segment("str_value"), visible=True, + node_execution_id=self._node_exec_id, ) _variables = [ node_var,