mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
Merge remote-tracking branch 'origin/main' into feat/support-agent-sandbox
This commit is contained in:
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_engine.layers.base import (
|
||||
GraphEngineLayer,
|
||||
@ -43,6 +43,7 @@ def test_layer_runtime_state_available_after_engine_layer() -> None:
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
layer = LayerForTest()
|
||||
|
||||
@ -8,7 +8,7 @@ from core.variables import IntegerVariable, StringVariable
|
||||
from core.workflow.entities.graph_init_params import GraphInitParams
|
||||
from core.workflow.entities.pause_reason import SchedulingPause
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_engine.entities.commands import (
|
||||
AbortCommand,
|
||||
@ -67,6 +67,7 @@ def test_abort_command():
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=shared_runtime_state, # Use shared instance
|
||||
command_channel=command_channel,
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Send abort command before starting
|
||||
@ -173,6 +174,7 @@ def test_pause_command():
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=shared_runtime_state,
|
||||
command_channel=command_channel,
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
pause_command = PauseCommand(reason="User requested pause")
|
||||
@ -228,6 +230,7 @@ def test_update_variables_command_updates_pool():
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=shared_runtime_state,
|
||||
command_channel=command_channel,
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
update_command = UpdateVariablesCommand(
|
||||
|
||||
@ -7,7 +7,7 @@ This test validates that:
|
||||
"""
|
||||
|
||||
from core.workflow.enums import NodeType
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphRunSucceededEvent,
|
||||
@ -44,6 +44,7 @@ def test_streaming_output_with_blocking_equals_one():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Execute the workflow
|
||||
@ -139,6 +140,7 @@ def test_streaming_output_with_blocking_not_equals_one():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Execute the workflow
|
||||
|
||||
@ -11,7 +11,7 @@ from hypothesis import HealthCheck, given, settings
|
||||
from hypothesis import strategies as st
|
||||
|
||||
from core.workflow.enums import ErrorStrategy
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphRunPartialSucceededEvent,
|
||||
@ -469,6 +469,7 @@ def test_layer_system_basic():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Add debug logging layer
|
||||
@ -525,6 +526,7 @@ def test_layer_chaining():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Chain multiple layers
|
||||
@ -572,6 +574,7 @@ def test_layer_error_handling():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Add faulty layer
|
||||
@ -753,6 +756,7 @@ def test_graph_run_emits_partial_success_when_node_failure_recovered():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
events = list(engine.run())
|
||||
|
||||
@ -566,7 +566,7 @@ class MockIterationNode(MockNodeMixin, IterationNode):
|
||||
# Import dependencies
|
||||
from core.workflow.entities import GraphInitParams
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.runtime import GraphRuntimeState
|
||||
|
||||
@ -623,6 +623,7 @@ class MockIterationNode(MockNodeMixin, IterationNode):
|
||||
graph=iteration_graph,
|
||||
graph_runtime_state=graph_runtime_state_copy,
|
||||
command_channel=InMemoryChannel(), # Use InMemoryChannel for sub-graphs
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
return graph_engine
|
||||
@ -641,7 +642,7 @@ class MockLoopNode(MockNodeMixin, LoopNode):
|
||||
# Import dependencies
|
||||
from core.workflow.entities import GraphInitParams
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.runtime import GraphRuntimeState
|
||||
|
||||
@ -685,6 +686,7 @@ class MockLoopNode(MockNodeMixin, LoopNode):
|
||||
graph=loop_graph,
|
||||
graph_runtime_state=graph_runtime_state_copy,
|
||||
command_channel=InMemoryChannel(), # Use InMemoryChannel for sub-graphs
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
return graph_engine
|
||||
|
||||
@ -17,7 +17,7 @@ from core.app.workflow.node_factory import DifyNodeFactory
|
||||
from core.workflow.entities import GraphInitParams
|
||||
from core.workflow.enums import NodeType, WorkflowNodeExecutionStatus
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphRunSucceededEvent,
|
||||
@ -123,6 +123,7 @@ def test_parallel_streaming_workflow():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Define LLM outputs
|
||||
|
||||
@ -12,7 +12,7 @@ from unittest.mock import MagicMock, Mock, patch
|
||||
from core.app.entities.app_invoke_entities import InvokeFrom
|
||||
from core.workflow.entities.graph_init_params import GraphInitParams
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphRunStartedEvent,
|
||||
@ -41,6 +41,7 @@ class TestStopEventPropagation:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Verify stop_event was created
|
||||
@ -84,6 +85,7 @@ class TestStopEventPropagation:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Set the stop_event before running
|
||||
@ -131,6 +133,7 @@ class TestStopEventPropagation:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Initially not set
|
||||
@ -155,6 +158,7 @@ class TestStopEventPropagation:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Verify WorkerPool has the stop_event
|
||||
@ -174,6 +178,7 @@ class TestStopEventPropagation:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Verify Dispatcher has the stop_event
|
||||
@ -311,6 +316,7 @@ class TestStopEventIntegration:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Set stop_event before running
|
||||
@ -360,6 +366,7 @@ class TestStopEventIntegration:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# All nodes should share the same stop_event
|
||||
@ -385,6 +392,7 @@ class TestStopEventTimeoutBehavior:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
dispatcher = engine._dispatcher
|
||||
@ -411,6 +419,7 @@ class TestStopEventTimeoutBehavior:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
worker_pool = engine._worker_pool
|
||||
@ -460,6 +469,7 @@ class TestStopEventResumeBehavior:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Simulate a previous execution that set stop_event
|
||||
@ -490,6 +500,7 @@ class TestWorkerStopBehavior:
|
||||
graph=mock_graph,
|
||||
graph_runtime_state=runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
# Get the worker pool and check workers
|
||||
|
||||
@ -32,7 +32,7 @@ from core.variables import (
|
||||
)
|
||||
from core.workflow.entities.graph_init_params import GraphInitParams
|
||||
from core.workflow.graph import Graph
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphEngineEvent,
|
||||
@ -309,10 +309,12 @@ class TableTestRunner:
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
min_workers=self.graph_engine_min_workers,
|
||||
max_workers=self.graph_engine_max_workers,
|
||||
scale_up_threshold=self.graph_engine_scale_up_threshold,
|
||||
scale_down_idle_time=self.graph_engine_scale_down_idle_time,
|
||||
config=GraphEngineConfig(
|
||||
min_workers=self.graph_engine_min_workers,
|
||||
max_workers=self.graph_engine_max_workers,
|
||||
scale_up_threshold=self.graph_engine_scale_up_threshold,
|
||||
scale_down_idle_time=self.graph_engine_scale_down_idle_time,
|
||||
),
|
||||
)
|
||||
|
||||
# Execute and collect events
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from core.workflow.graph_engine import GraphEngine
|
||||
from core.workflow.graph_engine import GraphEngine, GraphEngineConfig
|
||||
from core.workflow.graph_engine.command_channels import InMemoryChannel
|
||||
from core.workflow.graph_events import (
|
||||
GraphRunSucceededEvent,
|
||||
@ -27,6 +27,7 @@ def test_tool_in_chatflow():
|
||||
graph=graph,
|
||||
graph_runtime_state=graph_runtime_state,
|
||||
command_channel=InMemoryChannel(),
|
||||
config=GraphEngineConfig(),
|
||||
)
|
||||
|
||||
events = list(engine.run())
|
||||
|
||||
Reference in New Issue
Block a user