Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: enhance test (#29002)

wangxiaoleid6bbf0f97585
diff --git a/api/tests/fixtures/workflow/iteration_flatten_output_disabled_workflow.yml b/api/tests/fixtures/workflow/iteration_flatten_output_disabled_workflow.yml
index 9cae6385c88..b2451c7a9e7 100644
--- a/api/tests/fixtures/workflow/iteration_flatten_output_disabled_workflow.yml
+++ b/api/tests/fixtures/workflow/iteration_flatten_output_disabled_workflow.yml
@@ -233,7 +233,7 @@ workflow:
- value_selector:
- iteration_node
- output
- value_type: array[array[number]]
+ value_type: array[number]
variable: output
selected: false
title: End
diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_iteration_flatten_output.py b/api/tests/unit_tests/core/workflow/graph_engine/test_iteration_flatten_output.py
index 98f344babf6..b9bf4be13a0 100644
--- a/api/tests/unit_tests/core/workflow/graph_engine/test_iteration_flatten_output.py
+++ b/api/tests/unit_tests/core/workflow/graph_engine/test_iteration_flatten_output.py
@@ -7,9 +7,31 @@ This module tests the iteration node's ability to:
"""
from .test_database_utils import skip_if_database_unavailable
+from .test_mock_config import MockConfigBuilder, NodeMockConfig
from .test_table_runner import TableTestRunner, WorkflowTestCase
+def _create_iteration_mock_config():
+ """Helper to create a mock config for iteration tests."""
+
+ def code_inner_handler(node):
+ pool = node.graph_runtime_state.variable_pool
+ item_seg = pool.get(["iteration_node", "item"])
+ if item_seg is not None:
+ item = item_seg.to_object()
+ return {"result": [item, item * 2]}
+ # This fallback is likely unreachable, but if it is,
+ # it doesn't simulate iteration with different values as the comment suggests.
+ return {"result": [1, 2]}
+
+ return (
+ MockConfigBuilder()
+ .with_node_output("code_node", {"result": [1, 2, 3]})
+ .with_node_config(NodeMockConfig(node_id="code_inner_node", custom_handler=code_inner_handler))
+ .build()
+ )
+
+
@skip_if_database_unavailable()
def test_iteration_with_flatten_output_enabled():
"""
@@ -27,7 +49,8 @@ def test_iteration_with_flatten_output_enabled():
inputs={},
expected_outputs={"output": [1, 2, 2, 4, 3, 6]},
description="Iteration with flatten_output=True flattens nested arrays",
- use_auto_mock=False, # Run code nodes directly
+ use_auto_mock=True, # Use auto-mock to avoid sandbox service
+ mock_config=_create_iteration_mock_config(),
)
result = runner.run_test_case(test_case)
@@ -56,7 +79,8 @@ def test_iteration_with_flatten_output_disabled():
inputs={},
expected_outputs={"output": [[1, 2], [2, 4], [3, 6]]},
description="Iteration with flatten_output=False preserves nested structure",
- use_auto_mock=False, # Run code nodes directly
+ use_auto_mock=True, # Use auto-mock to avoid sandbox service
+ mock_config=_create_iteration_mock_config(),
)
result = runner.run_test_case(test_case)
@@ -81,14 +105,16 @@ def test_iteration_flatten_output_comparison():
inputs={},
expected_outputs={"output": [1, 2, 2, 4, 3, 6]},
description="flatten_output=True: Flattened output",
- use_auto_mock=False, # Run code nodes directly
+ use_auto_mock=True, # Use auto-mock to avoid sandbox service
+ mock_config=_create_iteration_mock_config(),
),
WorkflowTestCase(
fixture_path="iteration_flatten_output_disabled_workflow",
inputs={},
expected_outputs={"output": [[1, 2], [2, 4], [3, 6]]},
description="flatten_output=False: Nested output",
- use_auto_mock=False, # Run code nodes directly
+ use_auto_mock=True, # Use auto-mock to avoid sandbox service
+ mock_config=_create_iteration_mock_config(),
),
]