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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore: add Type to test (#35942)
Asuka Minato140ad6ba4e7e
diff --git a/api/providers/trace/trace-aliyun/tests/unit_tests/aliyun_trace/test_aliyun_trace_utils.py b/api/providers/trace/trace-aliyun/tests/unit_tests/aliyun_trace/test_aliyun_trace_utils.pyindex 1b97746deaa..0900dfda97f 100644--- a/api/providers/trace/trace-aliyun/tests/unit_tests/aliyun_trace/test_aliyun_trace_utils.py+++ b/api/providers/trace/trace-aliyun/tests/unit_tests/aliyun_trace/test_aliyun_trace_utils.py@@ -3,6 +3,7 @@ from collections.abc import Mappingfrom typing import Any, castfrom unittest.mock import MagicMock+import pytestfrom dify_trace_aliyun.entities.semconv import (GEN_AI_FRAMEWORK,GEN_AI_SESSION_ID,@@ -31,7 +32,7 @@ from graphon.enums import WorkflowNodeExecutionStatusfrom models import EndUser-def test_get_user_id_from_message_data_no_end_user(monkeypatch):+def test_get_user_id_from_message_data_no_end_user(monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.from_account_id = "account_id"message_data.from_end_user_id = None@@ -39,7 +40,7 @@ def test_get_user_id_from_message_data_no_end_user(monkeypatch):assert get_user_id_from_message_data(message_data) == "account_id"-def test_get_user_id_from_message_data_with_end_user(monkeypatch):+def test_get_user_id_from_message_data_with_end_user(monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.from_account_id = "account_id"message_data.from_end_user_id = "end_user_id"@@ -57,7 +58,7 @@ def test_get_user_id_from_message_data_with_end_user(monkeypatch):assert get_user_id_from_message_data(message_data) == "session_id"-def test_get_user_id_from_message_data_end_user_not_found(monkeypatch):+def test_get_user_id_from_message_data_end_user_not_found(monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.from_account_id = "account_id"message_data.from_end_user_id = "end_user_id"@@ -111,7 +112,7 @@ def test_get_workflow_node_status():assert status.status_code == StatusCode.UNSET-def test_create_links_from_trace_id(monkeypatch):+def test_create_links_from_trace_id(monkeypatch: pytest.MonkeyPatch):# Mock create_linkmock_link = MagicMock(spec=Link)import dify_trace_aliyun.data_exporter.traceclientdiff --git a/api/providers/trace/trace-langfuse/tests/unit_tests/langfuse_trace/test_langfuse_trace.py b/api/providers/trace/trace-langfuse/tests/unit_tests/langfuse_trace/test_langfuse_trace.pyindex 952f10c34f9..95e27c791f7 100644--- a/api/providers/trace/trace-langfuse/tests/unit_tests/langfuse_trace/test_langfuse_trace.py+++ b/api/providers/trace/trace-langfuse/tests/unit_tests/langfuse_trace/test_langfuse_trace.py@@ -40,7 +40,7 @@ def langfuse_config():@pytest.fixture-def trace_instance(langfuse_config, monkeypatch):+def trace_instance(langfuse_config, monkeypatch: pytest.MonkeyPatch):# Mock Langfuse client to avoid network callsmock_client = MagicMock()monkeypatch.setattr("dify_trace_langfuse.langfuse_trace.Langfuse", lambda **kwargs: mock_client)@@ -49,7 +49,7 @@ def trace_instance(langfuse_config, monkeypatch):return instance-def test_init(langfuse_config, monkeypatch):+def test_init(langfuse_config, monkeypatch: pytest.MonkeyPatch):mock_langfuse = MagicMock()monkeypatch.setattr("dify_trace_langfuse.langfuse_trace.Langfuse", mock_langfuse)monkeypatch.setenv("FILES_URL", "http://test.url")@@ -64,7 +64,7 @@ def test_init(langfuse_config, monkeypatch):assert instance.file_base_url == "http://test.url"-def test_trace_dispatch(trace_instance, monkeypatch):+def test_trace_dispatch(trace_instance, monkeypatch: pytest.MonkeyPatch):methods = ["workflow_trace","message_trace",@@ -114,7 +114,7 @@ def test_trace_dispatch(trace_instance, monkeypatch):mocks["generate_name_trace"].assert_called_once_with(info)-def test_workflow_trace_with_message_id(trace_instance, monkeypatch):+def test_workflow_trace_with_message_id(trace_instance, monkeypatch: pytest.MonkeyPatch):# Setup trace infotrace_info = WorkflowTraceInfo(workflow_id="wf-1",@@ -218,7 +218,7 @@ def test_workflow_trace_with_message_id(trace_instance, monkeypatch):assert other_span.level == LevelEnum.ERROR-def test_workflow_trace_no_message_id(trace_instance, monkeypatch):+def test_workflow_trace_no_message_id(trace_instance, monkeypatch: pytest.MonkeyPatch):trace_info = WorkflowTraceInfo(workflow_id="wf-1",tenant_id="tenant-1",@@ -259,7 +259,7 @@ def test_workflow_trace_no_message_id(trace_instance, monkeypatch):assert trace_data.name == TraceTaskName.WORKFLOW_TRACE-def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):+def test_workflow_trace_missing_app_id(trace_instance, monkeypatch: pytest.MonkeyPatch):trace_info = WorkflowTraceInfo(workflow_id="wf-1",tenant_id="tenant-1",@@ -287,7 +287,7 @@ def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):trace_instance.workflow_trace(trace_info)-def test_message_trace_basic(trace_instance, monkeypatch):+def test_message_trace_basic(trace_instance, monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.id = "msg-1"message_data.from_account_id = "acc-1"@@ -331,7 +331,7 @@ def test_message_trace_basic(trace_instance, monkeypatch):assert gen_data.usage.total == 30-def test_message_trace_with_end_user(trace_instance, monkeypatch):+def test_message_trace_with_end_user(trace_instance, monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.id = "msg-1"message_data.from_account_id = "acc-1"@@ -636,7 +636,7 @@ def test_langfuse_trace_entity_with_list_dict_input():assert data.input[0]["content"] == "hello"-def test_workflow_trace_handles_usage_extraction_error(trace_instance, monkeypatch, caplog):+def test_workflow_trace_handles_usage_extraction_error(trace_instance, monkeypatch: pytest.MonkeyPatch, caplog):# Setup trace info to trigger LLM node usage extractiontrace_info = WorkflowTraceInfo(workflow_id="wf-1",diff --git a/api/providers/trace/trace-langsmith/tests/unit_tests/langsmith_trace/test_langsmith_trace.py b/api/providers/trace/trace-langsmith/tests/unit_tests/langsmith_trace/test_langsmith_trace.pyindex 45e5894e4a0..ee59acb17ed 100644--- a/api/providers/trace/trace-langsmith/tests/unit_tests/langsmith_trace/test_langsmith_trace.py+++ b/api/providers/trace/trace-langsmith/tests/unit_tests/langsmith_trace/test_langsmith_trace.py@@ -35,7 +35,7 @@ def langsmith_config():@pytest.fixture-def trace_instance(langsmith_config, monkeypatch):+def trace_instance(langsmith_config, monkeypatch: pytest.MonkeyPatch):# Mock LangSmith clientmock_client = MagicMock()monkeypatch.setattr("dify_trace_langsmith.langsmith_trace.Client", lambda **kwargs: mock_client)@@ -44,7 +44,7 @@ def trace_instance(langsmith_config, monkeypatch):return instance-def test_init(langsmith_config, monkeypatch):+def test_init(langsmith_config, monkeypatch: pytest.MonkeyPatch):mock_client_class = MagicMock()monkeypatch.setattr("dify_trace_langsmith.langsmith_trace.Client", mock_client_class)monkeypatch.setenv("FILES_URL", "http://test.url")@@ -57,7 +57,7 @@ def test_init(langsmith_config, monkeypatch):assert instance.file_base_url == "http://test.url"-def test_trace_dispatch(trace_instance, monkeypatch):+def test_trace_dispatch(trace_instance, monkeypatch: pytest.MonkeyPatch):methods = ["workflow_trace","message_trace",@@ -107,7 +107,7 @@ def test_trace_dispatch(trace_instance, monkeypatch):mocks["generate_name_trace"].assert_called_once_with(info)-def test_workflow_trace(trace_instance, monkeypatch):+def test_workflow_trace(trace_instance, monkeypatch: pytest.MonkeyPatch):# Setup trace infoworkflow_data = MagicMock()workflow_data.created_at = _dt()@@ -223,7 +223,7 @@ def test_workflow_trace(trace_instance, monkeypatch):assert call_args[4].run_type == LangSmithRunType.retriever-def test_workflow_trace_no_start_time(trace_instance, monkeypatch):+def test_workflow_trace_no_start_time(trace_instance, monkeypatch: pytest.MonkeyPatch):workflow_data = MagicMock()workflow_data.created_at = _dt()workflow_data.finished_at = _dt() + timedelta(seconds=1)@@ -266,7 +266,7 @@ def test_workflow_trace_no_start_time(trace_instance, monkeypatch):assert trace_instance.add_run.called-def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):+def test_workflow_trace_missing_app_id(trace_instance, monkeypatch: pytest.MonkeyPatch):trace_info = MagicMock(spec=WorkflowTraceInfo)trace_info.trace_id = "trace-1"trace_info.message_id = None@@ -290,7 +290,7 @@ def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):trace_instance.workflow_trace(trace_info)-def test_message_trace(trace_instance, monkeypatch):+def test_message_trace(trace_instance, monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.id = "msg-1"message_data.from_account_id = "acc-1"@@ -516,7 +516,7 @@ def test_update_run_error(trace_instance):trace_instance.update_run(update_data)-def test_workflow_trace_usage_extraction_error(trace_instance, monkeypatch, caplog):+def test_workflow_trace_usage_extraction_error(trace_instance, monkeypatch: pytest.MonkeyPatch, caplog):workflow_data = MagicMock()workflow_data.created_at = _dt()workflow_data.finished_at = _dt() + timedelta(seconds=1)diff --git a/api/providers/trace/trace-mlflow/tests/unit_tests/mlflow_trace/test_mlflow_trace.py b/api/providers/trace/trace-mlflow/tests/unit_tests/mlflow_trace/test_mlflow_trace.pyindex 46c9750a5da..324f894b252 100644--- a/api/providers/trace/trace-mlflow/tests/unit_tests/mlflow_trace/test_mlflow_trace.py+++ b/api/providers/trace/trace-mlflow/tests/unit_tests/mlflow_trace/test_mlflow_trace.py@@ -614,7 +614,7 @@ class TestMessageTrace:span.set_status.assert_called_once()span.add_event.assert_called_once()- def test_message_trace_with_file_data(self, trace_instance, mock_tracing, mock_db, monkeypatch):+ def test_message_trace_with_file_data(self, trace_instance, mock_tracing, mock_db, monkeypatch: pytest.MonkeyPatch):span = MagicMock()mock_tracing["start"].return_value = spanmock_tracing["set"].return_value = "token"diff --git a/api/providers/trace/trace-opik/tests/unit_tests/opik_trace/test_opik_trace.py b/api/providers/trace/trace-opik/tests/unit_tests/opik_trace/test_opik_trace.pyindex eefed3c78c7..5daaa7132c8 100644--- a/api/providers/trace/trace-opik/tests/unit_tests/opik_trace/test_opik_trace.py+++ b/api/providers/trace/trace-opik/tests/unit_tests/opik_trace/test_opik_trace.py@@ -35,7 +35,7 @@ def opik_config():@pytest.fixture-def trace_instance(opik_config, monkeypatch):+def trace_instance(opik_config, monkeypatch: pytest.MonkeyPatch):mock_client = MagicMock()monkeypatch.setattr("dify_trace_opik.opik_trace.Opik", lambda **kwargs: mock_client)@@ -65,7 +65,7 @@ def test_prepare_opik_uuid():assert result is not None-def test_init(opik_config, monkeypatch):+def test_init(opik_config, monkeypatch: pytest.MonkeyPatch):mock_opik = MagicMock()monkeypatch.setattr("dify_trace_opik.opik_trace.Opik", mock_opik)monkeypatch.setenv("FILES_URL", "http://test.url")@@ -82,7 +82,7 @@ def test_init(opik_config, monkeypatch):assert instance.project == opik_config.project-def test_trace_dispatch(trace_instance, monkeypatch):+def test_trace_dispatch(trace_instance, monkeypatch: pytest.MonkeyPatch):methods = ["workflow_trace","message_trace",@@ -132,7 +132,7 @@ def test_trace_dispatch(trace_instance, monkeypatch):mocks["generate_name_trace"].assert_called_once_with(info)-def test_workflow_trace_with_message_id(trace_instance, monkeypatch):+def test_workflow_trace_with_message_id(trace_instance, monkeypatch: pytest.MonkeyPatch):# Define constants for better readabilityWORKFLOW_ID = "fb05c7cd-6cec-4add-8a84-df03a408b4ce"WORKFLOW_RUN_ID = "33c67568-7a8a-450e-8916-a5f135baeaef"@@ -221,7 +221,7 @@ def test_workflow_trace_with_message_id(trace_instance, monkeypatch):assert trace_instance.add_span.call_count >= 1-def test_workflow_trace_no_message_id(trace_instance, monkeypatch):+def test_workflow_trace_no_message_id(trace_instance, monkeypatch: pytest.MonkeyPatch):# Define constants for better readabilityWORKFLOW_ID = "f0708b36-b1d7-42b3-a876-1d01b7d8f1a3"WORKFLOW_RUN_ID = "d42ec285-c2fd-4248-8866-5c9386b101ac"@@ -265,7 +265,7 @@ def test_workflow_trace_no_message_id(trace_instance, monkeypatch):trace_instance.add_trace.assert_called_once()-def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):+def test_workflow_trace_missing_app_id(trace_instance, monkeypatch: pytest.MonkeyPatch):trace_info = WorkflowTraceInfo(workflow_id="5745f1b8-f8e6-4859-8110-996acb6c8d6a",tenant_id="tenant-1",@@ -293,7 +293,7 @@ def test_workflow_trace_missing_app_id(trace_instance, monkeypatch):trace_instance.workflow_trace(trace_info)-def test_message_trace_basic(trace_instance, monkeypatch):+def test_message_trace_basic(trace_instance, monkeypatch: pytest.MonkeyPatch):# Define constants for better readabilityMESSAGE_DATA_ID = "e3a26712-8cac-4a25-94a4-a3bff21ee3ab"CONVERSATION_ID = "9d3f3751-7521-4c19-9307-20e3cf6789a3"@@ -340,7 +340,7 @@ def test_message_trace_basic(trace_instance, monkeypatch):trace_instance.add_span.assert_called_once()-def test_message_trace_with_end_user(trace_instance, monkeypatch):+def test_message_trace_with_end_user(trace_instance, monkeypatch: pytest.MonkeyPatch):message_data = MagicMock()message_data.id = "85411059-79fb-4deb-a76c-c2e215f1b97e"message_data.from_account_id = "acc-1"@@ -614,7 +614,7 @@ def test_get_project_url_error(trace_instance):trace_instance.get_project_url()-def test_workflow_trace_usage_extraction_error_fixed(trace_instance, monkeypatch, caplog):+def test_workflow_trace_usage_extraction_error_fixed(trace_instance, monkeypatch: pytest.MonkeyPatch, caplog):trace_info = WorkflowTraceInfo(workflow_id="86a52565-4a6b-4a1b-9bfd-98e4595e70de",tenant_id="66e8e918-472e-4b69-8051-12502c34fc07",diff --git a/api/providers/trace/trace-weave/tests/unit_tests/weave_trace/test_weave_trace.py b/api/providers/trace/trace-weave/tests/unit_tests/weave_trace/test_weave_trace.pyindex 6028d0c550f..30646815d83 100644--- a/api/providers/trace/trace-weave/tests/unit_tests/weave_trace/test_weave_trace.py+++ b/api/providers/trace/trace-weave/tests/unit_tests/weave_trace/test_weave_trace.py@@ -267,14 +267,14 @@ class TestInit:with pytest.raises(ValueError, match="Weave login failed"):WeaveDataTrace(config)- def test_init_files_url_from_env(self, mock_wandb, mock_weave, monkeypatch):+ def test_init_files_url_from_env(self, mock_wandb, mock_weave, monkeypatch: pytest.MonkeyPatch):"""Test FILES_URL is read from environment."""monkeypatch.setenv("FILES_URL", "http://files.example.com")config = _make_weave_config()instance = WeaveDataTrace(config)assert instance.file_base_url == "http://files.example.com"- def test_init_files_url_default(self, mock_wandb, mock_weave, monkeypatch):+ def test_init_files_url_default(self, mock_wandb, mock_weave, monkeypatch: pytest.MonkeyPatch):"""Test FILES_URL defaults to http://127.0.0.1:5001."""monkeypatch.delenv("FILES_URL", raising=False)config = _make_weave_config()@@ -302,7 +302,7 @@ class TestGetProjectUrl:url = instance.get_project_url()assert url == "https://wandb.ai/my-project"- def test_get_project_url_exception_raises(self, trace_instance, monkeypatch):+ def test_get_project_url_exception_raises(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Raises ValueError when exception occurs in get_project_url."""monkeypatch.setattr(trace_instance, "entity", None)monkeypatch.setattr(trace_instance, "project_name", None)@@ -583,7 +583,7 @@ class TestFinishCall:class TestWorkflowTrace:- def _setup_repo(self, monkeypatch, nodes=None):+ def _setup_repo(self, monkeypatch: pytest.MonkeyPatch, nodes=None):"""Helper to patch session/repo dependencies."""if nodes is None:nodes = []@@ -599,7 +599,7 @@ class TestWorkflowTrace:monkeypatch.setattr("dify_trace_weave.weave_trace.db", MagicMock(engine="engine"))return repo- def test_workflow_trace_no_nodes_no_message_id(self, trace_instance, monkeypatch):+ def test_workflow_trace_no_nodes_no_message_id(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Workflow trace with no nodes and no message_id."""self._setup_repo(monkeypatch, nodes=[])monkeypatch.setattr(trace_instance, "get_service_account_with_tenant", lambda app_id: MagicMock())@@ -614,7 +614,7 @@ class TestWorkflowTrace:assert trace_instance.start_call.call_count == 1assert trace_instance.finish_call.call_count == 1- def test_workflow_trace_with_message_id(self, trace_instance, monkeypatch):+ def test_workflow_trace_with_message_id(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Workflow trace with message_id creates both message and workflow runs."""self._setup_repo(monkeypatch, nodes=[])monkeypatch.setattr(trace_instance, "get_service_account_with_tenant", lambda app_id: MagicMock())@@ -629,7 +629,7 @@ class TestWorkflowTrace:assert trace_instance.start_call.call_count == 2assert trace_instance.finish_call.call_count == 2- def test_workflow_trace_with_node_execution(self, trace_instance, monkeypatch):+ def test_workflow_trace_with_node_execution(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Workflow trace iterates node executions and creates node runs."""node = _make_node(id="node-1",@@ -652,7 +652,7 @@ class TestWorkflowTrace:# workflow run + node run = 2 callsassert trace_instance.start_call.call_count == 2- def test_workflow_trace_with_llm_node(self, trace_instance, monkeypatch):+ def test_workflow_trace_with_llm_node(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""LLM node uses process_data prompts as inputs."""node = _make_node(node_type=BuiltinNodeTypes.LLM,@@ -680,7 +680,7 @@ class TestWorkflowTrace:# The key "messages" should be present (validator transforms the list)assert "messages" in node_run.inputs- def test_workflow_trace_with_non_llm_node_uses_inputs(self, trace_instance, monkeypatch):+ def test_workflow_trace_with_non_llm_node_uses_inputs(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Non-LLM node uses node_execution.inputs directly."""node = _make_node(node_type=BuiltinNodeTypes.TOOL,@@ -701,7 +701,7 @@ class TestWorkflowTrace:node_run = node_call_args[0][0]assert node_run.inputs.get("tool_input") == "val"- def test_workflow_trace_missing_app_id_raises(self, trace_instance, monkeypatch):+ def test_workflow_trace_missing_app_id_raises(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Raises ValueError when app_id is missing from metadata."""monkeypatch.setattr("dify_trace_weave.weave_trace.sessionmaker", lambda bind: MagicMock())monkeypatch.setattr("dify_trace_weave.weave_trace.db", MagicMock(engine="engine"))@@ -714,7 +714,7 @@ class TestWorkflowTrace:with pytest.raises(ValueError, match="No app_id found in trace_info metadata"):trace_instance.workflow_trace(trace_info)- def test_workflow_trace_start_time_none_defaults_to_now(self, trace_instance, monkeypatch):+ def test_workflow_trace_start_time_none_defaults_to_now(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""start_time defaults to datetime.now() when None."""self._setup_repo(monkeypatch, nodes=[])monkeypatch.setattr(trace_instance, "get_service_account_with_tenant", lambda app_id: MagicMock())@@ -727,7 +727,7 @@ class TestWorkflowTrace:assert trace_instance.start_call.call_count == 1- def test_workflow_trace_node_created_at_none(self, trace_instance, monkeypatch):+ def test_workflow_trace_node_created_at_none(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Node with created_at=None uses datetime.now()."""node = _make_node(created_at=None, elapsed_time=0.5)self._setup_repo(monkeypatch, nodes=[node])@@ -740,7 +740,7 @@ class TestWorkflowTrace:trace_instance.workflow_trace(trace_info)assert trace_instance.start_call.call_count == 2- def test_workflow_trace_chat_mode_llm_node_adds_provider(self, trace_instance, monkeypatch):+ def test_workflow_trace_chat_mode_llm_node_adds_provider(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Chat mode LLM node adds ls_provider and ls_model_name to attributes."""node = _make_node(node_type=BuiltinNodeTypes.LLM,@@ -765,7 +765,7 @@ class TestWorkflowTrace:assert node_run.attributes.get("ls_provider") == "openai"assert node_run.attributes.get("ls_model_name") == "gpt-4"- def test_workflow_trace_nodes_sorted_by_created_at(self, trace_instance, monkeypatch):+ def test_workflow_trace_nodes_sorted_by_created_at(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""Nodes are sorted by created_at before processing."""node1 = _make_node(id="node-b", created_at=_dt() + timedelta(seconds=2))node2 = _make_node(id="node-a", created_at=_dt())@@ -799,7 +799,7 @@ class TestMessageTrace:trace_instance.message_trace(trace_info)trace_instance.start_call.assert_not_called()- def test_basic_message_trace(self, trace_instance, monkeypatch):+ def test_basic_message_trace(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""message_trace creates message run and llm child run."""monkeypatch.setattr("dify_trace_weave.weave_trace.db.session.get",@@ -816,7 +816,7 @@ class TestMessageTrace:assert trace_instance.start_call.call_count == 2assert trace_instance.finish_call.call_count == 2- def test_message_trace_with_file_data(self, trace_instance, monkeypatch):+ def test_message_trace_with_file_data(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""message_trace appends file URL to file_list."""file_data = MagicMock()file_data.url = "path/to/file.png"@@ -839,7 +839,7 @@ class TestMessageTrace:message_run = trace_instance.start_call.call_args_list[0][0][0]assert "http://files.test/path/to/file.png" in message_run.file_list- def test_message_trace_with_end_user(self, trace_instance, monkeypatch):+ def test_message_trace_with_end_user(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""message_trace looks up end user and sets end_user_id attribute."""end_user = MagicMock()end_user.session_id = "session-xyz"@@ -862,7 +862,7 @@ class TestMessageTrace:message_run = trace_instance.start_call.call_args_list[0][0][0]assert message_run.attributes.get("end_user_id") == "session-xyz"- def test_message_trace_no_end_user(self, trace_instance, monkeypatch):+ def test_message_trace_no_end_user(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""message_trace handles when from_end_user_id is None."""mock_db = MagicMock()mock_db.session.get.return_value = None@@ -880,7 +880,7 @@ class TestMessageTrace:trace_instance.message_trace(trace_info)assert trace_instance.start_call.call_count == 2- def test_message_trace_trace_id_fallback_to_message_id(self, trace_instance, monkeypatch):+ def test_message_trace_trace_id_fallback_to_message_id(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""trace_id falls back to message_id when trace_id is None."""mock_db = MagicMock()mock_db.session.get.return_value = None@@ -895,7 +895,7 @@ class TestMessageTrace:message_run = trace_instance.start_call.call_args_list[0][0][0]assert message_run.id == "msg-1"- def test_message_trace_file_list_none(self, trace_instance, monkeypatch):+ def test_message_trace_file_list_none(self, trace_instance, monkeypatch: pytest.MonkeyPatch):"""message_trace handles file_list=None gracefully."""mock_db = MagicMock()mock_db.session.get.return_value = Nonediff --git a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.pyindex a907f918c36..37b2331f0f8 100644--- a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py+++ b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py@@ -20,7 +20,7 @@ def test_validate_distance_function_rejects_unsupported_values():factory._validate_distance_function("dot_product")-def test_factory_init_vector_uses_existing_index_struct_class_prefix(monkeypatch):+def test_factory_init_vector_uses_existing_index_struct_class_prefix(monkeypatch: pytest.MonkeyPatch):factory = AlibabaCloudMySQLVectorFactory()dataset = SimpleNamespace(id="dataset-1",@@ -45,7 +45,7 @@ def test_factory_init_vector_uses_existing_index_struct_class_prefix(monkeypatchassert vector_cls.call_args.kwargs["collection_name"] == "existing_collection"-def test_factory_init_vector_generates_collection_name_when_index_struct_is_missing(monkeypatch):+def test_factory_init_vector_generates_collection_name_when_index_struct_is_missing(monkeypatch: pytest.MonkeyPatch):factory = AlibabaCloudMySQLVectorFactory()dataset = SimpleNamespace(id="dataset-2",diff --git a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector.py b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector.pyindex d1d471761d8..2e8052b7dcd 100644--- a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector.py+++ b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector.py@@ -83,7 +83,7 @@ def test_get_type_is_analyticdb():assert vector.get_type() == "analyticdb"-def test_factory_builds_openapi_config_when_host_is_missing(monkeypatch):+def test_factory_builds_openapi_config_when_host_is_missing(monkeypatch: pytest.MonkeyPatch):factory = AnalyticdbVectorFactory()dataset = SimpleNamespace(id="dataset-1", index_struct_dict=None, index_struct=None)@@ -109,7 +109,7 @@ def test_factory_builds_openapi_config_when_host_is_missing(monkeypatch):assert dataset.index_struct is not None-def test_factory_builds_sql_config_when_host_is_present(monkeypatch):+def test_factory_builds_sql_config_when_host_is_present(monkeypatch: pytest.MonkeyPatch):factory = AnalyticdbVectorFactory()dataset = SimpleNamespace(id="dataset-2", index_struct_dict={"vector_store": {"class_prefix": "EXISTING"}}, index_struct=Nonediff --git a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.pyindex d2d735ae3ea..26bd3853338 100644--- a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py+++ b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_openapi.py@@ -24,7 +24,7 @@ def _request_class(name: str):return _Request-def _install_openapi_stubs(monkeypatch):+def _install_openapi_stubs(monkeypatch: pytest.MonkeyPatch):gpdb_package = types.ModuleType("alibabacloud_gpdb20160503")gpdb_package.__path__ = []gpdb_models = types.ModuleType("alibabacloud_gpdb20160503.models")@@ -130,7 +130,7 @@ def test_openapi_config_to_client_params():assert params["read_timeout"] == 60000-def test_init_creates_openapi_client_and_runs_initialize(monkeypatch):+def test_init_creates_openapi_client_and_runs_initialize(monkeypatch: pytest.MonkeyPatch):stubs = _install_openapi_stubs(monkeypatch)initialize_mock = MagicMock()monkeypatch.setattr(openapi_module.AnalyticdbVectorOpenAPI, "_initialize", initialize_mock)@@ -145,7 +145,7 @@ def test_init_creates_openapi_client_and_runs_initialize(monkeypatch):initialize_mock.assert_called_once_with()-def test_initialize_skips_when_cached(monkeypatch):+def test_initialize_skips_when_cached(monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -164,7 +164,7 @@ def test_initialize_skips_when_cached(monkeypatch):vector._create_namespace_if_not_exists.assert_not_called()-def test_initialize_runs_when_cache_is_missing(monkeypatch):+def test_initialize_runs_when_cache_is_missing(monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -184,7 +184,7 @@ def test_initialize_runs_when_cache_is_missing(monkeypatch):openapi_module.redis_client.set.assert_called_once()-def test_initialize_vector_database_calls_openapi_client(monkeypatch):+def test_initialize_vector_database_calls_openapi_client(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector.config = _config()@@ -199,7 +199,7 @@ def test_initialize_vector_database_calls_openapi_client(monkeypatch):assert request.manager_account_password == "password"-def test_create_namespace_creates_when_namespace_not_found(monkeypatch):+def test_create_namespace_creates_when_namespace_not_found(monkeypatch: pytest.MonkeyPatch):stubs = _install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector.config = _config()@@ -211,7 +211,7 @@ def test_create_namespace_creates_when_namespace_not_found(monkeypatch):vector._client.create_namespace.assert_called_once()-def test_create_namespace_raises_on_unexpected_api_error(monkeypatch):+def test_create_namespace_raises_on_unexpected_api_error(monkeypatch: pytest.MonkeyPatch):stubs = _install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector.config = _config()@@ -222,7 +222,7 @@ def test_create_namespace_raises_on_unexpected_api_error(monkeypatch):vector._create_namespace_if_not_exists()-def test_create_namespace_noop_when_namespace_exists(monkeypatch):+def test_create_namespace_noop_when_namespace_exists(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector.config = _config()@@ -234,7 +234,7 @@ def test_create_namespace_noop_when_namespace_exists(monkeypatch):vector._client.create_namespace.assert_not_called()-def test_create_collection_if_not_exists_creates_when_missing(monkeypatch):+def test_create_collection_if_not_exists_creates_when_missing(monkeypatch: pytest.MonkeyPatch):stubs = _install_openapi_stubs(monkeypatch)lock = MagicMock()lock.__enter__.return_value = None@@ -255,7 +255,7 @@ def test_create_collection_if_not_exists_creates_when_missing(monkeypatch):openapi_module.redis_client.set.assert_called_once()-def test_create_collection_if_not_exists_skips_when_cached(monkeypatch):+def test_create_collection_if_not_exists_skips_when_cached(monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -274,7 +274,7 @@ def test_create_collection_if_not_exists_skips_when_cached(monkeypatch):vector._client.create_collection.assert_not_called()-def test_create_collection_if_not_exists_raises_on_non_404_errors(monkeypatch):+def test_create_collection_if_not_exists_raises_on_non_404_errors(monkeypatch: pytest.MonkeyPatch):stubs = _install_openapi_stubs(monkeypatch)lock = MagicMock()lock.__enter__.return_value = None@@ -293,7 +293,7 @@ def test_create_collection_if_not_exists_raises_on_non_404_errors(monkeypatch):vector.create_collection_if_not_exists(embedding_dimension=512)-def test_openapi_add_delete_and_search_methods(monkeypatch):+def test_openapi_add_delete_and_search_methods(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector._collection_name = "collection_1"@@ -348,7 +348,7 @@ def test_openapi_add_delete_and_search_methods(monkeypatch):assert docs_by_text[0].page_content == "high"-def test_text_exists_returns_false_when_matches_empty(monkeypatch):+def test_text_exists_returns_false_when_matches_empty(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector._collection_name = "collection_1"@@ -361,7 +361,7 @@ def test_text_exists_returns_false_when_matches_empty(monkeypatch):assert vector.text_exists("missing-id") is False-def test_openapi_delete_success(monkeypatch):+def test_openapi_delete_success(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector._collection_name = "collection_1"@@ -372,7 +372,7 @@ def test_openapi_delete_success(monkeypatch):vector._client.delete_collection.assert_called_once()-def test_openapi_delete_propagates_errors(monkeypatch):+def test_openapi_delete_propagates_errors(monkeypatch: pytest.MonkeyPatch):_install_openapi_stubs(monkeypatch)vector = AnalyticdbVectorOpenAPI.__new__(AnalyticdbVectorOpenAPI)vector._collection_name = "collection_1"diff --git a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.pyindex 49a2ae72d0a..cd255b37cfc 100644--- a/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py+++ b/api/providers/vdb/vdb-analyticdb/tests/unit_tests/test_analyticdb_vector_sql.py@@ -53,7 +53,7 @@ def test_sql_config_rejects_min_connection_greater_than_max_connection():AnalyticdbVectorBySqlConfig.model_validate(values)-def test_initialize_skips_when_cache_exists(monkeypatch):+def test_initialize_skips_when_cache_exists(monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -70,7 +70,7 @@ def test_initialize_skips_when_cache_exists(monkeypatch):vector._initialize_vector_database.assert_not_called()-def test_initialize_runs_when_cache_is_missing(monkeypatch):+def test_initialize_runs_when_cache_is_missing(monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -88,7 +88,7 @@ def test_initialize_runs_when_cache_is_missing(monkeypatch):sql_module.redis_client.set.assert_called_once()-def test_create_connection_pool_uses_psycopg2_pool(monkeypatch):+def test_create_connection_pool_uses_psycopg2_pool(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.config = AnalyticdbVectorBySqlConfig(**_config_values())vector.databaseName = "knowledgebase"@@ -119,7 +119,7 @@ def test_get_cursor_context_manager_handles_connection_lifecycle():pool.putconn.assert_called_once_with(connection)-def test_add_texts_inserts_only_documents_with_metadata(monkeypatch):+def test_add_texts_inserts_only_documents_with_metadata(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.table_name = "dify.collection"@@ -273,7 +273,7 @@ def test_delete_drops_table():cursor.execute.assert_called_once()-def test_init_normalizes_collection_name_and_creates_pool_when_missing(monkeypatch):+def test_init_normalizes_collection_name_and_creates_pool_when_missing(monkeypatch: pytest.MonkeyPatch):config = AnalyticdbVectorBySqlConfig(**_config_values())created_pool = MagicMock()@@ -288,7 +288,7 @@ def test_init_normalizes_collection_name_and_creates_pool_when_missing(monkeypatassert vector.pool is created_pool-def test_initialize_vector_database_handles_existing_database_and_search_config(monkeypatch):+def test_initialize_vector_database_handles_existing_database_and_search_config(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.config = AnalyticdbVectorBySqlConfig(**_config_values())vector.databaseName = "knowledgebase"@@ -326,7 +326,7 @@ def test_initialize_vector_database_handles_existing_database_and_search_config(assert any("CREATE SCHEMA IF NOT EXISTS dify" in call.args[0] for call in worker_cursor.execute.call_args_list)-def test_initialize_vector_database_raises_runtime_error_when_zhparser_fails(monkeypatch):+def test_initialize_vector_database_raises_runtime_error_when_zhparser_fails(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.config = AnalyticdbVectorBySqlConfig(**_config_values())vector.databaseName = "knowledgebase"@@ -353,7 +353,7 @@ def test_initialize_vector_database_raises_runtime_error_when_zhparser_fails(monworker_connection.rollback.assert_called_once()-def test_create_collection_if_not_exists_creates_table_indexes_and_cache(monkeypatch):+def test_create_collection_if_not_exists_creates_table_indexes_and_cache(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.config = AnalyticdbVectorBySqlConfig(**_config_values())vector._collection_name = "collection"@@ -381,7 +381,7 @@ def test_create_collection_if_not_exists_creates_table_indexes_and_cache(monkeypsql_module.redis_client.set.assert_called_once()-def test_create_collection_if_not_exists_raises_for_non_existing_error(monkeypatch):+def test_create_collection_if_not_exists_raises_for_non_existing_error(monkeypatch: pytest.MonkeyPatch):vector = AnalyticdbVectorBySql.__new__(AnalyticdbVectorBySql)vector.config = AnalyticdbVectorBySqlConfig(**_config_values())vector._collection_name = "collection"diff --git a/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py b/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.pyindex 851c09f47a3..f0dddee3b90 100644--- a/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py+++ b/api/providers/vdb/vdb-baidu/tests/unit_tests/test_baidu_vector.py@@ -121,7 +121,7 @@ def _build_fake_pymochow_modules():@pytest.fixture-def baidu_module(monkeypatch):+def baidu_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_pymochow_modules().items():monkeypatch.setitem(sys.modules, name, module)import dify_vdb_baidu.baidu_vector as module@@ -254,7 +254,7 @@ def test_search_methods_delegate_to_database_table(baidu_module):assert vector._get_search_res.call_count == 2-def test_factory_initializes_collection_name_and_index_struct(baidu_module, monkeypatch):+def test_factory_initializes_collection_name_and_index_struct(baidu_module, monkeypatch: pytest.MonkeyPatch):factory = baidu_module.BaiduVectorFactory()dataset = SimpleNamespace(id="dataset-1", index_struct_dict=None, index_struct=None)monkeypatch.setattr(baidu_module.Dataset, "gen_collection_name_by_id", lambda _id: "AUTO_COLLECTION")@@ -279,7 +279,7 @@ def test_factory_initializes_collection_name_and_index_struct(baidu_module, monkassert dataset.index_struct is not None-def test_init_get_type_to_index_struct_and_create_delegate(baidu_module, monkeypatch):+def test_init_get_type_to_index_struct_and_create_delegate(baidu_module, monkeypatch: pytest.MonkeyPatch):init_client = MagicMock(return_value="client")init_database = MagicMock(return_value="database")monkeypatch.setattr(baidu_module.BaiduVector, "_init_client", init_client)@@ -372,7 +372,7 @@ def test_get_search_result_handles_invalid_metadata_json(baidu_module):assert "document_id" not in docs[0].metadata-def test_init_client_constructs_configuration_and_client(baidu_module, monkeypatch):+def test_init_client_constructs_configuration_and_client(baidu_module, monkeypatch: pytest.MonkeyPatch):credentials = MagicMock(return_value="credentials")configuration = MagicMock(return_value="configuration")client_cls = MagicMock(return_value="client")@@ -411,7 +411,7 @@ def test_init_database_raises_for_unknown_create_database_error(baidu_module):vector._init_database()-def test_create_table_handles_cache_and_validation_paths(baidu_module, monkeypatch):+def test_create_table_handles_cache_and_validation_paths(baidu_module, monkeypatch: pytest.MonkeyPatch):vector = baidu_module.BaiduVector.__new__(baidu_module.BaiduVector)vector._collection_name = "collection_1"vector._client_config = SimpleNamespace(@@ -460,7 +460,7 @@ def test_create_table_handles_cache_and_validation_paths(baidu_module, monkeypatvector._wait_for_index_ready.assert_called_once_with(table, 3600)-def test_create_table_raises_for_invalid_index_or_metric(baidu_module, monkeypatch):+def test_create_table_raises_for_invalid_index_or_metric(baidu_module, monkeypatch: pytest.MonkeyPatch):vector = baidu_module.BaiduVector.__new__(baidu_module.BaiduVector)vector._collection_name = "collection_1"vector._db = MagicMock()@@ -493,7 +493,7 @@ def test_create_table_raises_for_invalid_index_or_metric(baidu_module, monkeypatvector._create_table(3)-def test_create_table_raises_timeout_if_table_never_becomes_normal(baidu_module, monkeypatch):+def test_create_table_raises_timeout_if_table_never_becomes_normal(baidu_module, monkeypatch: pytest.MonkeyPatch):vector = baidu_module.BaiduVector.__new__(baidu_module.BaiduVector)vector._collection_name = "collection_1"vector._client_config = SimpleNamespace(@@ -524,7 +524,9 @@ def test_create_table_raises_timeout_if_table_never_becomes_normal(baidu_module,vector._create_table(3)-def test_factory_uses_existing_collection_prefix_when_index_struct_exists(baidu_module, monkeypatch):+def test_factory_uses_existing_collection_prefix_when_index_struct_exists(+ baidu_module, monkeypatch: pytest.MonkeyPatch+):factory = baidu_module.BaiduVectorFactory()dataset = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py b/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.pyindex b209c9df967..f18f9a65614 100644--- a/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py+++ b/api/providers/vdb/vdb-chroma/tests/unit_tests/test_chroma_vector.py@@ -44,7 +44,7 @@ def _build_fake_chroma_modules():@pytest.fixture-def chroma_module(monkeypatch):+def chroma_module(monkeypatch: pytest.MonkeyPatch):fake_chroma = _build_fake_chroma_modules()monkeypatch.setitem(sys.modules, "chromadb", fake_chroma)import dify_vdb_chroma.chroma_vector as module@@ -73,7 +73,7 @@ def test_chroma_config_to_params_builds_expected_payload(chroma_module):assert params["settings"].chroma_client_auth_credentials == "credentials"-def test_create_collection_uses_redis_lock_and_cache(chroma_module, monkeypatch):+def test_create_collection_uses_redis_lock_and_cache(chroma_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -173,7 +173,7 @@ def test_search_by_full_text_returns_empty_list(chroma_module):assert vector.search_by_full_text("query") == []-def test_factory_init_vector_uses_existing_or_generated_collection(chroma_module, monkeypatch):+def test_factory_init_vector_uses_existing_or_generated_collection(chroma_module, monkeypatch: pytest.MonkeyPatch):factory = chroma_module.ChromaVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1", index_struct_dict={"vector_store": {"class_prefix": "EXISTING"}}, index_struct=Nonediff --git a/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py b/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.pyindex a7473f1b917..4f8395e475e 100644--- a/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py+++ b/api/providers/vdb/vdb-clickzetta/tests/unit_tests/test_clickzetta_vector.py@@ -45,7 +45,7 @@ def _build_fake_clickzetta_module():@pytest.fixture-def clickzetta_module(monkeypatch):+def clickzetta_module(monkeypatch: pytest.MonkeyPatch):monkeypatch.setitem(sys.modules, "clickzetta", _build_fake_clickzetta_module())import dify_vdb_clickzetta.clickzetta_vector as module@@ -218,7 +218,7 @@ def test_search_by_like_returns_documents_with_default_score(clickzetta_module):assert docs[0].metadata["score"] == 0.5-def test_factory_initializes_clickzetta_vector(clickzetta_module, monkeypatch):+def test_factory_initializes_clickzetta_vector(clickzetta_module, monkeypatch: pytest.MonkeyPatch):factory = clickzetta_module.ClickzettaVectorFactory()dataset = SimpleNamespace(id="dataset-1")@@ -243,7 +243,7 @@ def test_factory_initializes_clickzetta_vector(clickzetta_module, monkeypatch):assert vector_cls.call_args.kwargs["collection_name"] == "collection"-def test_connection_pool_singleton_and_config_key(clickzetta_module, monkeypatch):+def test_connection_pool_singleton_and_config_key(clickzetta_module, monkeypatch: pytest.MonkeyPatch):clickzetta_module.ClickzettaConnectionPool._instance = Nonemonkeypatch.setattr(clickzetta_module.ClickzettaConnectionPool, "_start_cleanup_thread", MagicMock())@@ -255,7 +255,7 @@ def test_connection_pool_singleton_and_config_key(clickzetta_module, monkeypatchassert "username:instance:service:workspace:cluster:dify" in key-def test_connection_pool_create_connection_retries_and_configures(clickzetta_module, monkeypatch):+def test_connection_pool_create_connection_retries_and_configures(clickzetta_module, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(clickzetta_module.ClickzettaConnectionPool, "_start_cleanup_thread", MagicMock())pool = clickzetta_module.ClickzettaConnectionPool()config = _config(clickzetta_module)@@ -274,7 +274,7 @@ def test_connection_pool_create_connection_retries_and_configures(clickzetta_modpool._configure_connection.assert_called_once_with(connection)-def test_connection_pool_create_connection_raises_after_retries(clickzetta_module, monkeypatch):+def test_connection_pool_create_connection_raises_after_retries(clickzetta_module, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(clickzetta_module.ClickzettaConnectionPool, "_start_cleanup_thread", MagicMock())pool = clickzetta_module.ClickzettaConnectionPool()config = _config(clickzetta_module)@@ -318,7 +318,7 @@ def test_connection_pool_configure_connection_swallows_errors(clickzetta_module)monkeypatch.undo()-def test_connection_pool_get_return_cleanup_and_shutdown(clickzetta_module, monkeypatch):+def test_connection_pool_get_return_cleanup_and_shutdown(clickzetta_module, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(clickzetta_module.ClickzettaConnectionPool, "_start_cleanup_thread", MagicMock())pool = clickzetta_module.ClickzettaConnectionPool()config = _config(clickzetta_module)@@ -360,7 +360,7 @@ def test_connection_pool_get_return_cleanup_and_shutdown(clickzetta_module, monkassert pool._shutdown is True-def test_connection_pool_start_cleanup_thread_runs_worker_once(clickzetta_module, monkeypatch):+def test_connection_pool_start_cleanup_thread_runs_worker_once(clickzetta_module, monkeypatch: pytest.MonkeyPatch):pool = clickzetta_module.ClickzettaConnectionPool.__new__(clickzetta_module.ClickzettaConnectionPool)pool._shutdown = Falsepool._cleanup_expired_connections = MagicMock(side_effect=lambda: setattr(pool, "_shutdown", True))@@ -384,7 +384,7 @@ def test_connection_pool_start_cleanup_thread_runs_worker_once(clickzetta_modulepool._cleanup_expired_connections.assert_called_once()-def test_vector_init_connection_context_and_helpers(clickzetta_module, monkeypatch):+def test_vector_init_connection_context_and_helpers(clickzetta_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()pool.get_connection.return_value = "conn"monkeypatch.setattr(clickzetta_module.ClickzettaConnectionPool, "get_instance", MagicMock(return_value=pool))@@ -405,7 +405,7 @@ def test_vector_init_connection_context_and_helpers(clickzetta_module, monkeypatassert vector._ensure_connection() == "conn"-def test_write_queue_initialization_worker_and_execute_write(clickzetta_module, monkeypatch):+def test_write_queue_initialization_worker_and_execute_write(clickzetta_module, monkeypatch: pytest.MonkeyPatch):class _Thread:def __init__(self, target, daemon):self.target = target@@ -579,7 +579,7 @@ def test_create_inverted_index_branches(clickzetta_module):vector._create_inverted_index(cursor)-def test_add_texts_batches_and_insert_batch_behaviors(clickzetta_module, monkeypatch):+def test_add_texts_batches_and_insert_batch_behaviors(clickzetta_module, monkeypatch: pytest.MonkeyPatch):vector = clickzetta_module.ClickzettaVector.__new__(clickzetta_module.ClickzettaVector)vector._config = _config(clickzetta_module)vector._config.batch_size = 2@@ -811,7 +811,7 @@ def test_clickzetta_pool_cleanup_and_shutdown_edge_paths(clickzetta_module):assert pool._shutdown is True-def test_clickzetta_pool_cleanup_thread_and_worker_exception_paths(clickzetta_module, monkeypatch):+def test_clickzetta_pool_cleanup_thread_and_worker_exception_paths(clickzetta_module, monkeypatch: pytest.MonkeyPatch):pool = clickzetta_module.ClickzettaConnectionPool.__new__(clickzetta_module.ClickzettaConnectionPool)pool._shutdown = Falsediff --git a/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py b/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.pyindex 7e5c40b8f2f..d474b566d39 100644--- a/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py+++ b/api/providers/vdb/vdb-couchbase/tests/unit_tests/test_couchbase_vector.py@@ -150,7 +150,7 @@ def _build_fake_couchbase_modules():@pytest.fixture-def couchbase_module(monkeypatch):+def couchbase_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_couchbase_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -194,7 +194,7 @@ def test_init_sets_cluster_handles(couchbase_module):vector._cluster.wait_until_ready.assert_called_once()-def test_create_and_create_collection_branches(couchbase_module, monkeypatch):+def test_create_and_create_collection_branches(couchbase_module, monkeypatch: pytest.MonkeyPatch):vector = couchbase_module.CouchbaseVector.__new__(couchbase_module.CouchbaseVector)vector._collection_name = "collection_1"vector._client_config = _config(couchbase_module)@@ -319,7 +319,7 @@ def test_search_methods_and_format_metadata(couchbase_module):assert vector._format_metadata({"metadata.a": 1, "plain": 2}) == {"a": 1, "plain": 2}-def test_delete_collection_and_factory(couchbase_module, monkeypatch):+def test_delete_collection_and_factory(couchbase_module, monkeypatch: pytest.MonkeyPatch):vector = couchbase_module.CouchbaseVector("collection_1", _config(couchbase_module))scopes = [SimpleNamespace(collections=[SimpleNamespace(name="other")]),diff --git a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.pyindex f81ed6beeab..91cc2e0fdbb 100644--- a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py+++ b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_ja_vector.py@@ -28,7 +28,7 @@ def _build_fake_elasticsearch_modules():@pytest.fixture-def elasticsearch_ja_module(monkeypatch):+def elasticsearch_ja_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_elasticsearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -39,7 +39,7 @@ def elasticsearch_ja_module(monkeypatch):return importlib.reload(ja_module)-def test_create_collection_cache_hit(elasticsearch_ja_module, monkeypatch):+def test_create_collection_cache_hit(elasticsearch_ja_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -57,7 +57,7 @@ def test_create_collection_cache_hit(elasticsearch_ja_module, monkeypatch):elasticsearch_ja_module.redis_client.set.assert_not_called()-def test_create_collection_create_and_exists_paths(elasticsearch_ja_module, monkeypatch):+def test_create_collection_create_and_exists_paths(elasticsearch_ja_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -87,7 +87,7 @@ def test_create_collection_create_and_exists_paths(elasticsearch_ja_module, monkelasticsearch_ja_module.redis_client.set.assert_called_once()-def test_ja_factory_uses_existing_or_generated_collection(elasticsearch_ja_module, monkeypatch):+def test_ja_factory_uses_existing_or_generated_collection(elasticsearch_ja_module, monkeypatch: pytest.MonkeyPatch):factory = elasticsearch_ja_module.ElasticSearchJaVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_vector.py b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_vector.pyindex 48f1f6dc266..d54c105a0fa 100644--- a/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_vector.py+++ b/api/providers/vdb/vdb-elasticsearch/tests/unit_tests/test_elasticsearch_vector.py@@ -38,7 +38,7 @@ def _build_fake_elasticsearch_modules():@pytest.fixture-def elasticsearch_module(monkeypatch):+def elasticsearch_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_elasticsearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -287,7 +287,7 @@ def test_search_by_vector_and_full_text(elasticsearch_module):assert "bool" in query-def test_create_and_create_collection_paths(elasticsearch_module, monkeypatch):+def test_create_and_create_collection_paths(elasticsearch_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -331,7 +331,7 @@ def test_create_and_create_collection_paths(elasticsearch_module, monkeypatch):elasticsearch_module.redis_client.set.assert_called_once()-def test_elasticsearch_factory_branches(elasticsearch_module, monkeypatch):+def test_elasticsearch_factory_branches(elasticsearch_module, monkeypatch: pytest.MonkeyPatch):factory = elasticsearch_module.ElasticSearchVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py b/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.pyindex f9a557ecce6..8b197662e30 100644--- a/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py+++ b/api/providers/vdb/vdb-hologres/tests/unit_tests/test_hologres_vector.py@@ -38,7 +38,7 @@ def _build_fake_hologres_modules():@pytest.fixture-def hologres_module(monkeypatch):+def hologres_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_hologres_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -266,7 +266,7 @@ def test_delete_handles_existing_and_missing_tables(hologres_module):vector._client.drop_table.assert_called_once_with(vector.table_name)-def test_create_collection_returns_early_when_cache_hits(hologres_module, monkeypatch):+def test_create_collection_returns_early_when_cache_hits(hologres_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = False@@ -281,7 +281,7 @@ def test_create_collection_returns_early_when_cache_hits(hologres_module, monkeyhologres_module.redis_client.set.assert_not_called()-def test_create_collection_creates_table_and_indexes(hologres_module, monkeypatch):+def test_create_collection_creates_table_and_indexes(hologres_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = False@@ -313,7 +313,7 @@ def test_create_collection_creates_table_and_indexes(hologres_module, monkeypatchologres_module.redis_client.set.assert_called_once()-def test_create_collection_raises_when_table_never_becomes_ready(hologres_module, monkeypatch):+def test_create_collection_raises_when_table_never_becomes_ready(hologres_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = False@@ -331,7 +331,7 @@ def test_create_collection_raises_when_table_never_becomes_ready(hologres_modulehologres_module.redis_client.set.assert_not_called()-def test_hologres_factory_uses_existing_or_generated_collection(hologres_module, monkeypatch):+def test_hologres_factory_uses_existing_or_generated_collection(hologres_module, monkeypatch: pytest.MonkeyPatch):factory = hologres_module.HologresVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py b/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.pyindex ba3f14912b4..a1617b6d43c 100644--- a/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py+++ b/api/providers/vdb/vdb-huawei-cloud/tests/unit_tests/test_huawei_cloud_vector.py@@ -29,7 +29,7 @@ def _build_fake_elasticsearch_modules():@pytest.fixture-def huawei_module(monkeypatch):+def huawei_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_elasticsearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -155,7 +155,7 @@ def test_search_by_vector_and_full_text(huawei_module):assert docs[0].page_content == "text-hit"-def test_search_by_vector_skips_hits_without_metadata(huawei_module, monkeypatch):+def test_search_by_vector_skips_hits_without_metadata(huawei_module, monkeypatch: pytest.MonkeyPatch):class FakeDocument:def __init__(self, page_content, vector, metadata):self.page_content = page_content@@ -185,7 +185,7 @@ def test_search_by_vector_skips_hits_without_metadata(huawei_module, monkeypatchassert docs == []-def test_create_and_create_collection_paths(huawei_module, monkeypatch):+def test_create_and_create_collection_paths(huawei_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -218,7 +218,7 @@ def test_create_and_create_collection_paths(huawei_module, monkeypatch):huawei_module.redis_client.set.assert_called_once()-def test_huawei_factory_branches(huawei_module, monkeypatch):+def test_huawei_factory_branches(huawei_module, monkeypatch: pytest.MonkeyPatch):factory = huawei_module.HuaweiCloudVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-iris/tests/unit_tests/test_iris_vector.py b/api/providers/vdb/vdb-iris/tests/unit_tests/test_iris_vector.pyindex 8c038e82b95..b4ea6ea6c1a 100644--- a/api/providers/vdb/vdb-iris/tests/unit_tests/test_iris_vector.py+++ b/api/providers/vdb/vdb-iris/tests/unit_tests/test_iris_vector.py@@ -23,7 +23,7 @@ def _build_fake_iris_module():@pytest.fixture-def iris_module(monkeypatch):+def iris_module(monkeypatch: pytest.MonkeyPatch):monkeypatch.setitem(sys.modules, "iris", _build_fake_iris_module())import dify_vdb_iris.iris_vector as module@@ -249,7 +249,7 @@ def test_iris_vector_init_get_cursor_and_create(iris_module):vector._create_collection.assert_called_once_with(2)-def test_iris_vector_crud_and_vector_search(iris_module, monkeypatch):+def test_iris_vector_crud_and_vector_search(iris_module, monkeypatch: pytest.MonkeyPatch):with patch.object(iris_module, "get_iris_pool", return_value=MagicMock()):vector = iris_module.IrisVector("collection", _config(iris_module))@@ -297,7 +297,7 @@ def test_iris_vector_crud_and_vector_search(iris_module, monkeypatch):assert docs[0].metadata["score"] == pytest.approx(0.9)-def test_iris_vector_full_text_search_paths(iris_module, monkeypatch):+def test_iris_vector_full_text_search_paths(iris_module, monkeypatch: pytest.MonkeyPatch):cfg = _config(iris_module, IRIS_TEXT_INDEX=True)with patch.object(iris_module, "get_iris_pool", return_value=MagicMock()):vector = iris_module.IrisVector("collection", cfg)@@ -344,7 +344,7 @@ def test_iris_vector_full_text_search_paths(iris_module, monkeypatch):assert vector_like.search_by_full_text("100%", top_k=1) == []-def test_iris_vector_delete_create_collection_and_factory(iris_module, monkeypatch):+def test_iris_vector_delete_create_collection_and_factory(iris_module, monkeypatch: pytest.MonkeyPatch):with patch.object(iris_module, "get_iris_pool", return_value=MagicMock()):vector = iris_module.IrisVector("collection", _config(iris_module, IRIS_TEXT_INDEX=True))diff --git a/api/providers/vdb/vdb-lindorm/tests/unit_tests/test_lindorm_vector.py b/api/providers/vdb/vdb-lindorm/tests/unit_tests/test_lindorm_vector.pyindex 238145c1d66..4a408d1b101 100644--- a/api/providers/vdb/vdb-lindorm/tests/unit_tests/test_lindorm_vector.py+++ b/api/providers/vdb/vdb-lindorm/tests/unit_tests/test_lindorm_vector.py@@ -47,7 +47,7 @@ def _build_fake_opensearch_modules():@pytest.fixture-def lindorm_module(monkeypatch):+def lindorm_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_opensearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -100,7 +100,7 @@ def test_to_opensearch_params_and_init(lindorm_module):assert vector_ugc._routing == "route"-def test_create_refresh_and_add_texts_success(lindorm_module, monkeypatch):+def test_create_refresh_and_add_texts_success(lindorm_module, monkeypatch: pytest.MonkeyPatch):vector = lindorm_module.LindormVectorStore("collection", _config(lindorm_module), using_ugc=True, routing_value="route")@@ -301,7 +301,7 @@ def test_search_by_full_text_success_and_error(lindorm_module):vector.search_by_full_text("hello")-def test_create_collection_paths(lindorm_module, monkeypatch):+def test_create_collection_paths(lindorm_module, monkeypatch: pytest.MonkeyPatch):vector = lindorm_module.LindormVectorStore("collection", _config(lindorm_module), using_ugc=False)with pytest.raises(ValueError, match="cannot be empty"):@@ -331,7 +331,7 @@ def test_create_collection_paths(lindorm_module, monkeypatch):vector._client.indices.create.assert_not_called()-def test_lindorm_factory_branches(lindorm_module, monkeypatch):+def test_lindorm_factory_branches(lindorm_module, monkeypatch: pytest.MonkeyPatch):factory = lindorm_module.LindormVectorStoreFactory()monkeypatch.setattr(lindorm_module.dify_config, "LINDORM_URL", "http://localhost:9200")diff --git a/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py b/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.pyindex c22f4304e51..762ec330b29 100644--- a/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py+++ b/api/providers/vdb/vdb-matrixone/tests/unit_tests/test_matrixone_vector.py@@ -32,7 +32,7 @@ def _build_fake_mo_vector_modules():@pytest.fixture-def matrixone_module(monkeypatch):+def matrixone_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_mo_vector_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -70,7 +70,7 @@ def test_matrixone_config_validation(matrixone_module, field, value, message):matrixone_module.MatrixoneConfig.model_validate(values)-def test_get_client_creates_full_text_index_when_cache_misses(matrixone_module, monkeypatch):+def test_get_client_creates_full_text_index_when_cache_misses(matrixone_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -86,7 +86,7 @@ def test_get_client_creates_full_text_index_when_cache_misses(matrixone_module,matrixone_module.redis_client.set.assert_called_once()-def test_get_client_skips_index_creation_when_cache_hits(matrixone_module, monkeypatch):+def test_get_client_skips_index_creation_when_cache_hits(matrixone_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -146,7 +146,7 @@ def test_get_type_and_create_delegate_to_add_texts(matrixone_module):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_get_client_handles_full_text_index_creation_error(matrixone_module, monkeypatch):+def test_get_client_handles_full_text_index_creation_error(matrixone_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -165,7 +165,7 @@ def test_get_client_handles_full_text_index_creation_error(matrixone_module, monmatrixone_module.redis_client.set.assert_not_called()-def test_add_texts_generates_ids_and_inserts(matrixone_module, monkeypatch):+def test_add_texts_generates_ids_and_inserts(matrixone_module, monkeypatch: pytest.MonkeyPatch):vector = matrixone_module.MatrixoneVector("collection_1", _valid_config(matrixone_module))vector.client = MagicMock()monkeypatch.setattr(matrixone_module.uuid, "uuid4", lambda: "generated-uuid")@@ -224,7 +224,7 @@ def test_search_by_vector_builds_documents(matrixone_module):assert vector.client.query.call_args.kwargs["filter"] == {"document_id": {"$in": ["d-1"]}}-def test_matrixone_factory_uses_existing_or_generated_collection(matrixone_module, monkeypatch):+def test_matrixone_factory_uses_existing_or_generated_collection(matrixone_module, monkeypatch: pytest.MonkeyPatch):factory = matrixone_module.MatrixoneVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-milvus/tests/unit_tests/test_milvus.py b/api/providers/vdb/vdb-milvus/tests/unit_tests/test_milvus.pyindex 36c0ed8f6fe..730ff9f296e 100644--- a/api/providers/vdb/vdb-milvus/tests/unit_tests/test_milvus.py+++ b/api/providers/vdb/vdb-milvus/tests/unit_tests/test_milvus.py@@ -99,7 +99,7 @@ def _build_fake_pymilvus_modules():@pytest.fixture-def milvus_module(monkeypatch):+def milvus_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_pymilvus_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -327,7 +327,7 @@ def test_process_search_results_and_search_methods(milvus_module):assert "document_id" in vector._client.search.call_args.kwargs["filter"]-def test_create_collection_cache_and_existing_collection(milvus_module, monkeypatch):+def test_create_collection_cache_and_existing_collection(milvus_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -351,7 +351,7 @@ def test_create_collection_cache_and_existing_collection(milvus_module, monkeypamilvus_module.redis_client.set.assert_called()-def test_create_collection_builds_schema_and_indexes(milvus_module, monkeypatch):+def test_create_collection_builds_schema_and_indexes(milvus_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -385,7 +385,7 @@ def test_create_collection_builds_schema_and_indexes(milvus_module, monkeypatch)assert call_kwargs["consistency_level"] == "Session"-def test_factory_initializes_milvus_vector(milvus_module, monkeypatch):+def test_factory_initializes_milvus_vector(milvus_module, monkeypatch: pytest.MonkeyPatch):factory = milvus_module.MilvusVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py b/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.pyindex 228ea926395..900c75fdabf 100644--- a/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py+++ b/api/providers/vdb/vdb-myscale/tests/unit_tests/test_myscale_vector.py@@ -38,7 +38,7 @@ def _build_fake_clickhouse_connect_module():@pytest.fixture-def myscale_module(monkeypatch):+def myscale_module(monkeypatch: pytest.MonkeyPatch):fake_module = _build_fake_clickhouse_connect_module()monkeypatch.setitem(sys.modules, "clickhouse_connect", fake_module)@@ -90,7 +90,7 @@ def test_delete_by_ids_short_circuits_on_empty_list(myscale_module):vector._client.command.assert_not_called()-def test_factory_initializes_lower_case_collection_name(myscale_module, monkeypatch):+def test_factory_initializes_lower_case_collection_name(myscale_module, monkeypatch: pytest.MonkeyPatch):factory = myscale_module.MyScaleVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",@@ -160,7 +160,7 @@ def test_create_collection_builds_expected_sql(myscale_module):assert "INDEX text_idx text TYPE fts('tokenizer=unicode')" in sql-def test_add_texts_inserts_rows_and_returns_ids(myscale_module, monkeypatch):+def test_add_texts_inserts_rows_and_returns_ids(myscale_module, monkeypatch: pytest.MonkeyPatch):vector = myscale_module.MyScaleVector("collection_1", _config(myscale_module))monkeypatch.setattr(myscale_module.uuid, "uuid4", lambda: "generated-uuid")docs = [diff --git a/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py b/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.pyindex 31f9ff3e56e..36393cc486d 100644--- a/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py+++ b/api/providers/vdb/vdb-oceanbase/tests/unit_tests/test_oceanbase_vector.py@@ -53,7 +53,7 @@ def _build_fake_pyobvector_module():@pytest.fixture-def oceanbase_module(monkeypatch):+def oceanbase_module(monkeypatch: pytest.MonkeyPatch):monkeypatch.setitem(sys.modules, "pyobvector", _build_fake_pyobvector_module())import dify_vdb_oceanbase.oceanbase_vector as module@@ -208,7 +208,7 @@ def test_create_delegates_to_collection_and_insert(oceanbase_module):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_create_collection_cache_and_existing_table_short_circuits(oceanbase_module, monkeypatch):+def test_create_collection_cache_and_existing_table_short_circuits(oceanbase_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -234,7 +234,7 @@ def test_create_collection_cache_and_existing_table_short_circuits(oceanbase_modvector.delete.assert_not_called()-def test_create_collection_happy_path_with_hybrid_and_index(oceanbase_module, monkeypatch):+def test_create_collection_happy_path_with_hybrid_and_index(oceanbase_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -271,7 +271,7 @@ def test_create_collection_happy_path_with_hybrid_and_index(oceanbase_module, mooceanbase_module.redis_client.set.assert_called_once()-def test_create_collection_error_paths(oceanbase_module, monkeypatch):+def test_create_collection_error_paths(oceanbase_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -308,7 +308,7 @@ def test_create_collection_error_paths(oceanbase_module, monkeypatch):vector._create_collection()-def test_create_collection_fulltext_and_metadata_index_exceptions(oceanbase_module, monkeypatch):+def test_create_collection_fulltext_and_metadata_index_exceptions(oceanbase_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -517,7 +517,7 @@ def test_delete_success_and_exception(oceanbase_module):vector.delete()-def test_oceanbase_factory_uses_existing_or_generated_collection(oceanbase_module, monkeypatch):+def test_oceanbase_factory_uses_existing_or_generated_collection(oceanbase_module, monkeypatch: pytest.MonkeyPatch):factory = oceanbase_module.OceanBaseVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py b/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.pyindex 09abd625fc1..57c9b14d9f7 100644--- a/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py+++ b/api/providers/vdb/vdb-opengauss/tests/unit_tests/test_opengauss.py@@ -37,7 +37,7 @@ def _build_fake_psycopg2_modules():@pytest.fixture-def opengauss_module(monkeypatch):+def opengauss_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_psycopg2_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -88,7 +88,7 @@ def test_opengauss_config_validation_rejects_min_greater_than_max(opengauss_moduopengauss_module.OpenGaussConfig.model_validate(values)-def test_init_sets_table_name_and_vector_type(opengauss_module, monkeypatch):+def test_init_sets_table_name_and_vector_type(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -99,7 +99,7 @@ def test_init_sets_table_name_and_vector_type(opengauss_module, monkeypatch):assert vector.pool is pool-def test_create_index_with_pq_executes_pq_sql(opengauss_module, monkeypatch):+def test_create_index_with_pq_executes_pq_sql(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -126,7 +126,7 @@ def test_create_index_with_pq_executes_pq_sql(opengauss_module, monkeypatch):opengauss_module.redis_client.set.assert_called_once()-def test_create_index_skips_index_sql_for_large_dimension(opengauss_module, monkeypatch):+def test_create_index_skips_index_sql_for_large_dimension(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -158,7 +158,7 @@ def test_search_by_vector_validates_top_k(opengauss_module):vector.search_by_vector([0.1, 0.2], top_k=0)-def test_delete_by_ids_short_circuits_with_empty_input(opengauss_module, monkeypatch):+def test_delete_by_ids_short_circuits_with_empty_input(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))vector = opengauss_module.OpenGauss("collection_1", _config(opengauss_module))@@ -200,7 +200,7 @@ def test_create_calls_collection_insert_and_index(opengauss_module):vector._create_index.assert_called_once_with(2)-def test_create_index_returns_early_on_cache_hit(opengauss_module, monkeypatch):+def test_create_index_returns_early_on_cache_hit(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -220,7 +220,7 @@ def test_create_index_returns_early_on_cache_hit(opengauss_module, monkeypatch):opengauss_module.redis_client.set.assert_not_called()-def test_create_index_without_pq_executes_standard_index_sql(opengauss_module, monkeypatch):+def test_create_index_without_pq_executes_standard_index_sql(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -245,7 +245,7 @@ def test_create_index_without_pq_executes_standard_index_sql(opengauss_module, massert any("embedding_cosine_embedding_collection_1_idx" in query for query in sql)-def test_add_texts_uses_execute_values(opengauss_module, monkeypatch):+def test_add_texts_uses_execute_values(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))vector = opengauss_module.OpenGauss("collection_1", _config(opengauss_module))@@ -342,7 +342,7 @@ def test_search_by_full_text_validates_top_k(opengauss_module):vector.search_by_full_text("query", top_k=0)-def test_create_collection_cache_and_create_path(opengauss_module, monkeypatch):+def test_create_collection_cache_and_create_path(opengauss_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(opengauss_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))lock = MagicMock()@@ -370,7 +370,7 @@ def test_create_collection_cache_and_create_path(opengauss_module, monkeypatch):opengauss_module.redis_client.set.assert_called_once()-def test_opengauss_factory_uses_existing_or_generated_collection(opengauss_module, monkeypatch):+def test_opengauss_factory_uses_existing_or_generated_collection(opengauss_module, monkeypatch: pytest.MonkeyPatch):factory = opengauss_module.OpenGaussFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch.py b/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch.pyindex f2ed7cb6fbe..b2b004a4de9 100644--- a/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch.py+++ b/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch.py@@ -59,7 +59,7 @@ def _build_fake_opensearch_modules():@pytest.fixture-def opensearch_module(monkeypatch):+def opensearch_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_opensearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -95,7 +95,7 @@ class TestOpenSearchConfig:assert params["connection_class"].__name__ == "Urllib3HttpConnection"assert params["http_auth"] == ("admin", "password")- def test_to_opensearch_params_with_aws_managed_iam(self, opensearch_module, monkeypatch):+ def test_to_opensearch_params_with_aws_managed_iam(self, opensearch_module, monkeypatch: pytest.MonkeyPatch):class _Session:def get_credentials(self):return "creds"diff --git a/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch_vector.py b/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch_vector.pyindex 1c2921f85be..80bf20e8206 100644--- a/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch_vector.py+++ b/api/providers/vdb/vdb-opensearch/tests/unit_tests/test_opensearch_vector.py@@ -58,7 +58,7 @@ def _build_fake_opensearch_modules():@pytest.fixture-def opensearch_module(monkeypatch):+def opensearch_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_opensearch_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -116,7 +116,7 @@ def test_config_validation_for_aws_auth_and_https_fields(opensearch_module):opensearch_module.OpenSearchConfig.model_validate(values)-def test_create_aws_managed_iam_auth(opensearch_module, monkeypatch):+def test_create_aws_managed_iam_auth(opensearch_module, monkeypatch: pytest.MonkeyPatch):class _Session:def get_credentials(self):return "creds"@@ -167,7 +167,7 @@ def test_init_and_create_delegate_calls(opensearch_module):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_add_texts_supports_regular_and_aoss_clients(opensearch_module, monkeypatch):+def test_add_texts_supports_regular_and_aoss_clients(opensearch_module, monkeypatch: pytest.MonkeyPatch):vector = opensearch_module.OpenSearchVector("Collection_1", _config(opensearch_module, aws_service="es"))docs = [Document(page_content="a", metadata={"doc_id": "1"}),@@ -308,7 +308,7 @@ def test_search_by_full_text_and_filters(opensearch_module):assert query["query"]["bool"]["filter"] == [{"terms": {"metadata.document_id": ["d-1"]}}]-def test_create_collection_cache_and_create_path(opensearch_module, monkeypatch):+def test_create_collection_cache_and_create_path(opensearch_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -331,7 +331,7 @@ def test_create_collection_cache_and_create_path(opensearch_module, monkeypatch)opensearch_module.redis_client.set.assert_called()-def test_opensearch_factory_initializes_expected_collection_name(opensearch_module, monkeypatch):+def test_opensearch_factory_initializes_expected_collection_name(opensearch_module, monkeypatch: pytest.MonkeyPatch):factory = opensearch_module.OpenSearchVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-oracle/tests/unit_tests/test_oraclevector.py b/api/providers/vdb/vdb-oracle/tests/unit_tests/test_oraclevector.pyindex 678cf876b07..46027c7e449 100644--- a/api/providers/vdb/vdb-oracle/tests/unit_tests/test_oraclevector.py+++ b/api/providers/vdb/vdb-oracle/tests/unit_tests/test_oraclevector.py@@ -51,7 +51,7 @@ def _connection_with_cursor(cursor):@pytest.fixture-def oracle_module(monkeypatch):+def oracle_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_oracle_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -94,7 +94,7 @@ def test_oracle_config_validation_autonomous_requirements(oracle_module):)-def test_init_and_get_type(oracle_module, monkeypatch):+def test_init_and_get_type(oracle_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(oracle_module.oracledb, "create_pool", MagicMock(return_value=pool))vector = oracle_module.OracleVector("collection_1", _config(oracle_module))@@ -139,7 +139,7 @@ def test_numpy_converters_and_type_handlers(oracle_module):assert out_float64.dtype == numpy.float64-def test_get_connection_supports_standard_and_autonomous_paths(oracle_module, monkeypatch):+def test_get_connection_supports_standard_and_autonomous_paths(oracle_module, monkeypatch: pytest.MonkeyPatch):connect = MagicMock(return_value="connection")monkeypatch.setattr(oracle_module.oracledb, "connect", connect)@@ -173,7 +173,7 @@ def test_create_delegates_collection_and_insert(oracle_module):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_add_texts_inserts_and_logs_on_failures(oracle_module, monkeypatch):+def test_add_texts_inserts_and_logs_on_failures(oracle_module, monkeypatch: pytest.MonkeyPatch):vector = oracle_module.OracleVector.__new__(oracle_module.OracleVector)vector.table_name = "embedding_collection_1"vector.input_type_handler = MagicMock()@@ -279,7 +279,7 @@ def _fake_nltk_module(*, missing_data=False):return nltk, nltk_corpus-def test_search_by_full_text_chinese_and_english_paths(oracle_module, monkeypatch):+def test_search_by_full_text_chinese_and_english_paths(oracle_module, monkeypatch: pytest.MonkeyPatch):vector = oracle_module.OracleVector.__new__(oracle_module.OracleVector)vector.table_name = "embedding_collection_1"@@ -305,7 +305,7 @@ def test_search_by_full_text_chinese_and_english_paths(oracle_module, monkeypatcassert "doc_id_0" in en_params-def test_search_by_full_text_empty_query_and_missing_nltk(oracle_module, monkeypatch):+def test_search_by_full_text_empty_query_and_missing_nltk(oracle_module, monkeypatch: pytest.MonkeyPatch):vector = oracle_module.OracleVector.__new__(oracle_module.OracleVector)vector.table_name = "embedding_collection_1"vector._get_connection = MagicMock()@@ -320,7 +320,7 @@ def test_search_by_full_text_empty_query_and_missing_nltk(oracle_module, monkeypvector.search_by_full_text("english query")-def test_create_collection_cache_and_execute_path(oracle_module, monkeypatch):+def test_create_collection_cache_and_execute_path(oracle_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -346,7 +346,9 @@ def test_create_collection_cache_and_execute_path(oracle_module, monkeypatch):oracle_module.redis_client.set.assert_called_once()-def test_oracle_factory_init_vector_uses_existing_or_generated_collection(oracle_module, monkeypatch):+def test_oracle_factory_init_vector_uses_existing_or_generated_collection(+ oracle_module, monkeypatch: pytest.MonkeyPatch+):factory = oracle_module.OracleVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py b/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.pyindex c3291f7f125..1841e881397 100644--- a/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py+++ b/api/providers/vdb/vdb-pgvecto-rs/tests/unit_tests/test_pgvecto_rs.py@@ -79,7 +79,7 @@ def _patch_both(monkeypatch, module, calls, execute_results=None):@pytest.fixture-def pgvecto_module(monkeypatch):+def pgvecto_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_pgvecto_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -126,7 +126,7 @@ def test_collection_base_has_expected_annotations(pgvecto_module):assert {"id", "text", "meta", "vector"} <= set(annotations)-def test_init_get_type_and_create_delegate(pgvecto_module, monkeypatch):+def test_init_get_type_and_create_delegate(pgvecto_module, monkeypatch: pytest.MonkeyPatch):module, _ = pgvecto_modulesession_calls = []monkeypatch.setattr(module, "create_engine", MagicMock(return_value="engine"))@@ -145,7 +145,7 @@ def test_init_get_type_and_create_delegate(pgvecto_module, monkeypatch):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_create_collection_cache_and_sql_execution(pgvecto_module, monkeypatch):+def test_create_collection_cache_and_sql_execution(pgvecto_module, monkeypatch: pytest.MonkeyPatch):module, _ = pgvecto_modulesession_calls = []monkeypatch.setattr(module, "create_engine", MagicMock(return_value="engine"))@@ -169,7 +169,7 @@ def test_create_collection_cache_and_sql_execution(pgvecto_module, monkeypatch):module.redis_client.set.assert_called()-def test_add_texts_get_ids_and_delete_methods(pgvecto_module, monkeypatch):+def test_add_texts_get_ids_and_delete_methods(pgvecto_module, monkeypatch: pytest.MonkeyPatch):module, _ = pgvecto_moduleinit_calls = []runtime_calls = []@@ -241,7 +241,7 @@ def test_add_texts_get_ids_and_delete_methods(pgvecto_module, monkeypatch):assert any("DROP TABLE IF EXISTS collection_1" in str(args[0]) for args, _ in runtime_calls)-def test_text_exists_search_and_full_text(pgvecto_module, monkeypatch):+def test_text_exists_search_and_full_text(pgvecto_module, monkeypatch: pytest.MonkeyPatch):module, _ = pgvecto_moduleinit_calls = []monkeypatch.setattr(module, "create_engine", MagicMock(return_value="engine"))@@ -313,7 +313,7 @@ def test_text_exists_search_and_full_text(pgvecto_module, monkeypatch):assert vector.search_by_full_text("hello") == []-def test_factory_uses_existing_or_generated_collection(pgvecto_module, monkeypatch):+def test_factory_uses_existing_or_generated_collection(pgvecto_module, monkeypatch: pytest.MonkeyPatch):module, _ = pgvecto_modulefactory = module.PGVectoRSFactory()dataset_with_index = SimpleNamespace(diff --git a/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py b/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.pyindex 99a6e00c16a..38e472df636 100644--- a/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py+++ b/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py@@ -336,7 +336,7 @@ def test_create_delegates_collection_creation_and_insert():vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_add_texts_uses_execute_values_and_returns_ids(monkeypatch):+def test_add_texts_uses_execute_values_and_returns_ids(monkeypatch: pytest.MonkeyPatch):vector = PGVector.__new__(PGVector)vector.table_name = "embedding_collection_1"@@ -387,7 +387,7 @@ def test_text_get_and_delete_methods():assert any("DROP TABLE IF EXISTS embedding_collection_1" in sql for sql in executed_sql)-def test_delete_by_ids_handles_empty_undefined_table_and_generic_exception(monkeypatch):+def test_delete_by_ids_handles_empty_undefined_table_and_generic_exception(monkeypatch: pytest.MonkeyPatch):vector = PGVector.__new__(PGVector)vector.table_name = "embedding_collection_1"cursor = MagicMock()@@ -464,7 +464,7 @@ def test_search_by_full_text_branches_for_bigm_and_standard():assert "bigm_similarity" in cursor.execute.call_args_list[1].args[0]-def test_pgvector_factory_initializes_expected_collection_name(monkeypatch):+def test_pgvector_factory_initializes_expected_collection_name(monkeypatch: pytest.MonkeyPatch):factory = pgvector_module.PGVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-qdrant/tests/unit_tests/test_qdrant_vector.py b/api/providers/vdb/vdb-qdrant/tests/unit_tests/test_qdrant_vector.pyindex 0ed5491fbe0..89ee0a47f1e 100644--- a/api/providers/vdb/vdb-qdrant/tests/unit_tests/test_qdrant_vector.py+++ b/api/providers/vdb/vdb-qdrant/tests/unit_tests/test_qdrant_vector.py@@ -121,7 +121,7 @@ def _build_fake_qdrant_modules():@pytest.fixture-def qdrant_module(monkeypatch):+def qdrant_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_qdrant_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -170,7 +170,7 @@ def test_init_and_basic_behaviour(qdrant_module):vector.add_texts.assert_called_once()-def test_create_collection_and_add_texts(qdrant_module, monkeypatch):+def test_create_collection_and_add_texts(qdrant_module, monkeypatch: pytest.MonkeyPatch):vector = qdrant_module.QdrantVector("collection_1", "group-1", _config(qdrant_module))lock = MagicMock()lock.__enter__.return_value = None@@ -288,7 +288,7 @@ def test_search_and_helper_methods(qdrant_module):assert doc.page_content == "doc"-def test_qdrant_factory_paths(qdrant_module, monkeypatch):+def test_qdrant_factory_paths(qdrant_module, monkeypatch: pytest.MonkeyPatch):factory = qdrant_module.QdrantVectorFactory()dataset = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py b/api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.pyindex f97ad1400ae..c5f3a9f847a 100644--- a/api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py+++ b/api/providers/vdb/vdb-relyt/tests/unit_tests/test_relyt_vector.py@@ -59,7 +59,7 @@ def _patch_both(monkeypatch, module, session):@pytest.fixture-def relyt_module(monkeypatch):+def relyt_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_relyt_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -97,7 +97,7 @@ def test_relyt_config_validation(relyt_module, field, value, message):relyt_module.RelytConfig.model_validate(values)-def test_init_get_type_and_create_delegate(relyt_module, monkeypatch):+def test_init_get_type_and_create_delegate(relyt_module, monkeypatch: pytest.MonkeyPatch):engine = MagicMock()monkeypatch.setattr(relyt_module, "create_engine", MagicMock(return_value=engine))vector = relyt_module.RelytVector("collection_1", _config(relyt_module), group_id="group-1")@@ -114,7 +114,7 @@ def test_init_get_type_and_create_delegate(relyt_module, monkeypatch):vector.add_texts.assert_called_once_with(docs, [[0.1, 0.2]])-def test_create_collection_cache_and_sql_execution(relyt_module, monkeypatch):+def test_create_collection_cache_and_sql_execution(relyt_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -142,7 +142,7 @@ def test_create_collection_cache_and_sql_execution(relyt_module, monkeypatch):relyt_module.redis_client.set.assert_called_once()-def test_add_texts_and_metadata_queries(relyt_module, monkeypatch):+def test_add_texts_and_metadata_queries(relyt_module, monkeypatch: pytest.MonkeyPatch):vector = relyt_module.RelytVector.__new__(relyt_module.RelytVector)vector._collection_name = "collection_1"vector._group_id = "group-1"@@ -212,7 +212,7 @@ def test_delete_by_metadata_field_calls_delete_by_uuids(relyt_module):# 3. delete_by_ids translates to uuids-def test_delete_by_ids_translates_to_uuids(relyt_module, monkeypatch):+def test_delete_by_ids_translates_to_uuids(relyt_module, monkeypatch: pytest.MonkeyPatch):vector = relyt_module.RelytVector.__new__(relyt_module.RelytVector)vector._collection_name = "collection_1"vector.client = MagicMock()@@ -225,7 +225,7 @@ def test_delete_by_ids_translates_to_uuids(relyt_module, monkeypatch):# 4. text_exists True-def test_text_exists_true(relyt_module, monkeypatch):+def test_text_exists_true(relyt_module, monkeypatch: pytest.MonkeyPatch):vector = relyt_module.RelytVector.__new__(relyt_module.RelytVector)vector._collection_name = "collection_1"vector.client = MagicMock()@@ -236,7 +236,7 @@ def test_text_exists_true(relyt_module, monkeypatch):# 5. text_exists False-def test_text_exists_false(relyt_module, monkeypatch):+def test_text_exists_false(relyt_module, monkeypatch: pytest.MonkeyPatch):vector = relyt_module.RelytVector.__new__(relyt_module.RelytVector)vector._collection_name = "collection_1"vector.client = MagicMock()@@ -284,7 +284,7 @@ def test_search_by_vector_filters_by_score_and_ids(relyt_module):# 8. delete commits session-def test_delete_drops_table(relyt_module, monkeypatch):+def test_delete_drops_table(relyt_module, monkeypatch: pytest.MonkeyPatch):vector = relyt_module.RelytVector.__new__(relyt_module.RelytVector)vector._collection_name = "collection_1"vector.client = MagicMock()@@ -295,7 +295,7 @@ def test_delete_drops_table(relyt_module, monkeypatch):session.execute.assert_called_once()-def test_relyt_factory_existing_and_generated_collection(relyt_module, monkeypatch):+def test_relyt_factory_existing_and_generated_collection(relyt_module, monkeypatch: pytest.MonkeyPatch):factory = relyt_module.RelytVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py b/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.pyindex 62a11e04457..49d4b160cf9 100644--- a/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py+++ b/api/providers/vdb/vdb-tablestore/tests/unit_tests/test_tablestore_vector.py@@ -77,7 +77,7 @@ def _build_fake_tablestore_module():@pytest.fixture-def tablestore_module(monkeypatch):+def tablestore_module(monkeypatch: pytest.MonkeyPatch):fake_module = _build_fake_tablestore_module()monkeypatch.setitem(sys.modules, "tablestore", fake_module)@@ -177,7 +177,7 @@ def test_get_by_ids_text_exists_delete_and_wrappers(tablestore_module):vector._delete_table_if_exist.assert_called_once()-def test_create_collection_and_table_index_lifecycle(tablestore_module, monkeypatch):+def test_create_collection_and_table_index_lifecycle(tablestore_module, monkeypatch: pytest.MonkeyPatch):vector = tablestore_module.TableStoreVector("collection_1", _config(tablestore_module))lock = MagicMock()lock.__enter__.return_value = None@@ -289,7 +289,7 @@ def test_write_row_and_search_helpers(tablestore_module):assert "score" not in docs[0].metadata-def test_tablestore_factory_uses_existing_or_generated_collection(tablestore_module, monkeypatch):+def test_tablestore_factory_uses_existing_or_generated_collection(tablestore_module, monkeypatch: pytest.MonkeyPatch):factory = tablestore_module.TableStoreVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-tencent/tests/unit_tests/test_tencent_vector.py b/api/providers/vdb/vdb-tencent/tests/unit_tests/test_tencent_vector.pyindex 299e40ee1ef..e1fe227a29a 100644--- a/api/providers/vdb/vdb-tencent/tests/unit_tests/test_tencent_vector.py+++ b/api/providers/vdb/vdb-tencent/tests/unit_tests/test_tencent_vector.py@@ -136,7 +136,7 @@ def _build_fake_tencent_modules():@pytest.fixture-def tencent_module(monkeypatch):+def tencent_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_tencent_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -187,7 +187,7 @@ def test_config_and_init_paths(tencent_module):assert vector._enable_hybrid_search is False-def test_create_collection_branches(tencent_module, monkeypatch):+def test_create_collection_branches(tencent_module, monkeypatch: pytest.MonkeyPatch):vector = tencent_module.TencentVector("collection_1", _config(tencent_module))lock = MagicMock()@@ -279,7 +279,7 @@ def test_create_add_delete_and_search_behaviour(tencent_module):vector._client.drop_collection.assert_called_once()-def test_tencent_factory_existing_and_generated_collection(tencent_module, monkeypatch):+def test_tencent_factory_existing_and_generated_collection(tencent_module, monkeypatch: pytest.MonkeyPatch):factory = tencent_module.TencentVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-tidb-vector/tests/unit_tests/test_tidb_vector.py b/api/providers/vdb/vdb-tidb-vector/tests/unit_tests/test_tidb_vector.pyindex bdbed2f7403..ed03cbee88d 100644--- a/api/providers/vdb/vdb-tidb-vector/tests/unit_tests/test_tidb_vector.py+++ b/api/providers/vdb/vdb-tidb-vector/tests/unit_tests/test_tidb_vector.py@@ -46,7 +46,7 @@ def test_tidb_config_validation(tidb_module, field, value, message):tidb_module.TiDBVectorConfig.model_validate(values)-def test_init_get_type_and_distance_func(tidb_module, monkeypatch):+def test_init_get_type_and_distance_func(tidb_module, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(tidb_module, "create_engine", MagicMock(return_value="engine"))vector = tidb_module.TiDBVector("collection_1", _config(tidb_module), distance_func="L2")@@ -63,7 +63,7 @@ def test_init_get_type_and_distance_func(tidb_module, monkeypatch):assert vector._get_distance_func() == "VEC_COSINE_DISTANCE"-def test_table_builds_columns_with_tidb_vector_type(tidb_module, monkeypatch):+def test_table_builds_columns_with_tidb_vector_type(tidb_module, monkeypatch: pytest.MonkeyPatch):fake_tidb_vector = types.ModuleType("tidb_vector")fake_tidb_sqlalchemy = types.ModuleType("tidb_vector.sqlalchemy")@@ -107,7 +107,7 @@ def test_create_calls_collection_and_add_texts(tidb_module):assert vector._dimension == 2-def test_create_collection_skips_when_cache_hit(tidb_module, monkeypatch):+def test_create_collection_skips_when_cache_hit(tidb_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -127,7 +127,7 @@ def test_create_collection_skips_when_cache_hit(tidb_module, monkeypatch):tidb_module.redis_client.set.assert_not_called()-def test_create_collection_executes_create_sql_and_sets_cache(tidb_module, monkeypatch):+def test_create_collection_executes_create_sql_and_sets_cache(tidb_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -160,7 +160,7 @@ def test_create_collection_executes_create_sql_and_sets_cache(tidb_module, monketidb_module.redis_client.set.assert_called_once()-def test_add_texts_batches_inserts_and_returns_ids(tidb_module, monkeypatch):+def test_add_texts_batches_inserts_and_returns_ids(tidb_module, monkeypatch: pytest.MonkeyPatch):class _InsertStmt:def __init__(self, table):self.table = table@@ -198,7 +198,7 @@ def test_add_texts_batches_inserts_and_returns_ids(tidb_module, monkeypatch):@pytest.fixture-def tidb_vector_with_session(tidb_module, monkeypatch):+def tidb_vector_with_session(tidb_module, monkeypatch: pytest.MonkeyPatch):vector = tidb_module.TiDBVector.__new__(tidb_module.TiDBVector)vector._collection_name = "collection_1"vector._engine = MagicMock()@@ -354,7 +354,7 @@ def test_delete_by_metadata_field_does_nothing_when_no_ids(tidb_module):# Test search_by_vector filters and scores-def test_search_by_vector_filters_and_scores(tidb_module, monkeypatch):+def test_search_by_vector_filters_and_scores(tidb_module, monkeypatch: pytest.MonkeyPatch):session = MagicMock()session.execute.return_value = [('{"doc_id":"id-1","document_id":"d-1"}', "text-1", 0.2),@@ -392,7 +392,7 @@ def test_search_by_vector_filters_and_scores(tidb_module, monkeypatch):# Test delete drops table-def test_delete_drops_table(tidb_module, monkeypatch):+def test_delete_drops_table(tidb_module, monkeypatch: pytest.MonkeyPatch):session = MagicMock()session.execute.return_value = None@@ -413,7 +413,7 @@ def test_delete_drops_table(tidb_module, monkeypatch):assert "DROP TABLE IF EXISTS collection_1" in drop_sql-def test_tidb_factory_uses_existing_or_generated_collection(tidb_module, monkeypatch):+def test_tidb_factory_uses_existing_or_generated_collection(tidb_module, monkeypatch: pytest.MonkeyPatch):factory = tidb_module.TiDBVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py b/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.pyindex a884275c89c..55d27ad264d 100644--- a/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py+++ b/api/providers/vdb/vdb-upstash/tests/unit_tests/test_upstash_vector.py@@ -36,7 +36,7 @@ def _build_fake_upstash_module():@pytest.fixture-def upstash_module(monkeypatch):+def upstash_module(monkeypatch: pytest.MonkeyPatch):# Remove patched modules if presentfor modname in ["upstash_vector", "dify_vdb_upstash.upstash_vector"]:if modname in sys.modules:@@ -65,7 +65,7 @@ def test_upstash_config_validation(upstash_module, field, value, message):upstash_module.UpstashVectorConfig.model_validate(values)-def test_init_get_type_and_dimension(upstash_module, monkeypatch):+def test_init_get_type_and_dimension(upstash_module, monkeypatch: pytest.MonkeyPatch):vector = upstash_module.UpstashVector("collection_1", _config(upstash_module))assert vector.get_type() == upstash_module.VectorType.UPSTASH@@ -162,7 +162,7 @@ def test_search_by_vector_filter_threshold_and_delete(upstash_module):vector.index.reset.assert_called_once()-def test_upstash_factory_uses_existing_or_generated_collection(upstash_module, monkeypatch):+def test_upstash_factory_uses_existing_or_generated_collection(upstash_module, monkeypatch: pytest.MonkeyPatch):factory = upstash_module.UpstashVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py b/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.pyindex 4dfb956c002..32f47c67edb 100644--- a/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py+++ b/api/providers/vdb/vdb-vastbase/tests/unit_tests/test_vastbase_vector.py@@ -37,7 +37,7 @@ def _build_fake_psycopg2_modules():@pytest.fixture-def vastbase_module(monkeypatch):+def vastbase_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_psycopg2_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -93,7 +93,7 @@ def test_vastbase_config_rejects_invalid_connection_window(vastbase_module):)-def test_init_and_get_cursor_context_manager(vastbase_module, monkeypatch):+def test_init_and_get_cursor_context_manager(vastbase_module, monkeypatch: pytest.MonkeyPatch):pool = MagicMock()monkeypatch.setattr(vastbase_module.psycopg2.pool, "SimpleConnectionPool", MagicMock(return_value=pool))@@ -114,7 +114,7 @@ def test_init_and_get_cursor_context_manager(vastbase_module, monkeypatch):pool.putconn.assert_called_once_with(conn)-def test_create_and_add_texts(vastbase_module, monkeypatch):+def test_create_and_add_texts(vastbase_module, monkeypatch: pytest.MonkeyPatch):vector = vastbase_module.VastbaseVector.__new__(vastbase_module.VastbaseVector)vector.table_name = "embedding_collection_1"vector._create_collection = MagicMock()@@ -205,7 +205,7 @@ def test_search_by_vector_and_full_text(vastbase_module):assert full_docs[0].page_content == "full-text"-def test_create_collection_cache_and_dimension_branches(vastbase_module, monkeypatch):+def test_create_collection_cache_and_dimension_branches(vastbase_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -240,7 +240,7 @@ def test_create_collection_cache_and_dimension_branches(vastbase_module, monkeypvastbase_module.redis_client.set.assert_called()-def test_vastbase_factory_uses_existing_or_generated_collection(vastbase_module, monkeypatch):+def test_vastbase_factory_uses_existing_or_generated_collection(vastbase_module, monkeypatch: pytest.MonkeyPatch):factory = vastbase_module.VastbaseVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",diff --git a/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py b/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.pyindex 544b8163bef..6559ad97d28 100644--- a/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py+++ b/api/providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py@@ -79,7 +79,7 @@ def _build_fake_vikingdb_modules():@pytest.fixture-def vikingdb_module(monkeypatch):+def vikingdb_module(monkeypatch: pytest.MonkeyPatch):for name, module in _build_fake_vikingdb_modules().items():monkeypatch.setitem(sys.modules, name, module)@@ -117,7 +117,7 @@ def test_init_get_type_and_has_checks(vikingdb_module):assert vector._has_index() is False-def test_create_collection_cache_and_creation_paths(vikingdb_module, monkeypatch):+def test_create_collection_cache_and_creation_paths(vikingdb_module, monkeypatch: pytest.MonkeyPatch):lock = MagicMock()lock.__enter__.return_value = Nonelock.__exit__.return_value = None@@ -253,7 +253,7 @@ def test_delete_drops_index_and_collection_when_present(vikingdb_module):vector._client.drop_collection.assert_not_called()-def test_vikingdb_factory_validates_config_and_builds_vector(vikingdb_module, monkeypatch):+def test_vikingdb_factory_validates_config_and_builds_vector(vikingdb_module, monkeypatch: pytest.MonkeyPatch):factory = vikingdb_module.VikingDBVectorFactory()dataset_with_index = SimpleNamespace(id="dataset-1",@@ -293,7 +293,9 @@ def test_vikingdb_factory_validates_config_and_builds_vector(vikingdb_module, mo("VIKINGDB_SCHEME", "VIKINGDB_SCHEME should not be None"),],)-def test_vikingdb_factory_raises_when_required_config_missing(vikingdb_module, monkeypatch, field, message):+def test_vikingdb_factory_raises_when_required_config_missing(+ vikingdb_module, monkeypatch: pytest.MonkeyPatch, field, message+):factory = vikingdb_module.VikingDBVectorFactory()dataset = SimpleNamespace(id="dataset-1", index_struct_dict={"vector_store": {"class_prefix": "existing"}}, index_struct=Nonediff --git a/api/tests/integration_tests/controllers/console/app/test_chat_message_permissions.py b/api/tests/integration_tests/controllers/console/app/test_chat_message_permissions.pyindex 3b5e822b900..90131fe98dc 100644--- a/api/tests/integration_tests/controllers/console/app/test_chat_message_permissions.py+++ b/api/tests/integration_tests/controllers/console/app/test_chat_message_permissions.py@@ -13,7 +13,7 @@ from controllers.console.app import wrapsfrom libs.datetime_utils import naive_utc_nowfrom models import App, Tenantfrom models.account import Account, TenantAccountJoin, TenantAccountRole-from models.enums import ConversationFromSource+from models.enums import AppStatus, ConversationFromSourcefrom models.model import AppModefrom services.app_generate_service import AppGenerateService@@ -28,7 +28,7 @@ class TestChatMessageApiPermissions:app.id = str(uuid.uuid4())app.mode = AppMode.CHATapp.tenant_id = str(uuid.uuid4())- app.status = "normal"+ app.status = AppStatus.NORMALreturn app@pytest.fixture@@ -78,7 +78,7 @@ class TestChatMessageApiPermissions:self,test_client: FlaskClient,auth_header,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,mock_app_model,mock_account,role: TenantAccountRole,@@ -130,7 +130,7 @@ class TestChatMessageApiPermissions:self,test_client: FlaskClient,auth_header,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,mock_app_model,mock_account,role: TenantAccountRole,diff --git a/api/tests/integration_tests/controllers/console/app/test_feedback_export_api.py b/api/tests/integration_tests/controllers/console/app/test_feedback_export_api.pyindex 309a0b015ad..c4db0d51113 100644--- a/api/tests/integration_tests/controllers/console/app/test_feedback_export_api.py+++ b/api/tests/integration_tests/controllers/console/app/test_feedback_export_api.py@@ -14,7 +14,7 @@ from controllers.console.app import wrapsfrom libs.datetime_utils import naive_utc_nowfrom models import App, Tenantfrom models.account import Account, TenantAccountJoin, TenantAccountRole-from models.enums import FeedbackFromSource, FeedbackRating+from models.enums import AppStatus, FeedbackFromSource, FeedbackRatingfrom models.model import AppMode, MessageFeedbackfrom services.feedback_service import FeedbackService@@ -29,7 +29,7 @@ class TestFeedbackExportApi:app.id = str(uuid.uuid4())app.mode = AppMode.CHATapp.tenant_id = str(uuid.uuid4())- app.status = "normal"+ app.status = AppStatus.NORMALapp.name = "Test App"return app@@ -135,7 +135,7 @@ class TestFeedbackExportApi:self,test_client: FlaskClient,auth_header,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,mock_app_model,mock_account,role: TenantAccountRole,@@ -167,7 +167,13 @@ class TestFeedbackExportApi:mock_export_feedbacks.assert_called_once()def test_feedback_export_csv_format(- self, test_client: FlaskClient, auth_header, monkeypatch, mock_app_model, mock_account, sample_feedback_data+ self,+ test_client: FlaskClient,+ auth_header,+ monkeypatch: pytest.MonkeyPatch,+ mock_app_model,+ mock_account,+ sample_feedback_data,):"""Test feedback export in CSV format."""@@ -202,7 +208,13 @@ class TestFeedbackExportApi:assert "text/csv" in response.content_typedef test_feedback_export_json_format(- self, test_client: FlaskClient, auth_header, monkeypatch, mock_app_model, mock_account, sample_feedback_data+ self,+ test_client: FlaskClient,+ auth_header,+ monkeypatch: pytest.MonkeyPatch,+ mock_app_model,+ mock_account,+ sample_feedback_data,):"""Test feedback export in JSON format."""@@ -246,7 +258,7 @@ class TestFeedbackExportApi:assert "application/json" in response.content_typedef test_feedback_export_with_filters(- self, test_client: FlaskClient, auth_header, monkeypatch, mock_app_model, mock_account+ self, test_client: FlaskClient, auth_header, monkeypatch: pytest.MonkeyPatch, mock_app_model, mock_account):"""Test feedback export with various filters."""@@ -287,7 +299,7 @@ class TestFeedbackExportApi:)def test_feedback_export_invalid_date_format(- self, test_client: FlaskClient, auth_header, monkeypatch, mock_app_model, mock_account+ self, test_client: FlaskClient, auth_header, monkeypatch: pytest.MonkeyPatch, mock_app_model, mock_account):"""Test feedback export with invalid date format."""@@ -312,7 +324,7 @@ class TestFeedbackExportApi:assert "Parameter validation error" in response_json["error"]def test_feedback_export_server_error(- self, test_client: FlaskClient, auth_header, monkeypatch, mock_app_model, mock_account+ self, test_client: FlaskClient, auth_header, monkeypatch: pytest.MonkeyPatch, mock_app_model, mock_account):"""Test feedback export with server error."""diff --git a/api/tests/integration_tests/controllers/console/app/test_model_config_permissions.py b/api/tests/integration_tests/controllers/console/app/test_model_config_permissions.pyindex 04945e57a07..ab08c7a6d89 100644--- a/api/tests/integration_tests/controllers/console/app/test_model_config_permissions.py+++ b/api/tests/integration_tests/controllers/console/app/test_model_config_permissions.py@@ -11,6 +11,7 @@ from controllers.console.app import wrapsfrom libs.datetime_utils import naive_utc_nowfrom models import App, Tenantfrom models.account import Account, TenantAccountJoin, TenantAccountRole+from models.enums import AppStatusfrom models.model import AppModefrom services.app_model_config_service import AppModelConfigService@@ -25,7 +26,7 @@ class TestModelConfigResourcePermissions:app.id = str(uuid.uuid4())app.mode = AppMode.CHATapp.tenant_id = str(uuid.uuid4())- app.status = "normal"+ app.status = AppStatus.NORMALapp.app_model_config_id = str(uuid.uuid4())return app@@ -73,7 +74,7 @@ class TestModelConfigResourcePermissions:self,test_client: FlaskClient,auth_header,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,mock_app_model,mock_account,role: TenantAccountRole,diff --git a/api/tests/integration_tests/core/datasource/test_datasource_manager_integration.py b/api/tests/integration_tests/core/datasource/test_datasource_manager_integration.pyindex a876b0c4aae..7d0b5752629 100644--- a/api/tests/integration_tests/core/datasource/test_datasource_manager_integration.py+++ b/api/tests/integration_tests/core/datasource/test_datasource_manager_integration.py@@ -1,5 +1,7 @@from collections.abc import Generator+from pytest_mock import MockerFixture+from core.datasource.datasource_manager import DatasourceManagerfrom core.datasource.entities.datasource_entities import DatasourceMessagefrom graphon.node_events import StreamCompletedEvent@@ -19,7 +21,7 @@ def _gen_var_stream() -> Generator[DatasourceMessage, None, None]:)-def test_stream_node_events_accumulates_variables(mocker):+def test_stream_node_events_accumulates_variables(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "stream_online_results", return_value=_gen_var_stream())events = list(DatasourceManager.stream_node_events(diff --git a/api/tests/integration_tests/core/workflow/nodes/datasource/test_datasource_node_integration.py b/api/tests/integration_tests/core/workflow/nodes/datasource/test_datasource_node_integration.pyindex 2392084c366..2c1e667c580 100644--- a/api/tests/integration_tests/core/workflow/nodes/datasource/test_datasource_node_integration.py+++ b/api/tests/integration_tests/core/workflow/nodes/datasource/test_datasource_node_integration.py@@ -1,3 +1,5 @@+from pytest_mock import MockerFixture+from core.app.entities.app_invoke_entities import DIFY_RUN_CONTEXT_KEYfrom core.workflow.nodes.datasource.datasource_node import DatasourceNodefrom core.workflow.nodes.datasource.entities import DatasourceNodeData@@ -44,7 +46,7 @@ class _GP:call_depth = 0-def test_node_integration_minimal_stream(mocker):+def test_node_integration_minimal_stream(mocker: MockerFixture):sys_d = {"sys": {"datasource_type": "online_document",diff --git a/api/tests/integration_tests/workflow/nodes/test_tool.py b/api/tests/integration_tests/workflow/nodes/test_tool.pyindex a8e9422c1ee..493330e02ba 100644--- a/api/tests/integration_tests/workflow/nodes/test_tool.py+++ b/api/tests/integration_tests/workflow/nodes/test_tool.py@@ -2,6 +2,8 @@ import timeimport uuidfrom unittest.mock import MagicMock, patch+import pytest+from core.app.entities.app_invoke_entities import InvokeFrom, UserFromfrom core.tools.utils.configuration import ToolParameterConfigurationManagerfrom core.workflow.node_factory import DifyNodeFactory@@ -71,7 +73,7 @@ def init_tool_node(config: dict):return node-def test_tool_variable_invoke(monkeypatch):+def test_tool_variable_invoke(monkeypatch: pytest.MonkeyPatch):node = init_tool_node(config={"id": "1",@@ -106,7 +108,7 @@ def test_tool_variable_invoke(monkeypatch):assert item.node_run_result.outputs.get("text") is not None-def test_tool_mixed_invoke(monkeypatch):+def test_tool_mixed_invoke(monkeypatch: pytest.MonkeyPatch):node = init_tool_node(config={"id": "1",diff --git a/api/tests/test_containers_integration_tests/libs/test_rate_limiter_integration.py b/api/tests/test_containers_integration_tests/libs/test_rate_limiter_integration.pyindex 178fc2e4fb1..390795486b9 100644--- a/api/tests/test_containers_integration_tests/libs/test_rate_limiter_integration.py+++ b/api/tests/test_containers_integration_tests/libs/test_rate_limiter_integration.py@@ -11,7 +11,7 @@ from libs import helper as helper_module@pytest.mark.usefixtures("flask_app_with_containers")-def test_rate_limiter_counts_multiple_attempts_in_same_second(monkeypatch):+def test_rate_limiter_counts_multiple_attempts_in_same_second(monkeypatch: pytest.MonkeyPatch):prefix = f"test_rate_limit:{uuid.uuid4().hex}"limiter = helper_module.RateLimiter(prefix=prefix, max_attempts=2, time_window=60)key = limiter._get_key("203.0.113.10")diff --git a/api/tests/test_containers_integration_tests/services/test_agent_service.py b/api/tests/test_containers_integration_tests/services/test_agent_service.pyindex 00a2f9a59f4..cbd939c7a47 100644--- a/api/tests/test_containers_integration_tests/services/test_agent_service.py+++ b/api/tests/test_containers_integration_tests/services/test_agent_service.py@@ -6,7 +6,7 @@ from faker import Fakerfrom sqlalchemy.orm import Sessionfrom core.plugin.impl.exc import PluginDaemonClientSideError-from models import Account+from models import Account, CreatorUserRolefrom models.enums import ConversationFromSource, MessageFileBelongsTofrom models.model import AppModelConfig, Conversation, EndUser, Message, MessageAgentThoughtfrom services.account_service import AccountService, TenantService@@ -246,7 +246,7 @@ class TestAgentService:tool_input=json.dumps({"test_tool": {"input": "test_input"}}),observation=json.dumps({"test_tool": {"output": "test_output"}}),tokens=50,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(thought1)@@ -294,7 +294,7 @@ class TestAgentService:agent_thoughts = self._create_test_agent_thoughts(db_session_with_containers, message)# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the result structureassert result is not None@@ -370,7 +370,7 @@ class TestAgentService:# Execute the method under test with non-existent messagewith pytest.raises(ValueError, match="Message not found"):- AgentService.get_agent_logs(app, str(conversation.id), fake.uuid4())+ AgentService.get_agent_logs(app, conversation.id, fake.uuid4())def test_get_agent_logs_with_end_user(self, db_session_with_containers: Session, mock_external_service_dependencies@@ -451,7 +451,7 @@ class TestAgentService:db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -523,7 +523,7 @@ class TestAgentService:db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -561,14 +561,14 @@ class TestAgentService:tool_input=json.dumps({"error_tool": {"input": "test_input"}}),observation=json.dumps({"error_tool": {"output": "error_output"}}),tokens=50,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(thought_with_error)db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -592,7 +592,7 @@ class TestAgentService:conversation, message = self._create_test_conversation_and_message(db_session_with_containers, app, account)# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -654,7 +654,7 @@ class TestAgentService:# Execute the method under testwith pytest.raises(ValueError, match="App model config not found"):- AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ AgentService.get_agent_logs(app, conversation.id, message.id)def test_get_agent_logs_agent_config_not_found(self, db_session_with_containers: Session, mock_external_service_dependencies@@ -673,7 +673,7 @@ class TestAgentService:# Execute the method under testwith pytest.raises(ValueError, match="Agent config not found"):- AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ AgentService.get_agent_logs(app, conversation.id, message.id)def test_list_agent_providers_success(self, db_session_with_containers: Session, mock_external_service_dependencies@@ -687,7 +687,7 @@ class TestAgentService:app, account = self._create_test_app_and_account(db_session_with_containers, mock_external_service_dependencies)# Execute the method under test- result = AgentService.list_agent_providers(str(account.id), str(app.tenant_id))+ result = AgentService.list_agent_providers(account.id, app.tenant_id)# Verify the resultassert result is not None@@ -696,7 +696,7 @@ class TestAgentService:# Verify the mock was called correctlymock_plugin_client = mock_external_service_dependencies["plugin_agent_client"].return_value- mock_plugin_client.fetch_agent_strategy_providers.assert_called_once_with(str(app.tenant_id))+ mock_plugin_client.fetch_agent_strategy_providers.assert_called_once_with(app.tenant_id)def test_get_agent_provider_success(self, db_session_with_containers: Session, mock_external_service_dependencies):"""@@ -710,7 +710,7 @@ class TestAgentService:provider_name = "test_provider"# Execute the method under test- result = AgentService.get_agent_provider(str(account.id), str(app.tenant_id), provider_name)+ result = AgentService.get_agent_provider(account.id, app.tenant_id, provider_name)# Verify the resultassert result is not None@@ -718,7 +718,7 @@ class TestAgentService:# Verify the mock was called correctlymock_plugin_client = mock_external_service_dependencies["plugin_agent_client"].return_value- mock_plugin_client.fetch_agent_strategy_provider.assert_called_once_with(str(app.tenant_id), provider_name)+ mock_plugin_client.fetch_agent_strategy_provider.assert_called_once_with(app.tenant_id, provider_name)def test_get_agent_provider_plugin_error(self, db_session_with_containers: Session, mock_external_service_dependencies@@ -740,7 +740,7 @@ class TestAgentService:# Execute the method under testwith pytest.raises(ValueError, match=error_message):- AgentService.get_agent_provider(str(account.id), str(app.tenant_id), provider_name)+ AgentService.get_agent_provider(account.id, app.tenant_id, provider_name)def test_get_agent_logs_with_complex_tool_data(self, db_session_with_containers: Session, mock_external_service_dependencies@@ -796,14 +796,14 @@ class TestAgentService:{"tool1": {"output1": "result1"}, "tool2": {"output2": "result2"}, "tool3": {"output3": "result3"}}),tokens=100,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(complex_thought)db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -891,14 +891,14 @@ class TestAgentService:observation=json.dumps({"file_tool": {"output": "test_output"}}),message_files=json.dumps(["file1", "file2"]),tokens=50,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(thought_with_files)db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -926,7 +926,7 @@ class TestAgentService:mock_external_service_dependencies["current_user"].timezone = "Asia/Shanghai"# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -960,14 +960,14 @@ class TestAgentService:tool_input="", # Empty inputobservation="", # Empty observationtokens=50,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(empty_thought)db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the resultassert result is not None@@ -1001,14 +1001,14 @@ class TestAgentService:tool_input="invalid json", # Malformed JSONobservation="invalid json", # Malformed JSONtokens=50,- created_by_role="account",+ created_by_role=CreatorUserRole.ACCOUNT,created_by=message.from_account_id,)db_session_with_containers.add(malformed_thought)db_session_with_containers.commit()# Execute the method under test- result = AgentService.get_agent_logs(app, str(conversation.id), str(message.id))+ result = AgentService.get_agent_logs(app, conversation.id, message.id)# Verify the result - should handle malformed JSON gracefullyassert result is not Nonediff --git a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.pyindex 7c5d2390bac..a5ec06dc13a 100644--- a/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py+++ b/api/tests/test_containers_integration_tests/services/test_app_dsl_service.py@@ -198,7 +198,7 @@ class TestAppDslService:def test_check_version_compatibility_newer_version_returns_pending(self):assert _check_version_compatibility("99.0.0") == ImportStatus.PENDING- def test_check_version_compatibility_major_older_returns_pending(self, monkeypatch):+ def test_check_version_compatibility_major_older_returns_pending(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service, "CURRENT_DSL_VERSION", "1.0.0")assert _check_version_compatibility("0.9.9") == ImportStatus.PENDING@@ -272,7 +272,9 @@ class TestAppDslService:assert result.status == ImportStatus.FAILEDassert "Missing app data" in result.error- def test_import_app_yaml_error_returns_failed(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_yaml_error_returns_failed(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):def bad_safe_load(_content: str):raise yaml.YAMLError("bad")@@ -287,7 +289,9 @@ class TestAppDslService:assert result.status == ImportStatus.FAILEDassert result.error.startswith("Invalid YAML format:")- def test_import_app_unexpected_error_returns_failed(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_unexpected_error_returns_failed(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):monkeypatch.setattr(AppDslService,"_create_or_update_app",@@ -305,7 +309,9 @@ class TestAppDslService:# ── Import: YAML URL ──────────────────────────────────────────────- def test_import_app_yaml_url_fetch_error_returns_failed(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_yaml_url_fetch_error_returns_failed(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):monkeypatch.setattr(app_dsl_service.ssrf_proxy,"get",@@ -321,7 +327,9 @@ class TestAppDslService:assert result.status == ImportStatus.FAILEDassert "Error fetching YAML from URL: boom" in result.error- def test_import_app_yaml_url_empty_content_returns_failed(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_yaml_url_empty_content_returns_failed(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):response = MagicMock()response.content = b""response.raise_for_status.return_value = None@@ -336,7 +344,9 @@ class TestAppDslService:assert result.status == ImportStatus.FAILEDassert "Empty content" in result.error- def test_import_app_yaml_url_file_too_large_returns_failed(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_yaml_url_file_too_large_returns_failed(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):response = MagicMock()response.content = b"x" * (DSL_MAX_SIZE + 1)response.raise_for_status.return_value = None@@ -379,7 +389,9 @@ class TestAppDslService:assert result.imported_dsl_version == "99.0.0"assert requested_urls == [yaml_url]- def test_import_app_yaml_url_github_blob_rewrites_to_raw(self, db_session_with_containers: Session, monkeypatch):+ def test_import_app_yaml_url_github_blob_rewrites_to_raw(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):yaml_url = "https://github.com/acme/repo/blob/main/app.yml"raw_url = "https://raw.githubusercontent.com/acme/repo/main/app.yml"yaml_bytes = _pending_yaml_content()@@ -491,7 +503,7 @@ class TestAppDslService:@pytest.mark.parametrize("has_workflow", [True, False])def test_import_app_legacy_versions_extract_dependencies(- self, db_session_with_containers: Session, monkeypatch, has_workflow: bool+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch, has_workflow: bool):monkeypatch.setattr(AppDslService,@@ -554,7 +566,9 @@ class TestAppDslService:assert result.status == ImportStatus.FAILEDassert "expired" in result.error- def test_confirm_import_success_deletes_redis_key(self, db_session_with_containers: Session, monkeypatch):+ def test_confirm_import_success_deletes_redis_key(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):import_id = str(uuid4())redis_key = f"{IMPORT_INFO_REDIS_KEY_PREFIX}{import_id}"@@ -614,7 +628,9 @@ class TestAppDslService:result = service.check_dependencies(app_model=app_model)assert result.leaked_dependencies == []- def test_check_dependencies_calls_analysis_service(self, db_session_with_containers: Session, monkeypatch):+ def test_check_dependencies_calls_analysis_service(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):app_id = str(uuid4())pending = CheckDependenciesPendingData(dependencies=[], app_id=app_id)redis_client.setex(@@ -665,7 +681,9 @@ class TestAppDslService:with pytest.raises(ValueError, match="loss app mode"):service._create_or_update_app(app=None, data={"app": {}}, account=_account_mock())- def test_create_or_update_app_existing_app_updates_fields(self, db_session_with_containers: Session, monkeypatch):+ def test_create_or_update_app_existing_app_updates_fields(+ self, db_session_with_containers: Session, monkeypatch: pytest.MonkeyPatch+ ):fixed_now = object()monkeypatch.setattr(app_dsl_service, "naive_utc_now", lambda: fixed_now)@@ -778,8 +796,8 @@ class TestAppDslService:service = AppDslService(db_session_with_containers)with pytest.raises(ValueError, match="Missing model_config"):service._create_or_update_app(- app=_app_stub(mode=AppMode.CHAT.value),- data={"app": {"mode": AppMode.CHAT.value}},+ app=_app_stub(mode=AppMode.CHAT),+ data={"app": {"mode": AppMode.CHAT}},account=_account_mock(),)@@ -794,7 +812,7 @@ class TestAppDslService:service._create_or_update_app(app=app,data={- "app": {"mode": AppMode.CHAT.value},+ "app": {"mode": AppMode.CHAT},"model_config": {"model": {"provider": "openai"}},},account=account,@@ -807,14 +825,14 @@ class TestAppDslService:service = AppDslService(db_session_with_containers)with pytest.raises(ValueError, match="Invalid app mode"):service._create_or_update_app(- app=_app_stub(mode=AppMode.RAG_PIPELINE.value),- data={"app": {"mode": AppMode.RAG_PIPELINE.value}},+ app=_app_stub(mode=AppMode.RAG_PIPELINE),+ data={"app": {"mode": AppMode.RAG_PIPELINE}},account=_account_mock(),)# ── Export ─────────────────────────────────────────────────────────- def test_export_dsl_delegates_by_mode(self, monkeypatch):+ def test_export_dsl_delegates_by_mode(self, monkeypatch: pytest.MonkeyPatch):workflow_calls: list[bool] = []model_calls: list[bool] = []monkeypatch.setattr(@@ -836,14 +854,14 @@ class TestAppDslService:assert workflow_calls == [True]chat_app = _app_stub(- mode=AppMode.CHAT.value,+ mode=AppMode.CHAT,icon_type="emoji",app_model_config=SimpleNamespace(to_dict=lambda: {"agent_mode": {"tools": []}}),)AppDslService.export_dsl(chat_app)assert model_calls == [True]- def test_export_dsl_preserves_icon_and_icon_type(self, monkeypatch):+ def test_export_dsl_preserves_icon_and_icon_type(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(AppDslService,"_append_workflow_export_data",@@ -1011,7 +1029,7 @@ class TestAppDslService:# ── Workflow Export Data ───────────────────────────────────────────- def test_append_workflow_export_data_filters_and_overrides(self, monkeypatch):+ def test_append_workflow_export_data_filters_and_overrides(self, monkeypatch: pytest.MonkeyPatch):workflow_dict = {"graph": {"nodes": [@@ -1111,7 +1129,7 @@ class TestAppDslService:assert nodes[5]["data"]["subscription_id"] == ""assert export_data["dependencies"] == [{"tenant": _DEFAULT_TENANT_ID, "dep": "dep-1"}]- def test_append_workflow_export_data_missing_workflow_raises(self, monkeypatch):+ def test_append_workflow_export_data_missing_workflow_raises(self, monkeypatch: pytest.MonkeyPatch):workflow_service = MagicMock()workflow_service.get_draft_workflow.return_value = Nonemonkeypatch.setattr(app_dsl_service, "WorkflowService", lambda: workflow_service)@@ -1126,7 +1144,7 @@ class TestAppDslService:# ── Model Config Export Data ──────────────────────────────────────- def test_append_model_config_export_data_filters_credential_id(self, monkeypatch):+ def test_append_model_config_export_data_filters_credential_id(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(AppDslService,"_extract_dependencies_from_model_config",@@ -1160,7 +1178,7 @@ class TestAppDslService:# ── Dependency Extraction ─────────────────────────────────────────- def test_extract_dependencies_from_workflow_graph_covers_all_node_types(self, monkeypatch):+ def test_extract_dependencies_from_workflow_graph_covers_all_node_types(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.DependenciesAnalysisService,"analyze_tool_dependency",@@ -1230,7 +1248,7 @@ class TestAppDslService:"model:m4",]- def test_extract_dependencies_from_workflow_graph_handles_exceptions(self, monkeypatch):+ def test_extract_dependencies_from_workflow_graph_handles_exceptions(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.ToolNodeData,"model_validate",@@ -1241,7 +1259,7 @@ class TestAppDslService:)assert deps == []- def test_extract_dependencies_from_model_config_parses_providers(self, monkeypatch):+ def test_extract_dependencies_from_model_config_parses_providers(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.DependenciesAnalysisService,"analyze_model_provider_dependency",@@ -1264,7 +1282,7 @@ class TestAppDslService:)assert deps == ["model:p1", "model:p2", "tool:t1"]- def test_extract_dependencies_from_model_config_handles_exceptions(self, monkeypatch):+ def test_extract_dependencies_from_model_config_handles_exceptions(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.DependenciesAnalysisService,"analyze_model_provider_dependency",@@ -1278,7 +1296,7 @@ class TestAppDslService:def test_get_leaked_dependencies_empty_returns_empty(self):assert AppDslService.get_leaked_dependencies(_DEFAULT_TENANT_ID, []) == []- def test_get_leaked_dependencies_delegates(self, monkeypatch):+ def test_get_leaked_dependencies_delegates(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.DependenciesAnalysisService,"get_leaked_dependencies",@@ -1289,7 +1307,7 @@ class TestAppDslService:# ── Encryption/Decryption ─────────────────────────────────────────- def test_encrypt_decrypt_dataset_id_respects_config(self, monkeypatch):+ def test_encrypt_decrypt_dataset_id_respects_config(self, monkeypatch: pytest.MonkeyPatch):tenant_id = _DEFAULT_TENANT_IDdataset_uuid = "00000000-0000-0000-0000-000000000000"@@ -1314,7 +1332,7 @@ class TestAppDslService:value = "00000000-0000-0000-0000-000000000000"assert AppDslService.decrypt_dataset_id(encrypted_data=value, tenant_id=_DEFAULT_TENANT_ID) == value- def test_decrypt_dataset_id_returns_none_on_invalid_data(self, monkeypatch):+ def test_decrypt_dataset_id_returns_none_on_invalid_data(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.dify_config,"DSL_EXPORT_ENCRYPT_DATASET_ID",@@ -1322,7 +1340,7 @@ class TestAppDslService:)assert AppDslService.decrypt_dataset_id(encrypted_data="not-base64", tenant_id=_DEFAULT_TENANT_ID) is None- def test_decrypt_dataset_id_returns_none_when_decrypted_is_not_uuid(self, monkeypatch):+ def test_decrypt_dataset_id_returns_none_when_decrypted_is_not_uuid(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(app_dsl_service.dify_config,"DSL_EXPORT_ENCRYPT_DATASET_ID",diff --git a/api/tests/test_containers_integration_tests/services/test_app_service.py b/api/tests/test_containers_integration_tests/services/test_app_service.pyindex b695ae9fd9e..837b63d1eaf 100644--- a/api/tests/test_containers_integration_tests/services/test_app_service.py+++ b/api/tests/test_containers_integration_tests/services/test_app_service.py@@ -6,6 +6,7 @@ from sqlalchemy.orm import Sessionfrom constants.model_template import default_app_templatesfrom models import Account+from models.enums import AppStatus, CustomizeTokenStrategyfrom models.model import App, IconType, Sitefrom services.account_service import AccountService, TenantServicefrom tests.test_containers_integration_tests.helpers import generate_valid_password@@ -1079,9 +1080,9 @@ class TestAppService:site.app_id = app.idsite.code = fake.postalcode()site.title = fake.company()- site.status = "normal"+ site.status = AppStatus.NORMALsite.default_language = "en-US"- site.customize_token_strategy = "uuid"+ site.customize_token_strategy = CustomizeTokenStrategy.UUIDdb_session_with_containers.add(site)db_session_with_containers.commit()diff --git a/api/tests/test_containers_integration_tests/services/test_conversation_service.py b/api/tests/test_containers_integration_tests/services/test_conversation_service.pyindex 8aa10129c11..5f3914eb19d 100644--- a/api/tests/test_containers_integration_tests/services/test_conversation_service.py+++ b/api/tests/test_containers_integration_tests/services/test_conversation_service.py@@ -10,6 +10,7 @@ from sqlalchemy import selectfrom sqlalchemy.orm import Sessionfrom core.app.entities.app_invoke_entities import InvokeFrom+from models import TenantAccountRolefrom models.account import Account, Tenant, TenantAccountJoinfrom models.enums import ConversationFromSourcefrom models.model import App, Conversation, EndUser, Message, MessageAnnotation@@ -22,7 +23,7 @@ from services.message_service import MessageServiceclass ConversationServiceIntegrationTestDataFactory:@staticmethod- def create_app_and_account(db_session_with_containers):+ def create_app_and_account(db_session_with_containers: Session):tenant = Tenant(name=f"Tenant {uuid4()}")db_session_with_containers.add(tenant)db_session_with_containers.flush()@@ -41,7 +42,7 @@ class ConversationServiceIntegrationTestDataFactory:tenant_join = TenantAccountJoin(tenant_id=tenant.id,account_id=account.id,- role="owner",+ role=TenantAccountRole.OWNER,current=True,)db_session_with_containers.add(tenant_join)@@ -155,7 +156,7 @@ class ConversationServiceIntegrationTestDataFactory:total_price=Decimal(0),currency="USD",status="normal",- invoke_from=InvokeFrom.WEB_APP.value,+ invoke_from=InvokeFrom.WEB_APP,from_source=ConversationFromSource.API if isinstance(user, EndUser) else ConversationFromSource.CONSOLE,from_end_user_id=user.id if isinstance(user, EndUser) else None,from_account_id=user.id if isinstance(user, Account) else None,diff --git a/api/tests/test_containers_integration_tests/services/test_conversation_service_variables.py b/api/tests/test_containers_integration_tests/services/test_conversation_service_variables.pyindex 6c292dbc4b2..853630ad65c 100644--- a/api/tests/test_containers_integration_tests/services/test_conversation_service_variables.py+++ b/api/tests/test_containers_integration_tests/services/test_conversation_service_variables.py@@ -25,7 +25,7 @@ from services.errors.conversation import (class ConversationServiceVariableIntegrationFactory:@staticmethod- def create_app_and_account(db_session_with_containers):+ def create_app_and_account(db_session_with_containers: Session):tenant = Tenant(name=f"Tenant {uuid4()}")db_session_with_containers.add(tenant)db_session_with_containers.flush()diff --git a/api/tests/test_containers_integration_tests/services/test_dataset_service_document.py b/api/tests/test_containers_integration_tests/services/test_dataset_service_document.pyindex 2bec703f0cc..0c089e506bf 100644--- a/api/tests/test_containers_integration_tests/services/test_dataset_service_document.py+++ b/api/tests/test_containers_integration_tests/services/test_dataset_service_document.py@@ -6,6 +6,7 @@ from unittest.mock import create_autospec, patchfrom uuid import uuid4import pytest+from sqlalchemy.orm import Sessionfrom werkzeug.exceptions import Forbidden, NotFoundfrom core.rag.index_processor.constant.index_type import IndexStructureType@@ -119,13 +120,13 @@ def current_user_mock():yield current_user-def test_get_document_returns_none_when_document_id_is_missing(db_session_with_containers):+def test_get_document_returns_none_when_document_id_is_missing(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)assert DocumentService.get_document(dataset.id, None) is None-def test_get_document_queries_by_dataset_and_document_id(db_session_with_containers):+def test_get_document_queries_by_dataset_and_document_id(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers, dataset=dataset)@@ -135,7 +136,7 @@ def test_get_document_queries_by_dataset_and_document_id(db_session_with_containassert result.id == document.id-def test_get_documents_by_ids_returns_empty_for_empty_input(db_session_with_containers):+def test_get_documents_by_ids_returns_empty_for_empty_input(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)result = DocumentService.get_documents_by_ids(dataset.id, [])@@ -143,7 +144,7 @@ def test_get_documents_by_ids_returns_empty_for_empty_input(db_session_with_contassert result == []-def test_get_documents_by_ids_uses_single_batch_query(db_session_with_containers):+def test_get_documents_by_ids_uses_single_batch_query(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)doc_a = DocumentServiceIntegrationFactory.create_document(db_session_with_containers, dataset=dataset, name="a.txt")doc_b = DocumentServiceIntegrationFactory.create_document(@@ -158,13 +159,13 @@ def test_get_documents_by_ids_uses_single_batch_query(db_session_with_containersassert {document.id for document in result} == {doc_a.id, doc_b.id}-def test_update_documents_need_summary_returns_zero_for_empty_input(db_session_with_containers):+def test_update_documents_need_summary_returns_zero_for_empty_input(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)assert DocumentService.update_documents_need_summary(dataset.id, []) == 0-def test_update_documents_need_summary_updates_matching_non_qa_documents(db_session_with_containers):+def test_update_documents_need_summary_updates_matching_non_qa_documents(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)paragraph_doc = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -195,7 +196,7 @@ def test_update_documents_need_summary_updates_matching_non_qa_documents(db_sessassert refreshed_qa.need_summary is True-def test_get_document_download_url_uses_signed_url_helper(db_session_with_containers):+def test_get_document_download_url_uses_signed_url_helper(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -215,7 +216,7 @@ def test_get_document_download_url_uses_signed_url_helper(db_session_with_contaiget_url.assert_called_once_with(upload_file_id=upload_file.id, as_attachment=True)-def test_get_upload_file_id_for_upload_file_document_rejects_invalid_source_type(db_session_with_containers):+def test_get_upload_file_id_for_upload_file_document_rejects_invalid_source_type(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -232,7 +233,9 @@ def test_get_upload_file_id_for_upload_file_document_rejects_invalid_source_type)-def test_get_upload_file_id_for_upload_file_document_rejects_missing_upload_file_id(db_session_with_containers):+def test_get_upload_file_id_for_upload_file_document_rejects_missing_upload_file_id(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -248,7 +251,7 @@ def test_get_upload_file_id_for_upload_file_document_rejects_missing_upload_file)-def test_get_upload_file_id_for_upload_file_document_returns_string_id(db_session_with_containers):+def test_get_upload_file_id_for_upload_file_document_returns_string_id(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -265,7 +268,9 @@ def test_get_upload_file_id_for_upload_file_document_returns_string_id(db_sessioassert result == "99"-def test_get_upload_file_for_upload_file_document_raises_when_file_service_returns_nothing(db_session_with_containers):+def test_get_upload_file_for_upload_file_document_raises_when_file_service_returns_nothing(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -278,7 +283,7 @@ def test_get_upload_file_for_upload_file_document_raises_when_file_service_returDocumentService._get_upload_file_for_upload_file_document(document)-def test_get_upload_file_for_upload_file_document_returns_upload_file(db_session_with_containers):+def test_get_upload_file_for_upload_file_document_returns_upload_file(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -296,7 +301,9 @@ def test_get_upload_file_for_upload_file_document_returns_upload_file(db_sessionassert result.id == upload_file.id-def test_get_upload_files_by_document_id_for_zip_download_raises_for_missing_documents(db_session_with_containers):+def test_get_upload_files_by_document_id_for_zip_download_raises_for_missing_documents(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)with pytest.raises(NotFound, match="Document not found"):@@ -307,7 +314,9 @@ def test_get_upload_files_by_document_id_for_zip_download_raises_for_missing_doc)-def test_get_upload_files_by_document_id_for_zip_download_rejects_cross_tenant_access(db_session_with_containers):+def test_get_upload_files_by_document_id_for_zip_download_rejects_cross_tenant_access(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -329,7 +338,9 @@ def test_get_upload_files_by_document_id_for_zip_download_rejects_cross_tenant_a)-def test_get_upload_files_by_document_id_for_zip_download_rejects_missing_upload_files(db_session_with_containers):+def test_get_upload_files_by_document_id_for_zip_download_rejects_missing_upload_files(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -345,7 +356,9 @@ def test_get_upload_files_by_document_id_for_zip_download_rejects_missing_upload)-def test_get_upload_files_by_document_id_for_zip_download_returns_document_keyed_mapping(db_session_with_containers):+def test_get_upload_files_by_document_id_for_zip_download_returns_document_keyed_mapping(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file_a = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -395,7 +408,7 @@ def test_prepare_document_batch_download_zip_raises_not_found_for_missing_datasedef test_prepare_document_batch_download_zip_translates_permission_error_to_forbidden(- db_session_with_containers,+ db_session_with_containers: Session,current_user_mock,):dataset = DocumentServiceIntegrationFactory.create_dataset(@@ -418,7 +431,7 @@ def test_prepare_document_batch_download_zip_translates_permission_error_to_forbdef test_prepare_document_batch_download_zip_returns_upload_files_in_requested_order(- db_session_with_containers,+ db_session_with_containers: Session,current_user_mock,):dataset = DocumentServiceIntegrationFactory.create_dataset(@@ -461,7 +474,7 @@ def test_prepare_document_batch_download_zip_returns_upload_files_in_requested_oassert download_name.endswith(".zip")-def test_get_document_by_dataset_id_returns_enabled_documents(db_session_with_containers):+def test_get_document_by_dataset_id_returns_enabled_documents(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)enabled_document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -480,7 +493,9 @@ def test_get_document_by_dataset_id_returns_enabled_documents(db_session_with_coassert [document.id for document in result] == [enabled_document.id]-def test_get_working_documents_by_dataset_id_returns_completed_enabled_unarchived_documents(db_session_with_containers):+def test_get_working_documents_by_dataset_id_returns_completed_enabled_unarchived_documents(+ db_session_with_containers: Session,+):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)available_document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -501,7 +516,7 @@ def test_get_working_documents_by_dataset_id_returns_completed_enabled_unarchiveassert [document.id for document in result] == [available_document.id]-def test_get_error_documents_by_dataset_id_returns_error_and_paused_documents(db_session_with_containers):+def test_get_error_documents_by_dataset_id_returns_error_and_paused_documents(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)error_document = DocumentServiceIntegrationFactory.create_document(db_session_with_containers,@@ -526,7 +541,7 @@ def test_get_error_documents_by_dataset_id_returns_error_and_paused_documents(dbassert {document.id for document in result} == {error_document.id, paused_document.id}-def test_get_batch_documents_filters_by_current_user_tenant(db_session_with_containers):+def test_get_batch_documents_filters_by_current_user_tenant(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)batch = f"batch-{uuid4()}"matching_document = DocumentServiceIntegrationFactory.create_document(@@ -549,7 +564,7 @@ def test_get_batch_documents_filters_by_current_user_tenant(db_session_with_contassert [document.id for document in result] == [matching_document.id]-def test_get_document_file_detail_returns_upload_file(db_session_with_containers):+def test_get_document_file_detail_returns_upload_file(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -563,7 +578,7 @@ def test_get_document_file_detail_returns_upload_file(db_session_with_containersassert result.id == upload_file.id-def test_delete_document_emits_signal_and_commits(db_session_with_containers):+def test_delete_document_emits_signal_and_commits(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)upload_file = DocumentServiceIntegrationFactory.create_upload_file(db_session_with_containers,@@ -588,7 +603,7 @@ def test_delete_document_emits_signal_and_commits(db_session_with_containers):)-def test_delete_documents_ignores_empty_input(db_session_with_containers):+def test_delete_documents_ignores_empty_input(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)with patch("services.dataset_service.batch_clean_document_task.delay") as delay:@@ -597,7 +612,7 @@ def test_delete_documents_ignores_empty_input(db_session_with_containers):delay.assert_not_called()-def test_delete_documents_deletes_rows_and_dispatches_cleanup_task(db_session_with_containers):+def test_delete_documents_deletes_rows_and_dispatches_cleanup_task(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)dataset.chunk_structure = IndexStructureType.PARAGRAPH_INDEXdb_session_with_containers.commit()@@ -637,14 +652,14 @@ def test_delete_documents_deletes_rows_and_dispatches_cleanup_task(db_session_wiassert set(args[3]) == {upload_file_a.id, upload_file_b.id}-def test_get_documents_position_returns_next_position_when_documents_exist(db_session_with_containers):+def test_get_documents_position_returns_next_position_when_documents_exist(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)DocumentServiceIntegrationFactory.create_document(db_session_with_containers, dataset=dataset, position=3)assert DocumentService.get_documents_position(dataset.id) == 4-def test_get_documents_position_defaults_to_one_when_dataset_is_empty(db_session_with_containers):+def test_get_documents_position_defaults_to_one_when_dataset_is_empty(db_session_with_containers: Session):dataset = DocumentServiceIntegrationFactory.create_dataset(db_session_with_containers)assert DocumentService.get_documents_position(dataset.id) == 1diff --git a/api/tests/test_containers_integration_tests/services/test_document_service_display_status.py b/api/tests/test_containers_integration_tests/services/test_document_service_display_status.pyindex c0047df8107..383a5f6374f 100644--- a/api/tests/test_containers_integration_tests/services/test_document_service_display_status.py+++ b/api/tests/test_containers_integration_tests/services/test_document_service_display_status.py@@ -2,6 +2,7 @@ import datetimefrom uuid import uuid4from sqlalchemy import select+from sqlalchemy.orm import Sessionfrom core.rag.index_processor.constant.index_type import IndexStructureTypefrom models.dataset import Dataset, Document@@ -58,7 +59,7 @@ def _create_document(return document-def test_build_display_status_filters_available(db_session_with_containers):+def test_build_display_status_filters_available(db_session_with_containers: Session):dataset = _create_dataset(db_session_with_containers)available_doc = _create_document(db_session_with_containers,@@ -97,7 +98,7 @@ def test_build_display_status_filters_available(db_session_with_containers):assert [row.id for row in rows] == [available_doc.id]-def test_apply_display_status_filter_applies_when_status_present(db_session_with_containers):+def test_apply_display_status_filter_applies_when_status_present(db_session_with_containers: Session):dataset = _create_dataset(db_session_with_containers)waiting_doc = _create_document(db_session_with_containers,@@ -121,7 +122,7 @@ def test_apply_display_status_filter_applies_when_status_present(db_session_withassert [row.id for row in rows] == [waiting_doc.id]-def test_apply_display_status_filter_returns_same_when_invalid(db_session_with_containers):+def test_apply_display_status_filter_returns_same_when_invalid(db_session_with_containers: Session):dataset = _create_dataset(db_session_with_containers)doc1 = _create_document(db_session_with_containers,diff --git a/api/tests/test_containers_integration_tests/services/test_end_user_service.py b/api/tests/test_containers_integration_tests/services/test_end_user_service.pyindex 074d448aab4..3f611d92f72 100644--- a/api/tests/test_containers_integration_tests/services/test_end_user_service.py+++ b/api/tests/test_containers_integration_tests/services/test_end_user_service.py@@ -7,6 +7,7 @@ import pytestfrom sqlalchemy.orm import Sessionfrom core.app.entities.app_invoke_entities import InvokeFrom+from models import TenantAccountRolefrom models.account import Account, Tenant, TenantAccountJoinfrom models.model import App, DefaultEndUserSessionID, EndUserfrom services.end_user_service import EndUserService@@ -16,7 +17,7 @@ class TestEndUserServiceFactory:"""Factory class for creating test data and mock objects for end user service tests."""@staticmethod- def create_app_and_account(db_session_with_containers):+ def create_app_and_account(db_session_with_containers: Session):tenant = Tenant(name=f"Tenant {uuid4()}")db_session_with_containers.add(tenant)db_session_with_containers.flush()@@ -35,7 +36,7 @@ class TestEndUserServiceFactory:tenant_join = TenantAccountJoin(tenant_id=tenant.id,account_id=account.id,- role="owner",+ role=TenantAccountRole.OWNER,current=True,)db_session_with_containers.add(tenant_join)diff --git a/api/tests/test_containers_integration_tests/services/test_feature_service.py b/api/tests/test_containers_integration_tests/services/test_feature_service.pyindex f78aeaf984d..a678e37b41d 100644--- a/api/tests/test_containers_integration_tests/services/test_feature_service.py+++ b/api/tests/test_containers_integration_tests/services/test_feature_service.py@@ -644,7 +644,7 @@ class TestFeatureService:assert result.max_plugin_package_size == 15728640# Verify default license status- assert result.license.status.value == "none"+ assert result.license.status == "none"assert result.license.expired_at == ""assert result.license.workspaces.enabled is Falsediff --git a/api/tests/test_containers_integration_tests/services/test_feedback_service.py b/api/tests/test_containers_integration_tests/services/test_feedback_service.pyindex 3dcd6586e24..a4663450d49 100644--- a/api/tests/test_containers_integration_tests/services/test_feedback_service.py+++ b/api/tests/test_containers_integration_tests/services/test_feedback_service.py@@ -23,7 +23,7 @@ class TestFeedbackService:"""Test FeedbackService methods."""@pytest.fixture- def mock_db_session(self, monkeypatch):+ def mock_db_session(self, monkeypatch: pytest.MonkeyPatch):"""Mock database session."""mock_session = mock.Mock()monkeypatch.setattr(db, "session", mock_session)diff --git a/api/tests/test_containers_integration_tests/services/test_human_input_delivery_test_service.py b/api/tests/test_containers_integration_tests/services/test_human_input_delivery_test_service.pyindex ce63e7a71aa..bfc2af6509f 100644--- a/api/tests/test_containers_integration_tests/services/test_human_input_delivery_test_service.py+++ b/api/tests/test_containers_integration_tests/services/test_human_input_delivery_test_service.py@@ -122,7 +122,7 @@ class TestEmailDeliveryTestHandler:with pytest.raises(DeliveryTestUnsupportedError):handler.send_test(context=MagicMock(), method=MagicMock())- def test_send_test_feature_disabled(self, monkeypatch):+ def test_send_test_feature_disabled(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(service_module.FeatureService,"get_features",@@ -137,7 +137,7 @@ class TestEmailDeliveryTestHandler:with pytest.raises(DeliveryTestError, match="Email delivery is not available"):handler.send_test(context=context, method=method)- def test_send_test_mail_not_inited(self, monkeypatch):+ def test_send_test_mail_not_inited(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(service_module.FeatureService,"get_features",@@ -154,7 +154,7 @@ class TestEmailDeliveryTestHandler:with pytest.raises(DeliveryTestError, match="Mail client is not initialized."):handler.send_test(context=context, method=method)- def test_send_test_no_recipients(self, monkeypatch):+ def test_send_test_no_recipients(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(service_module.FeatureService,"get_features",@@ -173,7 +173,7 @@ class TestEmailDeliveryTestHandler:with pytest.raises(DeliveryTestError, match="No recipients configured"):handler.send_test(context=context, method=method)- def test_send_test_success(self, monkeypatch):+ def test_send_test_success(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(service_module.FeatureService,"get_features",@@ -209,7 +209,7 @@ class TestEmailDeliveryTestHandler:assert kwargs["to"] == "[email protected]"assert "RENDERED_Subj" in kwargs["subject"]- def test_send_test_sanitizes_subject(self, monkeypatch):+ def test_send_test_sanitizes_subject(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(service_module.FeatureService,"get_features",diff --git a/api/tests/test_containers_integration_tests/services/test_message_service_execution_extra_content.py b/api/tests/test_containers_integration_tests/services/test_message_service_execution_extra_content.pyindex 44e5a82868f..52ebc0131f2 100644--- a/api/tests/test_containers_integration_tests/services/test_message_service_execution_extra_content.py+++ b/api/tests/test_containers_integration_tests/services/test_message_service_execution_extra_content.py@@ -1,6 +1,7 @@from __future__ import annotationsimport pytest+from sqlalchemy.orm import Sessionfrom services.message_service import MessageServicefrom tests.test_containers_integration_tests.helpers.execution_extra_content import (@@ -9,7 +10,7 @@ from tests.test_containers_integration_tests.helpers.execution_extra_content imp@pytest.mark.usefixtures("flask_req_ctx_with_containers")-def test_pagination_returns_extra_contents(db_session_with_containers):+def test_pagination_returns_extra_contents(db_session_with_containers: Session):fixture = create_human_input_message_fixture(db_session_with_containers)pagination = MessageService.pagination_by_first_id(diff --git a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.pyindex 80289c448a1..a8d295e6a90 100644--- a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py@@ -16,7 +16,7 @@ from sqlalchemy.orm import Sessionfrom core.rag.index_processor.constant.index_type import IndexStructureType, IndexTechniqueTypefrom extensions.ext_redis import redis_client-from models import Account, Tenant, TenantAccountJoin, TenantAccountRole+from models import Account, AccountStatus, Tenant, TenantAccountJoin, TenantAccountRole, TenantStatusfrom models.dataset import Dataset, Document, DocumentSegmentfrom models.enums import DataSourceType, DocumentCreatedFrom, IndexingStatus, SegmentStatusfrom tasks.create_segment_to_index_task import create_segment_to_index_task@@ -73,7 +73,7 @@ class TestCreateSegmentToIndexTask:email=fake.email(),name=fake.name(),interface_language="en-US",- status="active",+ status=AccountStatus.ACTIVE,)db_session_with_containers.add(account)@@ -82,7 +82,7 @@ class TestCreateSegmentToIndexTask:# Create tenanttenant = Tenant(name=fake.company(),- status="normal",+ status=TenantStatus.NORMAL,plan="basic",)db_session_with_containers.add(tenant)diff --git a/api/tests/test_containers_integration_tests/tasks/test_dataset_indexing_task.py b/api/tests/test_containers_integration_tests/tasks/test_dataset_indexing_task.pyindex a5a3cd10b50..5287cd06dbc 100644--- a/api/tests/test_containers_integration_tests/tasks/test_dataset_indexing_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_dataset_indexing_task.py@@ -12,7 +12,7 @@ from sqlalchemy.orm import Sessionfrom core.indexing_runner import DocumentIsPausedErrorfrom core.rag.index_processor.constant.index_type import IndexTechniqueTypefrom enums.cloud_plan import CloudPlan-from models import Account, Tenant, TenantAccountJoin, TenantAccountRole+from models import Account, AccountStatus, Tenant, TenantAccountJoin, TenantAccountRole, TenantStatusfrom models.dataset import Dataset, Documentfrom models.enums import DataSourceType, DocumentCreatedFrom, IndexingStatusfrom tasks.document_indexing_task import (@@ -54,7 +54,7 @@ class _TrackedSessionContext:@pytest.fixture(autouse=True)-def _ensure_testcontainers_db(db_session_with_containers):+def _ensure_testcontainers_db(db_session_with_containers: Session):"""Ensure this suite always runs on testcontainers infrastructure."""return db_session_with_containers@@ -121,12 +121,12 @@ class TestDatasetIndexingTaskIntegration:email=fake.email(),name=fake.name(),interface_language="en-US",- status="active",+ status=AccountStatus.ACTIVE,)db_session_with_containers.add(account)db_session_with_containers.flush()- tenant = Tenant(name=fake.company(), status="normal")+ tenant = Tenant(name=fake.company(), status=TenantStatus.NORMAL)db_session_with_containers.add(tenant)db_session_with_containers.flush()diff --git a/api/tests/test_containers_integration_tests/tasks/test_mail_account_deletion_task.py b/api/tests/test_containers_integration_tests/tasks/test_mail_account_deletion_task.pyindex ff72232d12d..c4895839c9b 100644--- a/api/tests/test_containers_integration_tests/tasks/test_mail_account_deletion_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_mail_account_deletion_task.py@@ -5,6 +5,7 @@ from faker import Fakerfrom sqlalchemy.orm import Sessionfrom libs.email_i18n import EmailType+from models import TenantStatusfrom models.account import Account, Tenant, TenantAccountJoin, TenantAccountRolefrom tasks.mail_account_deletion_task import send_account_deletion_verification_code, send_deletion_success_task@@ -55,7 +56,7 @@ class TestMailAccountDeletionTask:# Create tenanttenant = Tenant(name=fake.company(),- status="normal",+ status=TenantStatus.NORMAL,)db_session_with_containers.add(tenant)db_session_with_containers.commit()diff --git a/api/tests/test_containers_integration_tests/tasks/test_mail_email_code_login_task.py b/api/tests/test_containers_integration_tests/tasks/test_mail_email_code_login_task.pyindex 8e9da6aaaa4..0eec166fe2f 100644--- a/api/tests/test_containers_integration_tests/tasks/test_mail_email_code_login_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_mail_email_code_login_task.py@@ -18,6 +18,7 @@ from sqlalchemy import deletefrom sqlalchemy.orm import Sessionfrom libs.email_i18n import EmailType+from models import AccountStatus, TenantStatusfrom models.account import Account, Tenant, TenantAccountJoin, TenantAccountRolefrom tasks.mail_email_code_login import send_email_code_login_mail_task@@ -91,7 +92,7 @@ class TestSendEmailCodeLoginMailTask:email=fake.email(),name=fake.name(),interface_language="en-US",- status="active",+ status=AccountStatus.ACTIVE,)db_session_with_containers.add(account)@@ -120,7 +121,7 @@ class TestSendEmailCodeLoginMailTask:tenant = Tenant(name=fake.company(),plan="basic",- status="normal",+ status=TenantStatus.NORMAL,)db_session_with_containers.add(tenant)diff --git a/api/tests/test_containers_integration_tests/tasks/test_mail_human_input_delivery_task.py b/api/tests/test_containers_integration_tests/tasks/test_mail_human_input_delivery_task.pyindex f505361727b..a452bee9f81 100644--- a/api/tests/test_containers_integration_tests/tasks/test_mail_human_input_delivery_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_mail_human_input_delivery_task.py@@ -31,7 +31,7 @@ from tasks.mail_human_input_delivery_task import dispatch_human_input_email_task@pytest.fixture(autouse=True)-def cleanup_database(db_session_with_containers):+def cleanup_database(db_session_with_containers: Session):db_session_with_containers.execute(delete(HumanInputFormRecipient))db_session_with_containers.execute(delete(HumanInputDelivery))db_session_with_containers.execute(delete(HumanInputForm))@@ -43,7 +43,7 @@ def cleanup_database(db_session_with_containers):db_session_with_containers.commit()-def _create_workspace_member(db_session_with_containers):+def _create_workspace_member(db_session_with_containers: Session):account = Account(email="[email protected]",name="Owner",diff --git a/api/tests/test_containers_integration_tests/tasks/test_remove_app_and_related_data_task.py b/api/tests/test_containers_integration_tests/tasks/test_remove_app_and_related_data_task.pyindex 03c02ea3412..204f5339785 100644--- a/api/tests/test_containers_integration_tests/tasks/test_remove_app_and_related_data_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_remove_app_and_related_data_task.py@@ -21,7 +21,7 @@ from tasks.remove_app_and_related_data_task import (@pytest.fixture(autouse=True)-def cleanup_database(db_session_with_containers):+def cleanup_database(db_session_with_containers: Session):db_session_with_containers.execute(delete(WorkflowDraftVariable))db_session_with_containers.execute(delete(WorkflowDraftVariableFile))db_session_with_containers.execute(delete(UploadFile))@@ -30,7 +30,7 @@ def cleanup_database(db_session_with_containers):db_session_with_containers.commit()-def _create_tenant_and_app(db_session_with_containers):+def _create_tenant_and_app(db_session_with_containers: Session):tenant = Tenant(name=f"test_tenant_{uuid.uuid4()}")db_session_with_containers.add(tenant)db_session_with_containers.flush()diff --git a/api/tests/unit_tests/controllers/common/test_helpers.py b/api/tests/unit_tests/controllers/common/test_helpers.pyindex 59c463177cf..376a7a90c55 100644--- a/api/tests/unit_tests/controllers/common/test_helpers.py+++ b/api/tests/unit_tests/controllers/common/test_helpers.py@@ -57,7 +57,7 @@ class TestGuessFileInfoFromResponse:(False, "bin"),],)- def test_generated_filename_when_missing(self, monkeypatch, magic_available, expected_ext):+ def test_generated_filename_when_missing(self, monkeypatch: pytest.MonkeyPatch, magic_available, expected_ext):if magic_available:if helpers.magic is None:pytest.skip("python-magic is not installed, cannot run 'magic_available=True' test variant")@@ -155,7 +155,7 @@ class TestMagicImportWarnings:)def test_magic_import_warning_per_platform(self,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,platform_name,expected_message,):diff --git a/api/tests/unit_tests/controllers/common/test_schema.py b/api/tests/unit_tests/controllers/common/test_schema.pyindex fbca2539a57..6cf36e3bce8 100644--- a/api/tests/unit_tests/controllers/common/test_schema.py+++ b/api/tests/unit_tests/controllers/common/test_schema.py@@ -101,7 +101,7 @@ def test_register_schema_models_registers_multiple_models():assert called_names == ["UserModel", "ProductModel"]-def test_register_schema_models_calls_register_schema_model(monkeypatch):+def test_register_schema_models_calls_register_schema_model(monkeypatch: pytest.MonkeyPatch):from controllers.common.schema import register_schema_modelsnamespace = MagicMock(spec=Namespace)diff --git a/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py b/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.pyindex 412edb9dfe9..66d257ee666 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py@@ -68,7 +68,7 @@ def _segment():)-def test_get_segment_with_summary(monkeypatch):+def test_get_segment_with_summary(monkeypatch: pytest.MonkeyPatch):segment = _segment()summary = SimpleNamespace(summary_content="summary")diff --git a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing.py b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing.pyindex 09ed2aaf697..4fa5d214937 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing.py@@ -3,6 +3,7 @@ from unittest.mock import MagicMock, PropertyMock, patchimport pytestfrom flask import Flask+from pytest_mock import MockerFixturefrom werkzeug.exceptions import NotFoundfrom controllers.console import console_ns@@ -35,7 +36,7 @@ def dataset():@pytest.fixture(autouse=True)-def bypass_decorators(mocker):+def bypass_decorators(mocker: MockerFixture):"""Bypass all decorators on the API method."""mocker.patch("controllers.console.datasets.hit_testing.setup_required",@@ -56,7 +57,7 @@ def bypass_decorators(mocker):class TestHitTestingApi:- def test_hit_testing_success(self, app, dataset, dataset_id):+ def test_hit_testing_success(self, app: Flask, dataset, dataset_id):api = HitTestingApi()method = unwrap(api.post)@@ -99,7 +100,7 @@ class TestHitTestingApi:assert "records" in resultassert result["records"] == []- def test_hit_testing_success_with_optional_record_fields(self, app, dataset, dataset_id):+ def test_hit_testing_success_with_optional_record_fields(self, app: Flask, dataset, dataset_id):api = HitTestingApi()method = unwrap(api.post)@@ -150,7 +151,7 @@ class TestHitTestingApi:assert result["query"] == payload["query"]assert result["records"] == records- def test_hit_testing_dataset_not_found(self, app, dataset_id):+ def test_hit_testing_dataset_not_found(self, app: Flask, dataset_id):api = HitTestingApi()method = unwrap(api.post)@@ -175,7 +176,7 @@ class TestHitTestingApi:with pytest.raises(NotFound, match="Dataset not found"):method(api, dataset_id)- def test_hit_testing_invalid_args(self, app, dataset, dataset_id):+ def test_hit_testing_invalid_args(self, app: Flask, dataset, dataset_id):api = HitTestingApi()method = unwrap(api.post)diff --git a/api/tests/unit_tests/controllers/console/datasets/test_metadata.py b/api/tests/unit_tests/controllers/console/datasets/test_metadata.pyindex 0105aacd657..4042190ff6b 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_metadata.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_metadata.py@@ -3,6 +3,7 @@ from unittest.mock import MagicMock, PropertyMock, patchimport pytestfrom flask import Flask+from pytest_mock import MockerFixturefrom werkzeug.exceptions import NotFoundfrom controllers.console import console_ns@@ -60,7 +61,7 @@ def metadata_id():@pytest.fixture(autouse=True)-def bypass_decorators(mocker):+def bypass_decorators(mocker: MockerFixture):"""Bypass setup/login/license decorators."""mocker.patch("controllers.console.datasets.metadata.setup_required",diff --git a/api/tests/unit_tests/controllers/console/datasets/test_website.py b/api/tests/unit_tests/controllers/console/datasets/test_website.pyindex 9f0da6e76f7..9991a0d3451 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_website.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_website.py@@ -2,6 +2,7 @@ from unittest.mock import Mock, PropertyMock, patchimport pytestfrom flask import Flask+from pytest_mock import MockerFixturefrom controllers.console import console_nsfrom controllers.console.datasets.error import WebsiteCrawlError@@ -31,7 +32,7 @@ def app():@pytest.fixture(autouse=True)-def bypass_auth_and_setup(mocker):+def bypass_auth_and_setup(mocker: MockerFixture):"""Bypass setup/login/account decorators."""mocker.patch("controllers.console.datasets.website.login_required",@@ -48,7 +49,7 @@ def bypass_auth_and_setup(mocker):class TestWebsiteCrawlApi:- def test_crawl_success(self, app, mocker):+ def test_crawl_success(self, app, mocker: MockerFixture):api = WebsiteCrawlApi()method = unwrap(api.post)@@ -85,7 +86,7 @@ class TestWebsiteCrawlApi:assert status == 200assert result["job_id"] == "job-1"- def test_crawl_invalid_payload(self, app, mocker):+ def test_crawl_invalid_payload(self, app, mocker: MockerFixture):api = WebsiteCrawlApi()method = unwrap(api.post)@@ -113,7 +114,7 @@ class TestWebsiteCrawlApi:with pytest.raises(WebsiteCrawlError, match="invalid payload"):method(api)- def test_crawl_service_error(self, app, mocker):+ def test_crawl_service_error(self, app, mocker: MockerFixture):api = WebsiteCrawlApi()method = unwrap(api.post)@@ -150,7 +151,7 @@ class TestWebsiteCrawlApi:class TestWebsiteCrawlStatusApi:- def test_get_status_success(self, app, mocker):+ def test_get_status_success(self, app, mocker: MockerFixture):api = WebsiteCrawlStatusApi()method = unwrap(api.get)@@ -181,7 +182,7 @@ class TestWebsiteCrawlStatusApi:assert status == 200assert result["status"] == "completed"- def test_get_status_invalid_provider(self, app, mocker):+ def test_get_status_invalid_provider(self, app, mocker: MockerFixture):api = WebsiteCrawlStatusApi()method = unwrap(api.get)@@ -203,7 +204,7 @@ class TestWebsiteCrawlStatusApi:with pytest.raises(WebsiteCrawlError, match="invalid provider"):method(api, job_id)- def test_get_status_service_error(self, app, mocker):+ def test_get_status_service_error(self, app, mocker: MockerFixture):api = WebsiteCrawlStatusApi()method = unwrap(api.get)diff --git a/api/tests/unit_tests/controllers/console/datasets/test_wraps.py b/api/tests/unit_tests/controllers/console/datasets/test_wraps.pyindex e358435de4a..2cfa938af80 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_wraps.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_wraps.py@@ -1,6 +1,7 @@from unittest.mock import Mockimport pytest+from pytest_mock import MockerFixturefrom controllers.console.datasets.error import PipelineNotFoundErrorfrom controllers.console.datasets.wraps import get_rag_pipeline@@ -16,7 +17,7 @@ class TestGetRagPipeline:with pytest.raises(ValueError, match="missing pipeline_id"):dummy_view()- def test_pipeline_not_found(self, mocker):+ def test_pipeline_not_found(self, mocker: MockerFixture):@get_rag_pipelinedef dummy_view(**kwargs):return "ok"@@ -34,7 +35,7 @@ class TestGetRagPipeline:with pytest.raises(PipelineNotFoundError):dummy_view(pipeline_id="pipeline-1")- def test_pipeline_found_and_injected(self, mocker):+ def test_pipeline_found_and_injected(self, mocker: MockerFixture):pipeline = Mock(spec=Pipeline)pipeline.id = "pipeline-1"pipeline.tenant_id = "tenant-1"@@ -57,7 +58,7 @@ class TestGetRagPipeline:assert result is pipeline- def test_pipeline_id_removed_from_kwargs(self, mocker):+ def test_pipeline_id_removed_from_kwargs(self, mocker: MockerFixture):pipeline = Mock(spec=Pipeline)@get_rag_pipeline@@ -79,7 +80,7 @@ class TestGetRagPipeline:assert result == "ok"- def test_pipeline_id_cast_to_string(self, mocker):+ def test_pipeline_id_cast_to_string(self, mocker: MockerFixture):pipeline = Mock(spec=Pipeline)@get_rag_pipelinediff --git a/api/tests/unit_tests/controllers/console/test_admin.py b/api/tests/unit_tests/controllers/console/test_admin.pyindex 16197fcd0cf..27f332ac51f 100644--- a/api/tests/unit_tests/controllers/console/test_admin.py+++ b/api/tests/unit_tests/controllers/console/test_admin.py@@ -4,6 +4,7 @@ import uuidfrom unittest.mock import Mock, PropertyMock, patchimport pytest+from pytest_mock import MockerFixturefrom werkzeug.exceptions import NotFound, Unauthorizedfrom controllers.console.admin import (@@ -18,7 +19,7 @@ from models.model import App, InstalledApp, RecommendedApp@pytest.fixture(autouse=True)-def bypass_only_edition_cloud(mocker):+def bypass_only_edition_cloud(mocker: MockerFixture):"""Bypass only_edition_cloud decorator by setting EDITION to "CLOUD"."""@@ -29,7 +30,7 @@ def bypass_only_edition_cloud(mocker):@pytest.fixture-def mock_admin_auth(mocker):+def mock_admin_auth(mocker: MockerFixture):"""Provide valid admin authentication for controller tests."""@@ -44,7 +45,7 @@ def mock_admin_auth(mocker):@pytest.fixture-def mock_console_payload(mocker):+def mock_console_payload(mocker: MockerFixture):payload = {"app_id": str(uuid.uuid4()),"language": "en-US",@@ -62,7 +63,7 @@ def mock_console_payload(mocker):@pytest.fixture-def mock_banner_payload(mocker):+def mock_banner_payload(mocker: MockerFixture):mocker.patch("flask_restx.namespace.Namespace.payload",new_callable=PropertyMock,@@ -78,7 +79,7 @@ def mock_banner_payload(mocker):@pytest.fixture-def mock_session_factory(mocker):+def mock_session_factory(mocker: MockerFixture):mock_session = Mock()mock_session.execute = Mock()mock_session.add = Mock()@@ -97,7 +98,7 @@ class TestDeleteExploreBannerApi:def setup_method(self):self.api = DeleteExploreBannerApi()- def test_delete_banner_not_found(self, mocker, mock_admin_auth):+ def test_delete_banner_not_found(self, mocker: MockerFixture, mock_admin_auth):mocker.patch("controllers.console.admin.db.session.execute",return_value=Mock(scalar_one_or_none=lambda: None),@@ -106,7 +107,7 @@ class TestDeleteExploreBannerApi:with pytest.raises(NotFound, match="is not found"):self.api.delete(uuid.uuid4())- def test_delete_banner_success(self, mocker, mock_admin_auth):+ def test_delete_banner_success(self, mocker: MockerFixture, mock_admin_auth):mock_banner = Mock()mocker.patch(@@ -126,7 +127,7 @@ class TestInsertExploreBannerApi:def setup_method(self):self.api = InsertExploreBannerApi()- def test_insert_banner_success(self, mocker, mock_admin_auth, mock_banner_payload):+ def test_insert_banner_success(self, mocker: MockerFixture, mock_admin_auth, mock_banner_payload):mocker.patch("controllers.console.admin.db.session.add")mocker.patch("controllers.console.admin.db.session.commit")@@ -168,7 +169,7 @@ class TestInsertExploreAppApiDelete:def setup_method(self):self.api = InsertExploreAppApi()- def test_delete_when_not_in_explore(self, mocker, mock_admin_auth):+ def test_delete_when_not_in_explore(self, mocker: MockerFixture, mock_admin_auth):mocker.patch("controllers.console.admin.session_factory.create_session",return_value=Mock(@@ -183,7 +184,7 @@ class TestInsertExploreAppApiDelete:assert status == 204assert response["result"] == "success"- def test_delete_when_in_explore_with_trial_app(self, mocker, mock_admin_auth):+ def test_delete_when_in_explore_with_trial_app(self, mocker: MockerFixture, mock_admin_auth):"""Test deleting an app from explore that has a trial app."""app_id = uuid.uuid4()@@ -225,7 +226,7 @@ class TestInsertExploreAppApiDelete:assert response["result"] == "success"assert mock_app.is_public is False- def test_delete_with_installed_apps(self, mocker, mock_admin_auth):+ def test_delete_with_installed_apps(self, mocker: MockerFixture, mock_admin_auth):"""Test deleting an app that has installed apps in other tenants."""app_id = uuid.uuid4()@@ -270,7 +271,7 @@ class TestInsertExploreAppListApi:def setup_method(self):self.api = InsertExploreAppListApi()- def test_app_not_found(self, mocker, mock_admin_auth, mock_console_payload):+ def test_app_not_found(self, mocker: MockerFixture, mock_admin_auth, mock_console_payload):mocker.patch("controllers.console.admin.db.session.execute",return_value=Mock(scalar_one_or_none=lambda: None),@@ -281,7 +282,7 @@ class TestInsertExploreAppListApi:def test_create_recommended_app(self,- mocker,+ mocker: MockerFixture,mock_admin_auth,mock_console_payload,):@@ -318,7 +319,9 @@ class TestInsertExploreAppListApi:assert response["result"] == "success"assert mock_app.is_public is True- def test_update_recommended_app(self, mocker, mock_admin_auth, mock_console_payload, mock_session_factory):+ def test_update_recommended_app(+ self, mocker: MockerFixture, mock_admin_auth, mock_console_payload, mock_session_factory+ ):mock_app = Mock(spec=App)mock_app.id = "app-id"mock_app.site = None@@ -344,7 +347,7 @@ class TestInsertExploreAppListApi:def test_site_data_overrides_payload(self,- mocker,+ mocker: MockerFixture,mock_admin_auth,mock_console_payload,mock_session_factory,@@ -381,7 +384,7 @@ class TestInsertExploreAppListApi:def test_create_trial_app_when_can_trial_enabled(self,- mocker,+ mocker: MockerFixture,mock_admin_auth,mock_console_payload,mock_session_factory,@@ -413,7 +416,7 @@ class TestInsertExploreAppListApi:def test_update_recommended_app_with_trial(self,- mocker,+ mocker: MockerFixture,mock_admin_auth,mock_console_payload,mock_session_factory,@@ -450,7 +453,7 @@ class TestInsertExploreAppListApi:def test_update_recommended_app_without_trial(self,- mocker,+ mocker: MockerFixture,mock_admin_auth,mock_console_payload,mock_session_factory,diff --git a/api/tests/unit_tests/controllers/console/test_feature.py b/api/tests/unit_tests/controllers/console/test_feature.pyindex d8debc1f2ce..1711aede614 100644--- a/api/tests/unit_tests/controllers/console/test_feature.py+++ b/api/tests/unit_tests/controllers/console/test_feature.py@@ -1,3 +1,4 @@+from pytest_mock import MockerFixturefrom werkzeug.exceptions import Unauthorized@@ -11,7 +12,7 @@ def unwrap(func):class TestFeatureApi:- def test_get_tenant_features_success(self, mocker):+ def test_get_tenant_features_success(self, mocker: MockerFixture):from controllers.console.feature import FeatureApimocker.patch(@@ -32,7 +33,7 @@ class TestFeatureApi:class TestSystemFeatureApi:- def test_get_system_features_authenticated(self, mocker):+ def test_get_system_features_authenticated(self, mocker: MockerFixture):"""current_user.is_authenticated == True"""@@ -56,7 +57,7 @@ class TestSystemFeatureApi:assert result == {"features": {"sys_feature": True}}- def test_get_system_features_unauthenticated(self, mocker):+ def test_get_system_features_unauthenticated(self, mocker: MockerFixture):"""current_user.is_authenticated raises Unauthorized"""diff --git a/api/tests/unit_tests/controllers/console/workspace/test_models.py b/api/tests/unit_tests/controllers/console/workspace/test_models.pyindex 4246e3c04c7..3c4acbab445 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_models.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_models.py@@ -32,7 +32,7 @@ class TestDefaultModelApi:with (app.test_request_context("/",- query_string={"model_type": ModelType.LLM.value},+ query_string={"model_type": ModelType.LLM},),patch("controllers.console.workspace.models.current_account_with_tenant",@@ -53,7 +53,7 @@ class TestDefaultModelApi:payload = {"model_settings": [{- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"provider": "openai","model": "gpt-4",}@@ -77,7 +77,7 @@ class TestDefaultModelApi:method = unwrap(api.get)with (- app.test_request_context("/", query_string={"model_type": ModelType.LLM.value}),+ app.test_request_context("/", query_string={"model_type": ModelType.LLM}),patch("controllers.console.workspace.models.current_account_with_tenant", return_value=(MagicMock(), "t1")),patch("controllers.console.workspace.models.ModelProviderService") as service,):@@ -113,7 +113,7 @@ class TestModelProviderModelApi:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"load_balancing": {"configs": [{"weight": 1}],"enabled": True,@@ -139,7 +139,7 @@ class TestModelProviderModelApi:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,}with (@@ -180,7 +180,7 @@ class TestModelProviderModelCredentialApi:"/",query_string={"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,},),patch(@@ -208,7 +208,7 @@ class TestModelProviderModelCredentialApi:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"credentials": {"key": "val"},}@@ -229,7 +229,7 @@ class TestModelProviderModelCredentialApi:method = unwrap(api.get)with (- app.test_request_context("/", query_string={"model": "gpt", "model_type": ModelType.LLM.value}),+ app.test_request_context("/", query_string={"model": "gpt", "model_type": ModelType.LLM}),patch("controllers.console.workspace.models.current_account_with_tenant", return_value=(MagicMock(), "t1")),patch("controllers.console.workspace.models.ModelProviderService") as service,patch("controllers.console.workspace.models.ModelLoadBalancingService") as lb,@@ -248,7 +248,7 @@ class TestModelProviderModelCredentialApi:payload = {"model": "gpt",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"credential_id": "123e4567-e89b-12d3-a456-426614174000",}@@ -269,7 +269,7 @@ class TestModelProviderModelCredentialSwitchApi:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"credential_id": "abc",}@@ -293,7 +293,7 @@ class TestModelEnableDisableApis:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,}with (@@ -314,7 +314,7 @@ class TestModelEnableDisableApis:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,}with (@@ -337,7 +337,7 @@ class TestModelProviderModelValidateApi:payload = {"model": "gpt-4",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"credentials": {"key": "val"},}@@ -360,7 +360,7 @@ class TestModelProviderModelValidateApi:payload = {"model": model_name,- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"credentials": {},}@@ -412,7 +412,7 @@ class TestParameterAndAvailableModels:):service_mock.return_value.get_models_by_model_type.return_value = []- result = method(api, ModelType.LLM.value)+ result = method(api, ModelType.LLM)assert "data" in result@@ -442,6 +442,6 @@ class TestParameterAndAvailableModels:):service.return_value.get_models_by_model_type.return_value = []- result = method(api, ModelType.LLM.value)+ result = method(api, ModelType.LLM)assert result["data"] == []diff --git a/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py b/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.pyindex d1b09c3a584..598677faffa 100644--- a/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py+++ b/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py@@ -189,7 +189,7 @@ class TestGetUserTenant:"""Test get_user_tenant decorator"""@patch("controllers.inner_api.plugin.wraps.Tenant")- def test_should_inject_tenant_and_user_models(self, mock_tenant_class, app: Flask, monkeypatch):+ def test_should_inject_tenant_and_user_models(self, mock_tenant_class, app: Flask, monkeypatch: pytest.MonkeyPatch):"""Test that decorator injects tenant_model and user_model into kwargs"""# Arrange@@ -244,7 +244,9 @@ class TestGetUserTenant:protected_view()@patch("controllers.inner_api.plugin.wraps.Tenant")- def test_should_use_default_session_id_when_user_id_empty(self, mock_tenant_class, app: Flask, monkeypatch):+ def test_should_use_default_session_id_when_user_id_empty(+ self, mock_tenant_class, app: Flask, monkeypatch: pytest.MonkeyPatch+ ):"""Test that default session ID is used when user_id is empty string"""# Arrangediff --git a/api/tests/unit_tests/controllers/service_api/app/test_conversation.py b/api/tests/unit_tests/controllers/service_api/app/test_conversation.pyindex 6dc8f54d428..74c13d50f6e 100644--- a/api/tests/unit_tests/controllers/service_api/app/test_conversation.py+++ b/api/tests/unit_tests/controllers/service_api/app/test_conversation.py@@ -340,7 +340,7 @@ class TestConversationAppModeValidation:@pytest.mark.parametrize("mode",[- AppMode.CHAT.value,+ AppMode.CHAT,AppMode.AGENT_CHAT.value,AppMode.ADVANCED_CHAT.value,],@@ -365,7 +365,7 @@ class TestConversationAppModeValidation:app raises NotChatAppError."""app = Mock(spec=App)- app.mode = AppMode.COMPLETION.value+ app.mode = AppMode.COMPLETIONapp_mode = AppMode.value_of(app.mode)assert app_mode not in {AppMode.CHAT, AppMode.AGENT_CHAT, AppMode.ADVANCED_CHAT}@@ -498,7 +498,7 @@ class TestConversationApiController:def test_list_not_chat(self, app) -> None:api = ConversationApi()handler = _unwrap(api.get)- app_model = SimpleNamespace(mode=AppMode.COMPLETION.value)+ app_model = SimpleNamespace(mode=AppMode.COMPLETION)end_user = SimpleNamespace()with app.test_request_context("/conversations", method="GET"):@@ -531,7 +531,7 @@ class TestConversationApiController:api = ConversationApi()handler = _unwrap(api.get)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -546,7 +546,7 @@ class TestConversationDetailApiController:def test_delete_not_chat(self, app) -> None:api = ConversationDetailApi()handler = _unwrap(api.delete)- app_model = SimpleNamespace(mode=AppMode.COMPLETION.value)+ app_model = SimpleNamespace(mode=AppMode.COMPLETION)end_user = SimpleNamespace()with app.test_request_context("/conversations/1", method="DELETE"):@@ -562,7 +562,7 @@ class TestConversationDetailApiController:api = ConversationDetailApi()handler = _unwrap(api.delete)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context("/conversations/1", method="DELETE"):@@ -580,7 +580,7 @@ class TestConversationRenameApiController:api = ConversationRenameApi()handler = _unwrap(api.post)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -596,7 +596,7 @@ class TestConversationVariablesApiController:def test_not_chat(self, app) -> None:api = ConversationVariablesApi()handler = _unwrap(api.get)- app_model = SimpleNamespace(mode=AppMode.COMPLETION.value)+ app_model = SimpleNamespace(mode=AppMode.COMPLETION)end_user = SimpleNamespace()with app.test_request_context("/conversations/1/variables", method="GET"):@@ -612,7 +612,7 @@ class TestConversationVariablesApiController:api = ConversationVariablesApi()handler = _unwrap(api.get)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -645,7 +645,7 @@ class TestConversationVariablesApiController:api = ConversationVariablesApi()handler = _unwrap(api.get)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -671,7 +671,7 @@ class TestConversationVariableDetailApiController:api = ConversationVariableDetailApi()handler = _unwrap(api.put)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -697,7 +697,7 @@ class TestConversationVariableDetailApiController:api = ConversationVariableDetailApi()handler = _unwrap(api.put)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(@@ -731,7 +731,7 @@ class TestConversationVariableDetailApiController:api = ConversationVariableDetailApi()handler = _unwrap(api.put)- app_model = SimpleNamespace(mode=AppMode.CHAT.value)+ app_model = SimpleNamespace(mode=AppMode.CHAT)end_user = SimpleNamespace()with app.test_request_context(diff --git a/api/tests/unit_tests/controllers/service_api/end_user/test_end_user.py b/api/tests/unit_tests/controllers/service_api/end_user/test_end_user.pyindex 3cc444e4676..9c310a4f456 100644--- a/api/tests/unit_tests/controllers/service_api/end_user/test_end_user.py+++ b/api/tests/unit_tests/controllers/service_api/end_user/test_end_user.py@@ -3,6 +3,7 @@ from unittest.mock import Mockfrom uuid import UUID, uuid4import pytest+from pytest_mock import MockerFixturefrom controllers.service_api.end_user.end_user import EndUserApifrom controllers.service_api.end_user.error import EndUserNotFoundError@@ -21,7 +22,9 @@ class TestEndUserApi:app.tenant_id = str(uuid4())return app- def test_get_end_user_returns_all_attributes(self, mocker, resource: EndUserApi, app_model: App) -> None:+ def test_get_end_user_returns_all_attributes(+ self, mocker: MockerFixture, resource: EndUserApi, app_model: App+ ) -> None:end_user = Mock(spec=EndUser)end_user.id = str(uuid4())end_user.tenant_id = app_model.tenant_id@@ -54,7 +57,7 @@ class TestEndUserApi:assert result["created_at"].startswith("2024-01-01T00:00:00")assert result["updated_at"].startswith("2024-01-02T00:00:00")- def test_get_end_user_not_found(self, mocker, resource: EndUserApi, app_model: App) -> None:+ def test_get_end_user_not_found(self, mocker: MockerFixture, resource: EndUserApi, app_model: App) -> None:mocker.patch("controllers.service_api.end_user.end_user.EndUserService.get_end_user_by_id", return_value=None)with pytest.raises(EndUserNotFoundError):diff --git a/api/tests/unit_tests/core/agent/output_parser/test_cot_output_parser.py b/api/tests/unit_tests/core/agent/output_parser/test_cot_output_parser.pyindex 9073ae1044f..c1a4da8cd38 100644--- a/api/tests/unit_tests/core/agent/output_parser/test_cot_output_parser.py+++ b/api/tests/unit_tests/core/agent/output_parser/test_cot_output_parser.py@@ -12,12 +12,13 @@ from types import SimpleNamespacefrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.agent.output_parser.cot_output_parser import CotAgentOutputParser@pytest.fixture-def mock_action_class(mocker):+def mock_action_class(mocker: MockerFixture):mock_action = MagicMock()mocker.patch("core.agent.output_parser.cot_output_parser.AgentScratchpadUnit.Action",diff --git a/api/tests/unit_tests/core/agent/strategy/test_plugin.py b/api/tests/unit_tests/core/agent/strategy/test_plugin.pyindex e0894f1e908..0fea04845d2 100644--- a/api/tests/unit_tests/core/agent/strategy/test_plugin.py+++ b/api/tests/unit_tests/core/agent/strategy/test_plugin.py@@ -3,6 +3,7 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.agent.strategy.plugin import PluginAgentStrategy@@ -213,7 +214,9 @@ class TestInvoke:(None, None, "msg"),],)- def test_invoke_optional_arguments(self, strategy, mocker, conversation_id, app_id, message_id) -> None:+ def test_invoke_optional_arguments(+ self, strategy, mocker: MockerFixture, conversation_id, app_id, message_id+ ) -> None:mock_manager = MagicMock()mock_manager.invoke = MagicMock(return_value=iter([]))diff --git a/api/tests/unit_tests/core/agent/test_base_agent_runner.py b/api/tests/unit_tests/core/agent/test_base_agent_runner.pyindex db4b293b163..d5fb853ee3b 100644--- a/api/tests/unit_tests/core/agent/test_base_agent_runner.py+++ b/api/tests/unit_tests/core/agent/test_base_agent_runner.py@@ -3,6 +3,7 @@ from decimal import Decimalfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport core.agent.base_agent_runner as modulefrom core.agent.base_agent_runner import BaseAgentRunner@@ -13,7 +14,7 @@ from core.agent.base_agent_runner import BaseAgentRunner@pytest.fixture-def mock_db_session(mocker):+def mock_db_session(mocker: MockerFixture):session = mocker.MagicMock()mocker.patch.object(module.db, "session", session)return session@@ -41,13 +42,13 @@ def runner(mocker, mock_db_session):class TestRepack:- def test_sets_empty_if_none(self, runner, mocker):+ def test_sets_empty_if_none(self, runner, mocker: MockerFixture):entity = mocker.MagicMock()entity.app_config.prompt_template.simple_prompt_template = Noneresult = runner._repack_app_generate_entity(entity)assert result.app_config.prompt_template.simple_prompt_template == ""- def test_keeps_existing(self, runner, mocker):+ def test_keeps_existing(self, runner, mocker: MockerFixture):entity = mocker.MagicMock()entity.app_config.prompt_template.simple_prompt_template = "abc"result = runner._repack_app_generate_entity(entity)@@ -60,7 +61,7 @@ class TestRepack:class TestUpdatePromptTool:- def build_param(self, mocker, **kwargs):+ def build_param(self, mocker: MockerFixture, **kwargs):p = mocker.MagicMock()p.form = kwargs.get("form")@@ -75,7 +76,7 @@ class TestUpdatePromptTool:p.required = kwargs.get("required", False)return p- def test_skip_non_llm(self, runner, mocker):+ def test_skip_non_llm(self, runner, mocker: MockerFixture):tool = mocker.MagicMock()param = self.build_param(mocker, form="NOT_LLM")tool.get_runtime_parameters.return_value = [param]@@ -86,7 +87,7 @@ class TestUpdatePromptTool:result = runner.update_prompt_message_tool(tool, prompt_tool)assert result.parameters["properties"] == {}- def test_enum_and_required(self, runner, mocker):+ def test_enum_and_required(self, runner, mocker: MockerFixture):option = mocker.MagicMock(value="opt1")param = self.build_param(mocker,@@ -104,7 +105,7 @@ class TestUpdatePromptTool:result = runner.update_prompt_message_tool(tool, prompt_tool)assert "p1" in result.parameters["required"]- def test_skip_file_type_param(self, runner, mocker):+ def test_skip_file_type_param(self, runner, mocker: MockerFixture):tool = mocker.MagicMock()param = self.build_param(mocker, form=module.ToolParameter.ToolParameterForm.LLM)param.type = module.ToolParameter.ToolParameterType.FILE@@ -116,7 +117,7 @@ class TestUpdatePromptTool:result = runner.update_prompt_message_tool(tool, prompt_tool)assert result.parameters["properties"] == {}- def test_duplicate_required_not_duplicated(self, runner, mocker):+ def test_duplicate_required_not_duplicated(self, runner, mocker: MockerFixture):tool = mocker.MagicMock()param = self.build_param(@@ -141,7 +142,7 @@ class TestUpdatePromptTool:class TestCreateAgentThought:- def test_with_files(self, runner, mock_db_session, mocker):+ def test_with_files(self, runner, mock_db_session, mocker: MockerFixture):mock_thought = mocker.MagicMock(id=10)mocker.patch.object(module, "MessageAgentThought", return_value=mock_thought)@@ -149,7 +150,7 @@ class TestCreateAgentThought:assert result == "10"assert runner.agent_thought_count == 1- def test_without_files(self, runner, mock_db_session, mocker):+ def test_without_files(self, runner, mock_db_session, mocker: MockerFixture):mock_thought = mocker.MagicMock(id=11)mocker.patch.object(module, "MessageAgentThought", return_value=mock_thought)@@ -163,7 +164,7 @@ class TestCreateAgentThought:class TestSaveAgentThought:- def setup_agent(self, mocker):+ def setup_agent(self, mocker: MockerFixture):agent = mocker.MagicMock()agent.tool = "tool1;tool2"agent.tool_labels = {}@@ -175,7 +176,7 @@ class TestSaveAgentThought:with pytest.raises(ValueError):runner.save_agent_thought("id", None, None, None, None, None, None, [], None)- def test_full_update(self, runner, mock_db_session, mocker):+ def test_full_update(self, runner, mock_db_session, mocker: MockerFixture):agent = self.setup_agent(mocker)mock_db_session.scalar.return_value = agent@@ -210,7 +211,7 @@ class TestSaveAgentThought:assert agent.tokens == 3assert "tool1" in json.loads(agent.tool_labels_str)- def test_label_fallback_when_none(self, runner, mock_db_session, mocker):+ def test_label_fallback_when_none(self, runner, mock_db_session, mocker: MockerFixture):agent = self.setup_agent(mocker)agent.tool = "unknown_tool"mock_db_session.scalar.return_value = agent@@ -220,7 +221,7 @@ class TestSaveAgentThought:labels = json.loads(agent.tool_labels_str)assert "unknown_tool" in labels- def test_json_failure_paths(self, runner, mock_db_session, mocker):+ def test_json_failure_paths(self, runner, mock_db_session, mocker: MockerFixture):agent = self.setup_agent(mocker)mock_db_session.scalar.return_value = agent@@ -241,13 +242,13 @@ class TestSaveAgentThought:assert mock_db_session.commit.called- def test_messages_ids_none(self, runner, mock_db_session, mocker):+ def test_messages_ids_none(self, runner, mock_db_session, mocker: MockerFixture):agent = self.setup_agent(mocker)mock_db_session.scalar.return_value = agentrunner.save_agent_thought("id", None, None, None, None, None, None, None, None)assert mock_db_session.commit.called- def test_success_dict_serialization(self, runner, mock_db_session, mocker):+ def test_success_dict_serialization(self, runner, mock_db_session, mocker: MockerFixture):agent = self.setup_agent(mocker)mock_db_session.scalar.return_value = agent@@ -273,19 +274,19 @@ class TestSaveAgentThought:class TestOrganizeUserPrompt:- def test_no_files(self, runner, mock_db_session, mocker):+ def test_no_files(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.scalars.return_value.all.return_value = []msg = mocker.MagicMock(id="1", query="hello", app_model_config=None)result = runner.organize_agent_user_prompt(msg)assert result.content == "hello"- def test_with_files_no_config(self, runner, mock_db_session, mocker):+ def test_with_files_no_config(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.scalars.return_value.all.return_value = [mocker.MagicMock()]msg = mocker.MagicMock(id="1", query="hello", app_model_config=None)result = runner.organize_agent_user_prompt(msg)assert result.content == "hello"- def test_image_detail_low_fallback(self, runner, mock_db_session, mocker):+ def test_image_detail_low_fallback(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.scalars.return_value.all.return_value = [mocker.MagicMock()]file_config = mocker.MagicMock()file_config.image_config = mocker.MagicMock(detail=None)@@ -305,27 +306,27 @@ class TestOrganizeUserPrompt:class TestOrganizeHistory:- def test_empty(self, runner, mock_db_session, mocker):+ def test_empty(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.execute.return_value.scalars.return_value.all.return_value = []mocker.patch.object(module, "extract_thread_messages", return_value=[])result = runner.organize_agent_history([])assert result == []- def test_with_answer_only(self, runner, mock_db_session, mocker):+ def test_with_answer_only(self, runner, mock_db_session, mocker: MockerFixture):msg = mocker.MagicMock(id="m1", answer="ans", agent_thoughts=[], app_model_config=None)mock_db_session.execute.return_value.scalars.return_value.all.return_value = [msg]mocker.patch.object(module, "extract_thread_messages", return_value=[msg])result = runner.organize_agent_history([])assert any(isinstance(x, module.AssistantPromptMessage) for x in result)- def test_skip_current_message(self, runner, mock_db_session, mocker):+ def test_skip_current_message(self, runner, mock_db_session, mocker: MockerFixture):msg = mocker.MagicMock(id="msg_current", agent_thoughts=[], answer="ans", app_model_config=None)mock_db_session.execute.return_value.scalars.return_value.all.return_value = [msg]mocker.patch.object(module, "extract_thread_messages", return_value=[msg])result = runner.organize_agent_history([])assert result == []- def test_with_tool_calls_invalid_json(self, runner, mock_db_session, mocker):+ def test_with_tool_calls_invalid_json(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool="tool1",tool_input="invalid",@@ -341,7 +342,7 @@ class TestOrganizeHistory:result = runner.organize_agent_history([])assert isinstance(result, list)- def test_empty_tool_name_split(self, runner, mock_db_session, mocker):+ def test_empty_tool_name_split(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool=";", thought="thinking")msg = mocker.MagicMock(id="m5", agent_thoughts=[thought], answer=None, app_model_config=None)@@ -350,7 +351,7 @@ class TestOrganizeHistory:result = runner.organize_agent_history([])assert isinstance(result, list)- def test_valid_json_tool_flow(self, runner, mock_db_session, mocker):+ def test_valid_json_tool_flow(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool="tool1",tool_input=json.dumps({"tool1": {"x": 1}}),@@ -379,7 +380,7 @@ class TestOrganizeHistory:class TestConvertToolToPromptMessageTool:- def test_basic_conversion(self, runner, mocker):+ def test_basic_conversion(self, runner, mocker: MockerFixture):tool = mocker.MagicMock(tool_name="tool1")runtime_param = mocker.MagicMock()@@ -404,7 +405,7 @@ class TestConvertToolToPromptMessageTool:prompt_tool, entity = runner._convert_tool_to_prompt_message_tool(tool)assert entity == tool_entity- def test_full_conversion_multiple_params(self, runner, mocker):+ def test_full_conversion_multiple_params(self, runner, mocker: MockerFixture):tool = mocker.MagicMock(tool_name="tool1")# LLM param with input_schema override@@ -441,7 +442,7 @@ class TestConvertToolToPromptMessageTool:class TestInitPromptToolsExtended:- def test_agent_tool_branch(self, runner, mocker):+ def test_agent_tool_branch(self, runner, mocker: MockerFixture):agent_tool = mocker.MagicMock(tool_name="agent_tool")runner.app_config.agent = mocker.MagicMock(tools=[agent_tool])mocker.patch.object(runner, "_convert_tool_to_prompt_message_tool", return_value=(MagicMock(), "entity"))@@ -449,7 +450,7 @@ class TestInitPromptToolsExtended:tools, prompts = runner._init_prompt_tools()assert "agent_tool" in tools- def test_exception_in_conversion(self, runner, mocker):+ def test_exception_in_conversion(self, runner, mocker: MockerFixture):agent_tool = mocker.MagicMock(tool_name="bad_tool")runner.app_config.agent = mocker.MagicMock(tools=[agent_tool])mocker.patch.object(runner, "_convert_tool_to_prompt_message_tool", side_effect=Exception)@@ -464,7 +465,7 @@ class TestInitPromptToolsExtended:class TestAdditionalCoverage:- def test_update_prompt_with_input_schema(self, runner, mocker):+ def test_update_prompt_with_input_schema(self, runner, mocker: MockerFixture):tool = mocker.MagicMock()param = mocker.MagicMock()@@ -487,7 +488,7 @@ class TestAdditionalCoverage:result = runner.update_prompt_message_tool(tool, prompt_tool)assert result.parameters["properties"]["p1"]["type"] == "number"- def test_save_agent_thought_existing_labels(self, runner, mock_db_session, mocker):+ def test_save_agent_thought_existing_labels(self, runner, mock_db_session, mocker: MockerFixture):agent = mocker.MagicMock()agent.tool = "tool1"agent.tool_labels = {"tool1": {"en_US": "existing"}}@@ -498,7 +499,7 @@ class TestAdditionalCoverage:labels = json.loads(agent.tool_labels_str)assert labels["tool1"]["en_US"] == "existing"- def test_save_agent_thought_tool_meta_string(self, runner, mock_db_session, mocker):+ def test_save_agent_thought_tool_meta_string(self, runner, mock_db_session, mocker: MockerFixture):agent = mocker.MagicMock()agent.tool = "tool1"agent.tool_labels = {}@@ -508,7 +509,7 @@ class TestAdditionalCoverage:runner.save_agent_thought("id", None, None, None, None, "meta_string", None, [], None)assert agent.tool_meta_str == "meta_string"- def test_convert_dataset_retriever_tool(self, runner, mocker):+ def test_convert_dataset_retriever_tool(self, runner, mocker: MockerFixture):ds_tool = mocker.MagicMock()ds_tool.entity.identity.name = "ds"ds_tool.entity.description.llm = "desc"@@ -525,7 +526,7 @@ class TestAdditionalCoverage:prompt = runner._convert_dataset_retriever_tool_to_prompt_message_tool(ds_tool)assert prompt is not None- def test_organize_user_prompt_with_file_objects(self, runner, mock_db_session, mocker):+ def test_organize_user_prompt_with_file_objects(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.scalars.return_value.all.return_value = [mocker.MagicMock()]file_config = mocker.MagicMock()@@ -544,7 +545,7 @@ class TestAdditionalCoverage:result = runner.organize_agent_user_prompt(msg)assert result is not None- def test_organize_history_without_tool_names(self, runner, mock_db_session, mocker):+ def test_organize_history_without_tool_names(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool=None, thought="thinking")msg = mocker.MagicMock(id="m3", agent_thoughts=[thought], answer=None, app_model_config=None)@@ -554,7 +555,7 @@ class TestAdditionalCoverage:result = runner.organize_agent_history([])assert isinstance(result, list)- def test_organize_history_multiple_tools_split(self, runner, mock_db_session, mocker):+ def test_organize_history_multiple_tools_split(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool="tool1;tool2",tool_input=json.dumps({"tool1": {}, "tool2": {}}),@@ -572,7 +573,7 @@ class TestAdditionalCoverage:# ================= Additional Surgical Coverage =================- def test_convert_tool_select_enum_branch(self, runner, mocker):+ def test_convert_tool_select_enum_branch(self, runner, mocker: MockerFixture):tool = mocker.MagicMock(tool_name="tool1")param = mocker.MagicMock()@@ -599,7 +600,7 @@ class TestAdditionalCoverage:class TestConvertDatasetRetrieverTool:- def test_required_param_added(self, runner, mocker):+ def test_required_param_added(self, runner, mocker: MockerFixture):ds_tool = mocker.MagicMock()ds_tool.entity.identity.name = "ds"ds_tool.entity.description.llm = "desc"@@ -619,7 +620,7 @@ class TestConvertDatasetRetrieverTool:class TestBaseAgentRunnerInit:- def test_init_sets_stream_tool_call_and_files(self, mocker):+ def test_init_sets_stream_tool_call_and_files(self, mocker: MockerFixture):session = mocker.MagicMock()session.scalar.return_value = 2mocker.patch.object(module.db, "session", session)@@ -662,7 +663,7 @@ class TestBaseAgentRunnerInit:class TestBaseAgentRunnerCoverage:- def test_convert_tool_skips_non_llm_param(self, runner, mocker):+ def test_convert_tool_skips_non_llm_param(self, runner, mocker: MockerFixture):tool = mocker.MagicMock(tool_name="tool1")param = mocker.MagicMock()@@ -680,7 +681,7 @@ class TestBaseAgentRunnerCoverage:assert prompt_tool.parameters["properties"] == {}- def test_init_prompt_tools_adds_dataset_tools(self, runner, mocker):+ def test_init_prompt_tools_adds_dataset_tools(self, runner, mocker: MockerFixture):dataset_tool = mocker.MagicMock()dataset_tool.entity.identity.name = "ds"runner.dataset_tools = [dataset_tool]@@ -692,7 +693,7 @@ class TestBaseAgentRunnerCoverage:assert tools["ds"] == dataset_toolassert len(prompt_tools) == 1- def test_update_prompt_message_tool_select_enum(self, runner, mocker):+ def test_update_prompt_message_tool_select_enum(self, runner, mocker: MockerFixture):tool = mocker.MagicMock()option1 = mocker.MagicMock(value="A")@@ -716,7 +717,7 @@ class TestBaseAgentRunnerCoverage:assert result.parameters["properties"]["select_param"]["enum"] == ["A", "B"]- def test_save_agent_thought_json_dumps_fallbacks(self, runner, mock_db_session, mocker):+ def test_save_agent_thought_json_dumps_fallbacks(self, runner, mock_db_session, mocker: MockerFixture):agent = mocker.MagicMock()agent.tool = "tool1"agent.tool_labels = {}@@ -754,7 +755,7 @@ class TestBaseAgentRunnerCoverage:assert isinstance(agent.observation, str)assert isinstance(agent.tool_meta_str, str)- def test_save_agent_thought_skips_empty_tool_name(self, runner, mock_db_session, mocker):+ def test_save_agent_thought_skips_empty_tool_name(self, runner, mock_db_session, mocker: MockerFixture):agent = mocker.MagicMock()agent.tool = "tool1;;"agent.tool_labels = {}@@ -768,7 +769,7 @@ class TestBaseAgentRunnerCoverage:labels = json.loads(agent.tool_labels_str)assert "" not in labels- def test_organize_history_includes_system_prompt(self, runner, mock_db_session, mocker):+ def test_organize_history_includes_system_prompt(self, runner, mock_db_session, mocker: MockerFixture):mock_db_session.execute.return_value.scalars.return_value.all.return_value = []mocker.patch.object(module, "extract_thread_messages", return_value=[])@@ -778,7 +779,7 @@ class TestBaseAgentRunnerCoverage:assert system_message in result- def test_organize_history_tool_inputs_and_observation_none(self, runner, mock_db_session, mocker):+ def test_organize_history_tool_inputs_and_observation_none(self, runner, mock_db_session, mocker: MockerFixture):thought = mocker.MagicMock(tool="tool1",tool_input=None,diff --git a/api/tests/unit_tests/core/agent/test_cot_agent_runner.py b/api/tests/unit_tests/core/agent/test_cot_agent_runner.pyindex cde8820e006..314305d371a 100644--- a/api/tests/unit_tests/core/agent/test_cot_agent_runner.py+++ b/api/tests/unit_tests/core/agent/test_cot_agent_runner.py@@ -2,6 +2,7 @@ import jsonfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.agent.cot_agent_runner import CotAgentRunnerfrom core.agent.entities import AgentScratchpadUnit@@ -25,7 +26,7 @@ class DummyRunner(CotAgentRunner):@pytest.fixture-def runner(mocker):+def runner(mocker: MockerFixture):# Prevent BaseAgentRunner __init__ from hitting databasemocker.patch("core.agent.base_agent_runner.BaseAgentRunner.organize_agent_history",@@ -165,7 +166,7 @@ class TestHandleInvokeAction:response, meta = runner._handle_invoke_action(action, {}, [])assert "there is not a tool named" in response- def test_tool_with_json_string_args(self, runner, mocker):+ def test_tool_with_json_string_args(self, runner, mocker: MockerFixture):action = AgentScratchpadUnit.Action(action_name="tool", action_input=json.dumps({"a": 1}))tool_instance = MagicMock()tool_instances = {"tool": tool_instance}@@ -180,7 +181,7 @@ class TestHandleInvokeAction:class TestOrganizeHistoricPromptMessages:- def test_empty_history(self, runner, mocker):+ def test_empty_history(self, runner, mocker: MockerFixture):mocker.patch("core.agent.cot_agent_runner.AgentHistoryPromptTransform.get_prompt",return_value=[],@@ -190,7 +191,7 @@ class TestOrganizeHistoricPromptMessages:class TestRun:- def test_run_handles_empty_parser_output(self, runner, mocker):+ def test_run_handles_empty_parser_output(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -202,7 +203,7 @@ class TestRun:results = list(runner.run(message, "query", {}))assert isinstance(results, list)- def test_run_with_action_and_tool_invocation(self, runner, mocker):+ def test_run_with_action_and_tool_invocation(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -223,7 +224,7 @@ class TestRun:with pytest.raises(AgentMaxIterationError):list(runner.run(message, "query", {"tool": MagicMock()}))- def test_run_respects_max_iteration_boundary(self, runner, mocker):+ def test_run_respects_max_iteration_boundary(self, runner, mocker: MockerFixture):runner.app_config.agent.max_iteration = 1message = MagicMock()message.id = "msg-id"@@ -245,7 +246,7 @@ class TestRun:with pytest.raises(AgentMaxIterationError):list(runner.run(message, "query", {"tool": MagicMock()}))- def test_run_basic_flow(self, runner, mocker):+ def test_run_basic_flow(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -257,7 +258,7 @@ class TestRun:results = list(runner.run(message, "query", {"name": "John"}))assert results- def test_run_max_iteration_error(self, runner, mocker):+ def test_run_max_iteration_error(self, runner, mocker: MockerFixture):runner.app_config.agent.max_iteration = 0message = MagicMock()message.id = "msg-id"@@ -272,7 +273,7 @@ class TestRun:with pytest.raises(AgentMaxIterationError):list(runner.run(message, "query", {}))- def test_run_increase_usage_aggregation(self, runner, mocker):+ def test_run_increase_usage_aggregation(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"runner.app_config.agent.max_iteration = 2@@ -329,7 +330,7 @@ class TestRun:assert final_usage.completion_price == 2assert final_usage.total_price == 4- def test_run_when_no_action_branch(self, runner, mocker):+ def test_run_when_no_action_branch(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -341,7 +342,7 @@ class TestRun:results = list(runner.run(message, "query", {}))assert results[-1].delta.message.content == ""- def test_run_usage_missing_key_branch(self, runner, mocker):+ def test_run_usage_missing_key_branch(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -354,7 +355,7 @@ class TestRun:list(runner.run(message, "query", {}))- def test_run_prompt_tool_update_branch(self, runner, mocker):+ def test_run_prompt_tool_update_branch(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -410,7 +411,7 @@ class TestRun:class TestInitReactState:- def test_init_react_state_resets_state(self, runner, mocker):+ def test_init_react_state_resets_state(self, runner, mocker: MockerFixture):mocker.patch.object(runner, "_organize_historic_prompt_messages", return_value=["historic"])runner._agent_scratchpad = ["old"]runner._query = "old"@@ -423,7 +424,7 @@ class TestInitReactState:class TestHandleInvokeActionExtended:- def test_tool_with_invalid_json_string_args(self, runner, mocker):+ def test_tool_with_invalid_json_string_args(self, runner, mocker: MockerFixture):action = AgentScratchpadUnit.Action(action_name="tool", action_input="not-json")tool_instance = MagicMock()tool_instances = {"tool": tool_instance}@@ -457,7 +458,7 @@ class TestFillInputsEdgeCases:class TestOrganizeHistoricPromptMessagesExtended:- def test_user_message_flushes_scratchpad(self, runner, mocker):+ def test_user_message_flushes_scratchpad(self, runner, mocker: MockerFixture):from graphon.model_runtime.entities.message_entities import UserPromptMessageuser_message = UserPromptMessage(content="Hi")@@ -480,7 +481,7 @@ class TestOrganizeHistoricPromptMessagesExtended:with pytest.raises(NotImplementedError):runner._organize_historic_prompt_messages([])- def test_agent_history_transform_invocation(self, runner, mocker):+ def test_agent_history_transform_invocation(self, runner, mocker: MockerFixture):mock_transform = MagicMock()mock_transform.get_prompt.return_value = []@@ -495,7 +496,7 @@ class TestOrganizeHistoricPromptMessagesExtended:class TestRunAdditionalBranches:- def test_run_with_no_action_final_answer_empty(self, runner, mocker):+ def test_run_with_no_action_final_answer_empty(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -507,7 +508,7 @@ class TestRunAdditionalBranches:results = list(runner.run(message, "query", {}))assert any(hasattr(r, "delta") for r in results)- def test_run_with_final_answer_action_string(self, runner, mocker):+ def test_run_with_final_answer_action_string(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -521,7 +522,7 @@ class TestRunAdditionalBranches:results = list(runner.run(message, "query", {}))assert results[-1].delta.message.content == "done"- def test_run_with_final_answer_action_dict(self, runner, mocker):+ def test_run_with_final_answer_action_dict(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"@@ -535,7 +536,7 @@ class TestRunAdditionalBranches:results = list(runner.run(message, "query", {}))assert json.loads(results[-1].delta.message.content) == {"a": 1}- def test_run_with_string_final_answer(self, runner, mocker):+ def test_run_with_string_final_answer(self, runner, mocker: MockerFixture):message = MagicMock()message.id = "msg-id"diff --git a/api/tests/unit_tests/core/agent/test_cot_chat_agent_runner.py b/api/tests/unit_tests/core/agent/test_cot_chat_agent_runner.pyindex ea8cc8aa864..8e7093fd123 100644--- a/api/tests/unit_tests/core/agent/test_cot_chat_agent_runner.py+++ b/api/tests/unit_tests/core/agent/test_cot_chat_agent_runner.py@@ -1,6 +1,7 @@from unittest.mock import MagicMock, patchimport pytest+from pytest_mock import MockerFixturefrom core.agent.cot_chat_agent_runner import CotChatAgentRunnerfrom graphon.model_runtime.entities.message_entities import TextPromptMessageContent@@ -55,7 +56,7 @@ def runner():class TestOrganizeSystemPrompt:- def test_organize_system_prompt_success(self, runner, mocker):+ def test_organize_system_prompt_success(self, runner, mocker: MockerFixture):first_prompt = "Instruction: {{instruction}}, Tools: {{tools}}, Names: {{tool_names}}"runner.app_config = DummyAppConfig(DummyAgentConfig(DummyPrompt(first_prompt)))@@ -154,7 +155,7 @@ class TestOrganizeUserQuery:class TestOrganizePromptMessages:- def test_no_scratchpad(self, runner, mocker):+ def test_no_scratchpad(self, runner, mocker: MockerFixture):runner.app_config = DummyAppConfig(DummyAgentConfig(DummyPrompt("{{instruction}}")))runner._organize_system_prompt = MagicMock(return_value="system")runner._organize_user_query = MagicMock(return_value=["query"])@@ -164,7 +165,7 @@ class TestOrganizePromptMessages:assert "query" in resultrunner._organize_historic_prompt_messages.assert_called_once()- def test_with_final_scratchpad(self, runner, mocker):+ def test_with_final_scratchpad(self, runner, mocker: MockerFixture):runner.app_config = DummyAppConfig(DummyAgentConfig(DummyPrompt("{{instruction}}")))runner._organize_system_prompt = MagicMock(return_value="system")runner._organize_user_query = MagicMock(return_value=["query"])@@ -177,7 +178,7 @@ class TestOrganizePromptMessages:combined = "".join([m.content for m in assistant_msgs if isinstance(m.content, str)])assert "Final Answer: done" in combined- def test_with_thought_action_observation(self, runner, mocker):+ def test_with_thought_action_observation(self, runner, mocker: MockerFixture):runner.app_config = DummyAppConfig(DummyAgentConfig(DummyPrompt("{{instruction}}")))runner._organize_system_prompt = MagicMock(return_value="system")runner._organize_user_query = MagicMock(return_value=["query"])@@ -197,7 +198,7 @@ class TestOrganizePromptMessages:assert "Action: action" in combinedassert "Observation: observe" in combined- def test_multiple_units_mixed(self, runner, mocker):+ def test_multiple_units_mixed(self, runner, mocker: MockerFixture):runner.app_config = DummyAppConfig(DummyAgentConfig(DummyPrompt("{{instruction}}")))runner._organize_system_prompt = MagicMock(return_value="system")runner._organize_user_query = MagicMock(return_value=["query"])diff --git a/api/tests/unit_tests/core/agent/test_cot_completion_agent_runner.py b/api/tests/unit_tests/core/agent/test_cot_completion_agent_runner.pyindex 2f5873d865f..0d949c357dc 100644--- a/api/tests/unit_tests/core/agent/test_cot_completion_agent_runner.py+++ b/api/tests/unit_tests/core/agent/test_cot_completion_agent_runner.py@@ -1,6 +1,7 @@import jsonimport pytest+from pytest_mock import MockerFixturefrom core.agent.cot_completion_agent_runner import CotCompletionAgentRunnerfrom graphon.model_runtime.entities.message_entities import (@@ -74,7 +75,7 @@ class TestOrganizeInstructionPrompt:class TestOrganizeHistoricPrompt:- def test_with_user_and_assistant_string(self, runner, mocker):+ def test_with_user_and_assistant_string(self, runner, mocker: MockerFixture):user_msg = UserPromptMessage(content="Hello")assistant_msg = AssistantPromptMessage(content="Hi there")@@ -89,7 +90,7 @@ class TestOrganizeHistoricPrompt:assert "Question: Hello" in resultassert "Hi there" in result- def test_assistant_list_with_text_content(self, runner, mocker):+ def test_assistant_list_with_text_content(self, runner, mocker: MockerFixture):text_content = TextPromptMessageContent(data="Partial answer")assistant_msg = AssistantPromptMessage(content=[text_content])@@ -103,7 +104,7 @@ class TestOrganizeHistoricPrompt:assert "Partial answer" in result- def test_assistant_list_with_non_text_content_ignored(self, runner, mocker):+ def test_assistant_list_with_non_text_content_ignored(self, runner, mocker: MockerFixture):non_text_content = ImagePromptMessageContent(format="url", mime_type="image/png")assistant_msg = AssistantPromptMessage(content=[non_text_content])@@ -116,7 +117,7 @@ class TestOrganizeHistoricPrompt:result = runner._organize_historic_prompt()assert result == ""- def test_empty_history(self, runner, mocker):+ def test_empty_history(self, runner, mocker: MockerFixture):mocker.patch.object(runner,"_organize_historic_prompt_messages",@@ -136,7 +137,7 @@ class TestOrganizePromptMessages:def test_full_flow_with_scratchpad(self,runner,- mocker,+ mocker: MockerFixture,dummy_app_config_factory,dummy_agent_config_factory,dummy_prompt_entity_factory,@@ -171,7 +172,12 @@ class TestOrganizePromptMessages:assert "Question: What is Python?" in contentdef test_no_scratchpad(- self, runner, mocker, dummy_app_config_factory, dummy_agent_config_factory, dummy_prompt_entity_factory+ self,+ runner,+ mocker: MockerFixture,+ dummy_app_config_factory,+ dummy_agent_config_factory,+ dummy_prompt_entity_factory,):template = "SYS {{historic_messages}} {{agent_scratchpad}} {{query}}"@@ -198,7 +204,7 @@ class TestOrganizePromptMessages:def test_partial_scratchpad_units(self,runner,- mocker,+ mocker: MockerFixture,thought,action,observation,diff --git a/api/tests/unit_tests/core/agent/test_fc_agent_runner.py b/api/tests/unit_tests/core/agent/test_fc_agent_runner.pyindex 17ab5babcbd..3a4347e7239 100644--- a/api/tests/unit_tests/core/agent/test_fc_agent_runner.py+++ b/api/tests/unit_tests/core/agent/test_fc_agent_runner.py@@ -3,6 +3,7 @@ from typing import Anyfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.agent.errors import AgentMaxIterationErrorfrom core.agent.fc_agent_runner import FunctionCallAgentRunner@@ -68,7 +69,7 @@ class DummyResult:@pytest.fixture-def runner(mocker):+def runner(mocker: MockerFixture):# Completely bypass BaseAgentRunner __init__ to avoid DB / Flask contextmocker.patch("core.agent.base_agent_runner.BaseAgentRunner.__init__",@@ -230,7 +231,7 @@ class TestOrganizeUserQuery:result = runner._organize_user_query(None, [])assert len(result) == 1- def test_with_files_uses_image_detail_config(self, runner, mocker):+ def test_with_files_uses_image_detail_config(self, runner, mocker: MockerFixture):file_content = TextPromptMessageContent(data="file-content")mock_to_prompt = mocker.patch("core.agent.fc_agent_runner.file_manager.to_prompt_message_content",@@ -352,7 +353,7 @@ class TestRunMethod:assert len(outputs) == 1assert runner.save_agent_thought.call_args.kwargs["thought"] == "hi"- def test_run_streaming_tool_call_inputs_type_error(self, runner, mocker):+ def test_run_streaming_tool_call_inputs_type_error(self, runner, mocker: MockerFixture):message = MagicMock(id="m1")runner.stream_tool_call = True@@ -398,7 +399,7 @@ class TestRunMethod:outputs = list(runner.run(message, "query"))assert len(outputs) >= 1- def test_run_with_tool_instance_and_files(self, runner, mocker):+ def test_run_with_tool_instance_and_files(self, runner, mocker: MockerFixture):message = MagicMock(id="m1")tool_call = MagicMock()diff --git a/api/tests/unit_tests/core/agent/test_plugin_entities.py b/api/tests/unit_tests/core/agent/test_plugin_entities.pyindex 9955190aca5..aa3098a2a1f 100644--- a/api/tests/unit_tests/core/agent/test_plugin_entities.py+++ b/api/tests/unit_tests/core/agent/test_plugin_entities.py@@ -9,6 +9,7 @@ mocking; ensure entity invariants and validation rules remain stable.import pytestfrom pydantic import ValidationError+from pytest_mock import MockerFixturefrom core.agent.plugin_entities import (AgentFeature,@@ -28,12 +29,12 @@ from core.tools.entities.tool_entities import ToolIdentity, ToolProviderIdentity@pytest.fixture-def mock_identity(mocker):+def mock_identity(mocker: MockerFixture):return mocker.MagicMock(spec=AgentStrategyIdentity)@pytest.fixture-def mock_provider_identity(mocker):+def mock_provider_identity(mocker: MockerFixture):return mocker.MagicMock(spec=AgentStrategyProviderIdentity)@@ -47,7 +48,7 @@ class TestAgentStrategyParameterType:"enum_member",list(AgentStrategyParameter.AgentStrategyParameterType),)- def test_as_normal_type_calls_external_function(self, mocker, enum_member) -> None:+ def test_as_normal_type_calls_external_function(self, mocker: MockerFixture, enum_member) -> None:mock_func = mocker.patch("core.agent.plugin_entities.as_normal_type",return_value="normalized",@@ -58,7 +59,7 @@ class TestAgentStrategyParameterType:mock_func.assert_called_once_with(enum_member)assert result == "normalized"- def test_as_normal_type_propagates_exception(self, mocker) -> None:+ def test_as_normal_type_propagates_exception(self, mocker: MockerFixture) -> None:enum_member = AgentStrategyParameter.AgentStrategyParameterType.STRINGmocker.patch("core.agent.plugin_entities.as_normal_type",@@ -79,7 +80,7 @@ class TestAgentStrategyParameterType:(AgentStrategyParameter.AgentStrategyParameterType.FILES, []),],)- def test_cast_value_calls_external_function(self, mocker, enum_member, value) -> None:+ def test_cast_value_calls_external_function(self, mocker: MockerFixture, enum_member, value) -> None:mock_func = mocker.patch("core.agent.plugin_entities.cast_parameter_value",return_value="casted",@@ -90,7 +91,7 @@ class TestAgentStrategyParameterType:mock_func.assert_called_once_with(enum_member, value)assert result == "casted"- def test_cast_value_propagates_exception(self, mocker) -> None:+ def test_cast_value_propagates_exception(self, mocker: MockerFixture) -> None:enum_member = AgentStrategyParameter.AgentStrategyParameterType.STRINGmocker.patch("core.agent.plugin_entities.cast_parameter_value",@@ -136,7 +137,7 @@ class TestAgentStrategyParameter:assert any(error["loc"] == ("type",) for error in exc_info.value.errors())- def test_init_frontend_parameter_calls_external(self, mocker) -> None:+ def test_init_frontend_parameter_calls_external(self, mocker: MockerFixture) -> None:mock_func = mocker.patch("core.agent.plugin_entities.init_frontend_parameter",return_value="frontend",@@ -153,7 +154,7 @@ class TestAgentStrategyParameter:mock_func.assert_called_once_with(param, param.type, "value")assert result == "frontend"- def test_init_frontend_parameter_propagates_exception(self, mocker) -> None:+ def test_init_frontend_parameter_propagates_exception(self, mocker: MockerFixture) -> None:mocker.patch("core.agent.plugin_entities.init_frontend_parameter",side_effect=RuntimeError("error"),diff --git a/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py b/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.pyindex 1c5b6ed944b..6dbf301f656 100644--- a/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py+++ b/api/tests/unit_tests/core/app/app_config/common/test_parameters_mapping.py@@ -10,7 +10,7 @@ class TestGetParametersFromFeatureDict:"""Test suite for get_parameters_from_feature_dict"""@pytest.fixture- def mock_config(self, monkeypatch):+ def mock_config(self, monkeypatch: pytest.MonkeyPatch):"""Mock dify_config values"""mock = MagicMock()mock.UPLOAD_IMAGE_FILE_SIZE_LIMIT = 1@@ -23,7 +23,7 @@ class TestGetParametersFromFeatureDict:return mock@pytest.fixture- def mock_default_file_limits(self, monkeypatch):+ def mock_default_file_limits(self, monkeypatch: pytest.MonkeyPatch):"""Mock DEFAULT_FILE_NUMBER_LIMITS constant"""monkeypatch.setattr(parameters_mapping, "DEFAULT_FILE_NUMBER_LIMITS", 99)return 99diff --git a/api/tests/unit_tests/core/app/app_config/common/test_sensitive_word_avoidance_manager.py b/api/tests/unit_tests/core/app/app_config/common/test_sensitive_word_avoidance_manager.pyindex 013ed0cbc41..bd4ca5ff85a 100644--- a/api/tests/unit_tests/core/app/app_config/common/test_sensitive_word_avoidance_manager.py+++ b/api/tests/unit_tests/core/app/app_config/common/test_sensitive_word_avoidance_manager.py@@ -1,6 +1,7 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.common.sensitive_word_avoidance.manager import (SensitiveWordAvoidanceConfigManager,@@ -26,7 +27,7 @@ class TestSensitiveWordAvoidanceConfigManagerConvert:# Assertassert result is None- def test_convert_returns_entity_when_enabled(self, mocker):+ def test_convert_returns_entity_when_enabled(self, mocker: MockerFixture):# Arrangemock_entity = MagicMock()mocker.patch(@@ -48,7 +49,7 @@ class TestSensitiveWordAvoidanceConfigManagerConvert:# Assertassert result == mock_entity- def test_convert_enabled_without_type_or_config(self, mocker):+ def test_convert_enabled_without_type_or_config(self, mocker: MockerFixture):# Arrangemock_entity = MagicMock()patched = mocker.patch(@@ -135,7 +136,7 @@ class TestSensitiveWordAvoidanceConfigManagerValidateAndSetDefaults:with pytest.raises(ValueError, match="must be a dict"):SensitiveWordAvoidanceConfigManager.validate_and_set_defaults(tenant_id="tenant1", config=config)- def test_validate_calls_moderation_factory(self, mocker):+ def test_validate_calls_moderation_factory(self, mocker: MockerFixture):# Arrangemock_validate = mocker.patch("core.app.app_config.common.sensitive_word_avoidance.manager.ModerationFactory.validate_config"@@ -159,7 +160,7 @@ class TestSensitiveWordAvoidanceConfigManagerValidateAndSetDefaults:assert result_config["sensitive_word_avoidance"]["enabled"] is Trueassert fields == ["sensitive_word_avoidance"]- def test_validate_sets_empty_dict_when_config_none(self, mocker):+ def test_validate_sets_empty_dict_when_config_none(self, mocker: MockerFixture):# Arrangemock_validate = mocker.patch("core.app.app_config.common.sensitive_word_avoidance.manager.ModerationFactory.validate_config"@@ -179,7 +180,7 @@ class TestSensitiveWordAvoidanceConfigManagerValidateAndSetDefaults:# Assertmock_validate.assert_called_once_with(name="mock_type", tenant_id="tenant1", config={})- def test_validate_only_structure_validate_skips_factory(self, mocker):+ def test_validate_only_structure_validate_skips_factory(self, mocker: MockerFixture):# Arrangemock_validate = mocker.patch("core.app.app_config.common.sensitive_word_avoidance.manager.ModerationFactory.validate_config"diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_agent_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_agent_manager.pyindex 992b580376b..359b04070bb 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_agent_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_agent_manager.py@@ -1,6 +1,7 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.easy_ui_based_app.agent.manager import AgentConfigManager@@ -84,7 +85,7 @@ class TestAgentConfigManagerConvert:assert result.strategy.name == "CHAIN_OF_THOUGHT"- def test_convert_skips_disabled_tools(self, mocker, base_config):+ def test_convert_skips_disabled_tools(self, mocker: MockerFixture, base_config):# Patch AgentEntity to bypass pydantic validationmock_agent_entity = mocker.patch("core.app.app_config.easy_ui_based_app.agent.manager.AgentEntity",@@ -128,7 +129,7 @@ class TestAgentConfigManagerConvert:mock_validate.assert_called_once()mock_agent_entity.assert_called_once()- def test_convert_tool_requires_minimum_keys(self, mocker, base_config):+ def test_convert_tool_requires_minimum_keys(self, mocker: MockerFixture, base_config):mock_validate = mocker.patch("core.app.app_config.easy_ui_based_app.agent.manager.AgentToolEntity.model_validate",return_value=MagicMock(),diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.pyindex a688e2a5c50..3a239eac0e7 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py@@ -2,6 +2,7 @@ import uuidfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.easy_ui_based_app.dataset.manager import DatasetConfigManagerfrom core.entities.agent_entities import PlanningStrategy@@ -69,7 +70,7 @@ class TestDatasetConfigManagerConvert:assert result.dataset_ids == [valid_uuid]assert result.retrieve_config.query_variable == "query"- def test_convert_single_with_metadata_configs(self, valid_uuid, mocker):+ def test_convert_single_with_metadata_configs(self, valid_uuid, mocker: MockerFixture):mock_retrieve_config = MagicMock()mock_entity = MagicMock()mock_entity.dataset_ids = [valid_uuid]@@ -258,7 +259,7 @@ class TestExtractDatasetConfig:with pytest.raises(ValueError):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config)- def test_extract_invalid_uuid(self, mocker):+ def test_extract_invalid_uuid(self, mocker: MockerFixture):invalid_uuid = "not-a-uuid"config = {"agent_mode": {@@ -270,7 +271,7 @@ class TestExtractDatasetConfig:with pytest.raises(ValueError):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config)- def test_extract_dataset_not_exists(self, valid_uuid, mocker):+ def test_extract_dataset_not_exists(self, valid_uuid, mocker: MockerFixture):mocker.patch("core.app.app_config.easy_ui_based_app.dataset.manager.DatasetService.get_dataset",return_value=None,@@ -292,7 +293,7 @@ class TestExtractDatasetConfig:class TestIsDatasetExists:- def test_dataset_exists_true(self, mocker, valid_uuid):+ def test_dataset_exists_true(self, mocker: MockerFixture, valid_uuid):mock_dataset = MagicMock()mock_dataset.tenant_id = "tenant1"mocker.patch(@@ -302,14 +303,14 @@ class TestIsDatasetExists:assert DatasetConfigManager.is_dataset_exists("tenant1", valid_uuid)- def test_dataset_exists_false_when_not_found(self, mocker, valid_uuid):+ def test_dataset_exists_false_when_not_found(self, mocker: MockerFixture, valid_uuid):mocker.patch("core.app.app_config.easy_ui_based_app.dataset.manager.DatasetService.get_dataset",return_value=None,)assert not DatasetConfigManager.is_dataset_exists("tenant1", valid_uuid)- def test_dataset_exists_false_when_tenant_mismatch(self, mocker, valid_uuid):+ def test_dataset_exists_false_when_tenant_mismatch(self, mocker: MockerFixture, valid_uuid):mock_dataset = MagicMock()mock_dataset.tenant_id = "other"mocker.patch(diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.pyindex 186b4a501d3..e5b581b6a09 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py@@ -2,6 +2,7 @@ from types import SimpleNamespacefrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.easy_ui_based_app.model_config.converter import ModelConfigConverterfrom core.entities.model_entities import ModelStatus@@ -16,7 +17,7 @@ from graphon.model_runtime.entities.model_entities import ModelPropertyKeyclass TestModelConfigConverter:@pytest.fixture(autouse=True)- def patch_response_entity(self, mocker):+ def patch_response_entity(self, mocker: MockerFixture):"""Patch ModelConfigWithCredentialsEntity to bypass Pydantic validationand return a simple namespace object instead.@@ -69,7 +70,7 @@ class TestModelConfigConverter:return bundle@pytest.fixture- def patch_provider_manager(self, mocker, mock_provider_bundle):+ def patch_provider_manager(self, mocker: MockerFixture, mock_provider_bundle):mock_manager = MagicMock()mock_manager.get_provider_model_bundle.return_value = mock_provider_bundlemocker.patch(@@ -99,7 +100,7 @@ class TestModelConfigConverter:assert result.parameters == {"temperature": 0.7}assert result.stop == ["\n"]- def test_convert_mode_from_schema_valid(self, mock_app_config, mock_provider_bundle, mocker):+ def test_convert_mode_from_schema_valid(self, mock_app_config, mock_provider_bundle, mocker: MockerFixture):mock_app_config.model.mode = Nonemock_provider_bundle.model_type_instance.get_model_schema.return_value.model_properties = {@@ -116,7 +117,9 @@ class TestModelConfigConverter:result = ModelConfigConverter.convert(mock_app_config)assert result.mode == LLMMode.COMPLETION- def test_convert_mode_from_schema_invalid_fallback(self, mock_app_config, mock_provider_bundle, mocker):+ def test_convert_mode_from_schema_invalid_fallback(+ self, mock_app_config, mock_provider_bundle, mocker: MockerFixture+ ):mock_provider_bundle.model_type_instance.get_model_schema.return_value.model_properties = {ModelPropertyKey.MODE: "invalid"}@@ -135,7 +138,7 @@ class TestModelConfigConverter:# Credential Errors# =============================- def test_convert_credentials_none_raises(self, mock_app_config, mock_provider_bundle, mocker):+ def test_convert_credentials_none_raises(self, mock_app_config, mock_provider_bundle, mocker: MockerFixture):mock_provider_bundle.configuration.get_current_credentials.return_value = Nonemock_manager = MagicMock()@@ -152,7 +155,7 @@ class TestModelConfigConverter:# Provider Model Errors# =============================- def test_convert_provider_model_none_raises(self, mock_app_config, mock_provider_bundle, mocker):+ def test_convert_provider_model_none_raises(self, mock_app_config, mock_provider_bundle, mocker: MockerFixture):mock_provider_bundle.configuration.get_provider_model.return_value = Nonemock_manager = MagicMock()@@ -174,7 +177,7 @@ class TestModelConfigConverter:],)def test_convert_provider_model_status_errors(- self, mock_app_config, mock_provider_bundle, mocker, status, expected_exception+ self, mock_app_config, mock_provider_bundle, mocker: MockerFixture, status, expected_exception):mock_provider = MagicMock()mock_provider.status = status@@ -194,7 +197,7 @@ class TestModelConfigConverter:# Schema Errors# =============================- def test_convert_model_schema_none_raises(self, mock_app_config, mock_provider_bundle, mocker):+ def test_convert_model_schema_none_raises(self, mock_app_config, mock_provider_bundle, mocker: MockerFixture):mock_provider_bundle.model_type_instance.get_model_schema.return_value = Nonemock_manager = MagicMock()diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_manager.pyindex 68bca485bbd..72e334004e1 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_manager.py@@ -1,6 +1,7 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixture# Targetfrom core.app.app_config.easy_ui_based_app.model_config.manager import ModelConfigManager@@ -107,7 +108,9 @@ class TestModelConfigManager:# validate_and_set_defaults# ==========================================================- def test_validate_and_set_defaults_success(self, mocker, valid_config, provider_entities, valid_model_list):+ def test_validate_and_set_defaults_success(+ self, mocker: MockerFixture, valid_config, provider_entities, valid_model_list+ ):self._patch_model_assembly(mocker,provider_entities=provider_entities,@@ -127,35 +130,37 @@ class TestModelConfigManager:with pytest.raises(ValueError, match="object type"):ModelConfigManager.validate_and_set_defaults("tenant1", {"model": "invalid"})- def test_validate_and_set_defaults_missing_provider(self, mocker, provider_entities):+ def test_validate_and_set_defaults_missing_provider(self, mocker: MockerFixture, provider_entities):config = {"model": {"name": "gpt-4", "completion_params": {}}}self._patch_model_assembly(mocker, provider_entities=provider_entities, model_list=[])with pytest.raises(ValueError, match="model.provider is required"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_invalid_provider(self, mocker, provider_entities):+ def test_validate_and_set_defaults_invalid_provider(self, mocker: MockerFixture, provider_entities):config = {"model": {"provider": "invalid/provider", "name": "gpt-4", "completion_params": {}}}self._patch_model_assembly(mocker, provider_entities=provider_entities, model_list=[])with pytest.raises(ValueError, match="model.provider is required"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_missing_name(self, mocker, provider_entities):+ def test_validate_and_set_defaults_missing_name(self, mocker: MockerFixture, provider_entities):config = {"model": {"provider": "openai/gpt", "completion_params": {}}}self._patch_model_assembly(mocker, provider_entities=provider_entities, model_list=[])with pytest.raises(ValueError, match="model.name is required"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_empty_models(self, mocker, provider_entities):+ def test_validate_and_set_defaults_empty_models(self, mocker: MockerFixture, provider_entities):config = {"model": {"provider": "openai/gpt", "name": "gpt-4", "completion_params": {}}}self._patch_model_assembly(mocker, provider_entities=provider_entities, model_list=[])with pytest.raises(ValueError, match="must be in the specified model list"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_invalid_model_name(self, mocker, provider_entities, valid_model_list):+ def test_validate_and_set_defaults_invalid_model_name(+ self, mocker: MockerFixture, provider_entities, valid_model_list+ ):config = {"model": {"provider": "openai/gpt", "name": "invalid", "completion_params": {}}}self._patch_model_assembly(mocker,@@ -166,7 +171,7 @@ class TestModelConfigManager:with pytest.raises(ValueError, match="must be in the specified model list"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_default_mode_when_missing(self, mocker, provider_entities):+ def test_validate_and_set_defaults_default_mode_when_missing(self, mocker: MockerFixture, provider_entities):model = MagicMock()model.model = "gpt-4"model.model_properties = {}@@ -178,7 +183,9 @@ class TestModelConfigManager:assert updated_config["model"]["mode"] == "completion"- def test_validate_and_set_defaults_missing_completion_params(self, mocker, provider_entities, valid_model_list):+ def test_validate_and_set_defaults_missing_completion_params(+ self, mocker: MockerFixture, provider_entities, valid_model_list+ ):config = {"model": {"provider": "openai/gpt", "name": "gpt-4"}}self._patch_model_assembly(mocker,@@ -189,7 +196,7 @@ class TestModelConfigManager:with pytest.raises(ValueError, match="completion_params is required"):ModelConfigManager.validate_and_set_defaults("tenant1", config)- def test_validate_and_set_defaults_provider_without_slash_converted(self, mocker, valid_model_list):+ def test_validate_and_set_defaults_provider_without_slash_converted(self, mocker: MockerFixture, valid_model_list):"""Covers branch where provider does not contain '/' andModelProviderID conversion is triggered (line 64).diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.pyindex fd49072cd53..3fd21ab22be 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py@@ -1,6 +1,7 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.easy_ui_based_app.prompt_template.manager import (PromptTemplateConfigManager,@@ -38,7 +39,7 @@ class TestPromptTemplateConfigManagerConvert:with pytest.raises(ValueError, match="prompt_type is required"):PromptTemplateConfigManager.convert({})- def test_convert_simple_prompt(self, mocker):+ def test_convert_simple_prompt(self, mocker: MockerFixture):mock_prompt_entity_cls = MagicMock()mock_prompt_entity_cls.PromptType = DummyPromptType()@@ -56,7 +57,7 @@ class TestPromptTemplateConfigManagerConvert:assert result == "simple_entity"mock_prompt_entity_cls.assert_called_once_with(prompt_type="simple", simple_prompt_template="hello")- def test_convert_advanced_chat_valid(self, mocker):+ def test_convert_advanced_chat_valid(self, mocker: MockerFixture):mock_prompt_entity_cls = MagicMock()mock_prompt_entity_cls.PromptType = DummyPromptType()mock_prompt_entity_cls.return_value = "advanced_entity"@@ -97,7 +98,7 @@ class TestPromptTemplateConfigManagerConvert:{"text": "hi", "role": 123},],)- def test_convert_advanced_invalid_message_fields(self, mocker, message):+ def test_convert_advanced_invalid_message_fields(self, mocker: MockerFixture, message):mock_prompt_entity_cls = MagicMock()mock_prompt_entity_cls.PromptType = DummyPromptType()@@ -114,7 +115,7 @@ class TestPromptTemplateConfigManagerConvert:with pytest.raises(ValueError):PromptTemplateConfigManager.convert(config)- def test_convert_advanced_completion_with_roles(self, mocker):+ def test_convert_advanced_completion_with_roles(self, mocker: MockerFixture):mock_prompt_entity_cls = MagicMock()mock_prompt_entity_cls.PromptType = DummyPromptType()mock_prompt_entity_cls.return_value = "advanced_entity"@@ -154,7 +155,7 @@ class TestValidateAndSetDefaults:def setup_method(self):self.valid_model = {"mode": "chat"}- def _patch_prompt_type(self, mocker):+ def _patch_prompt_type(self, mocker: MockerFixture):mock_prompt_entity_cls = MagicMock()mock_prompt_entity_cls.PromptType = DummyPromptType()mocker.patch(@@ -163,7 +164,7 @@ class TestValidateAndSetDefaults:)return mock_prompt_entity_cls- def test_default_prompt_type_set(self, mocker):+ def test_default_prompt_type_set(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {"model": self.valid_model}@@ -173,7 +174,7 @@ class TestValidateAndSetDefaults:assert result["prompt_type"] == "simple"assert isinstance(keys, list)- def test_invalid_prompt_type_raises(self, mocker):+ def test_invalid_prompt_type_raises(self, mocker: MockerFixture):class InvalidEnum(DummyPromptType):def __iter__(self):return iter([DummyEnumValue("valid")])@@ -191,7 +192,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_invalid_chat_prompt_config_type(self, mocker):+ def test_invalid_chat_prompt_config_type(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {@@ -203,7 +204,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_simple_mode_invalid_pre_prompt_type(self, mocker):+ def test_simple_mode_invalid_pre_prompt_type(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {@@ -215,7 +216,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_advanced_requires_one_config(self, mocker):+ def test_advanced_requires_one_config(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {@@ -228,7 +229,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_advanced_invalid_model_mode(self, mocker):+ def test_advanced_invalid_model_mode(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {@@ -240,7 +241,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_advanced_chat_prompt_length_exceeds(self, mocker):+ def test_advanced_chat_prompt_length_exceeds(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {@@ -252,7 +253,7 @@ class TestValidateAndSetDefaults:with pytest.raises(ValueError):PromptTemplateConfigManager.validate_and_set_defaults("chat_app", config)- def test_completion_prefix_defaults_set_when_empty(self, mocker):+ def test_completion_prefix_defaults_set_when_empty(self, mocker: MockerFixture):self._patch_prompt_type(mocker)config = {diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.pyindex d9fe7004ff7..b82417cfedb 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom core.app.app_config.easy_ui_based_app.variables.manager import (BasicVariablesConfigManager,@@ -15,7 +16,7 @@ class TestBasicVariablesConfigManagerConvert:assert variables == []assert external == []- def test_convert_external_data_tools_enabled_and_disabled(self, mocker):+ def test_convert_external_data_tools_enabled_and_disabled(self, mocker: MockerFixture):config = {"external_data_tools": [{"enabled": False},@@ -232,7 +233,7 @@ class TestValidateExternalDataToolsAndSetDefaults:with pytest.raises(ValueError):BasicVariablesConfigManager.validate_external_data_tools_and_set_defaults("tenant", config)- def test_validate_disabled_tool_skipped(self, mocker):+ def test_validate_disabled_tool_skipped(self, mocker: MockerFixture):config = {"external_data_tools": [{"enabled": False}]}spy = mocker.patch(@@ -250,7 +251,7 @@ class TestValidateExternalDataToolsAndSetDefaults:with pytest.raises(ValueError):BasicVariablesConfigManager.validate_external_data_tools_and_set_defaults("tenant", config)- def test_validate_enabled_tool_calls_factory(self, mocker):+ def test_validate_enabled_tool_calls_factory(self, mocker: MockerFixture):config = {"external_data_tools": [{"enabled": True, "type": "tool", "config": {"a": 1}}]}spy = mocker.patch(@@ -263,7 +264,7 @@ class TestValidateExternalDataToolsAndSetDefaults:class TestValidateAndSetDefaultsIntegration:- def test_validate_and_set_defaults_calls_both(self, mocker):+ def test_validate_and_set_defaults_calls_both(self, mocker: MockerFixture):config = {}spy_var = mocker.patch.object(diff --git a/api/tests/unit_tests/core/app/app_config/test_base_app_config_manager.py b/api/tests/unit_tests/core/app/app_config/test_base_app_config_manager.pyindex e99852cf761..e2ab3e2192b 100644--- a/api/tests/unit_tests/core/app/app_config/test_base_app_config_manager.py+++ b/api/tests/unit_tests/core/app/app_config/test_base_app_config_manager.py@@ -2,6 +2,7 @@ from collections import UserDictfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.base_app_config_manager import BaseAppConfigManager@@ -12,7 +13,7 @@ class TestBaseAppConfigManager:return {"key": "value", "another": 123}@pytest.fixture- def mock_app_additional_features(self, mocker):+ def mock_app_additional_features(self, mocker: MockerFixture):mock_instance = MagicMock()mocker.patch("core.app.app_config.base_app_config_manager.AppAdditionalFeatures",@@ -21,7 +22,7 @@ class TestBaseAppConfigManager:return mock_instance@pytest.fixture- def mock_managers(self, mocker):+ def mock_managers(self, mocker: MockerFixture):retrieval = mocker.patch("core.app.app_config.base_app_config_manager.RetrievalResourceConfigManager.convert",return_value="retrieval_result",@@ -72,7 +73,7 @@ class TestBaseAppConfigManager:)def test_convert_features_all_modes(self,- mocker,+ mocker: MockerFixture,mock_config_dict,mock_app_additional_features,mock_managers,@@ -107,7 +108,7 @@ class TestBaseAppConfigManager:mock_managers["speech_to_text"].assert_called_once_with(config=dict(mock_config_dict.items()))mock_managers["text_to_speech"].assert_called_once_with(config=dict(mock_config_dict.items()))- def test_convert_features_empty_config(self, mocker, mock_app_additional_features, mock_managers):+ def test_convert_features_empty_config(self, mocker: MockerFixture, mock_app_additional_features, mock_managers):# Arrangeempty_config = {}mock_app_mode = MagicMock()@@ -143,7 +144,7 @@ class TestBaseAppConfigManager:with pytest.raises((TypeError, AttributeError)):BaseAppConfigManager.convert_features(invalid_config, "CHAT")- def test_convert_features_manager_exception_propagates(self, mocker, mock_config_dict):+ def test_convert_features_manager_exception_propagates(self, mocker: MockerFixture, mock_config_dict):# Arrangemocker.patch("core.app.app_config.base_app_config_manager.RetrievalResourceConfigManager.convert",@@ -154,7 +155,9 @@ class TestBaseAppConfigManager:with pytest.raises(RuntimeError):BaseAppConfigManager.convert_features(mock_config_dict, "CHAT")- def test_convert_features_mapping_subclass(self, mocker, mock_app_additional_features, mock_managers):+ def test_convert_features_mapping_subclass(+ self, mocker: MockerFixture, mock_app_additional_features, mock_managers+ ):# Arrangeclass CustomMapping(UserDict):passdiff --git a/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py b/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.pyindex fa128aca874..dacd69a578c 100644--- a/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py+++ b/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom core.app.app_config.workflow_ui_based_app.variables.manager import (WorkflowVariablesConfigManager,@@ -10,19 +11,19 @@ from core.app.app_config.workflow_ui_based_app.variables.manager import (@pytest.fixture-def mock_workflow(mocker):+def mock_workflow(mocker: MockerFixture):workflow = mocker.MagicMock()workflow.graph_dict = {"nodes": []}return workflow@pytest.fixture-def mock_variable_entity(mocker):+def mock_variable_entity(mocker: MockerFixture):return mocker.patch("core.app.app_config.workflow_ui_based_app.variables.manager.VariableEntity")@pytest.fixture-def mock_rag_entity(mocker):+def mock_rag_entity(mocker: MockerFixture):return mocker.patch("core.app.app_config.workflow_ui_based_app.variables.manager.RagPipelineVariableEntity")diff --git a/api/tests/unit_tests/core/app/apps/advanced_chat/test_app_generator.py b/api/tests/unit_tests/core/app/apps/advanced_chat/test_app_generator.pyindex af5d203f126..bc3b06cd1b6 100644--- a/api/tests/unit_tests/core/app/apps/advanced_chat/test_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/advanced_chat/test_app_generator.py@@ -111,7 +111,7 @@ class TestAdvancedChatAppGeneratorInternals:workflow_id="workflow-id",)- def test_generate_loads_conversation_and_files(self, monkeypatch):+ def test_generate_loads_conversation_and_files(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()app_config = self._build_app_config()@@ -195,7 +195,7 @@ class TestAdvancedChatAppGeneratorInternals:assert captured["application_generate_entity"].files == built_filesassert build_files_called["called"] is True- def test_resume_delegates_to_generate(self, monkeypatch):+ def test_resume_delegates_to_generate(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()application_generate_entity = AdvancedChatAppGenerateEntity.model_construct(task_id="task",@@ -235,7 +235,7 @@ class TestAdvancedChatAppGeneratorInternals:assert result == {"resumed": True}assert captured["graph_runtime_state"] is not None- def test_single_iteration_generate_builds_debug_task(self, monkeypatch):+ def test_single_iteration_generate_builds_debug_task(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()app_config = self._build_app_config()captured: dict[str, object] = {}@@ -293,7 +293,7 @@ class TestAdvancedChatAppGeneratorInternals:assert captured["variable_loader"] is var_loaderassert captured["application_generate_entity"].single_iteration_run.node_id == "node-1"- def test_single_loop_generate_builds_debug_task(self, monkeypatch):+ def test_single_loop_generate_builds_debug_task(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()app_config = self._build_app_config()captured: dict[str, object] = {}@@ -351,7 +351,7 @@ class TestAdvancedChatAppGeneratorInternals:assert captured["variable_loader"] is var_loaderassert captured["application_generate_entity"].single_loop_run.node_id == "node-2"- def test_generate_internal_flow_initial_conversation_with_pause_layer(self, monkeypatch):+ def test_generate_internal_flow_initial_conversation_with_pause_layer(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 0app_config = self._build_app_config()@@ -449,7 +449,7 @@ class TestAdvancedChatAppGeneratorInternals:assert isinstance(captured["conversation"], ConversationSnapshot)assert isinstance(captured["message"], MessageSnapshot)- def test_generate_internal_flow_with_existing_records_skips_init(self, monkeypatch):+ def test_generate_internal_flow_with_existing_records_skips_init(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 0app_config = self._build_app_config()@@ -535,7 +535,7 @@ class TestAdvancedChatAppGeneratorInternals:db_session.refresh.assert_not_called()db_session.close.assert_called_once()- def test_generate_worker_raises_when_workflow_not_found(self, monkeypatch):+ def test_generate_worker_raises_when_workflow_not_found(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1app_config = self._build_app_config()@@ -594,7 +594,7 @@ class TestAdvancedChatAppGeneratorInternals:graph_runtime_state=None,)- def test_generate_worker_raises_when_app_not_found_for_internal_call(self, monkeypatch):+ def test_generate_worker_raises_when_app_not_found_for_internal_call(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1app_config = self._build_app_config()@@ -658,7 +658,7 @@ class TestAdvancedChatAppGeneratorInternals:graph_runtime_state=None,)- def test_generate_worker_handles_stopped_error(self, monkeypatch):+ def test_generate_worker_handles_stopped_error(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1app_config = self._build_app_config()@@ -732,7 +732,7 @@ class TestAdvancedChatAppGeneratorInternals:queue_manager.publish_error.assert_not_called()- def test_generate_worker_handles_validation_error(self, monkeypatch):+ def test_generate_worker_handles_validation_error(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1app_config = self._build_app_config()@@ -816,7 +816,7 @@ class TestAdvancedChatAppGeneratorInternals:queue_manager.publish_error.assert_called_once()- def test_generate_worker_handles_value_and_unknown_errors(self, monkeypatch):+ def test_generate_worker_handles_value_and_unknown_errors(self, monkeypatch: pytest.MonkeyPatch):app_config = self._build_app_config()@contextmanager@@ -897,7 +897,7 @@ class TestAdvancedChatAppGeneratorInternals:queue_manager.publish_error.assert_called_once()- def test_handle_response_closed_file_raises_stopped(self, monkeypatch):+ def test_handle_response_closed_file_raises_stopped(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1@@ -953,7 +953,7 @@ class TestAdvancedChatAppGeneratorInternals:stream=False,)- def test_handle_response_re_raises_value_error(self, monkeypatch):+ def test_handle_response_re_raises_value_error(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1app_config = self._build_app_config()@@ -1002,7 +1002,7 @@ class TestAdvancedChatAppGeneratorInternals:logger_exception.assert_called_once()- def test_generate_worker_handles_invoke_auth_error(self, monkeypatch):+ def test_generate_worker_handles_invoke_auth_error(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()generator._dialogue_count = 1@@ -1088,7 +1088,7 @@ class TestAdvancedChatAppGeneratorInternals:assert queue_manager.publish_error.called- def test_generate_debugger_enables_retrieve_source(self, monkeypatch):+ def test_generate_debugger_enables_retrieve_source(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()app_config = WorkflowUIBasedAppConfig(@@ -1167,7 +1167,7 @@ class TestAdvancedChatAppGeneratorInternals:assert app_config.additional_features.show_retrieve_source is Trueassert captured["application_generate_entity"].query == "hello"- def test_generate_service_api_sets_parent_message_id(self, monkeypatch):+ def test_generate_service_api_sets_parent_message_id(self, monkeypatch: pytest.MonkeyPatch):generator = AdvancedChatAppGenerator()app_config = WorkflowUIBasedAppConfig(diff --git a/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py b/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.pyindex 64bcfa9a187..1d72d7807de 100644--- a/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py+++ b/api/tests/unit_tests/core/app/apps/advanced_chat/test_generate_task_pipeline_core.py@@ -224,7 +224,7 @@ class TestAdvancedChatGenerateTaskPipeline:assert isinstance(responses[0], ValueError)- def test_handle_workflow_started_event_sets_run_id(self, monkeypatch):+ def test_handle_workflow_started_event_sets_run_id(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._graph_runtime_state = GraphRuntimeState(variable_pool=build_test_variable_pool(variables=build_system_variables(workflow_execution_id="run-id")),@@ -368,7 +368,7 @@ class TestAdvancedChatGenerateTaskPipeline:assert list(pipeline._handle_loop_next_event(loop_next)) == ["loop_next"]assert list(pipeline._handle_loop_completed_event(loop_done)) == ["loop_done"]- def test_workflow_finish_handlers(self, monkeypatch):+ def test_workflow_finish_handlers(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._workflow_run_id = "run-id"pipeline._graph_runtime_state = GraphRuntimeState(@@ -593,7 +593,7 @@ class TestAdvancedChatGenerateTaskPipeline:assert message.answer == "hello"assert message.message_metadata- def test_handle_stop_event_saves_message_for_moderation(self, monkeypatch):+ def test_handle_stop_event_saves_message_for_moderation(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._message_end_to_stream_response = lambda: "end"saved: list[str] = []@@ -614,7 +614,7 @@ class TestAdvancedChatGenerateTaskPipeline:assert responses == ["end"]assert saved == ["saved"]- def test_handle_message_end_event_applies_output_moderation(self, monkeypatch):+ def test_handle_message_end_event_applies_output_moderation(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._graph_runtime_state = GraphRuntimeState(variable_pool=VariablePool(system_variables=build_system_variables(workflow_execution_id="run-id")),diff --git a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.pyindex a871e8d93ba..d47b70e9502 100644--- a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py+++ b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py@@ -2,6 +2,7 @@ import uuidfrom types import SimpleNamespaceimport pytest+from pytest_mock import MockerFixturefrom core.app.app_config.entities import EasyUIBasedAppModelConfigFromfrom core.app.apps.agent_chat.app_config_manager import (@@ -11,7 +12,7 @@ from core.entities.agent_entities import PlanningStrategyclass TestAgentChatAppConfigManagerGetAppConfig:- def test_get_app_config_override_config(self, mocker):+ def test_get_app_config_override_config(self, mocker: MockerFixture):app_model = mocker.MagicMock(id="app1", tenant_id="tenant", mode="agent-chat")app_model_config = mocker.MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"ignored": True}@@ -45,7 +46,7 @@ class TestAgentChatAppConfigManagerGetAppConfig:assert result.variables == "variables"assert result.external_data_variables == "external"- def test_get_app_config_conversation_specific(self, mocker):+ def test_get_app_config_conversation_specific(self, mocker: MockerFixture):app_model = mocker.MagicMock(id="app1", tenant_id="tenant", mode="agent-chat")app_model_config = mocker.MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "p"}}@@ -76,7 +77,7 @@ class TestAgentChatAppConfigManagerGetAppConfig:assert result.app_model_config_dict == app_model_config.to_dict.return_valueassert result.app_model_config_from.value == "conversation-specific-config"- def test_get_app_config_latest_config(self, mocker):+ def test_get_app_config_latest_config(self, mocker: MockerFixture):app_model = mocker.MagicMock(id="app1", tenant_id="tenant", mode="agent-chat")app_model_config = mocker.MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "p"}}@@ -107,7 +108,7 @@ class TestAgentChatAppConfigManagerGetAppConfig:class TestAgentChatAppConfigManagerConfigValidate:- def test_config_validate_filters_related_keys(self, mocker):+ def test_config_validate_filters_related_keys(self, mocker: MockerFixture):config = {"model": {},"user_input_form": {},@@ -247,7 +248,7 @@ class TestValidateAgentModeAndSetDefaults:{"agent_mode": {"enabled": True, "tools": [{"dataset": {"enabled": True, "id": "bad"}}]}},)- def test_old_tool_dataset_id_not_exists(self, mocker):+ def test_old_tool_dataset_id_not_exists(self, mocker: MockerFixture):mocker.patch("core.app.apps.agent_chat.app_config_manager.DatasetConfigManager.is_dataset_exists",return_value=False,@@ -275,7 +276,7 @@ class TestValidateAgentModeAndSetDefaults:"tenant", {"agent_mode": {"enabled": True, "tools": [tool]}})- def test_valid_old_and_new_style_tools(self, mocker):+ def test_valid_old_and_new_style_tools(self, mocker: MockerFixture):mocker.patch("core.app.apps.agent_chat.app_config_manager.DatasetConfigManager.is_dataset_exists",return_value=True,diff --git a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.pyindex 80f7f94b1ac..6cd62c933a0 100644--- a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py@@ -2,6 +2,7 @@ import contextlibimport pytestfrom pydantic import ValidationError+from pytest_mock import MockerFixturefrom core.app.apps.agent_chat.app_generator import AgentChatAppGeneratorfrom core.app.apps.exc import GenerateTaskStoppedError@@ -16,7 +17,7 @@ class DummyAccount:@pytest.fixture-def generator(mocker):+def generator(mocker: MockerFixture):gen = AgentChatAppGenerator()mocker.patch("core.app.apps.agent_chat.app_generator.current_app",@@ -27,19 +28,19 @@ def generator(mocker):class TestAgentChatAppGeneratorGenerate:- def test_generate_rejects_blocking_mode(self, generator, mocker):+ def test_generate_rejects_blocking_mode(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock()user = DummyAccount("user")with pytest.raises(ValueError):generator.generate(app_model=app_model, user=user, args={}, invoke_from=mocker.MagicMock(), streaming=False)- def test_generate_requires_query(self, generator, mocker):+ def test_generate_requires_query(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock()user = DummyAccount("user")with pytest.raises(ValueError):generator.generate(app_model=app_model, user=user, args={"inputs": {}}, invoke_from=mocker.MagicMock())- def test_generate_rejects_non_string_query(self, generator, mocker):+ def test_generate_rejects_non_string_query(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock()user = DummyAccount("user")with pytest.raises(ValueError):@@ -50,7 +51,7 @@ class TestAgentChatAppGeneratorGenerate:invoke_from=mocker.MagicMock(),)- def test_generate_override_requires_debugger(self, generator, mocker):+ def test_generate_override_requires_debugger(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock()user = DummyAccount("user")@@ -62,7 +63,7 @@ class TestAgentChatAppGeneratorGenerate:invoke_from=InvokeFrom.WEB_APP,)- def test_generate_success_with_debugger_override(self, generator, mocker):+ def test_generate_success_with_debugger_override(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock(id="app1", tenant_id="tenant", mode="agent-chat")app_model_config = mocker.MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "p"}}@@ -142,7 +143,7 @@ class TestAgentChatAppGeneratorGenerate:assert result == {"result": "ok"}thread_obj.start.assert_called_once()- def test_generate_without_file_config(self, generator, mocker):+ def test_generate_without_file_config(self, generator, mocker: MockerFixture):app_model = mocker.MagicMock(id="app1", tenant_id="tenant", mode="agent-chat")app_model_config = mocker.MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "p"}}@@ -213,14 +214,14 @@ class TestAgentChatAppGeneratorGenerate:class TestAgentChatAppGeneratorWorker:@pytest.fixture(autouse=True)- def patch_context(self, mocker):+ def patch_context(self, mocker: MockerFixture):@contextlib.contextmanagerdef ctx_manager(*args, **kwargs):yieldmocker.patch("core.app.apps.agent_chat.app_generator.preserve_flask_contexts", ctx_manager)- def test_generate_worker_handles_generate_task_stopped(self, generator, mocker):+ def test_generate_worker_handles_generate_task_stopped(self, generator, mocker: MockerFixture):queue_manager = mocker.MagicMock()generator._get_conversation = mocker.MagicMock(return_value=mocker.MagicMock())generator._get_message = mocker.MagicMock(return_value=mocker.MagicMock())@@ -250,7 +251,7 @@ class TestAgentChatAppGeneratorWorker:Exception("bad"),],)- def test_generate_worker_publishes_errors(self, generator, mocker, error):+ def test_generate_worker_publishes_errors(self, generator, mocker: MockerFixture, error):queue_manager = mocker.MagicMock()generator._get_conversation = mocker.MagicMock(return_value=mocker.MagicMock())generator._get_message = mocker.MagicMock(return_value=mocker.MagicMock())@@ -271,7 +272,7 @@ class TestAgentChatAppGeneratorWorker:assert queue_manager.publish_error.called- def test_generate_worker_logs_value_error_when_debug(self, generator, mocker):+ def test_generate_worker_logs_value_error_when_debug(self, generator, mocker: MockerFixture):queue_manager = mocker.MagicMock()generator._get_conversation = mocker.MagicMock(return_value=mocker.MagicMock())generator._get_message = mocker.MagicMock(return_value=mocker.MagicMock())diff --git a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_runner.py b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_runner.pyindex 4567b354804..0260235b03a 100644--- a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_runner.py+++ b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_runner.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom core.agent.entities import AgentEntityfrom core.app.apps.agent_chat.app_runner import AgentChatAppRunner@@ -13,7 +14,7 @@ def runner():class TestAgentChatAppRunnerRun:- def test_run_app_not_found(self, runner, mocker):+ def test_run_app_not_found(self, runner, mocker: MockerFixture):app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", agent=mocker.MagicMock())generate_entity = mocker.MagicMock(app_config=app_config, inputs={}, query="q", files=[], stream=True)@@ -22,7 +23,7 @@ class TestAgentChatAppRunnerRun:with pytest.raises(ValueError):runner.run(generate_entity, mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock())- def test_run_moderation_error_direct_output(self, runner, mocker):+ def test_run_moderation_error_direct_output(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = mocker.MagicMock()@@ -45,7 +46,7 @@ class TestAgentChatAppRunnerRun:runner.direct_output.assert_called_once()- def test_run_annotation_reply_short_circuits(self, runner, mocker):+ def test_run_annotation_reply_short_circuits(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = mocker.MagicMock()@@ -74,7 +75,7 @@ class TestAgentChatAppRunnerRun:queue_manager.publish.assert_called_once()runner.direct_output.assert_called_once()- def test_run_hosting_moderation_short_circuits(self, runner, mocker):+ def test_run_hosting_moderation_short_circuits(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = mocker.MagicMock()@@ -98,7 +99,7 @@ class TestAgentChatAppRunnerRun:runner.run(generate_entity, mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock())- def test_run_model_schema_missing(self, runner, mocker):+ def test_run_model_schema_missing(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.CHAIN_OF_THOUGHT)@@ -140,7 +141,7 @@ class TestAgentChatAppRunnerRun:(LLMMode.COMPLETION, "CotCompletionAgentRunner"),],)- def test_run_chain_of_thought_modes(self, runner, mocker, mode, expected_runner):+ def test_run_chain_of_thought_modes(self, runner, mocker: MockerFixture, mode, expected_runner):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.CHAIN_OF_THOUGHT)@@ -196,7 +197,7 @@ class TestAgentChatAppRunnerRun:runner_instance.run.assert_called_once()runner._handle_invoke_result.assert_called_once()- def test_run_invalid_llm_mode_raises(self, runner, mocker):+ def test_run_invalid_llm_mode_raises(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.CHAIN_OF_THOUGHT)@@ -242,7 +243,7 @@ class TestAgentChatAppRunnerRun:with pytest.raises(ValueError):runner.run(generate_entity, mocker.MagicMock(), conversation, message)- def test_run_function_calling_strategy_selected_by_features(self, runner, mocker):+ def test_run_function_calling_strategy_selected_by_features(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.CHAIN_OF_THOUGHT)@@ -298,7 +299,7 @@ class TestAgentChatAppRunnerRun:assert app_config.agent.strategy == AgentEntity.Strategy.FUNCTION_CALLINGrunner_instance.run.assert_called_once()- def test_run_conversation_not_found(self, runner, mocker):+ def test_run_conversation_not_found(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.FUNCTION_CALLING)@@ -332,7 +333,7 @@ class TestAgentChatAppRunnerRun:with pytest.raises(ValueError):runner.run(generate_entity, mocker.MagicMock(), mocker.MagicMock(id="conv"), mocker.MagicMock(id="msg"))- def test_run_message_not_found(self, runner, mocker):+ def test_run_message_not_found(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = AgentEntity(provider="p", model="m", strategy=AgentEntity.Strategy.FUNCTION_CALLING)@@ -366,7 +367,7 @@ class TestAgentChatAppRunnerRun:with pytest.raises(ValueError):runner.run(generate_entity, mocker.MagicMock(), mocker.MagicMock(id="conv"), mocker.MagicMock(id="msg"))- def test_run_invalid_agent_strategy_raises(self, runner, mocker):+ def test_run_invalid_agent_strategy_raises(self, runner, mocker: MockerFixture):app_record = mocker.MagicMock(id="app1", tenant_id="tenant")app_config = mocker.MagicMock(app_id="app1", tenant_id="tenant", prompt_template=mocker.MagicMock())app_config.agent = mocker.MagicMock(strategy="invalid", provider="p", model="m")diff --git a/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py b/api/tests/unit_tests/core/app/apps/completion/test_app_runner.pyindex aa2085177e1..8dcf6e91935 100644--- a/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py+++ b/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py@@ -2,6 +2,7 @@ from types import SimpleNamespacefrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport core.app.apps.completion.app_runner as modulefrom core.app.apps.completion.app_runner import CompletionAppRunner@@ -47,7 +48,7 @@ def _build_generate_entity(app_config, file_upload_config=None):class TestCompletionAppRunner:- def test_run_app_not_found(self, runner, mocker):+ def test_run_app_not_found(self, runner, mocker: MockerFixture):session = mocker.MagicMock()session.scalar.return_value = Nonemocker.patch.object(module.db, "session", session)@@ -58,7 +59,7 @@ class TestCompletionAppRunner:with pytest.raises(ValueError):runner.run(app_generate_entity, MagicMock(), MagicMock())- def test_run_moderation_error_outputs_direct(self, runner, mocker):+ def test_run_moderation_error_outputs_direct(self, runner, mocker: MockerFixture):app_record = MagicMock(id="app1", tenant_id="tenant")session = mocker.MagicMock()@@ -78,7 +79,7 @@ class TestCompletionAppRunner:runner.direct_output.assert_called_once()runner._handle_invoke_result.assert_not_called()- def test_run_hosting_moderation_stops(self, runner, mocker):+ def test_run_hosting_moderation_stops(self, runner, mocker: MockerFixture):app_record = MagicMock(id="app1", tenant_id="tenant")session = mocker.MagicMock()@@ -97,7 +98,7 @@ class TestCompletionAppRunner:runner._handle_invoke_result.assert_not_called()- def test_run_dataset_and_external_tools_flow(self, runner, mocker):+ def test_run_dataset_and_external_tools_flow(self, runner, mocker: MockerFixture):app_record = MagicMock(id="app1", tenant_id="tenant")session = mocker.MagicMock()@@ -140,7 +141,7 @@ class TestCompletionAppRunner:assert dataset_retrieval.retrieve.call_args.kwargs["query"] == "query_from_input"runner._handle_invoke_result.assert_called_once()- def test_run_uses_low_image_detail_default(self, runner, mocker):+ def test_run_uses_low_image_detail_default(self, runner, mocker: MockerFixture):app_record = MagicMock(id="app1", tenant_id="tenant")session = mocker.MagicMock()diff --git a/api/tests/unit_tests/core/app/apps/completion/test_completion_app_config_manager.py b/api/tests/unit_tests/core/app/apps/completion/test_completion_app_config_manager.pyindex 024bd8f302c..353162be8c5 100644--- a/api/tests/unit_tests/core/app/apps/completion/test_completion_app_config_manager.py+++ b/api/tests/unit_tests/core/app/apps/completion/test_completion_app_config_manager.py@@ -1,6 +1,8 @@from types import SimpleNamespacefrom unittest.mock import MagicMock+from pytest_mock import MockerFixture+import core.app.apps.completion.app_config_manager as modulefrom core.app.app_config.entities import EasyUIBasedAppModelConfigFromfrom core.app.apps.completion.app_config_manager import CompletionAppConfigManager@@ -8,7 +10,7 @@ from models.model import AppModeclass TestCompletionAppConfigManager:- def test_get_app_config_with_override(self, mocker):+ def test_get_app_config_with_override(self, mocker: MockerFixture):app_model = MagicMock(tenant_id="tenant", id="app1", mode=AppMode.COMPLETION.value)app_model_config = MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "x"}}@@ -35,8 +37,8 @@ class TestCompletionAppConfigManager:assert result.external_data_variables == ["ext1"]assert result.app_mode == AppMode.COMPLETION- def test_get_app_config_without_override_uses_model_config(self, mocker):- app_model = MagicMock(tenant_id="tenant", id="app1", mode=AppMode.COMPLETION.value)+ def test_get_app_config_without_override_uses_model_config(self, mocker: MockerFixture):+ app_model = MagicMock(tenant_id="tenant", id="app1", mode=AppMode.COMPLETION)app_model_config = MagicMock(id="cfg1")app_model_config.to_dict.return_value = {"model": {"provider": "x"}}@@ -53,7 +55,7 @@ class TestCompletionAppConfigManager:assert result.app_model_config_from == EasyUIBasedAppModelConfigFrom.APP_LATEST_CONFIGassert result.app_model_config_dict == {"model": {"provider": "x"}}- def test_config_validate_filters_related_keys(self, mocker):+ def test_config_validate_filters_related_keys(self, mocker: MockerFixture):config = {"model": {"provider": "x"},"variables": ["v"],diff --git a/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py b/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.pyindex f2e35f9900b..de20dde6774 100644--- a/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py@@ -4,6 +4,7 @@ from unittest.mock import MagicMockimport pytestfrom pydantic import ValidationError+from pytest_mock import MockerFixtureimport core.app.apps.completion.app_generator as modulefrom core.app.apps.completion.app_generator import CompletionAppGenerator@@ -15,7 +16,7 @@ from services.errors.message import MessageNotExistsError@pytest.fixture-def generator(mocker):+def generator(mocker: MockerFixture):gen = CompletionAppGenerator()mocker.patch.object(module, "copy_current_request_context", side_effect=lambda fn: fn)@@ -69,7 +70,7 @@ class TestCompletionAppGenerator:streaming=False,)- def test_generate_success_no_file_config(self, generator, mocker):+ def test_generate_success_no_file_config(self, generator, mocker: MockerFixture):app_model_config = _build_app_model_config()mocker.patch.object(generator, "_get_app_model_config", return_value=app_model_config)mocker.patch.object(module.FileUploadConfigManager, "convert", return_value=None)@@ -99,7 +100,7 @@ class TestCompletionAppGenerator:assert result == "converted"module.file_factory.build_from_mappings.assert_not_called()- def test_generate_success_with_files(self, generator, mocker):+ def test_generate_success_with_files(self, generator, mocker: MockerFixture):app_model_config = _build_app_model_config()mocker.patch.object(generator, "_get_app_model_config", return_value=app_model_config)@@ -131,7 +132,7 @@ class TestCompletionAppGenerator:assert result == "converted"module.file_factory.build_from_mappings.assert_called_once()- def test_generate_override_model_config_debugger(self, generator, mocker):+ def test_generate_override_model_config_debugger(self, generator, mocker: MockerFixture):app_model_config = _build_app_model_config()mocker.patch.object(generator, "_get_app_model_config", return_value=app_model_config)@@ -165,7 +166,7 @@ class TestCompletionAppGenerator:assert get_app_config.call_args.kwargs["override_config_dict"] == override_config- def test_generate_more_like_this_message_not_found(self, generator, mocker):+ def test_generate_more_like_this_message_not_found(self, generator, mocker: MockerFixture):session = mocker.MagicMock()session.scalar.return_value = Nonemocker.patch.object(module.db, "session", session)@@ -178,7 +179,7 @@ class TestCompletionAppGenerator:invoke_from=InvokeFrom.WEB_APP,)- def test_generate_more_like_this_disabled(self, generator, mocker):+ def test_generate_more_like_this_disabled(self, generator, mocker: MockerFixture):app_model = _build_app_model()app_model.app_model_config = MagicMock(more_like_this=False, more_like_this_dict={"enabled": False})@@ -195,7 +196,7 @@ class TestCompletionAppGenerator:invoke_from=InvokeFrom.WEB_APP,)- def test_generate_more_like_this_app_model_config_missing(self, generator, mocker):+ def test_generate_more_like_this_app_model_config_missing(self, generator, mocker: MockerFixture):app_model = _build_app_model()app_model.app_model_config = None@@ -212,7 +213,7 @@ class TestCompletionAppGenerator:invoke_from=InvokeFrom.WEB_APP,)- def test_generate_more_like_this_message_config_none(self, generator, mocker):+ def test_generate_more_like_this_message_config_none(self, generator, mocker: MockerFixture):app_model = _build_app_model()app_model.app_model_config = MagicMock(more_like_this=True, more_like_this_dict={"enabled": True})@@ -229,7 +230,7 @@ class TestCompletionAppGenerator:invoke_from=InvokeFrom.WEB_APP,)- def test_generate_more_like_this_success(self, generator, mocker):+ def test_generate_more_like_this_success(self, generator, mocker: MockerFixture):app_model = _build_app_model()app_model.app_model_config = MagicMock(more_like_this=True, more_like_this_dict={"enabled": True})@@ -297,7 +298,7 @@ class TestCompletionAppGenerator:(RuntimeError("boom"), True),],)- def test_generate_worker_error_handling(self, generator, mocker, error, should_publish):+ def test_generate_worker_error_handling(self, generator, mocker: MockerFixture, error, should_publish):flask_app = MagicMock()flask_app.app_context.return_value = contextlib.nullcontext()diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_config_manager.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_config_manager.pyindex 5d4c9bcde06..6c1ee20ffbc 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_config_manager.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_config_manager.py@@ -1,12 +1,14 @@from types import SimpleNamespacefrom unittest.mock import MagicMock+from pytest_mock import MockerFixture+import core.app.apps.pipeline.pipeline_config_manager as modulefrom core.app.apps.pipeline.pipeline_config_manager import PipelineConfigManagerfrom models.model import AppMode-def test_get_pipeline_config(mocker):+def test_get_pipeline_config(mocker: MockerFixture):pipeline = MagicMock(tenant_id="tenant", id="pipe1")workflow = MagicMock(id="wf1")@@ -26,7 +28,7 @@ def test_get_pipeline_config(mocker):assert result.rag_pipeline_variables == ["var1"]-def test_config_validate_filters_related_keys(mocker):+def test_config_validate_filters_related_keys(mocker: MockerFixture):config = {"file_upload": {"enabled": True},"tts": {"enabled": True},diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.pyindex c36edf48fc8..dd91243a37b 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py@@ -3,6 +3,7 @@ from types import SimpleNamespacefrom unittest.mock import MagicMock, PropertyMockimport pytest+from pytest_mock import MockerFixtureimport core.app.apps.pipeline.pipeline_generator as modulefrom core.app.apps.exc import GenerateTaskStoppedError@@ -23,7 +24,7 @@ class FakeRagPipelineGenerateEntity(SimpleNamespace):@pytest.fixture-def generator(mocker):+def generator(mocker: MockerFixture):gen = module.PipelineGenerator()mocker.patch.object(module, "RagPipelineGenerateEntity", FakeRagPipelineGenerateEntity)@@ -88,7 +89,7 @@ class DummySession:return False-def test_generate_dataset_missing(generator, mocker):+def test_generate_dataset_missing(generator, mocker: MockerFixture):pipeline = _build_pipeline()pipeline.retrieve_dataset.return_value = None@@ -106,7 +107,7 @@ def test_generate_dataset_missing(generator, mocker):)-def test_generate_debugger_calls_generate(generator, mocker):+def test_generate_debugger_calls_generate(generator, mocker: MockerFixture):pipeline = _build_pipeline()workflow = _build_workflow()@@ -150,7 +151,7 @@ def test_generate_debugger_calls_generate(generator, mocker):assert result == {"result": "ok"}-def test_generate_published_pipeline_creates_documents_and_delay(generator, mocker):+def test_generate_published_pipeline_creates_documents_and_delay(generator, mocker: MockerFixture):pipeline = _build_pipeline()workflow = _build_workflow()@@ -228,7 +229,7 @@ def test_generate_published_pipeline_creates_documents_and_delay(generator, mocktask_proxy.delay.assert_called_once()-def test_generate_is_retry_calls_generate(generator, mocker):+def test_generate_is_retry_calls_generate(generator, mocker: MockerFixture):pipeline = _build_pipeline()workflow = _build_workflow()@@ -273,7 +274,7 @@ def test_generate_is_retry_calls_generate(generator, mocker):assert result == {"result": "ok"}-def test_generate_worker_handles_errors(generator, mocker):+def test_generate_worker_handles_errors(generator, mocker: MockerFixture):flask_app = MagicMock()flask_app.app_context.return_value = contextlib.nullcontext()mocker.patch.object(module, "preserve_flask_contexts", _dummy_preserve)@@ -308,7 +309,7 @@ def test_generate_worker_handles_errors(generator, mocker):queue_manager.publish_error.assert_called_once()-def test_generate_worker_sets_system_user_id_for_external_call(generator, mocker):+def test_generate_worker_sets_system_user_id_for_external_call(generator, mocker: MockerFixture):flask_app = MagicMock()flask_app.app_context.return_value = contextlib.nullcontext()mocker.patch.object(module, "preserve_flask_contexts", _dummy_preserve)@@ -341,7 +342,7 @@ def test_generate_worker_sets_system_user_id_for_external_call(generator, mockerassert module.PipelineRunner.call_args.kwargs["system_user_id"] == "session"-def test_generate_raises_when_workflow_not_found(generator, mocker):+def test_generate_raises_when_workflow_not_found(generator, mocker: MockerFixture):flask_app = MagicMock()mocker.patch.object(module, "preserve_flask_contexts", _dummy_preserve)@@ -369,7 +370,7 @@ def test_generate_raises_when_workflow_not_found(generator, mocker):)-def test_generate_success_returns_converted(generator, mocker):+def test_generate_success_returns_converted(generator, mocker: MockerFixture):flask_app = MagicMock()mocker.patch.object(module, "preserve_flask_contexts", _dummy_preserve)@@ -409,7 +410,7 @@ def test_generate_success_returns_converted(generator, mocker):assert result == "converted"-def test_single_iteration_generate_validates_inputs(generator, mocker):+def test_single_iteration_generate_validates_inputs(generator, mocker: MockerFixture):with pytest.raises(ValueError):generator.single_iteration_generate(_build_pipeline(), _build_workflow(), "", _build_user(), {})@@ -419,7 +420,7 @@ def test_single_iteration_generate_validates_inputs(generator, mocker):)-def test_single_iteration_generate_dataset_required(generator, mocker):+def test_single_iteration_generate_dataset_required(generator, mocker: MockerFixture):pipeline = _build_pipeline()pipeline.retrieve_dataset.return_value = None@@ -436,7 +437,7 @@ def test_single_iteration_generate_dataset_required(generator, mocker):)-def test_single_iteration_generate_success(generator, mocker):+def test_single_iteration_generate_success(generator, mocker: MockerFixture):pipeline = _build_pipeline()session = DummySession()@@ -476,7 +477,7 @@ def test_single_iteration_generate_success(generator, mocker):assert result == {"ok": True}-def test_single_loop_generate_success(generator, mocker):+def test_single_loop_generate_success(generator, mocker: MockerFixture):pipeline = _build_pipeline()session = DummySession()@@ -516,7 +517,7 @@ def test_single_loop_generate_success(generator, mocker):assert result == {"ok": True}-def test_handle_response_value_error_triggers_generate_task_stopped(generator, mocker):+def test_handle_response_value_error_triggers_generate_task_stopped(generator, mocker: MockerFixture):pipeline = _build_pipeline()workflow = _build_workflow()app_entity = FakeRagPipelineGenerateEntity(task_id="t")@@ -536,7 +537,7 @@ def test_handle_response_value_error_triggers_generate_task_stopped(generator, m)-def test_build_document_sets_metadata_for_builtin_fields(generator, mocker):+def test_build_document_sets_metadata_for_builtin_fields(generator, mocker: MockerFixture):class DummyDocument(SimpleNamespace):pass@@ -620,7 +621,7 @@ def test_format_datasource_info_list_missing_node_data(generator):)-def test_format_datasource_info_list_online_drive_folder(generator, mocker):+def test_format_datasource_info_list_online_drive_folder(generator, mocker: MockerFixture):workflow = MagicMock(graph_dict={"nodes": [diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_queue_manager.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_queue_manager.pyindex 9db83f5531e..abfc76afa05 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_queue_manager.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_queue_manager.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixtureimport core.app.apps.pipeline.pipeline_queue_manager as modulefrom core.app.apps.base_app_queue_manager import PublishFrom@@ -16,7 +17,7 @@ from core.app.entities.queue_entities import (from graphon.model_runtime.entities.llm_entities import LLMResult-def test_publish_sets_stop_listen_and_raises_on_stopped(mocker):+def test_publish_sets_stop_listen_and_raises_on_stopped(mocker: MockerFixture):manager = PipelineQueueManager(task_id="t", user_id="u", invoke_from=InvokeFrom.WEB_APP, app_mode="rag")manager._q = mocker.MagicMock()manager.stop_listen = mocker.MagicMock()@@ -28,7 +29,7 @@ def test_publish_sets_stop_listen_and_raises_on_stopped(mocker):manager.stop_listen.assert_called_once()-def test_publish_stop_events_trigger_stop_listen(mocker):+def test_publish_stop_events_trigger_stop_listen(mocker: MockerFixture):manager = PipelineQueueManager(task_id="t", user_id="u", invoke_from=InvokeFrom.WEB_APP, app_mode="rag")manager._q = mocker.MagicMock()manager.stop_listen = mocker.MagicMock()@@ -46,7 +47,7 @@ def test_publish_stop_events_trigger_stop_listen(mocker):manager.stop_listen.assert_called_once()-def test_publish_non_stop_event_no_stop_listen(mocker):+def test_publish_non_stop_event_no_stop_listen(mocker: MockerFixture):manager = PipelineQueueManager(task_id="t", user_id="u", invoke_from=InvokeFrom.WEB_APP, app_mode="rag")manager._q = mocker.MagicMock()manager.stop_listen = mocker.MagicMock()diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.pyindex 603062a51cb..1eed76cf843 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py@@ -22,6 +22,7 @@ from types import SimpleNamespacefrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport core.app.apps.pipeline.pipeline_runner as modulefrom core.app.apps.pipeline.pipeline_runner import PipelineRunner@@ -126,7 +127,7 @@ def test_update_document_status_on_failure(mocker, runner):session.commit.assert_called_once()-def test_run_pipeline_not_found(mocker):+def test_run_pipeline_not_found(mocker: MockerFixture):app_generate_entity = _build_app_generate_entity()app_generate_entity.invoke_from = InvokeFrom.WEB_APPapp_generate_entity.single_iteration_run = None@@ -150,7 +151,7 @@ def test_run_pipeline_not_found(mocker):runner.run()-def test_run_workflow_not_initialized(mocker):+def test_run_workflow_not_initialized(mocker: MockerFixture):app_generate_entity = _build_app_generate_entity()pipeline = MagicMock(id="pipe")@@ -174,7 +175,7 @@ def test_run_workflow_not_initialized(mocker):runner.run()-def test_run_single_iteration_path(mocker):+def test_run_single_iteration_path(mocker: MockerFixture):app_generate_entity = _build_app_generate_entity()app_generate_entity.single_iteration_run = MagicMock()@@ -223,7 +224,7 @@ def test_run_single_iteration_path(mocker):runner._handle_event.assert_called()-def test_run_normal_path_builds_graph(mocker):+def test_run_normal_path_builds_graph(mocker: MockerFixture):app_generate_entity = _build_app_generate_entity()pipeline = MagicMock(id="pipe")diff --git a/api/tests/unit_tests/core/app/apps/test_advanced_chat_app_generator.py b/api/tests/unit_tests/core/app/apps/test_advanced_chat_app_generator.pyindex f48a7fb38e2..835c9a8576a 100644--- a/api/tests/unit_tests/core/app/apps/test_advanced_chat_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/test_advanced_chat_app_generator.py@@ -45,7 +45,7 @@ def _make_generate_entity(app_config: WorkflowUIBasedAppConfig) -> AdvancedChatA@pytest.fixture(autouse=True)-def _mock_db_session(monkeypatch):+def _mock_db_session(monkeypatch: pytest.MonkeyPatch):session = MagicMock()def refresh_side_effect(obj):@@ -108,7 +108,7 @@ def test_init_generate_records_marks_existing_conversation():assert entity.is_new_conversation is False-def test_message_cycle_manager_uses_new_conversation_flag(monkeypatch):+def test_message_cycle_manager_uses_new_conversation_flag(monkeypatch: pytest.MonkeyPatch):app_config = _make_app_config()entity = _make_generate_entity(app_config)entity.conversation_id = "existing-conversation-id"diff --git a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py b/api/tests/unit_tests/core/app/apps/test_base_app_generator.pyindex b0f8b423e1e..f2a17006645 100644--- a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/test_base_app_generator.py@@ -369,7 +369,7 @@ def test_validate_inputs_optional_file_with_empty_string_ignores_default():class TestBaseAppGeneratorExtras:- def test_prepare_user_inputs_converts_files_and_lists(self, monkeypatch):+ def test_prepare_user_inputs_converts_files_and_lists(self, monkeypatch: pytest.MonkeyPatch):base_app_generator = BaseAppGenerator()variables = [diff --git a/api/tests/unit_tests/core/app/apps/test_base_app_runner.py b/api/tests/unit_tests/core/app/apps/test_base_app_runner.pyindex 17de39ca99f..c6eedf7be7e 100644--- a/api/tests/unit_tests/core/app/apps/test_base_app_runner.py+++ b/api/tests/unit_tests/core/app/apps/test_base_app_runner.py@@ -42,7 +42,7 @@ class _QueueRecorder:class TestAppRunner:- def test_recalc_llm_max_tokens_updates_parameters(self, monkeypatch):+ def test_recalc_llm_max_tokens_updates_parameters(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()model_schema = SimpleNamespace(@@ -65,7 +65,7 @@ class TestAppRunner:assert model_config.parameters["max_tokens"] == 20- def test_recalc_llm_max_tokens_returns_minus_one_when_no_context(self, monkeypatch):+ def test_recalc_llm_max_tokens_returns_minus_one_when_no_context(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()model_schema = SimpleNamespace(@@ -86,7 +86,7 @@ class TestAppRunner:assert runner.recalc_llm_max_tokens(model_config, prompt_messages=[]) == -1- def test_direct_output_streaming_publishes_chunks_and_end(self, monkeypatch):+ def test_direct_output_streaming_publishes_chunks_and_end(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()queue = _QueueRecorder()app_generate_entity = SimpleNamespace(model_conf=SimpleNamespace(model="mock"), stream=True)@@ -133,7 +133,7 @@ class TestAppRunner:stream=True,)- def test_organize_prompt_messages_simple_template(self, monkeypatch):+ def test_organize_prompt_messages_simple_template(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()model_config = SimpleNamespace(mode="chat", stop=["STOP"])prompt_template_entity = PromptTemplateEntity(@@ -158,7 +158,7 @@ class TestAppRunner:assert prompt_messages == ["simple-message"]assert stop == ["simple-stop"]- def test_organize_prompt_messages_advanced_completion_template(self, monkeypatch):+ def test_organize_prompt_messages_advanced_completion_template(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()model_config = SimpleNamespace(mode="completion", stop=["<END>"])captured: dict[str, object] = {}@@ -191,7 +191,7 @@ class TestAppRunner:assert memory_config.role_prefix.user == "U"assert memory_config.role_prefix.assistant == "A"- def test_organize_prompt_messages_advanced_chat_template(self, monkeypatch):+ def test_organize_prompt_messages_advanced_chat_template(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()model_config = SimpleNamespace(mode="chat", stop=["<END>"])captured: dict[str, object] = {}@@ -245,7 +245,7 @@ class TestAppRunner:files=[],)- def test_handle_invoke_result_stream_routes_chunks_and_builds_message(self, monkeypatch):+ def test_handle_invoke_result_stream_routes_chunks_and_builds_message(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()queue = _QueueRecorder()warning_logger = MagicMock()@@ -284,7 +284,7 @@ class TestAppRunner:assert queue.events[-1].llm_result.message.content == "abc"warning_logger.assert_called_once()- def test_handle_invoke_result_stream_agent_mode_handles_multimodal_errors(self, monkeypatch):+ def test_handle_invoke_result_stream_agent_mode_handles_multimodal_errors(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()queue = _QueueRecorder()exception_logger = MagicMock()@@ -331,7 +331,7 @@ class TestAppRunner:assert queue.events[-1].llm_result.usage == usageexception_logger.assert_called_once()- def test_handle_multimodal_image_content_fallback_return_branch(self, monkeypatch):+ def test_handle_multimodal_image_content_fallback_return_branch(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()class _ToggleBool:@@ -367,7 +367,7 @@ class TestAppRunner:db_session.add.assert_not_called()queue_manager.publish.assert_not_called()- def test_check_hosting_moderation_direct_output_called(self, monkeypatch):+ def test_check_hosting_moderation_direct_output_called(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()queue = _QueueRecorder()app_generate_entity = SimpleNamespace(stream=False)@@ -388,7 +388,7 @@ class TestAppRunner:assert result is Trueassert direct_output.called- def test_fill_in_inputs_from_external_data_tools(self, monkeypatch):+ def test_fill_in_inputs_from_external_data_tools(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()monkeypatch.setattr("core.app.apps.base_app_runner.ExternalDataFetch.fetch",@@ -405,7 +405,7 @@ class TestAppRunner:assert result == {"foo": "bar"}- def test_moderation_for_inputs_returns_result(self, monkeypatch):+ def test_moderation_for_inputs_returns_result(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()monkeypatch.setattr("core.app.apps.base_app_runner.InputModeration.check",@@ -424,7 +424,7 @@ class TestAppRunner:assert result == (True, {}, "")- def test_query_app_annotations_to_reply(self, monkeypatch):+ def test_query_app_annotations_to_reply(self, monkeypatch: pytest.MonkeyPatch):runner = AppRunner()monkeypatch.setattr("core.app.apps.base_app_runner.AnnotationReplyFeature.query",diff --git a/api/tests/unit_tests/core/app/apps/test_message_based_app_generator.py b/api/tests/unit_tests/core/app/apps/test_message_based_app_generator.pyindex 1250ac5ecf9..6a9b5e76194 100644--- a/api/tests/unit_tests/core/app/apps/test_message_based_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/test_message_based_app_generator.py@@ -85,7 +85,7 @@ def _make_chat_generate_entity(app_config: EasyUIBasedAppConfig) -> ChatAppGener@pytest.fixture(autouse=True)-def _mock_db_session(monkeypatch):+def _mock_db_session(monkeypatch: pytest.MonkeyPatch):session = MagicMock()def refresh_side_effect(obj):@@ -130,7 +130,7 @@ def test_init_generate_records_sets_conversation_fields_for_chat_entity():class TestMessageBasedAppGeneratorExtras:- def test_handle_response_closed_file_raises_stopped(self, monkeypatch):+ def test_handle_response_closed_file_raises_stopped(self, monkeypatch: pytest.MonkeyPatch):generator = MessageBasedAppGenerator()class _Pipeline:@@ -155,7 +155,7 @@ class TestMessageBasedAppGeneratorExtras:stream=False,)- def test_get_app_model_config_requires_valid_config(self, monkeypatch):+ def test_get_app_model_config_requires_valid_config(self, monkeypatch: pytest.MonkeyPatch):generator = MessageBasedAppGenerator()app_model = SimpleNamespace(id="app", app_model_config_id=None, app_model_config=None)diff --git a/api/tests/unit_tests/core/app/apps/test_pause_resume.py b/api/tests/unit_tests/core/app/apps/test_pause_resume.pyindex 6104b8d6ca2..aa71f4d9c40 100644--- a/api/tests/unit_tests/core/app/apps/test_pause_resume.py+++ b/api/tests/unit_tests/core/app/apps/test_pause_resume.py@@ -3,6 +3,8 @@ import timefrom types import ModuleType, SimpleNamespacefrom typing import Any+from pytest_mock import MockerFixture+import graphon.nodes.human_input.entities # noqa: F401from core.app.apps.advanced_chat import app_generator as adv_app_gen_modulefrom core.app.apps.workflow import app_generator as wf_app_gen_module@@ -101,7 +103,7 @@ class _StubToolNode(Node[_StubToolNodeData]):yield self._convert_node_run_result_to_graph_node_event(result)-def _patch_tool_node(mocker):+def _patch_tool_node(mocker: MockerFixture):original_resolve_node_class = node_factory_module.resolve_workflow_node_classdef _patched_resolve_node_class(*, node_type: NodeType, node_version: str) -> type[Node]:@@ -196,7 +198,7 @@ def _node_successes(events: list[GraphEngineEvent]) -> list[str]:return [evt.node_id for evt in events if isinstance(evt, NodeRunSucceededEvent)]-def test_workflow_app_pause_resume_matches_baseline(mocker):+def test_workflow_app_pause_resume_matches_baseline(mocker: MockerFixture):_patch_tool_node(mocker)baseline_state = _build_runtime_state("baseline")@@ -236,7 +238,7 @@ def test_workflow_app_pause_resume_matches_baseline(mocker):assert resumed_state.outputs == baseline_outputs-def test_advanced_chat_pause_resume_matches_baseline(mocker):+def test_advanced_chat_pause_resume_matches_baseline(mocker: MockerFixture):_patch_tool_node(mocker)baseline_state = _build_runtime_state("adv-baseline")diff --git a/api/tests/unit_tests/core/app/apps/test_streaming_utils.py b/api/tests/unit_tests/core/app/apps/test_streaming_utils.pyindex 58f0e47a4b8..12f3ed9f078 100644--- a/api/tests/unit_tests/core/app/apps/test_streaming_utils.py+++ b/api/tests/unit_tests/core/app/apps/test_streaming_utils.py@@ -54,7 +54,7 @@ class FakeTopic:return self._state["subscribed"]-def test_retrieve_events_calls_on_subscribe_after_subscription(monkeypatch):+def test_retrieve_events_calls_on_subscribe_after_subscription(monkeypatch: pytest.MonkeyPatch):topic = FakeTopic()def fake_get_response_topic(cls, app_mode, workflow_run_id):@@ -92,7 +92,7 @@ def test_normalize_terminal_events_empty_values():assert _normalize_terminal_events([]) == set({})-def test_stream_topic_events_emits_ping_and_idle_timeout(monkeypatch):+def test_stream_topic_events_emits_ping_and_idle_timeout(monkeypatch: pytest.MonkeyPatch):topic = FakeTopic()times = [1000.0, 1000.0, 1001.0, 1001.0, 1002.0]diff --git a/api/tests/unit_tests/core/app/apps/test_workflow_app_generator.py b/api/tests/unit_tests/core/app/apps/test_workflow_app_generator.pyindex 7e8367c6c44..0e9f8b6f355 100644--- a/api/tests/unit_tests/core/app/apps/test_workflow_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/test_workflow_app_generator.py@@ -1,6 +1,8 @@from types import SimpleNamespacefrom unittest.mock import MagicMock+from pytest_mock import MockerFixture+from core.app.apps.workflow.app_generator import SKIP_PREPARE_USER_INPUTS_KEY, WorkflowAppGenerator@@ -22,7 +24,7 @@ def test_should_prepare_user_inputs_keeps_validation_when_flag_false():assert WorkflowAppGenerator()._should_prepare_user_inputs(args)-def test_resume_delegates_to_generate(mocker):+def test_resume_delegates_to_generate(mocker: MockerFixture):generator = WorkflowAppGenerator()mock_generate = mocker.patch.object(generator, "_generate", return_value="ok")@@ -52,7 +54,7 @@ def test_resume_delegates_to_generate(mocker):assert kwargs["invoke_from"] == "debugger"-def test_generate_appends_pause_layer_and_forwards_state(mocker):+def test_generate_appends_pause_layer_and_forwards_state(mocker: MockerFixture):generator = WorkflowAppGenerator()mock_queue_manager = MagicMock()@@ -124,7 +126,7 @@ def test_generate_appends_pause_layer_and_forwards_state(mocker):assert worker_kwargs["kwargs"]["graph_runtime_state"] is graph_runtime_state-def test_resume_path_runs_worker_with_runtime_state(mocker):+def test_resume_path_runs_worker_with_runtime_state(mocker: MockerFixture):generator = WorkflowAppGenerator()runtime_state = MagicMock(name="runtime-state")diff --git a/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py b/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.pyindex 58c7bfa4bc2..4a0d4f490e5 100644--- a/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py+++ b/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py@@ -90,7 +90,7 @@ class TestWorkflowBasedAppRunner:with pytest.raises(ValueError, match="Neither single_iteration_run nor single_loop_run"):runner._prepare_single_node_execution(workflow, None, None, user_id="00000000-0000-0000-0000-000000000001")- def test_get_graph_and_variable_pool_for_single_node_run(self, monkeypatch):+ def test_get_graph_and_variable_pool_for_single_node_run(self, monkeypatch: pytest.MonkeyPatch):runner = WorkflowBasedAppRunner(queue_manager=SimpleNamespace(), app_id="app")graph_runtime_state = GraphRuntimeState(variable_pool=VariablePool(system_variables=default_system_variables()),@@ -142,7 +142,9 @@ class TestWorkflowBasedAppRunner:assert graph is not Noneassert variable_pool is graph_runtime_state.variable_pool- def test_get_graph_and_variable_pool_preloads_constructor_variables_before_graph_init(self, monkeypatch):+ def test_get_graph_and_variable_pool_preloads_constructor_variables_before_graph_init(+ self, monkeypatch: pytest.MonkeyPatch+ ):variable_loader = SimpleNamespace(load_variables=lambda selectors: ([@@ -232,7 +234,7 @@ class TestWorkflowBasedAppRunner:assert graph is not Noneassert variable_pool.get(["sys", "conversation_id"]).value == "conv-1"- def test_handle_graph_run_events_and_pause_notifications(self, monkeypatch):+ def test_handle_graph_run_events_and_pause_notifications(self, monkeypatch: pytest.MonkeyPatch):published: list[object] = []class _QueueManager:diff --git a/api/tests/unit_tests/core/app/apps/workflow/test_app_generator_extra.py b/api/tests/unit_tests/core/app/apps/workflow/test_app_generator_extra.pyindex 09ad078a70d..320189143ec 100644--- a/api/tests/unit_tests/core/app/apps/workflow/test_app_generator_extra.py+++ b/api/tests/unit_tests/core/app/apps/workflow/test_app_generator_extra.py@@ -67,7 +67,7 @@ class TestWorkflowAppGeneratorValidation:class TestWorkflowAppGeneratorHandleResponse:- def test_handle_response_closed_file_raises_stopped(self, monkeypatch):+ def test_handle_response_closed_file_raises_stopped(self, monkeypatch: pytest.MonkeyPatch):generator = WorkflowAppGenerator()app_config = WorkflowUIBasedAppConfig(@@ -116,7 +116,7 @@ class TestWorkflowAppGeneratorHandleResponse:class TestWorkflowAppGeneratorGenerate:- def test_generate_skips_prepare_inputs_when_flag_set(self, monkeypatch):+ def test_generate_skips_prepare_inputs_when_flag_set(self, monkeypatch: pytest.MonkeyPatch):generator = WorkflowAppGenerator()app_config = WorkflowUIBasedAppConfig(diff --git a/api/tests/unit_tests/core/app/apps/workflow/test_generate_task_pipeline_core.py b/api/tests/unit_tests/core/app/apps/workflow/test_generate_task_pipeline_core.pyindex 0bcc1029b0e..1311d5e9cb7 100644--- a/api/tests/unit_tests/core/app/apps/workflow/test_generate_task_pipeline_core.py+++ b/api/tests/unit_tests/core/app/apps/workflow/test_generate_task_pipeline_core.py@@ -187,7 +187,7 @@ class TestWorkflowGenerateTaskPipeline:assert isinstance(responses[0], ValueError)- def test_handle_workflow_started_event_sets_run_id(self, monkeypatch):+ def test_handle_workflow_started_event_sets_run_id(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._graph_runtime_state = GraphRuntimeState(variable_pool=build_test_variable_pool(variables=build_system_variables(workflow_execution_id="run-id")),@@ -408,7 +408,7 @@ class TestWorkflowGenerateTaskPipeline:assert list(pipeline._handle_human_input_form_timeout_event(timeout_event)) == ["timeout"]assert list(pipeline._handle_agent_log_event(agent_event)) == ["log"]- def test_wrapper_process_stream_response_emits_audio_end(self, monkeypatch):+ def test_wrapper_process_stream_response_emits_audio_end(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._workflow_features_dict = {"text_to_speech": {"enabled": True, "autoPlay": "enabled", "voice": "v", "language": "en"}@@ -560,7 +560,7 @@ class TestWorkflowGenerateTaskPipeline:responses = list(pipeline._wrapper_process_stream_response())assert responses == [PingStreamResponse(task_id="task")]- def test_wrapper_process_stream_response_final_audio_none_then_finish(self, monkeypatch):+ def test_wrapper_process_stream_response_final_audio_none_then_finish(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._workflow_features_dict = {"text_to_speech": {"enabled": True, "autoPlay": "enabled", "voice": "v", "language": "en"}@@ -597,7 +597,7 @@ class TestWorkflowGenerateTaskPipeline:assert sleep_spyassert any(isinstance(item, MessageAudioEndStreamResponse) for item in responses)- def test_wrapper_process_stream_response_handles_audio_exception(self, monkeypatch):+ def test_wrapper_process_stream_response_handles_audio_exception(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()pipeline._workflow_features_dict = {"text_to_speech": {"enabled": True, "autoPlay": "enabled", "voice": "v", "language": "en"}@@ -633,7 +633,7 @@ class TestWorkflowGenerateTaskPipeline:assert logger_exceptionassert any(isinstance(item, MessageAudioEndStreamResponse) for item in responses)- def test_database_session_rolls_back_on_error(self, monkeypatch):+ def test_database_session_rolls_back_on_error(self, monkeypatch: pytest.MonkeyPatch):pipeline = _make_pipeline()calls = {"enter": 0, "exit_exc": None}diff --git a/api/tests/unit_tests/core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline_core.py b/api/tests/unit_tests/core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline_core.pyindex a20d89d8077..f10e0084d03 100644--- a/api/tests/unit_tests/core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline_core.py+++ b/api/tests/unit_tests/core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline_core.py@@ -143,7 +143,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert pipeline._listen_audio_msg(publisher=None, task_id="task") is None- def test_process_stream_response_handles_chunks_and_end(self, monkeypatch):+ def test_process_stream_response_handles_chunks_and_end(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))@@ -245,7 +245,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert any(isinstance(event, QueueLLMChunkEvent) for event in events)assert any(isinstance(event, QueueStopEvent) for event in events)- def test_handle_stop_updates_usage(self, monkeypatch):+ def test_handle_stop_updates_usage(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))@@ -313,7 +313,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert pipeline._task_state.llm_result.usage.prompt_tokens == 10assert pipeline._task_state.llm_result.usage.completion_tokens == 5- def test_record_files_builds_file_payloads(self, monkeypatch):+ def test_record_files_builds_file_payloads(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))@@ -405,7 +405,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert filesassert len(files) == 3- def test_process_stream_response_handles_annotation_and_error(self, monkeypatch):+ def test_process_stream_response_handles_annotation_and_error(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))@@ -472,7 +472,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert isinstance(responses[-1], ValueError)assert pipeline._task_state.llm_result.message.content == "annotatedagent"- def test_agent_thought_to_stream_response_returns_payload(self, monkeypatch):+ def test_agent_thought_to_stream_response_returns_payload(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))@@ -681,7 +681,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert responses == ["payload"]- def test_wrapper_process_stream_response_with_tts_publisher(self, monkeypatch):+ def test_wrapper_process_stream_response_with_tts_publisher(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))entity = _make_entity(ChatAppGenerateEntity, AppMode.CHAT)@@ -715,7 +715,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert responses[1] == "payload"assert isinstance(responses[-1], MessageAudioEndStreamResponse)- def test_wrapper_process_stream_response_timeout_yields_audio_chunk(self, monkeypatch):+ def test_wrapper_process_stream_response_timeout_yields_audio_chunk(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))entity = _make_entity(ChatAppGenerateEntity, AppMode.CHAT)@@ -756,7 +756,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert any(isinstance(item, MessageAudioStreamResponse) for item in responses)assert isinstance(responses[-1], MessageAudioEndStreamResponse)- def test_process_stream_response_handles_stop_event_and_output_replacement(self, monkeypatch):+ def test_process_stream_response_handles_stop_event_and_output_replacement(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(@@ -896,7 +896,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert list(pipeline._process_stream_response(publisher=None)) == []- def test_save_message_persists_fields_and_emits_trace(self, monkeypatch):+ def test_save_message_persists_fields_and_emits_trace(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(@@ -981,7 +981,7 @@ class TestEasyUiBasedGenerateTaskPipeline:with pytest.raises(ValueError, match="Conversation conv not found"):pipeline._save_message(session=session)- def test_message_end_to_stream_response_includes_usage_metadata(self, monkeypatch):+ def test_message_end_to_stream_response_includes_usage_metadata(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(@@ -1021,7 +1021,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert response.id == "msg"assert response.metadata["usage"]["prompt_tokens"] == 1- def test_record_files_returns_none_when_message_has_no_files(self, monkeypatch):+ def test_record_files_returns_none_when_message_has_no_files(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(@@ -1059,7 +1059,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert response.files is None- def test_record_files_handles_local_fallback_and_tool_url_variants(self, monkeypatch):+ def test_record_files_handles_local_fallback_and_tool_url_variants(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(@@ -1155,7 +1155,7 @@ class TestEasyUiBasedGenerateTaskPipeline:assert response.id == "msg"assert response.answer == "hello"- def test_agent_thought_to_stream_response_returns_none_when_not_found(self, monkeypatch):+ def test_agent_thought_to_stream_response_returns_none_when_not_found(self, monkeypatch: pytest.MonkeyPatch):conversation = SimpleNamespace(id="conv", mode=AppMode.CHAT)message = SimpleNamespace(id="msg", created_at=datetime.now(UTC))pipeline = EasyUIBasedGenerateTaskPipeline(diff --git a/api/tests/unit_tests/core/app/workflow/test_node_factory.py b/api/tests/unit_tests/core/app/workflow/test_node_factory.pyindex 30a068f4c5a..7c9f1741290 100644--- a/api/tests/unit_tests/core/app/workflow/test_node_factory.py+++ b/api/tests/unit_tests/core/app/workflow/test_node_factory.py@@ -46,7 +46,7 @@ class TestDifyNodeFactory:lambda **_kwargs: node_class,)- def _factory(self, monkeypatch):+ def _factory(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.workflow.node_factory.dify_config.CODE_MAX_STRING_LENGTH", 10)monkeypatch.setattr("core.workflow.node_factory.dify_config.CODE_MAX_NUMBER", 10)monkeypatch.setattr("core.workflow.node_factory.dify_config.CODE_MIN_NUMBER", -10)@@ -72,20 +72,20 @@ class TestDifyNodeFactory:graph_runtime_state=SimpleNamespace(),)- def test_create_node_unknown_type(self, monkeypatch):+ def test_create_node_unknown_type(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)with pytest.raises(ValueError):factory.create_node({"id": "node-1", "data": {"type": "unknown"}})- def test_create_node_missing_mapping(self, monkeypatch):+ def test_create_node_missing_mapping(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)monkeypatch.setattr("core.workflow.node_factory.get_node_type_classes_mapping", lambda: {})with pytest.raises(ValueError):factory.create_node({"id": "node-1", "data": {"type": BuiltinNodeTypes.START}})- def test_create_node_missing_latest_class(self, monkeypatch):+ def test_create_node_missing_latest_class(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)monkeypatch.setattr("core.workflow.node_factory.get_node_type_classes_mapping",@@ -96,7 +96,7 @@ class TestDifyNodeFactory:with pytest.raises(ValueError):factory.create_node({"id": "node-1", "data": {"type": BuiltinNodeTypes.START}})- def test_create_node_selects_versioned_class(self, monkeypatch):+ def test_create_node_selects_versioned_class(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)selected_versions: list[tuple[str, str]] = []@@ -115,7 +115,7 @@ class TestDifyNodeFactory:assert node.id == "node-1"assert selected_versions == [("snapshot", "called")]- def test_create_node_code_branch(self, monkeypatch):+ def test_create_node_code_branch(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)self._stub_node_resolution(monkeypatch, DummyCodeNode)@@ -124,7 +124,7 @@ class TestDifyNodeFactory:assert isinstance(node, DummyCodeNode)assert node.id == "node-1"- def test_create_node_template_transform_branch(self, monkeypatch):+ def test_create_node_template_transform_branch(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)self._stub_node_resolution(monkeypatch, DummyTemplateTransformNode)@@ -133,7 +133,7 @@ class TestDifyNodeFactory:assert isinstance(node, DummyTemplateTransformNode)assert "jinja2_template_renderer" in node.kwargs- def test_create_node_http_request_branch(self, monkeypatch):+ def test_create_node_http_request_branch(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)self._stub_node_resolution(monkeypatch, DummyHttpRequestNode)@@ -142,7 +142,7 @@ class TestDifyNodeFactory:assert isinstance(node, DummyHttpRequestNode)assert "http_request_config" in node.kwargs- def test_create_node_knowledge_retrieval_branch(self, monkeypatch):+ def test_create_node_knowledge_retrieval_branch(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)self._stub_node_resolution(monkeypatch, DummyKnowledgeRetrievalNode)@@ -151,7 +151,7 @@ class TestDifyNodeFactory:assert isinstance(node, DummyKnowledgeRetrievalNode)assert node.kwargs == {}- def test_create_node_document_extractor_branch(self, monkeypatch):+ def test_create_node_document_extractor_branch(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory(monkeypatch)self._stub_node_resolution(monkeypatch, DummyDocumentExtractorNode)diff --git a/api/tests/unit_tests/core/app/workflow/test_observability_layer_extra.py b/api/tests/unit_tests/core/app/workflow/test_observability_layer_extra.pyindex 82552470a95..04ce5249049 100644--- a/api/tests/unit_tests/core/app/workflow/test_observability_layer_extra.py+++ b/api/tests/unit_tests/core/app/workflow/test_observability_layer_extra.py@@ -2,12 +2,14 @@ from __future__ import annotationsfrom types import SimpleNamespace+import pytest+from core.app.workflow.layers.observability import ObservabilityLayerfrom graphon.enums import BuiltinNodeTypesclass TestObservabilityLayerExtras:- def test_init_tracer_enabled_sets_tracer(self, monkeypatch):+ def test_init_tracer_enabled_sets_tracer(self, monkeypatch: pytest.MonkeyPatch):tracer = object()monkeypatch.setattr("core.app.workflow.layers.observability.dify_config.ENABLE_OTEL", True)monkeypatch.setattr("core.app.workflow.layers.observability.is_instrument_flag_enabled", lambda: False)@@ -18,7 +20,7 @@ class TestObservabilityLayerExtras:assert layer._is_disabled is Falseassert layer._tracer is tracer- def test_init_tracer_disables_when_get_tracer_fails(self, monkeypatch, caplog):+ def test_init_tracer_disables_when_get_tracer_fails(self, monkeypatch: pytest.MonkeyPatch, caplog):monkeypatch.setattr("core.app.workflow.layers.observability.dify_config.ENABLE_OTEL", True)monkeypatch.setattr("core.app.workflow.layers.observability.is_instrument_flag_enabled", lambda: False)@@ -33,7 +35,7 @@ class TestObservabilityLayerExtras:assert layer._tracer is Noneassert "Failed to get OpenTelemetry tracer" in caplog.text- def test_init_tracer_disables_when_otel_disabled(self, monkeypatch):+ def test_init_tracer_disables_when_otel_disabled(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.app.workflow.layers.observability.dify_config.ENABLE_OTEL", False)monkeypatch.setattr("core.app.workflow.layers.observability.is_instrument_flag_enabled", lambda: False)@@ -143,7 +145,7 @@ class TestObservabilityLayerExtras:assert layer._node_contexts == {}- def test_on_node_run_end_calls_span_end(self, monkeypatch):+ def test_on_node_run_end_calls_span_end(self, monkeypatch: pytest.MonkeyPatch):layer = ObservabilityLayer()layer._is_disabled = Falseended: list[str] = []@@ -164,7 +166,7 @@ class TestObservabilityLayerExtras:assert ended == ["ended"]assert "exec" not in layer._node_contexts- def test_on_node_run_end_logs_detach_failure(self, monkeypatch, caplog):+ def test_on_node_run_end_logs_detach_failure(self, monkeypatch: pytest.MonkeyPatch, caplog):layer = ObservabilityLayer()layer._is_disabled = False@@ -186,7 +188,7 @@ class TestObservabilityLayerExtras:assert "Failed to detach OpenTelemetry token" in caplog.textassert "exec" not in layer._node_contexts- def test_on_node_run_start_and_end_creates_span(self, monkeypatch):+ def test_on_node_run_start_and_end_creates_span(self, monkeypatch: pytest.MonkeyPatch):layer = ObservabilityLayer()layer._is_disabled = Falsediff --git a/api/tests/unit_tests/core/app/workflow/test_persistence_layer.py b/api/tests/unit_tests/core/app/workflow/test_persistence_layer.pyindex cacb4dd4fa9..23fe6820170 100644--- a/api/tests/unit_tests/core/app/workflow/test_persistence_layer.py+++ b/api/tests/unit_tests/core/app/workflow/test_persistence_layer.py@@ -120,7 +120,7 @@ class TestWorkflowPersistenceLayer:with pytest.raises(ValueError, match="workflow_execution_id must be provided"):layer._get_execution_id()- def test_prepare_workflow_inputs_excludes_conversation_id(self, monkeypatch):+ def test_prepare_workflow_inputs_excludes_conversation_id(self, monkeypatch: pytest.MonkeyPatch):layer, _, _, _ = _make_layer()monkeypatch.setattr(diff --git a/api/tests/unit_tests/core/base/test_app_generator_tts_publisher.py b/api/tests/unit_tests/core/base/test_app_generator_tts_publisher.pyindex 7b433ab57b9..1125ce6dbc5 100644--- a/api/tests/unit_tests/core/base/test_app_generator_tts_publisher.py+++ b/api/tests/unit_tests/core/base/test_app_generator_tts_publisher.py@@ -3,6 +3,7 @@ import queuefrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.base.tts.app_generator_tts_publisher import (AppGeneratorTTSPublisher,@@ -17,7 +18,7 @@ from core.base.tts.app_generator_tts_publisher import (@pytest.fixture-def mock_model_instance(mocker):+def mock_model_instance(mocker: MockerFixture):model = mocker.MagicMock()model.invoke_tts.return_value = [b"audio1", b"audio2"]model.get_tts_voices.return_value = [{"value": "voice1"}, {"value": "voice2"}]@@ -33,7 +34,7 @@ def mock_model_manager(mocker, mock_model_instance):@pytest.fixture(autouse=True)-def patch_threads(mocker):+def patch_threads(mocker: MockerFixture):"""Prevent real threads from starting during tests"""mocker.patch("threading.Thread.start", return_value=None)@@ -114,7 +115,7 @@ class TestProcessFuture:finish = audio_queue.get()assert finish.status == "finish"- def test_process_future_exception(self, mocker):+ def test_process_future_exception(self, mocker: MockerFixture):future_queue = queue.Queue()audio_queue = queue.Queue()@@ -222,7 +223,7 @@ class TestAppGeneratorTTSPublisher:publisher.executor.submit.assert_not_called()- def test_runtime_sentence_threshold_triggers_submit(self, mock_model_manager, mocker):+ def test_runtime_sentence_threshold_triggers_submit(self, mock_model_manager, mocker: MockerFixture):publisher = AppGeneratorTTSPublisher("tenant", "voice1")publisher.executor = MagicMock()@@ -297,7 +298,7 @@ class TestAppGeneratorTTSPublisher:publisher.executor.submit.assert_not_called()- def test_runtime_handles_agent_message_event_list_content(self, mock_model_manager, mocker):+ def test_runtime_handles_agent_message_event_list_content(self, mock_model_manager, mocker: MockerFixture):publisher = AppGeneratorTTSPublisher("tenant", "voice1")publisher.executor = MagicMock()@@ -332,7 +333,7 @@ class TestAppGeneratorTTSPublisher:assert publisher.msg_text == "Hello "- def test_runtime_handles_agent_message_event_empty_content(self, mock_model_manager, mocker):+ def test_runtime_handles_agent_message_event_empty_content(self, mock_model_manager, mocker: MockerFixture):publisher = AppGeneratorTTSPublisher("tenant", "voice1")publisher.executor = MagicMock()@@ -358,7 +359,7 @@ class TestAppGeneratorTTSPublisher:assert publisher.msg_text == ""- def test_runtime_resets_msg_text_when_text_tmp_not_str(self, mock_model_manager, mocker):+ def test_runtime_resets_msg_text_when_text_tmp_not_str(self, mock_model_manager, mocker: MockerFixture):publisher = AppGeneratorTTSPublisher("tenant", "voice1")publisher.executor = MagicMock()diff --git a/api/tests/unit_tests/core/callback_handler/test_agent_tool_callback_handler.py b/api/tests/unit_tests/core/callback_handler/test_agent_tool_callback_handler.pyindex 4c1aa335406..f9b3b1864e0 100644--- a/api/tests/unit_tests/core/callback_handler/test_agent_tool_callback_handler.py+++ b/api/tests/unit_tests/core/callback_handler/test_agent_tool_callback_handler.py@@ -1,8 +1,10 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport core.callback_handler.agent_tool_callback_handler as module+from core.callback_handler.agent_tool_callback_handler import DifyAgentCallbackHandler# -----------------------------# Fixtures@@ -10,17 +12,17 @@ import core.callback_handler.agent_tool_callback_handler as module@pytest.fixture-def enable_debug(mocker):+def enable_debug(mocker: MockerFixture):mocker.patch.object(module.dify_config, "DEBUG", True)@pytest.fixture-def disable_debug(mocker):+def disable_debug(mocker: MockerFixture):mocker.patch.object(module.dify_config, "DEBUG", False)@pytest.fixture-def mock_print(mocker):+def mock_print(mocker: MockerFixture):return mocker.patch("builtins.print")@@ -71,7 +73,7 @@ class TestPrintText:module.print_text("hello")mock_print.assert_called_once_with("hello", end="", file=None)- def test_print_text_with_color(self, mocker, mock_print):+ def test_print_text_with_color(self, mocker: MockerFixture, mock_print):mock_get_color = mocker.patch("core.callback_handler.agent_tool_callback_handler.get_colored_text",return_value="colored_text",@@ -82,7 +84,7 @@ class TestPrintText:mock_get_color.assert_called_once_with("hello", "green")mock_print.assert_called_once_with("colored_text", end="", file=None)- def test_print_text_with_file_flush(self, mocker):+ def test_print_text_with_file_flush(self, mocker: MockerFixture):mock_file = MagicMock()mock_print = mocker.patch("builtins.print")@@ -107,21 +109,25 @@ class TestDifyAgentCallbackHandler:assert handler.color == "green"assert handler.current_loop == 1- def test_on_tool_start_debug_enabled(self, handler, enable_debug, mocker):+ def test_on_tool_start_debug_enabled(self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_tool_start("tool1", {"a": 1})mock_print_text.assert_called()- def test_on_tool_start_debug_disabled(self, handler, disable_debug, mocker):+ def test_on_tool_start_debug_disabled(+ self, handler: DifyAgentCallbackHandler, disable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_tool_start("tool1", {"a": 1})mock_print_text.assert_not_called()- def test_on_tool_end_debug_enabled_and_trace(self, handler, enable_debug, mocker):+ def test_on_tool_end_debug_enabled_and_trace(+ self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")mock_trace_manager = MagicMock()@@ -137,7 +143,9 @@ class TestDifyAgentCallbackHandler:assert mock_print_text.call_count >= 1mock_trace_manager.add_trace_task.assert_called_once()- def test_on_tool_end_without_trace_manager(self, handler, enable_debug, mocker):+ def test_on_tool_end_without_trace_manager(+ self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_tool_end(@@ -148,14 +156,16 @@ class TestDifyAgentCallbackHandler:assert mock_print_text.call_count >= 1- def test_on_tool_error_debug_enabled(self, handler, enable_debug, mocker):+ def test_on_tool_error_debug_enabled(self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_tool_error(Exception("error"))mock_print_text.assert_called_once()- def test_on_tool_error_debug_disabled(self, handler, disable_debug, mocker):+ def test_on_tool_error_debug_disabled(+ self, handler: DifyAgentCallbackHandler, disable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_tool_error(Exception("error"))@@ -163,14 +173,16 @@ class TestDifyAgentCallbackHandler:mock_print_text.assert_not_called()@pytest.mark.parametrize("thought", ["thinking", ""])- def test_on_agent_start(self, handler, enable_debug, mocker, thought):+ def test_on_agent_start(self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture, thought):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_agent_start(thought)mock_print_text.assert_called()- def test_on_agent_finish_increments_loop(self, handler, enable_debug, mocker):+ def test_on_agent_finish_increments_loop(+ self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")current_loop = handler.current_loop@@ -179,19 +191,21 @@ class TestDifyAgentCallbackHandler:assert handler.current_loop == current_loop + 1mock_print_text.assert_called()- def test_on_datasource_start_debug_enabled(self, handler, enable_debug, mocker):+ def test_on_datasource_start_debug_enabled(+ self, handler: DifyAgentCallbackHandler, enable_debug, mocker: MockerFixture+ ):mock_print_text = mocker.patch("core.callback_handler.agent_tool_callback_handler.print_text")handler.on_datasource_start("ds1", {"x": 1})mock_print_text.assert_called_once()- def test_ignore_agent_property(self, disable_debug, handler):+ def test_ignore_agent_property(self, disable_debug, handler: DifyAgentCallbackHandler):assert handler.ignore_agent is True- def test_ignore_chat_model_property(self, disable_debug, handler):+ def test_ignore_chat_model_property(self, disable_debug, handler: DifyAgentCallbackHandler):assert handler.ignore_chat_model is True- def test_ignore_properties_when_debug_enabled(self, enable_debug, handler):+ def test_ignore_properties_when_debug_enabled(self, enable_debug, handler: DifyAgentCallbackHandler):assert handler.ignore_agent is Falseassert handler.ignore_chat_model is Falsediff --git a/api/tests/unit_tests/core/callback_handler/test_index_tool_callback_handler.py b/api/tests/unit_tests/core/callback_handler/test_index_tool_callback_handler.pyindex 8e5670e9be3..f23669c3c7b 100644--- a/api/tests/unit_tests/core/callback_handler/test_index_tool_callback_handler.py+++ b/api/tests/unit_tests/core/callback_handler/test_index_tool_callback_handler.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom core.app.entities.app_invoke_entities import InvokeFromfrom core.callback_handler.index_tool_callback_handler import (@@ -7,12 +8,12 @@ from core.callback_handler.index_tool_callback_handler import (@pytest.fixture-def mock_queue_manager(mocker):+def mock_queue_manager(mocker: MockerFixture):return mocker.Mock()@pytest.fixture-def handler(mock_queue_manager, mocker):+def handler(mock_queue_manager, mocker: MockerFixture):mocker.patch("core.callback_handler.index_tool_callback_handler.db",)@@ -34,7 +35,7 @@ class TestOnQuery:(InvokeFrom.WEB_APP, "end_user"),],)- def test_on_query_success_roles(self, mocker, mock_queue_manager, invoke_from, expected_role):+ def test_on_query_success_roles(self, mocker: MockerFixture, mock_queue_manager, invoke_from, expected_role):# Arrangemock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")@@ -57,7 +58,7 @@ class TestOnQuery:assert dataset_query.created_by_role == expected_rolemock_db.session.commit.assert_called_once()- def test_on_query_none_values(self, mocker, mock_queue_manager):+ def test_on_query_none_values(self, mocker: MockerFixture, mock_queue_manager):mock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")handler = DatasetIndexToolCallbackHandler(@@ -75,7 +76,7 @@ class TestOnQuery:class TestOnToolEnd:- def test_on_tool_end_no_metadata(self, handler, mocker):+ def test_on_tool_end_no_metadata(self, handler: DatasetIndexToolCallbackHandler, mocker: MockerFixture):mock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")document = mocker.Mock()@@ -85,7 +86,9 @@ class TestOnToolEnd:mock_db.session.commit.assert_not_called()- def test_on_tool_end_dataset_document_not_found(self, handler, mocker):+ def test_on_tool_end_dataset_document_not_found(+ self, handler: DatasetIndexToolCallbackHandler, mocker: MockerFixture+ ):mock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")mock_db.session.scalar.return_value = None@@ -96,7 +99,9 @@ class TestOnToolEnd:mock_db.session.scalar.assert_called_once()- def test_on_tool_end_parent_child_index_with_child(self, handler, mocker):+ def test_on_tool_end_parent_child_index_with_child(+ self, handler: DatasetIndexToolCallbackHandler, mocker: MockerFixture+ ):mock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")mock_dataset_doc = mocker.Mock()@@ -119,7 +124,7 @@ class TestOnToolEnd:mock_db.session.execute.assert_called_once()mock_db.session.commit.assert_called_once()- def test_on_tool_end_non_parent_child_index(self, handler, mocker):+ def test_on_tool_end_non_parent_child_index(self, handler: DatasetIndexToolCallbackHandler, mocker: MockerFixture):mock_db = mocker.patch("core.callback_handler.index_tool_callback_handler.db")mock_dataset_doc = mocker.Mock()@@ -139,12 +144,12 @@ class TestOnToolEnd:mock_db.session.execute.assert_called_once()mock_db.session.commit.assert_called_once()- def test_on_tool_end_empty_documents(self, handler):+ def test_on_tool_end_empty_documents(self, handler: DatasetIndexToolCallbackHandler):handler.on_tool_end([])class TestReturnRetrieverResourceInfo:- def test_publish_called(self, handler, mock_queue_manager, mocker):+ def test_publish_called(self, handler: DatasetIndexToolCallbackHandler, mock_queue_manager, mocker: MockerFixture):mock_event = mocker.patch("core.callback_handler.index_tool_callback_handler.QueueRetrieverResourcesEvent")resources = [mocker.Mock()]diff --git a/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py b/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.pyindex 131fb006eda..5b53c5965ce 100644--- a/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py+++ b/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py@@ -1,6 +1,7 @@from unittest.mock import MagicMock, callimport pytest+from pytest_mock import MockerFixturefrom core.callback_handler.workflow_tool_callback_handler import (DifyWorkflowCallbackHandler,@@ -26,13 +27,13 @@ def handler():@pytest.fixture-def mock_print_text(mocker):+def mock_print_text(mocker: MockerFixture):"""Mock print_text to avoid real stdout printing."""return mocker.patch("core.callback_handler.workflow_tool_callback_handler.print_text")class TestDifyWorkflowCallbackHandler:- def test_on_tool_execution_single_output_success(self, handler, mock_print_text):+ def test_on_tool_execution_single_output_success(self, handler: DifyWorkflowCallbackHandler, mock_print_text):# Arrangetool_name = "test_tool"tool_inputs = {"a": 1}@@ -62,7 +63,7 @@ class TestDifyWorkflowCallbackHandler:])- def test_on_tool_execution_multiple_outputs(self, handler, mock_print_text):+ def test_on_tool_execution_multiple_outputs(self, handler: DifyWorkflowCallbackHandler, mock_print_text):# Arrangetool_name = "multi_tool"outputs = [@@ -83,7 +84,7 @@ class TestDifyWorkflowCallbackHandler:assert results == outputsassert mock_print_text.call_count == 4 * len(outputs)- def test_on_tool_execution_empty_iterable(self, handler, mock_print_text):+ def test_on_tool_execution_empty_iterable(self, handler: DifyWorkflowCallbackHandler, mock_print_text):# Arrangetool_name = "empty_tool"@@ -108,7 +109,9 @@ class TestDifyWorkflowCallbackHandler:("not_iterable", AttributeError),],)- def test_on_tool_execution_invalid_outputs_type(self, handler, invalid_outputs, expected_exception):+ def test_on_tool_execution_invalid_outputs_type(+ self, handler: DifyWorkflowCallbackHandler, invalid_outputs, expected_exception+ ):# Arrangetool_name = "invalid_tool"@@ -122,7 +125,7 @@ class TestDifyWorkflowCallbackHandler:))- def test_on_tool_execution_long_json_truncation(self, handler, mock_print_text):+ def test_on_tool_execution_long_json_truncation(self, handler: DifyWorkflowCallbackHandler, mock_print_text):# Arrangetool_name = "long_json_tool"long_json = "x" * 1500@@ -144,7 +147,7 @@ class TestDifyWorkflowCallbackHandler:color="blue",)- def test_on_tool_execution_model_dump_json_exception(self, handler, mock_print_text):+ def test_on_tool_execution_model_dump_json_exception(self, handler: DifyWorkflowCallbackHandler, mock_print_text):# Arrangetool_name = "exception_tool"bad_message = MagicMock()@@ -163,7 +166,9 @@ class TestDifyWorkflowCallbackHandler:# Ensure first two prints happened before failureassert mock_print_text.call_count >= 2- def test_on_tool_execution_none_message_id_and_trace_manager(self, handler, mock_print_text):+ def test_on_tool_execution_none_message_id_and_trace_manager(+ self, handler: DifyWorkflowCallbackHandler, mock_print_text+ ):# Arrangetool_name = "optional_params_tool"message = DummyToolInvokeMessage('{"data": "ok"}')diff --git a/api/tests/unit_tests/core/datasource/test_datasource_manager.py b/api/tests/unit_tests/core/datasource/test_datasource_manager.pyindex deeac49bbc2..8842d678c7a 100644--- a/api/tests/unit_tests/core/datasource/test_datasource_manager.py+++ b/api/tests/unit_tests/core/datasource/test_datasource_manager.py@@ -2,6 +2,7 @@ import typesfrom collections.abc import Generatorimport pytest+from pytest_mock import MockerFixturefrom contexts.wrapper import RecyclableContextVarfrom core.datasource.datasource_manager import DatasourceManager@@ -37,7 +38,7 @@ def _invalidate_recyclable_contextvars() -> None:RecyclableContextVar.increment_thread_recycles()-def test_get_icon_url_calls_runtime(mocker):+def test_get_icon_url_calls_runtime(mocker: MockerFixture):fake_runtime = mocker.Mock()fake_runtime.get_icon_url.return_value = "https://icon"mocker.patch.object(DatasourceManager, "get_datasource_runtime", return_value=fake_runtime)@@ -52,7 +53,7 @@ def test_get_icon_url_calls_runtime(mocker):DatasourceManager.get_datasource_runtime.assert_called_once()-def test_get_datasource_runtime_delegates_to_provider_controller(mocker):+def test_get_datasource_runtime_delegates_to_provider_controller(mocker: MockerFixture):provider_controller = mocker.Mock()provider_controller.get_datasource.return_value = object()mocker.patch.object(DatasourceManager, "get_datasource_plugin_provider", return_value=provider_controller)@@ -114,7 +115,7 @@ def test_get_datasource_plugin_provider_creates_controller_and_caches(mocker, daassert ctrl_cls.call_count == 1-def test_get_datasource_plugin_provider_raises_when_provider_entity_missing(mocker):+def test_get_datasource_plugin_provider_raises_when_provider_entity_missing(mocker: MockerFixture):_invalidate_recyclable_contextvars()mocker.patch("core.datasource.datasource_manager.PluginDatasourceManager.fetch_datasource_provider",@@ -129,7 +130,7 @@ def test_get_datasource_plugin_provider_raises_when_provider_entity_missing(mock)-def test_get_datasource_plugin_provider_raises_for_unsupported_type(mocker):+def test_get_datasource_plugin_provider_raises_for_unsupported_type(mocker: MockerFixture):_invalidate_recyclable_contextvars()provider_entity = types.SimpleNamespace(declaration=object(), plugin_id="plugin", plugin_unique_identifier="uniq")mocker.patch(@@ -145,7 +146,7 @@ def test_get_datasource_plugin_provider_raises_for_unsupported_type(mocker):)-def test_get_datasource_plugin_provider_raises_when_controller_none(mocker):+def test_get_datasource_plugin_provider_raises_when_controller_none(mocker: MockerFixture):_invalidate_recyclable_contextvars()provider_entity = types.SimpleNamespace(declaration=object(), plugin_id="plugin", plugin_unique_identifier="uniq")mocker.patch(@@ -165,7 +166,7 @@ def test_get_datasource_plugin_provider_raises_when_controller_none(mocker):)-def test_stream_online_results_yields_messages_online_document(mocker):+def test_stream_online_results_yields_messages_online_document(mocker: MockerFixture):# stub runtime to yield a text messagedef _doc_messages(**_):yield from _gen_messages_text_only("hello")@@ -195,7 +196,7 @@ def test_stream_online_results_yields_messages_online_document(mocker):assert msgs[0].message.text == "hello"-def test_stream_online_results_sets_credentials_and_returns_empty_dict_online_document(mocker):+def test_stream_online_results_sets_credentials_and_returns_empty_dict_online_document(mocker: MockerFixture):class _Runtime:def __init__(self) -> None:self.runtime = types.SimpleNamespace(credentials=None)@@ -229,7 +230,7 @@ def test_stream_online_results_sets_credentials_and_returns_empty_dict_online_doassert final_value == {}-def test_stream_online_results_raises_when_missing_params(mocker):+def test_stream_online_results_raises_when_missing_params(mocker: MockerFixture):class _Runtime:def __init__(self) -> None:self.runtime = types.SimpleNamespace(credentials=None)@@ -279,7 +280,7 @@ def test_stream_online_results_raises_when_missing_params(mocker):)-def test_stream_online_results_yields_messages_and_returns_empty_dict_online_drive(mocker):+def test_stream_online_results_yields_messages_and_returns_empty_dict_online_drive(mocker: MockerFixture):class _Runtime:def __init__(self) -> None:self.runtime = types.SimpleNamespace(credentials=None)@@ -313,7 +314,7 @@ def test_stream_online_results_yields_messages_and_returns_empty_dict_online_driassert final_value == {}-def test_stream_online_results_raises_for_unsupported_stream_type(mocker):+def test_stream_online_results_raises_for_unsupported_stream_type(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "get_datasource_runtime", return_value=mocker.Mock())mocker.patch("core.datasource.datasource_manager.DatasourceProviderService.get_datasource_credentials",@@ -337,7 +338,7 @@ def test_stream_online_results_raises_for_unsupported_stream_type(mocker):)-def test_stream_node_events_emits_events_online_document(mocker):+def test_stream_node_events_emits_events_online_document(mocker: MockerFixture):# make manager's low-level stream produce TEXT onlymocker.patch.object(DatasourceManager,@@ -370,7 +371,7 @@ def test_stream_node_events_emits_events_online_document(mocker):assert events[-1].node_run_result.status == WorkflowNodeExecutionStatus.SUCCEEDED-def test_stream_node_events_builds_file_and_variables_from_messages(mocker):+def test_stream_node_events_builds_file_and_variables_from_messages(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "stream_online_results", return_value=_gen_messages_text_only("ignored"))def _transformed(**_kwargs):@@ -478,7 +479,7 @@ def test_stream_node_events_builds_file_and_variables_from_messages(mocker):assert events[-1].node_run_result.outputs["x"] == 1-def test_stream_node_events_raises_when_toolfile_missing(mocker):+def test_stream_node_events_raises_when_toolfile_missing(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "stream_online_results", return_value=_gen_messages_text_only("ignored"))def _transformed(**_kwargs):@@ -526,7 +527,7 @@ def test_stream_node_events_raises_when_toolfile_missing(mocker):)-def test_stream_node_events_online_drive_sets_variable_pool_file_and_outputs(mocker):+def test_stream_node_events_online_drive_sets_variable_pool_file_and_outputs(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "stream_online_results", return_value=_gen_messages_text_only("ignored"))file_in = File(@@ -580,7 +581,7 @@ def test_stream_node_events_online_drive_sets_variable_pool_file_and_outputs(mocassert completed.node_run_result.outputs["datasource_type"] == DatasourceProviderType.ONLINE_DRIVE-def test_stream_node_events_skips_file_build_for_non_online_types(mocker):+def test_stream_node_events_skips_file_build_for_non_online_types(mocker: MockerFixture):mocker.patch.object(DatasourceManager, "stream_online_results", return_value=_gen_messages_text_only("ignored"))def _transformed(**_kwargs):@@ -620,7 +621,7 @@ def test_stream_node_events_skips_file_build_for_non_online_types(mocker):assert events[-1].node_run_result.outputs["file"] is None-def test_get_upload_file_by_id_builds_file(mocker):+def test_get_upload_file_by_id_builds_file(mocker: MockerFixture):# fake UploadFile rowfake_row = types.SimpleNamespace(id="fid",@@ -654,7 +655,7 @@ def test_get_upload_file_by_id_builds_file(mocker):assert f.storage_key == "k"-def test_get_upload_file_by_id_raises_when_missing(mocker):+def test_get_upload_file_by_id_raises_when_missing(mocker: MockerFixture):class _S:def __enter__(self):return selfdiff --git a/api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py b/api/tests/unit_tests/core/extension/test_api_based_extension_requestor.pyindex 399b531205a..9c1cbe82a0c 100644--- a/api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py+++ b/api/tests/unit_tests/core/extension/test_api_based_extension_requestor.py@@ -1,11 +1,12 @@import httpximport pytest+from pytest_mock import MockerFixturefrom core.extension.api_based_extension_requestor import APIBasedExtensionRequestorfrom models.api_based_extension import APIBasedExtensionPoint-def test_request_success(mocker):+def test_request_success(mocker: MockerFixture):# Mock httpx.Client and its context managermock_client = mocker.MagicMock()mock_client_instance = mock_client.__enter__.return_value@@ -28,7 +29,7 @@ def test_request_success(mocker):)-def test_request_with_ssrf_proxy(mocker):+def test_request_with_ssrf_proxy(mocker: MockerFixture):# Mock dify_configmocker.patch("configs.dify_config.SSRF_PROXY_HTTP_URL", "http://proxy:8080")mocker.patch("configs.dify_config.SSRF_PROXY_HTTPS_URL", "https://proxy:8081")@@ -59,7 +60,7 @@ def test_request_with_ssrf_proxy(mocker):assert mock_transport.call_count == 2-def test_request_with_only_one_proxy_config(mocker):+def test_request_with_only_one_proxy_config(mocker: MockerFixture):# Mock dify_config with only one proxymocker.patch("configs.dify_config.SSRF_PROXY_HTTP_URL", "http://proxy:8080")mocker.patch("configs.dify_config.SSRF_PROXY_HTTPS_URL", None)@@ -84,7 +85,7 @@ def test_request_with_only_one_proxy_config(mocker):assert kwargs.get("mounts") is None-def test_request_timeout(mocker):+def test_request_timeout(mocker: MockerFixture):mock_client = mocker.MagicMock()mock_client_instance = mock_client.__enter__.return_valuemocker.patch("httpx.Client", return_value=mock_client)@@ -95,7 +96,7 @@ def test_request_timeout(mocker):requestor.request(APIBasedExtensionPoint.PING, {})-def test_request_connection_error(mocker):+def test_request_connection_error(mocker: MockerFixture):mock_client = mocker.MagicMock()mock_client_instance = mock_client.__enter__.return_valuemocker.patch("httpx.Client", return_value=mock_client)@@ -106,7 +107,7 @@ def test_request_connection_error(mocker):requestor.request(APIBasedExtensionPoint.PING, {})-def test_request_error_status_code(mocker):+def test_request_error_status_code(mocker: MockerFixture):mock_client = mocker.MagicMock()mock_client_instance = mock_client.__enter__.return_valuemocker.patch("httpx.Client", return_value=mock_client)@@ -121,7 +122,7 @@ def test_request_error_status_code(mocker):requestor.request(APIBasedExtensionPoint.PING, {})-def test_request_error_status_code_long_content(mocker):+def test_request_error_status_code_long_content(mocker: MockerFixture):mock_client = mocker.MagicMock()mock_client_instance = mock_client.__enter__.return_valuemocker.patch("httpx.Client", return_value=mock_client)diff --git a/api/tests/unit_tests/core/helper/test_creators.py b/api/tests/unit_tests/core/helper/test_creators.pyindex df67d3f5136..8750f6d9070 100644--- a/api/tests/unit_tests/core/helper/test_creators.py+++ b/api/tests/unit_tests/core/helper/test_creators.py@@ -8,7 +8,7 @@ from yarl import URL@pytest.fixture(autouse=True)-def _patch_creators_url(monkeypatch):+def _patch_creators_url(monkeypatch: pytest.MonkeyPatch):"""Patch the module-level creators_platform_api_url for all tests."""monkeypatch.setattr("core.helper.creators.creators_platform_api_url",diff --git a/api/tests/unit_tests/core/ops/test_base_trace_instance.py b/api/tests/unit_tests/core/ops/test_base_trace_instance.pyindex ac65d134546..15a2af17ca4 100644--- a/api/tests/unit_tests/core/ops/test_base_trace_instance.py+++ b/api/tests/unit_tests/core/ops/test_base_trace_instance.py@@ -18,7 +18,7 @@ class ConcreteTraceInstance(BaseTraceInstance):@pytest.fixture-def mock_db_session(monkeypatch):+def mock_db_session(monkeypatch: pytest.MonkeyPatch):mock_session = MagicMock(spec=Session)mock_session.__enter__.return_value = mock_sessionmock_session.__exit__.return_value = Nonediff --git a/api/tests/unit_tests/core/ops/test_ops_trace_manager.py b/api/tests/unit_tests/core/ops/test_ops_trace_manager.pyindex beb99f92cdf..33a32936825 100644--- a/api/tests/unit_tests/core/ops/test_ops_trace_manager.py+++ b/api/tests/unit_tests/core/ops/test_ops_trace_manager.py@@ -203,7 +203,7 @@ class DummySessionContext:@pytest.fixture(autouse=True)-def patch_provider_map(monkeypatch):+def patch_provider_map(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.provider_config_map", FakeProviderMap({"dummy": FAKE_PROVIDER_ENTRY}))@@ -212,7 +212,7 @@ def patch_provider_map(monkeypatch):@pytest.fixture(autouse=True)-def patch_timer_and_current_app(monkeypatch):+def patch_timer_and_current_app(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.threading.Timer", DummyTimer)monkeypatch.setattr("core.ops.ops_trace_manager.trace_manager_queue", queue.Queue())monkeypatch.setattr("core.ops.ops_trace_manager.trace_manager_timer", None)@@ -227,12 +227,12 @@ def patch_timer_and_current_app(monkeypatch):@pytest.fixture(autouse=True)-def patch_sqlalchemy_session(monkeypatch):+def patch_sqlalchemy_session(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.Session", DummySessionContext)@pytest.fixture-def encryption_mocks(monkeypatch):+def encryption_mocks(monkeypatch: pytest.MonkeyPatch):encrypt_mock = MagicMock(side_effect=lambda tenant, value: f"enc-{value}")batch_decrypt_mock = MagicMock(side_effect=lambda tenant, values: [f"dec-{value}" for value in values])obfuscate_mock = MagicMock(side_effect=lambda value: f"ob-{value}")@@ -243,7 +243,7 @@ def encryption_mocks(monkeypatch):@pytest.fixture-def mock_db(monkeypatch):+def mock_db(monkeypatch: pytest.MonkeyPatch):session = MagicMock()session.scalars.return_value.all.return_value = ["chat"]db_mock = MagicMock()@@ -254,7 +254,7 @@ def mock_db(monkeypatch):@pytest.fixture-def workflow_repo_fixture(monkeypatch):+def workflow_repo_fixture(monkeypatch: pytest.MonkeyPatch):repo = MagicMock()repo.get_workflow_run_by_id_without_tenant.return_value = make_workflow_run()monkeypatch.setattr(TraceTask, "_get_workflow_run_repo", classmethod(lambda cls: repo))@@ -340,13 +340,13 @@ def test_get_ops_trace_instance_handles_none_app(mock_db):assert OpsTraceManager.get_ops_trace_instance("app-id") is None-def test_get_ops_trace_instance_returns_none_when_disabled(mock_db, monkeypatch):+def test_get_ops_trace_instance_returns_none_when_disabled(mock_db, monkeypatch: pytest.MonkeyPatch):app = SimpleNamespace(id="app-id", tracing=json.dumps({"enabled": False}))mock_db.get.return_value = appassert OpsTraceManager.get_ops_trace_instance("app-id") is None-def test_get_ops_trace_instance_invalid_provider(mock_db, monkeypatch):+def test_get_ops_trace_instance_invalid_provider(mock_db, monkeypatch: pytest.MonkeyPatch):app = SimpleNamespace(id="app-id", tracing=json.dumps({"enabled": True, "tracing_provider": "missing"}))mock_db.get.return_value = appmonkeypatch.setattr("core.ops.ops_trace_manager.provider_config_map", FakeProviderMap({}))@@ -388,7 +388,7 @@ def test_get_app_config_through_message_id_app_model_config(mock_db):assert result.id == "cfg"-def test_update_app_tracing_config_invalid_provider(mock_db, monkeypatch):+def test_update_app_tracing_config_invalid_provider(mock_db, monkeypatch: pytest.MonkeyPatch):mock_db.get.return_value = Nonewith pytest.raises(ValueError, match="Invalid tracing provider"):OpsTraceManager.update_app_tracing_config("app", True, "bad")@@ -421,7 +421,7 @@ def test_get_app_tracing_config_returns_payload(mock_db):assert OpsTraceManager.get_app_tracing_config("app-id", mock_db) == payload-def test_check_and_project_helpers(monkeypatch):+def test_check_and_project_helpers(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.provider_config_map",FakeProviderMap(@@ -449,7 +449,7 @@ def test_check_and_project_helpers(monkeypatch):assert OpsTraceManager.get_trace_config_project_url({}, "dummy") == "url"-def test_trace_task_conversation_and_extract(monkeypatch):+def test_trace_task_conversation_and_extract(monkeypatch: pytest.MonkeyPatch):task = TraceTask(trace_type=TraceTaskName.CONVERSATION_TRACE, message_id="msg")assert task.conversation_trace(foo="bar") == {"foo": "bar"}assert task._extract_streaming_metrics(make_message_data(message_metadata="not json")) == {}@@ -525,7 +525,7 @@ def test_extract_streaming_metrics_invalid_json():assert task._extract_streaming_metrics(fake_message) == {}-def test_trace_queue_manager_add_and_collect(monkeypatch):+def test_trace_queue_manager_add_and_collect(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.OpsTraceManager.get_ops_trace_instance", classmethod(lambda cls, aid: True))@@ -536,7 +536,7 @@ def test_trace_queue_manager_add_and_collect(monkeypatch):assert tasks == [task]-def test_trace_queue_manager_run_invokes_send(monkeypatch):+def test_trace_queue_manager_run_invokes_send(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.OpsTraceManager.get_ops_trace_instance", classmethod(lambda cls, aid: True))@@ -556,7 +556,7 @@ def test_trace_queue_manager_run_invokes_send(monkeypatch):assert called["tasks"] == [task]-def test_trace_queue_manager_send_to_celery(monkeypatch):+def test_trace_queue_manager_send_to_celery(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.ops.ops_trace_manager.OpsTraceManager.get_ops_trace_instance", classmethod(lambda cls, aid: True))diff --git a/api/tests/unit_tests/core/ops/test_trace_queue_manager.py b/api/tests/unit_tests/core/ops/test_trace_queue_manager.pyindex a4903054e0a..13cf01651e3 100644--- a/api/tests/unit_tests/core/ops/test_trace_queue_manager.py+++ b/api/tests/unit_tests/core/ops/test_trace_queue_manager.py@@ -19,7 +19,7 @@ import pytest@pytest.fixture-def trace_queue_manager_and_task(monkeypatch):+def trace_queue_manager_and_task(monkeypatch: pytest.MonkeyPatch):"""Fixture to provide TraceQueueManager and TraceTask with delayed imports."""module_name = "core.ops.ops_trace_manager"if module_name not in sys.modules:diff --git a/api/tests/unit_tests/core/plugin/impl/test_agent_client.py b/api/tests/unit_tests/core/plugin/impl/test_agent_client.pyindex 1537ffacf5f..d8843f0eebf 100644--- a/api/tests/unit_tests/core/plugin/impl/test_agent_client.py+++ b/api/tests/unit_tests/core/plugin/impl/test_agent_client.py@@ -1,5 +1,7 @@from types import SimpleNamespace+from pytest_mock import MockerFixture+from core.plugin.entities.request import PluginInvokeContextfrom core.plugin.impl.agent import PluginAgentClient@@ -15,7 +17,7 @@ def _agent_provider(name: str = "agent") -> SimpleNamespace:class TestPluginAgentClient:- def test_fetch_agent_strategy_providers(self, mocker):+ def test_fetch_agent_strategy_providers(self, mocker: MockerFixture):client = PluginAgentClient()provider = _agent_provider("remote")@@ -43,7 +45,7 @@ class TestPluginAgentClient:assert result[0].declaration.identity.name == "org/plugin/remote"assert result[0].declaration.strategies[0].identity.provider == "org/plugin/remote"- def test_fetch_agent_strategy_provider(self, mocker):+ def test_fetch_agent_strategy_provider(self, mocker: MockerFixture):client = PluginAgentClient()provider = _agent_provider("provider")@@ -63,7 +65,7 @@ class TestPluginAgentClient:assert result.declaration.identity.name == "org/plugin/provider"assert result.declaration.strategies[0].identity.provider == "org/plugin/provider"- def test_invoke_merges_chunks_and_passes_context(self, mocker):+ def test_invoke_merges_chunks_and_passes_context(self, mocker: MockerFixture):client = PluginAgentClient()stream_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter(["raw"])diff --git a/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py b/api/tests/unit_tests/core/plugin/impl/test_asset_manager.pyindex 5f564062d53..c2cce5d6915 100644--- a/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py+++ b/api/tests/unit_tests/core/plugin/impl/test_asset_manager.py@@ -1,12 +1,13 @@from unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixturefrom core.plugin.impl.asset import PluginAssetManagerclass TestPluginAssetManager:- def test_fetch_asset_success(self, mocker):+ def test_fetch_asset_success(self, mocker: MockerFixture):manager = PluginAssetManager()response = MagicMock(status_code=200, content=b"asset-bytes")request_mock = mocker.patch.object(manager, "_request", return_value=response)@@ -16,14 +17,14 @@ class TestPluginAssetManager:assert result == b"asset-bytes"request_mock.assert_called_once_with(method="GET", path="plugin/tenant-1/asset/asset-1")- def test_fetch_asset_not_found_raises(self, mocker):+ def test_fetch_asset_not_found_raises(self, mocker: MockerFixture):manager = PluginAssetManager()mocker.patch.object(manager, "_request", return_value=MagicMock(status_code=404, content=b""))with pytest.raises(ValueError, match="can not found asset asset-1"):manager.fetch_asset("tenant-1", "asset-1")- def test_extract_asset_success(self, mocker):+ def test_extract_asset_success(self, mocker: MockerFixture):manager = PluginAssetManager()response = MagicMock(status_code=200, content=b"file-content")request_mock = mocker.patch.object(manager, "_request", return_value=response)@@ -37,7 +38,7 @@ class TestPluginAssetManager:params={"plugin_unique_identifier": "org/plugin:1", "file_path": "README.md"},)- def test_extract_asset_not_found_raises(self, mocker):+ def test_extract_asset_not_found_raises(self, mocker: MockerFixture):manager = PluginAssetManager()mocker.patch.object(manager, "_request", return_value=MagicMock(status_code=404, content=b""))diff --git a/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py b/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.pyindex 23894bd417b..b154f056ca2 100644--- a/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py+++ b/api/tests/unit_tests/core/plugin/impl/test_base_client_impl.py@@ -1,6 +1,7 @@import jsonimport pytest+from pytest_mock import MockerFixturefrom core.plugin.endpoint.exc import EndpointSetupFailedErrorfrom core.plugin.entities.plugin_daemon import PluginDaemonInnerError@@ -39,7 +40,7 @@ class _StreamContext:class TestBasePluginClientImpl:- def test_inject_trace_headers(self, mocker):+ def test_inject_trace_headers(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch("core.plugin.impl.base.dify_config.ENABLE_OTEL", True)trace_header = "00-abc-xyz-01"@@ -54,7 +55,7 @@ class TestBasePluginClientImpl:client._inject_trace_headers(headers_with_existing)assert headers_with_existing["TraceParent"] == "exists"- def test_stream_request_handles_data_lines_and_dict_payload(self, mocker):+ def test_stream_request_handles_data_lines_and_dict_payload(self, mocker: MockerFixture):client = BasePluginClient()stream_mock = mocker.patch("httpx.Client.stream",@@ -66,14 +67,14 @@ class TestBasePluginClientImpl:assert result == ["hello", "world"]assert stream_mock.call_args.kwargs["data"] == {"k": "v"}- def test_request_with_plugin_daemon_response_handles_request_exception(self, mocker):+ def test_request_with_plugin_daemon_response_handles_request_exception(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_request", side_effect=RuntimeError("boom"))with pytest.raises(ValueError, match="Failed to request plugin daemon"):client._request_with_plugin_daemon_response("GET", "plugin/tenant/path", bool)- def test_request_with_plugin_daemon_response_applies_transformer(self, mocker):+ def test_request_with_plugin_daemon_response_applies_transformer(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_request", return_value=_ResponseStub({"code": 0, "message": "", "data": True}))@@ -88,14 +89,14 @@ class TestBasePluginClientImpl:assert result is Trueassert transformed == {"code": 0, "message": "", "data": True}- def test_request_with_plugin_daemon_response_stream_malformed_json_error(self, mocker):+ def test_request_with_plugin_daemon_response_stream_malformed_json_error(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_stream_request", return_value=iter(['{"error":"bad-line"}']))with pytest.raises(ValueError, match="bad-line"):list(client._request_with_plugin_daemon_response_stream("GET", "p", bool))- def test_request_with_plugin_daemon_response_stream_plugin_daemon_inner_error(self, mocker):+ def test_request_with_plugin_daemon_response_stream_plugin_daemon_inner_error(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_stream_request", return_value=iter(['{"code":-500,"message":"not-json","data":null}'])@@ -105,14 +106,14 @@ class TestBasePluginClientImpl:list(client._request_with_plugin_daemon_response_stream("GET", "p", bool))assert exc_info.value.message == "not-json"- def test_request_with_plugin_daemon_response_stream_plugin_daemon_error(self, mocker):+ def test_request_with_plugin_daemon_response_stream_plugin_daemon_error(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_stream_request", return_value=iter(['{"code":-1,"message":"err","data":null}']))with pytest.raises(ValueError, match="plugin daemon: err, code: -1"):list(client._request_with_plugin_daemon_response_stream("GET", "p", bool))- def test_request_with_plugin_daemon_response_stream_empty_data_error(self, mocker):+ def test_request_with_plugin_daemon_response_stream_empty_data_error(self, mocker: MockerFixture):client = BasePluginClient()mocker.patch.object(client, "_stream_request", return_value=iter(['{"code":0,"message":"","data":null}']))diff --git a/api/tests/unit_tests/core/plugin/impl/test_datasource_manager.py b/api/tests/unit_tests/core/plugin/impl/test_datasource_manager.pyindex 4c5987d7599..94723dcfe28 100644--- a/api/tests/unit_tests/core/plugin/impl/test_datasource_manager.py+++ b/api/tests/unit_tests/core/plugin/impl/test_datasource_manager.py@@ -1,5 +1,7 @@from types import SimpleNamespace+from pytest_mock import MockerFixture+from core.datasource.entities.datasource_entities import (GetOnlineDocumentPageContentRequest,OnlineDriveBrowseFilesRequest,@@ -19,7 +21,7 @@ def _datasource_provider(name: str = "provider") -> SimpleNamespace:class TestPluginDatasourceManager:- def test_fetch_datasource_providers(self, mocker):+ def test_fetch_datasource_providers(self, mocker: MockerFixture):manager = PluginDatasourceManager()provider = _datasource_provider("remote")repack = mocker.patch("core.plugin.impl.datasource.ToolTransformService.repack_provider")@@ -52,7 +54,7 @@ class TestPluginDatasourceManager:assert result[1].declaration.datasources[0].identity.provider == "org/plugin/remote"repack.assert_called_once_with(tenant_id="tenant-1", provider=provider)- def test_fetch_installed_datasource_providers(self, mocker):+ def test_fetch_installed_datasource_providers(self, mocker: MockerFixture):manager = PluginDatasourceManager()provider = _datasource_provider("remote")repack = mocker.patch("core.plugin.impl.datasource.ToolTransformService.repack_provider")@@ -83,7 +85,7 @@ class TestPluginDatasourceManager:assert result[0].declaration.datasources[0].identity.provider == "org/plugin/remote"repack.assert_called_once_with(tenant_id="tenant-1", provider=provider)- def test_fetch_datasource_provider_local_and_remote(self, mocker):+ def test_fetch_datasource_provider_local_and_remote(self, mocker: MockerFixture):manager = PluginDatasourceManager()local = manager.fetch_datasource_provider("tenant-1", "langgenius/file/file")@@ -113,7 +115,7 @@ class TestPluginDatasourceManager:assert result.declaration.identity.name == "org/plugin/provider"assert result.declaration.datasources[0].identity.provider == "org/plugin/provider"- def test_get_website_crawl_streaming(self, mocker):+ def test_get_website_crawl_streaming(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter(["crawl"])@@ -132,7 +134,7 @@ class TestPluginDatasourceManager:assert stream_mock.call_count == 1- def test_get_online_document_pages_streaming(self, mocker):+ def test_get_online_document_pages_streaming(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter(["pages"])@@ -151,7 +153,7 @@ class TestPluginDatasourceManager:assert stream_mock.call_count == 1- def test_get_online_document_page_content_streaming(self, mocker):+ def test_get_online_document_page_content_streaming(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter(["content"])@@ -170,7 +172,7 @@ class TestPluginDatasourceManager:assert stream_mock.call_count == 1- def test_online_drive_browse_files_streaming(self, mocker):+ def test_online_drive_browse_files_streaming(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter(["browse"])@@ -189,7 +191,7 @@ class TestPluginDatasourceManager:assert stream_mock.call_count == 1- def test_online_drive_download_file_streaming(self, mocker):+ def test_online_drive_download_file_streaming(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter(["download"])@@ -208,14 +210,14 @@ class TestPluginDatasourceManager:assert stream_mock.call_count == 1- def test_validate_provider_credentials_returns_true_when_stream_yields_result(self, mocker):+ def test_validate_provider_credentials_returns_true_when_stream_yields_result(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter([SimpleNamespace(result=True)])assert manager.validate_provider_credentials("tenant-1", "user-1", "provider", "org/plugin", {"k": "v"}) is True- def test_validate_provider_credentials_returns_false_when_stream_empty(self, mocker):+ def test_validate_provider_credentials_returns_false_when_stream_empty(self, mocker: MockerFixture):manager = PluginDatasourceManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")stream_mock.return_value = iter([])diff --git a/api/tests/unit_tests/core/plugin/impl/test_debugging_client.py b/api/tests/unit_tests/core/plugin/impl/test_debugging_client.pyindex c80785aee04..05959207b1a 100644--- a/api/tests/unit_tests/core/plugin/impl/test_debugging_client.py+++ b/api/tests/unit_tests/core/plugin/impl/test_debugging_client.py@@ -1,10 +1,12 @@from types import SimpleNamespace+from pytest_mock import MockerFixture+from core.plugin.impl.debugging import PluginDebuggingClientclass TestPluginDebuggingClient:- def test_get_debugging_key(self, mocker):+ def test_get_debugging_key(self, mocker: MockerFixture):client = PluginDebuggingClient()request_mock = mocker.patch.object(client,diff --git a/api/tests/unit_tests/core/plugin/impl/test_endpoint_client_impl.py b/api/tests/unit_tests/core/plugin/impl/test_endpoint_client_impl.pyindex 4cf657a0500..7a24cc01d1e 100644--- a/api/tests/unit_tests/core/plugin/impl/test_endpoint_client_impl.py+++ b/api/tests/unit_tests/core/plugin/impl/test_endpoint_client_impl.py@@ -1,11 +1,12 @@import pytest+from pytest_mock import MockerFixturefrom core.plugin.impl.endpoint import PluginEndpointClientfrom core.plugin.impl.exc import PluginDaemonInternalServerErrorclass TestPluginEndpointClientImpl:- def test_create_endpoint(self, mocker):+ def test_create_endpoint(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=True)@@ -18,7 +19,7 @@ class TestPluginEndpointClientImpl:assert args[:3] == ("POST", "plugin/tenant-1/endpoint/setup", bool)assert kwargs["data"]["plugin_unique_identifier"] == "org/plugin:1"- def test_list_endpoints(self, mocker):+ def test_list_endpoints(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=["endpoint"])@@ -28,7 +29,7 @@ class TestPluginEndpointClientImpl:assert request_mock.call_args.args[1] == "plugin/tenant-1/endpoint/list"assert request_mock.call_args.kwargs["params"] == {"page": 2, "page_size": 20}- def test_list_endpoints_for_single_plugin(self, mocker):+ def test_list_endpoints_for_single_plugin(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=["endpoint"])@@ -38,7 +39,7 @@ class TestPluginEndpointClientImpl:assert request_mock.call_args.args[1] == "plugin/tenant-1/endpoint/list/plugin"assert request_mock.call_args.kwargs["params"] == {"plugin_id": "org/plugin", "page": 1, "page_size": 10}- def test_update_endpoint(self, mocker):+ def test_update_endpoint(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=True)@@ -47,7 +48,7 @@ class TestPluginEndpointClientImpl:assert result is Trueassert request_mock.call_args.args[:3] == ("POST", "plugin/tenant-1/endpoint/update", bool)- def test_enable_and_disable_endpoint(self, mocker):+ def test_enable_and_disable_endpoint(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=True)@@ -58,7 +59,7 @@ class TestPluginEndpointClientImpl:assert calls[0].args[1] == "plugin/tenant-1/endpoint/enable"assert calls[1].args[1] == "plugin/tenant-1/endpoint/disable"- def test_delete_endpoint_idempotent_and_re_raise(self, mocker):+ def test_delete_endpoint_idempotent_and_re_raise(self, mocker: MockerFixture):client = PluginEndpointClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response")diff --git a/api/tests/unit_tests/core/plugin/impl/test_exc_impl.py b/api/tests/unit_tests/core/plugin/impl/test_exc_impl.pyindex 8c6f1c6b7f7..d99a8c114fc 100644--- a/api/tests/unit_tests/core/plugin/impl/test_exc_impl.py+++ b/api/tests/unit_tests/core/plugin/impl/test_exc_impl.py@@ -1,11 +1,13 @@import json+from pytest_mock import MockerFixture+from core.plugin.impl import exc as exc_modulefrom core.plugin.impl.exc import PluginDaemonError, PluginInvokeErrorclass TestPluginImplExceptions:- def test_plugin_daemon_error_str_contains_request_id(self, mocker):+ def test_plugin_daemon_error_str_contains_request_id(self, mocker: MockerFixture):mocker.patch("core.plugin.impl.exc.get_request_id", return_value="req-123")error = PluginDaemonError("bad")@@ -21,7 +23,7 @@ class TestPluginImplExceptions:assert "RateLimit" in friendlyassert "too many" in friendly- def test_plugin_invoke_error_invalid_json_and_fallback(self, mocker):+ def test_plugin_invoke_error_invalid_json_and_fallback(self, mocker: MockerFixture):err = PluginInvokeError("plain text")assert err._get_error_object() == {}@@ -32,7 +34,7 @@ class TestPluginImplExceptions:err2 = PluginInvokeError("plain text")assert err2.get_error_message() == "plain text"- def test_plugin_invoke_error_get_error_object_handles_adapter_exception(self, mocker):+ def test_plugin_invoke_error_get_error_object_handles_adapter_exception(self, mocker: MockerFixture):adapter = mocker.patch.object(exc_module, "TypeAdapter")adapter.return_value.validate_json.side_effect = RuntimeError("invalid")diff --git a/api/tests/unit_tests/core/plugin/impl/test_model_client.py b/api/tests/unit_tests/core/plugin/impl/test_model_client.pyindex bcbebbb38b8..6dc572310c3 100644--- a/api/tests/unit_tests/core/plugin/impl/test_model_client.py+++ b/api/tests/unit_tests/core/plugin/impl/test_model_client.py@@ -4,13 +4,14 @@ import iofrom types import SimpleNamespaceimport pytest+from pytest_mock import MockerFixturefrom core.plugin.entities.plugin_daemon import PluginDaemonInnerErrorfrom core.plugin.impl.model import PluginModelClientclass TestPluginModelClient:- def test_fetch_model_providers(self, mocker):+ def test_fetch_model_providers(self, mocker: MockerFixture):client = PluginModelClient()request_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response", return_value=["provider-a"])@@ -23,7 +24,7 @@ class TestPluginModelClient:)assert request_mock.call_args.kwargs["params"] == {"page": 1, "page_size": 256}- def test_get_model_schema(self, mocker):+ def test_get_model_schema(self, mocker: MockerFixture):client = PluginModelClient()schema = SimpleNamespace(name="schema")stream_mock = mocker.patch.object(@@ -45,7 +46,7 @@ class TestPluginModelClient:assert result is schemaassert stream_mock.call_args.args[:2] == ("POST", "plugin/tenant-1/dispatch/model/schema")- def test_get_model_schema_empty_stream_returns_none(self, mocker):+ def test_get_model_schema_empty_stream_returns_none(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -53,7 +54,7 @@ class TestPluginModelClient:assert result is None- def test_validate_provider_credentials(self, mocker):+ def test_validate_provider_credentials(self, mocker: MockerFixture):client = PluginModelClient()stream_mock = mocker.patch.object(client,@@ -77,7 +78,7 @@ class TestPluginModelClient:"plugin/tenant-1/dispatch/model/validate_provider_credentials",)- def test_validate_provider_credentials_without_dict_update(self, mocker):+ def test_validate_provider_credentials_without_dict_update(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client,@@ -91,13 +92,13 @@ class TestPluginModelClient:assert result is Falseassert credentials == {"api_key": "same"}- def test_validate_provider_credentials_empty_returns_false(self, mocker):+ def test_validate_provider_credentials_empty_returns_false(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))assert client.validate_provider_credentials("tenant-1", "user-1", "org/plugin:1", "provider-a", {}) is False- def test_validate_model_credentials(self, mocker):+ def test_validate_model_credentials(self, mocker: MockerFixture):client = PluginModelClient()stream_mock = mocker.patch.object(client,@@ -123,7 +124,7 @@ class TestPluginModelClient:"plugin/tenant-1/dispatch/model/validate_model_credentials",)- def test_validate_model_credentials_empty_returns_false(self, mocker):+ def test_validate_model_credentials_empty_returns_false(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -132,7 +133,7 @@ class TestPluginModelClient:is False)- def test_invoke_llm(self, mocker):+ def test_invoke_llm(self, mocker: MockerFixture):client = PluginModelClient()stream_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter(["chunk-1"])@@ -160,7 +161,7 @@ class TestPluginModelClient:assert call_kwargs["data"]["data"]["stream"] is Falseassert call_kwargs["data"]["data"]["model_parameters"] == {"temperature": 0.1}- def test_invoke_llm_wraps_plugin_daemon_inner_error(self, mocker):+ def test_invoke_llm_wraps_plugin_daemon_inner_error(self, mocker: MockerFixture):client = PluginModelClient()def _boom():@@ -182,7 +183,7 @@ class TestPluginModelClient:))- def test_get_llm_num_tokens(self, mocker):+ def test_get_llm_num_tokens(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client,@@ -204,7 +205,7 @@ class TestPluginModelClient:assert result == 42- def test_get_llm_num_tokens_empty_returns_zero(self, mocker):+ def test_get_llm_num_tokens_empty_returns_zero(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -213,7 +214,7 @@ class TestPluginModelClient:== 0)- def test_invoke_text_embedding(self, mocker):+ def test_invoke_text_embedding(self, mocker: MockerFixture):client = PluginModelClient()embedding_result = SimpleNamespace(data=[[0.1, 0.2]])mocker.patch.object(@@ -233,7 +234,7 @@ class TestPluginModelClient:assert result is embedding_result- def test_invoke_text_embedding_empty_raises(self, mocker):+ def test_invoke_text_embedding_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -242,7 +243,7 @@ class TestPluginModelClient:"tenant-1", "user-1", "org/plugin:1", "provider-a", "embedding-a", {}, ["hello"], "x")- def test_invoke_multimodal_embedding(self, mocker):+ def test_invoke_multimodal_embedding(self, mocker: MockerFixture):client = PluginModelClient()embedding_result = SimpleNamespace(data=[[0.3, 0.4]])mocker.patch.object(@@ -262,7 +263,7 @@ class TestPluginModelClient:assert result is embedding_result- def test_invoke_multimodal_embedding_empty_raises(self, mocker):+ def test_invoke_multimodal_embedding_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -271,7 +272,7 @@ class TestPluginModelClient:"tenant-1", "user-1", "org/plugin:1", "provider-a", "embedding-a", {}, [{"type": "image"}], "x")- def test_get_text_embedding_num_tokens(self, mocker):+ def test_get_text_embedding_num_tokens(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client,@@ -287,7 +288,7 @@ class TestPluginModelClient:3,]- def test_get_text_embedding_num_tokens_empty_returns_list(self, mocker):+ def test_get_text_embedding_num_tokens_empty_returns_list(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -298,7 +299,7 @@ class TestPluginModelClient:== [])- def test_invoke_rerank(self, mocker):+ def test_invoke_rerank(self, mocker: MockerFixture):client = PluginModelClient()rerank_result = SimpleNamespace(scores=[0.9])mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([rerank_result]))@@ -318,14 +319,14 @@ class TestPluginModelClient:assert result is rerank_result- def test_invoke_rerank_empty_raises(self, mocker):+ def test_invoke_rerank_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))with pytest.raises(ValueError, match="Failed to invoke rerank"):client.invoke_rerank("tenant-1", "user-1", "org/plugin:1", "provider-a", "rerank-a", {}, "q", ["doc-1"])- def test_invoke_multimodal_rerank(self, mocker):+ def test_invoke_multimodal_rerank(self, mocker: MockerFixture):client = PluginModelClient()rerank_result = SimpleNamespace(scores=[0.8])mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([rerank_result]))@@ -345,7 +346,7 @@ class TestPluginModelClient:assert result is rerank_result- def test_invoke_multimodal_rerank_empty_raises(self, mocker):+ def test_invoke_multimodal_rerank_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -361,7 +362,7 @@ class TestPluginModelClient:[{"type": "image"}],)- def test_invoke_tts(self, mocker):+ def test_invoke_tts(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client,@@ -384,7 +385,7 @@ class TestPluginModelClient:assert result == [b"hello", b"!"]- def test_invoke_tts_wraps_plugin_daemon_inner_error(self, mocker):+ def test_invoke_tts_wraps_plugin_daemon_inner_error(self, mocker: MockerFixture):client = PluginModelClient()def _boom():@@ -396,7 +397,7 @@ class TestPluginModelClient:with pytest.raises(ValueError, match="tts error-400"):list(client.invoke_tts("tenant-1", "user-1", "org/plugin:1", "provider-a", "tts-a", {}, "hello", "alloy"))- def test_get_tts_model_voices(self, mocker):+ def test_get_tts_model_voices(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client,@@ -425,13 +426,13 @@ class TestPluginModelClient:assert result == [{"name": "Alloy", "value": "alloy"}, {"name": "Echo", "value": "echo"}]- def test_get_tts_model_voices_empty_returns_list(self, mocker):+ def test_get_tts_model_voices_empty_returns_list(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))assert client.get_tts_model_voices("tenant-1", "user-1", "org/plugin:1", "provider-a", "tts-a", {}) == []- def test_invoke_speech_to_text(self, mocker):+ def test_invoke_speech_to_text(self, mocker: MockerFixture):client = PluginModelClient()stream_mock = mocker.patch.object(client,@@ -452,7 +453,7 @@ class TestPluginModelClient:assert result == "transcribed text"assert stream_mock.call_args.kwargs["data"]["data"]["file"] == "616263"- def test_invoke_speech_to_text_empty_raises(self, mocker):+ def test_invoke_speech_to_text_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -461,7 +462,7 @@ class TestPluginModelClient:"tenant-1", "user-1", "org/plugin:1", "provider-a", "stt-a", {}, io.BytesIO(b"abc"))- def test_invoke_moderation(self, mocker):+ def test_invoke_moderation(self, mocker: MockerFixture):client = PluginModelClient()stream_mock = mocker.patch.object(client,@@ -482,7 +483,7 @@ class TestPluginModelClient:assert result is Trueassert stream_mock.call_args.kwargs["path"] == "plugin/tenant-1/dispatch/moderation/invoke"- def test_invoke_moderation_empty_raises(self, mocker):+ def test_invoke_moderation_empty_raises(self, mocker: MockerFixture):client = PluginModelClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))diff --git a/api/tests/unit_tests/core/plugin/impl/test_oauth_handler.py b/api/tests/unit_tests/core/plugin/impl/test_oauth_handler.pyindex 6fb4c994322..f6c9b1c6692 100644--- a/api/tests/unit_tests/core/plugin/impl/test_oauth_handler.py+++ b/api/tests/unit_tests/core/plugin/impl/test_oauth_handler.py@@ -2,6 +2,7 @@ from io import BytesIOfrom types import SimpleNamespaceimport pytest+from pytest_mock import MockerFixturefrom werkzeug import Requestfrom core.plugin.impl.oauth import OAuthHandler@@ -25,7 +26,7 @@ def _build_request(body: bytes = b"payload") -> Request:class TestOAuthHandler:- def test_get_authorization_url(self, mocker):+ def test_get_authorization_url(self, mocker: MockerFixture):handler = OAuthHandler()stream_mock = mocker.patch.object(handler,@@ -45,7 +46,7 @@ class TestOAuthHandler:assert response.authorization_url == "https://auth.example.com"assert stream_mock.call_count == 1- def test_get_authorization_url_no_response_raises(self, mocker):+ def test_get_authorization_url_no_response_raises(self, mocker: MockerFixture):handler = OAuthHandler()mocker.patch.object(handler, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -59,7 +60,7 @@ class TestOAuthHandler:system_credentials={},)- def test_get_credentials(self, mocker):+ def test_get_credentials(self, mocker: MockerFixture):handler = OAuthHandler()captured_data = {}@@ -85,7 +86,7 @@ class TestOAuthHandler:assert "raw_http_request" in captured_data["data"]assert stream_mock.call_count == 1- def test_get_credentials_no_response_raises(self, mocker):+ def test_get_credentials_no_response_raises(self, mocker: MockerFixture):handler = OAuthHandler()mocker.patch.object(handler, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -100,7 +101,7 @@ class TestOAuthHandler:request=_build_request(),)- def test_refresh_credentials(self, mocker):+ def test_refresh_credentials(self, mocker: MockerFixture):handler = OAuthHandler()stream_mock = mocker.patch.object(handler,@@ -121,7 +122,7 @@ class TestOAuthHandler:assert response.credentials == {"token": "new"}assert stream_mock.call_count == 1- def test_refresh_credentials_no_response_raises(self, mocker):+ def test_refresh_credentials_no_response_raises(self, mocker: MockerFixture):handler = OAuthHandler()mocker.patch.object(handler, "_request_with_plugin_daemon_response_stream", return_value=iter([]))diff --git a/api/tests/unit_tests/core/plugin/impl/test_tool_manager.py b/api/tests/unit_tests/core/plugin/impl/test_tool_manager.pyindex 80cf46f9bb9..3ae3cc18e4b 100644--- a/api/tests/unit_tests/core/plugin/impl/test_tool_manager.py+++ b/api/tests/unit_tests/core/plugin/impl/test_tool_manager.py@@ -1,5 +1,7 @@from types import SimpleNamespace+from pytest_mock import MockerFixture+from core.plugin.entities.plugin_daemon import CredentialTypefrom core.plugin.impl.tool import PluginToolManager@@ -15,7 +17,7 @@ def _tool_provider(name: str = "provider") -> SimpleNamespace:class TestPluginToolManager:- def test_fetch_tool_providers(self, mocker):+ def test_fetch_tool_providers(self, mocker: MockerFixture):manager = PluginToolManager()provider = _tool_provider("remote")mocker.patch("core.plugin.impl.tool.resolve_dify_schema_refs", return_value={"resolved": True})@@ -44,7 +46,7 @@ class TestPluginToolManager:assert result[0].declaration.identity.name == "org/plugin/remote"assert result[0].declaration.tools[0].identity.provider == "org/plugin/remote"- def test_fetch_tool_provider(self, mocker):+ def test_fetch_tool_provider(self, mocker: MockerFixture):manager = PluginToolManager()provider = _tool_provider("provider")mocker.patch("core.plugin.impl.tool.resolve_dify_schema_refs", return_value={"resolved": True})@@ -68,7 +70,7 @@ class TestPluginToolManager:assert result.declaration.identity.name == "org/plugin/provider"assert result.declaration.tools[0].identity.provider == "org/plugin/provider"- def test_invoke_merges_chunks(self, mocker):+ def test_invoke_merges_chunks(self, mocker: MockerFixture):manager = PluginToolManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream", return_value=iter(["chunk"])@@ -92,7 +94,7 @@ class TestPluginToolManager:assert merge_mock.call_count == 1assert stream_mock.call_args.kwargs["headers"]["X-Plugin-ID"] == "org/plugin"- def test_validate_credentials_paths(self, mocker):+ def test_validate_credentials_paths(self, mocker: MockerFixture):manager = PluginToolManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")@@ -108,7 +110,7 @@ class TestPluginToolManager:stream_mock.return_value = iter([])assert manager.validate_datasource_credentials("tenant-1", "user-1", "org/plugin/provider", {"k": "v"}) is False- def test_get_runtime_parameters_paths(self, mocker):+ def test_get_runtime_parameters_paths(self, mocker: MockerFixture):manager = PluginToolManager()stream_mock = mocker.patch.object(manager, "_request_with_plugin_daemon_response_stream")diff --git a/api/tests/unit_tests/core/plugin/impl/test_trigger_client.py b/api/tests/unit_tests/core/plugin/impl/test_trigger_client.pyindex 76da51c2c8b..811bb7e50dd 100644--- a/api/tests/unit_tests/core/plugin/impl/test_trigger_client.py+++ b/api/tests/unit_tests/core/plugin/impl/test_trigger_client.py@@ -2,6 +2,7 @@ from io import BytesIOfrom types import SimpleNamespaceimport pytest+from pytest_mock import MockerFixturefrom werkzeug import Requestfrom core.plugin.entities.plugin_daemon import CredentialType@@ -62,7 +63,7 @@ def _subscription_call_kwargs(method_name: str) -> dict:class TestPluginTriggerClient:- def test_fetch_trigger_providers(self, mocker):+ def test_fetch_trigger_providers(self, mocker: MockerFixture):client = PluginTriggerClient()provider = _trigger_provider("remote")@@ -89,7 +90,7 @@ class TestPluginTriggerClient:assert result[0].declaration.identity.name == "org/plugin/remote"assert result[0].declaration.events[0].identity.provider == "org/plugin/remote"- def test_fetch_trigger_provider(self, mocker):+ def test_fetch_trigger_provider(self, mocker: MockerFixture):client = PluginTriggerClient()provider = _trigger_provider("provider")@@ -108,7 +109,7 @@ class TestPluginTriggerClient:assert result.declaration.identity.name == "org/plugin/provider"assert result.declaration.events[0].identity.provider == "org/plugin/provider"- def test_invoke_trigger_event(self, mocker):+ def test_invoke_trigger_event(self, mocker: MockerFixture):client = PluginTriggerClient()stream_mock = mocker.patch.object(client,@@ -132,7 +133,7 @@ class TestPluginTriggerClient:assert result.variables == {"ok": True}assert stream_mock.call_count == 1- def test_invoke_trigger_event_no_response_raises(self, mocker):+ def test_invoke_trigger_event_no_response_raises(self, mocker: MockerFixture):client = PluginTriggerClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))@@ -150,7 +151,7 @@ class TestPluginTriggerClient:payload={"payload": 1},)- def test_validate_provider_credentials(self, mocker):+ def test_validate_provider_credentials(self, mocker: MockerFixture):client = PluginTriggerClient()stream_mock = mocker.patch.object(client, "_request_with_plugin_daemon_response_stream")@@ -163,7 +164,7 @@ class TestPluginTriggerClient:):client.validate_provider_credentials("tenant-1", "user-1", "org/plugin/provider", {"k": "v"})- def test_dispatch_event(self, mocker):+ def test_dispatch_event(self, mocker: MockerFixture):client = PluginTriggerClient()stream_mock = mocker.patch.object(client,@@ -195,7 +196,7 @@ class TestPluginTriggerClient:)@pytest.mark.parametrize("method_name", ["subscribe", "unsubscribe", "refresh"])- def test_subscription_operations_success(self, mocker, method_name):+ def test_subscription_operations_success(self, mocker: MockerFixture, method_name):client = PluginTriggerClient()stream_mock = mocker.patch.object(client,@@ -217,7 +218,7 @@ class TestPluginTriggerClient:("refresh", "No response received from plugin daemon for refresh"),],)- def test_subscription_operations_no_response(self, mocker, method_name, expected):+ def test_subscription_operations_no_response(self, mocker: MockerFixture, method_name, expected):client = PluginTriggerClient()mocker.patch.object(client, "_request_with_plugin_daemon_response_stream", return_value=iter([]))method = getattr(client, method_name)diff --git a/api/tests/unit_tests/core/plugin/test_backwards_invocation_app.py b/api/tests/unit_tests/core/plugin/test_backwards_invocation_app.pyindex 3feb4159ade..2ed7c70ed94 100644--- a/api/tests/unit_tests/core/plugin/test_backwards_invocation_app.py+++ b/api/tests/unit_tests/core/plugin/test_backwards_invocation_app.py@@ -4,6 +4,7 @@ from unittest.mock import MagicMockimport pytestfrom pydantic import BaseModel+from pytest_mock import MockerFixturefrom core.app.layers.pause_state_persist_layer import PauseStateLayerConfigfrom core.plugin.backwards_invocation.app import PluginAppBackwardsInvocation@@ -41,7 +42,7 @@ class TestBaseBackwardsInvocation:class TestPluginAppBackwardsInvocation:- def test_fetch_app_info_workflow_path(self, mocker):+ def test_fetch_app_info_workflow_path(self, mocker: MockerFixture):workflow = MagicMock()workflow.features_dict = {"feature": "v"}workflow.user_input_form.return_value = [{"name": "foo"}]@@ -57,7 +58,7 @@ class TestPluginAppBackwardsInvocation:assert result == {"data": {"mapped": True}}mapper.assert_called_once_with(features_dict={"feature": "v"}, user_input_form=[{"name": "foo"}])- def test_fetch_app_info_model_config_path(self, mocker):+ def test_fetch_app_info_model_config_path(self, mocker: MockerFixture):model_config = MagicMock()model_config.to_dict.return_value = {"user_input_form": [{"name": "bar"}], "k": "v"}app = MagicMock(mode=AppMode.COMPLETION, app_model_config=model_config)@@ -81,7 +82,7 @@ class TestPluginAppBackwardsInvocation:(AppMode.COMPLETION, "invoke_completion_app"),],)- def test_invoke_app_routes_by_mode(self, mocker, mode, route_method):+ def test_invoke_app_routes_by_mode(self, mocker: MockerFixture, mode, route_method):app = MagicMock(mode=mode)user = MagicMock()mocker.patch.object(PluginAppBackwardsInvocation, "_get_app", return_value=app)@@ -102,7 +103,7 @@ class TestPluginAppBackwardsInvocation:assert result == {"routed": True}assert route.call_count == 1- def test_invoke_app_uses_end_user_when_user_id_missing(self, mocker):+ def test_invoke_app_uses_end_user_when_user_id_missing(self, mocker: MockerFixture):app = MagicMock(mode=AppMode.WORKFLOW)end_user = MagicMock()mocker.patch.object(PluginAppBackwardsInvocation, "_get_app", return_value=app)@@ -127,7 +128,7 @@ class TestPluginAppBackwardsInvocation:get_or_create.assert_called_once_with(app)assert route.call_args.args[1] is end_user- def test_invoke_app_missing_query_for_chat_raises(self, mocker):+ def test_invoke_app_missing_query_for_chat_raises(self, mocker: MockerFixture):mocker.patch.object(PluginAppBackwardsInvocation, "_get_app", return_value=MagicMock(mode=AppMode.CHAT))mocker.patch.object(PluginAppBackwardsInvocation, "_get_user", return_value=MagicMock())@@ -143,7 +144,7 @@ class TestPluginAppBackwardsInvocation:files=[],)- def test_invoke_app_unexpected_mode_raises(self, mocker):+ def test_invoke_app_unexpected_mode_raises(self, mocker: MockerFixture):mocker.patch.object(PluginAppBackwardsInvocation, "_get_app", return_value=MagicMock(mode="other"))mocker.patch.object(PluginAppBackwardsInvocation, "_get_user", return_value=MagicMock())@@ -166,7 +167,7 @@ class TestPluginAppBackwardsInvocation:(AppMode.CHAT, "core.plugin.backwards_invocation.app.ChatAppGenerator.generate"),],)- def test_invoke_chat_app_agent_and_chat(self, mocker, mode, generator_path):+ def test_invoke_chat_app_agent_and_chat(self, mocker: MockerFixture, mode, generator_path):app = MagicMock(mode=mode, workflow=None)spy = mocker.patch(generator_path, return_value={"result": "ok"})@@ -183,7 +184,7 @@ class TestPluginAppBackwardsInvocation:assert result == {"result": "ok"}assert spy.call_count == 1- def test_invoke_chat_app_advanced_chat_injects_pause_state_config(self, mocker):+ def test_invoke_chat_app_advanced_chat_injects_pause_state_config(self, mocker: MockerFixture):workflow = MagicMock()workflow.created_by = "owner-id"@@ -242,7 +243,7 @@ class TestPluginAppBackwardsInvocation:files=[],)- def test_invoke_workflow_app_injects_pause_state_config(self, mocker):+ def test_invoke_workflow_app_injects_pause_state_config(self, mocker: MockerFixture):workflow = MagicMock()workflow.created_by = "owner-id"@@ -284,7 +285,7 @@ class TestPluginAppBackwardsInvocation:files=[],)- def test_invoke_completion_app(self, mocker):+ def test_invoke_completion_app(self, mocker: MockerFixture):spy = mocker.patch("core.plugin.backwards_invocation.app.CompletionAppGenerator.generate", return_value={"ok": 1})@@ -295,7 +296,7 @@ class TestPluginAppBackwardsInvocation:assert result == {"ok": 1}assert spy.call_count == 1- def test_get_user_returns_end_user(self, mocker):+ def test_get_user_returns_end_user(self, mocker: MockerFixture):session = MagicMock()session.scalar.side_effect = [MagicMock(id="end-user")]session_ctx = MagicMock()@@ -307,7 +308,7 @@ class TestPluginAppBackwardsInvocation:user = PluginAppBackwardsInvocation._get_user("uid")assert user.id == "end-user"- def test_get_user_falls_back_to_account_user(self, mocker):+ def test_get_user_falls_back_to_account_user(self, mocker: MockerFixture):session = MagicMock()session.scalar.side_effect = [None, MagicMock(id="account-user")]session_ctx = MagicMock()@@ -319,7 +320,7 @@ class TestPluginAppBackwardsInvocation:user = PluginAppBackwardsInvocation._get_user("uid")assert user.id == "account-user"- def test_get_user_raises_when_user_not_found(self, mocker):+ def test_get_user_raises_when_user_not_found(self, mocker: MockerFixture):session = MagicMock()session.scalar.side_effect = [None, None]session_ctx = MagicMock()@@ -331,21 +332,21 @@ class TestPluginAppBackwardsInvocation:with pytest.raises(ValueError, match="user not found"):PluginAppBackwardsInvocation._get_user("uid")- def test_get_app_returns_app(self, mocker):+ def test_get_app_returns_app(self, mocker: MockerFixture):app_obj = MagicMock(id="app")db = SimpleNamespace(session=MagicMock(scalar=MagicMock(return_value=app_obj)))mocker.patch("core.plugin.backwards_invocation.app.db", db)assert PluginAppBackwardsInvocation._get_app("app", "tenant") is app_obj- def test_get_app_raises_when_missing(self, mocker):+ def test_get_app_raises_when_missing(self, mocker: MockerFixture):db = SimpleNamespace(session=MagicMock(scalar=MagicMock(return_value=None)))mocker.patch("core.plugin.backwards_invocation.app.db", db)with pytest.raises(ValueError, match="app not found"):PluginAppBackwardsInvocation._get_app("app", "tenant")- def test_get_app_raises_when_query_fails(self, mocker):+ def test_get_app_raises_when_query_fails(self, mocker: MockerFixture):db = SimpleNamespace(session=MagicMock(scalar=MagicMock(side_effect=RuntimeError("db down"))))mocker.patch("core.plugin.backwards_invocation.app.db", db)diff --git a/api/tests/unit_tests/core/plugin/test_plugin_entities.py b/api/tests/unit_tests/core/plugin/test_plugin_entities.pyindex f1c4c7e7009..deac0ba1da5 100644--- a/api/tests/unit_tests/core/plugin/test_plugin_entities.py+++ b/api/tests/unit_tests/core/plugin/test_plugin_entities.py@@ -5,6 +5,7 @@ from enum import StrEnumimport pytestfrom flask import Responsefrom pydantic import ValidationError+from pytest_mock import MockerFixturefrom core.plugin.entities.endpoint import EndpointEntityWithInstancefrom core.plugin.entities.marketplace import MarketplacePluginDeclaration, MarketplacePluginSnapshot@@ -34,7 +35,7 @@ from graphon.model_runtime.entities.message_entities import (class TestEndpointEntity:- def test_endpoint_entity_with_instance_renders_url(self, mocker):+ def test_endpoint_entity_with_instance_renders_url(self, mocker: MockerFixture):mocker.patch("core.plugin.entities.endpoint.dify_config.ENDPOINT_URL_TEMPLATE", "https://dify.test/{hook_id}")now = datetime.datetime.now(datetime.UTC)diff --git a/api/tests/unit_tests/core/prompt/test_extract_thread_messages.py b/api/tests/unit_tests/core/prompt/test_extract_thread_messages.pyindex 1b114b369a2..1f46634b892 100644--- a/api/tests/unit_tests/core/prompt/test_extract_thread_messages.py+++ b/api/tests/unit_tests/core/prompt/test_extract_thread_messages.py@@ -1,5 +1,7 @@from uuid import uuid4+from pytest_mock import MockerFixture+from constants import UUID_NILfrom core.prompt.utils.extract_thread_messages import extract_thread_messagesfrom core.prompt.utils.get_thread_messages_length import get_thread_messages_length@@ -103,7 +105,7 @@ def test_extract_thread_messages_breaks_when_parent_is_none():assert result[0].id == id2-def test_get_thread_messages_length_excludes_newly_created_empty_answer(mocker):+def test_get_thread_messages_length_excludes_newly_created_empty_answer(mocker: MockerFixture):id1, id2 = str(uuid4()), str(uuid4())messages = [MockMessage(id2, id1, answer=""), # newest generated message should be excluded@@ -119,7 +121,7 @@ def test_get_thread_messages_length_excludes_newly_created_empty_answer(mocker):mock_scalars.assert_called_once()-def test_get_thread_messages_length_keeps_non_empty_latest_answer(mocker):+def test_get_thread_messages_length_keeps_non_empty_latest_answer(mocker: MockerFixture):id1, id2 = str(uuid4()), str(uuid4())messages = [MockMessage(id2, id1, answer="latest-answer"),diff --git a/api/tests/unit_tests/core/prompt/test_prompt_transform.py b/api/tests/unit_tests/core/prompt/test_prompt_transform.pyindex 5308c8e7b3b..3d71e734960 100644--- a/api/tests/unit_tests/core/prompt/test_prompt_transform.py+++ b/api/tests/unit_tests/core/prompt/test_prompt_transform.py@@ -209,7 +209,7 @@ class TestPromptTransform:assert result == ["only"]memory.get_history_prompt_messages.assert_called_with(max_token_limit=10, message_limit=None)- def test_append_chat_histories_extends_prompt_messages(self, monkeypatch):+ def test_append_chat_histories_extends_prompt_messages(self, monkeypatch: pytest.MonkeyPatch):transform = PromptTransform()memory = MagicMock()memory_config = SimpleNamespace(window=SimpleNamespace(enabled=False, size=None))diff --git a/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py b/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.pyindex 1e91c2dd88c..e233bd2ef07 100644--- a/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py+++ b/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba.py@@ -67,7 +67,7 @@ def _dataset(dataset_keyword_table=None, keyword_number=None):@pytest.fixture-def patched_runtime(monkeypatch):+def patched_runtime(monkeypatch: pytest.MonkeyPatch):session = MagicMock()db = SimpleNamespace(session=session)storage = MagicMock()@@ -151,7 +151,7 @@ def test_add_texts_without_keywords_list_always_uses_extractor(monkeypatch, patcassert set(keyword._update_segment_keywords.call_args.args[2]) == {"from-extractor"}-def test_text_exists_handles_missing_and_existing_keyword_table(monkeypatch):+def test_text_exists_handles_missing_and_existing_keyword_table(monkeypatch: pytest.MonkeyPatch):keyword = Jieba(_dataset(_dataset_keyword_table()))monkeypatch.setattr(keyword, "_get_dataset_keyword_table", MagicMock(return_value=None))@@ -308,7 +308,7 @@ def test_add_and_delete_ids_from_keyword_table_helpers():assert deleted["kw2"] == {"node-2"}-def test_retrieve_ids_by_query_ranks_by_keyword_frequency(monkeypatch):+def test_retrieve_ids_by_query_ranks_by_keyword_frequency(monkeypatch: pytest.MonkeyPatch):keyword = Jieba(_dataset(_dataset_keyword_table()))handler = MagicMock()handler.extract_keywords.return_value = ["kw-a", "kw-b"]@@ -350,7 +350,7 @@ def test_update_segment_keywords_updates_when_segment_exists(monkeypatch, patchepatched_runtime.session.commit.assert_not_called()-def test_create_segment_keywords_and_update_segment_keywords_index(monkeypatch):+def test_create_segment_keywords_and_update_segment_keywords_index(monkeypatch: pytest.MonkeyPatch):keyword = Jieba(_dataset(_dataset_keyword_table()))monkeypatch.setattr(keyword, "_get_dataset_keyword_table", MagicMock(return_value={}))monkeypatch.setattr(keyword, "_update_segment_keywords", MagicMock())@@ -365,7 +365,7 @@ def test_create_segment_keywords_and_update_segment_keywords_index(monkeypatch):keyword._save_dataset_keyword_table.assert_called_once()-def test_multi_create_segment_keywords_uses_provided_and_extracted_keywords(monkeypatch):+def test_multi_create_segment_keywords_uses_provided_and_extracted_keywords(monkeypatch: pytest.MonkeyPatch):keyword = Jieba(_dataset(_dataset_keyword_table(), keyword_number=2))handler = MagicMock()handler.extract_keywords.return_value = {"auto"}diff --git a/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py b/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.pyindex a4586c141bb..c8ee75bf431 100644--- a/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py+++ b/api/tests/unit_tests/core/rag/datasource/keyword/jieba/test_jieba_keyword_table_handler.py@@ -2,6 +2,8 @@ import sysimport typesfrom types import SimpleNamespace+import pytest+from core.rag.datasource.keyword.jieba.jieba_keyword_table_handler import JiebaKeywordTableHandlerfrom core.rag.datasource.keyword.jieba.stopwords import STOPWORDS@@ -38,7 +40,7 @@ def _install_fake_jieba_modules(monkeypatch.delitem(sys.modules, "jieba.analyse.tfidf", raising=False)-def test_init_uses_existing_default_tfidf(monkeypatch):+def test_init_uses_existing_default_tfidf(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")default_tfidf = _DummyTFIDF()analyse_module.default_tfidf = default_tfidf@@ -51,7 +53,7 @@ def test_init_uses_existing_default_tfidf(monkeypatch):assert handler._tfidf.stop_words == STOPWORDS-def test_load_tfidf_extractor_uses_tfidf_class_and_caches_default(monkeypatch):+def test_load_tfidf_extractor_uses_tfidf_class_and_caches_default(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")analyse_module.default_tfidf = None@@ -67,7 +69,7 @@ def test_load_tfidf_extractor_uses_tfidf_class_and_caches_default(monkeypatch):assert analyse_module.default_tfidf is handler._tfidf-def test_load_tfidf_extractor_imports_from_tfidf_submodule(monkeypatch):+def test_load_tfidf_extractor_imports_from_tfidf_submodule(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")analyse_module.default_tfidf = None@@ -85,7 +87,7 @@ def test_load_tfidf_extractor_imports_from_tfidf_submodule(monkeypatch):assert analyse_module.default_tfidf is handler._tfidf-def test_load_tfidf_extractor_falls_back_when_tfidf_unavailable(monkeypatch):+def test_load_tfidf_extractor_falls_back_when_tfidf_unavailable(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")analyse_module.default_tfidf = None_install_fake_jieba_modules(monkeypatch, analyse_module)@@ -96,7 +98,7 @@ def test_load_tfidf_extractor_falls_back_when_tfidf_unavailable(monkeypatch):assert fallback_keywords == ["two"]-def test_build_fallback_tfidf_uses_lcut_when_available(monkeypatch):+def test_build_fallback_tfidf_uses_lcut_when_available(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")_install_fake_jieba_modules(monkeypatch, analyse_module, jieba_attrs={"lcut": lambda _: ["x", "x", "y"]})@@ -105,7 +107,7 @@ def test_build_fallback_tfidf_uses_lcut_when_available(monkeypatch):assert tfidf.extract_tags("ignored", topK=1) == ["x"]-def test_build_fallback_tfidf_uses_cut_when_lcut_is_missing(monkeypatch):+def test_build_fallback_tfidf_uses_cut_when_lcut_is_missing(monkeypatch: pytest.MonkeyPatch):analyse_module = types.ModuleType("jieba.analyse")_install_fake_jieba_modules(monkeypatch,diff --git a/api/tests/unit_tests/core/rag/datasource/keyword/test_keyword_factory.py b/api/tests/unit_tests/core/rag/datasource/keyword/test_keyword_factory.pyindex 0d969a3270d..e1765b17cb4 100644--- a/api/tests/unit_tests/core/rag/datasource/keyword/test_keyword_factory.py+++ b/api/tests/unit_tests/core/rag/datasource/keyword/test_keyword_factory.py@@ -10,7 +10,7 @@ from core.rag.datasource.keyword.keyword_type import KeyWordTypefrom core.rag.models.document import Document-def test_get_keyword_factory_returns_jieba_factory(monkeypatch):+def test_get_keyword_factory_returns_jieba_factory(monkeypatch: pytest.MonkeyPatch):fake_module = types.ModuleType("core.rag.datasource.keyword.jieba.jieba")class FakeJieba:@@ -27,7 +27,7 @@ def test_get_keyword_factory_raises_for_unsupported_type():Keyword.get_keyword_factory("unsupported")-def test_keyword_initialization_uses_configured_factory(monkeypatch):+def test_keyword_initialization_uses_configured_factory(monkeypatch: pytest.MonkeyPatch):dataset = SimpleNamespace(id="dataset-1")fake_processor = MagicMock()diff --git a/api/tests/unit_tests/core/rag/datasource/test_datasource_retrieval.py b/api/tests/unit_tests/core/rag/datasource/test_datasource_retrieval.pyindex b0ecad4d0cc..d38213dd894 100644--- a/api/tests/unit_tests/core/rag/datasource/test_datasource_retrieval.py+++ b/api/tests/unit_tests/core/rag/datasource/test_datasource_retrieval.py@@ -182,7 +182,7 @@ class TestRetrievalServiceInternals:app.app_context.return_value.__exit__.return_value = Falsereturn app- def test_retrieve_with_attachment_ids_only(self, monkeypatch, internal_dataset):+ def test_retrieve_with_attachment_ids_only(self, monkeypatch: pytest.MonkeyPatch, internal_dataset):with (patch("core.rag.datasource.retrieval_service.RetrievalService._get_dataset", return_value=internal_dataset),patch("core.rag.datasource.retrieval_service.RetrievalService._retrieve") as mock_retrieve,@@ -699,7 +699,9 @@ class TestRetrievalServiceInternals:assert RetrievalService.format_retrieval_documents(documents) == []- def test_format_retrieval_documents_with_parent_child_summary_and_attachments(self, monkeypatch):+ def test_format_retrieval_documents_with_parent_child_summary_and_attachments(+ self, monkeypatch: pytest.MonkeyPatch+ ):dataset_doc_parent = SimpleNamespace(id="doc-parent",doc_form=IndexStructureType.PARENT_CHILD_INDEX,@@ -877,7 +879,7 @@ class TestRetrievalServiceInternals:assert result_by_segment_id["segment-parent-summary"].summary == "summary for parent"assert result_by_segment_id["segment-parent-summary"].child_chunks == []- def test_format_retrieval_documents_rolls_back_and_raises_when_db_fails(self, monkeypatch):+ def test_format_retrieval_documents_rolls_back_and_raises_when_db_fails(self, monkeypatch: pytest.MonkeyPatch):rollback = Mock()monkeypatch.setattr(retrieval_service_module.db.session, "rollback", rollback)monkeypatch.setattr(retrieval_service_module.db.session, "scalars", Mock(side_effect=RuntimeError("db error")))@@ -936,7 +938,7 @@ class TestRetrievalServiceInternals:future_ok.cancel.assert_called()def test_retrieve_internal_raises_value_error_when_exceptions_exist(- self, monkeypatch, internal_dataset, internal_flask_app+ self, monkeypatch: pytest.MonkeyPatch, internal_dataset, internal_flask_app):executor = _ImmediateExecutor()monkeypatch.setattr(retrieval_service_module, "ThreadPoolExecutor", lambda *args, **kwargs: executor)@@ -958,7 +960,9 @@ class TestRetrievalServiceInternals:query="query",)- def test_retrieve_internal_hybrid_weighted_attachment_flow(self, monkeypatch, internal_dataset, internal_flask_app):+ def test_retrieve_internal_hybrid_weighted_attachment_flow(+ self, monkeypatch: pytest.MonkeyPatch, internal_dataset, internal_flask_app+ ):executor = _ImmediateExecutor()monkeypatch.setattr(retrieval_service_module, "ThreadPoolExecutor", lambda *args, **kwargs: executor)monkeypatch.setattr(diff --git a/api/tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py b/api/tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.pyindex 7b6ee97f1c6..067159398d2 100644--- a/api/tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py+++ b/api/tests/unit_tests/core/rag/datasource/vdb/test_vector_factory.py@@ -102,7 +102,9 @@ def test_gen_index_struct_dict(vector_factory_module):("HOLOGRES", "dify_vdb_hologres.hologres_vector", "HologresVectorFactory"),],)-def test_get_vector_factory_supported(vector_factory_module, monkeypatch, vector_type, module_path, class_name):+def test_get_vector_factory_supported(+ vector_factory_module, monkeypatch: pytest.MonkeyPatch, vector_type, module_path, class_name+):expected_cls = _register_fake_factory_module(monkeypatch, module_path, class_name)result_cls = vector_factory_module.Vector.get_vector_factory(getattr(vector_factory_module.VectorType, vector_type))@@ -119,7 +121,7 @@ class _PluginChromaFactory:"""Stub used only for entry-point override test."""-def test_get_vector_factory_entry_point_overrides_builtin(vector_factory_module, monkeypatch):+def test_get_vector_factory_entry_point_overrides_builtin(vector_factory_module, monkeypatch: pytest.MonkeyPatch):from importlib.metadata import EntryPointfrom core.rag.datasource.vdb import vector_backend_registry as reg@@ -171,7 +173,7 @@ def test_vector_init_uses_default_and_custom_attributes(vector_factory_module):assert default_vector._vector_processor == "processor"-def test_lazy_embeddings_defer_real_load_until_first_embed_call(vector_factory_module, monkeypatch):+def test_lazy_embeddings_defer_real_load_until_first_embed_call(vector_factory_module, monkeypatch: pytest.MonkeyPatch):"""``Vector(dataset)`` must not transitively call ``ModelManager`` duringconstruction. The real embedding model should only be materialized on thefirst ``embed_*`` call (i.e. create / search paths) so cleanup paths@@ -214,7 +216,7 @@ def test_lazy_embeddings_defer_real_load_until_first_embed_call(vector_factory_minner_model.embed_documents.assert_called_once_with(["world"])-def test_init_vector_prefers_dataset_index_struct(vector_factory_module, monkeypatch):+def test_init_vector_prefers_dataset_index_struct(vector_factory_module, monkeypatch: pytest.MonkeyPatch):calls = {"vector_type": None, "init_args": None}class _Factory:@@ -242,7 +244,7 @@ def test_init_vector_prefers_dataset_index_struct(vector_factory_module, monkeypassert calls["init_args"] == (vector._dataset, ["doc_id"], "embeddings")-def test_init_vector_uses_whitelist_override(vector_factory_module, monkeypatch):+def test_init_vector_uses_whitelist_override(vector_factory_module, monkeypatch: pytest.MonkeyPatch):class _Expr:def __eq__(self, _other):return "expr"@@ -279,7 +281,7 @@ def test_init_vector_uses_whitelist_override(vector_factory_module, monkeypatch)assert calls["vector_type"] == vector_factory_module.VectorType.TIDB_ON_QDRANT-def test_init_vector_raises_when_vector_store_missing(vector_factory_module, monkeypatch):+def test_init_vector_raises_when_vector_store_missing(vector_factory_module, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(vector_factory_module.dify_config, "VECTOR_STORE", None)monkeypatch.setattr(vector_factory_module.dify_config, "VECTOR_STORE_WHITELIST_ENABLE", False)@@ -343,7 +345,7 @@ def test_create_skips_empty_text_documents_before_embedding(vector_factory_modulvector._vector_processor.create.assert_not_called()-def test_create_multimodal_filters_missing_uploads(vector_factory_module, monkeypatch):+def test_create_multimodal_filters_missing_uploads(vector_factory_module, monkeypatch: pytest.MonkeyPatch):class _Field:def in_(self, value):return value@@ -484,7 +486,7 @@ def test_vector_delegation_methods(vector_factory_module):vector._vector_processor.delete_by_metadata_field.assert_called_once_with("doc_id", "doc-1")-def test_search_by_file_handles_missing_and_existing_upload(vector_factory_module, monkeypatch):+def test_search_by_file_handles_missing_and_existing_upload(vector_factory_module, monkeypatch: pytest.MonkeyPatch):vector = vector_factory_module.Vector.__new__(vector_factory_module.Vector)vector._embeddings = MagicMock()vector._vector_processor = MagicMock()@@ -507,7 +509,7 @@ def test_search_by_file_handles_missing_and_existing_upload(vector_factory_modulassert payload["file_id"] == "file-2"-def test_delete_clears_redis_cache_when_collection_exists(vector_factory_module, monkeypatch):+def test_delete_clears_redis_cache_when_collection_exists(vector_factory_module, monkeypatch: pytest.MonkeyPatch):delete_mock = MagicMock()redis_delete = MagicMock()monkeypatch.setattr(vector_factory_module.redis_client, "delete", redis_delete)@@ -526,7 +528,7 @@ def test_delete_clears_redis_cache_when_collection_exists(vector_factory_module,redis_delete.assert_not_called()-def test_get_embeddings_builds_cache_embedding(vector_factory_module, monkeypatch):+def test_get_embeddings_builds_cache_embedding(vector_factory_module, monkeypatch: pytest.MonkeyPatch):model_manager = MagicMock()model_manager.get_model_instance.return_value = "model-instance"diff --git a/api/tests/unit_tests/core/rag/extractor/test_csv_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_csv_extractor.pyindex e6a06f163e8..2e1c5715c23 100644--- a/api/tests/unit_tests/core/rag/extractor/test_csv_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_csv_extractor.py@@ -39,7 +39,7 @@ class TestCSVExtractor:with pytest.raises(ValueError, match="Source column 'missing_col' not found"):extractor.extract()- def test_extract_wraps_unicode_error_when_autodetect_disabled(self, monkeypatch):+ def test_extract_wraps_unicode_error_when_autodetect_disabled(self, monkeypatch: pytest.MonkeyPatch):extractor = CSVExtractor("dummy.csv", autodetect_encoding=False)def raise_decode(*args, **kwargs):@@ -50,7 +50,7 @@ class TestCSVExtractor:with pytest.raises(RuntimeError, match="Error loading dummy.csv"):extractor.extract()- def test_extract_autodetect_encoding_success(self, monkeypatch):+ def test_extract_autodetect_encoding_success(self, monkeypatch: pytest.MonkeyPatch):extractor = CSVExtractor("dummy.csv", autodetect_encoding=True)attempted_encodings: list[str | None] = []@@ -75,7 +75,7 @@ class TestCSVExtractor:assert docs[0].page_content == "id: source-1;body: hello"assert attempted_encodings == [None, "bad", "utf-8"]- def test_extract_autodetect_encoding_all_attempts_fail_returns_empty(self, monkeypatch):+ def test_extract_autodetect_encoding_all_attempts_fail_returns_empty(self, monkeypatch: pytest.MonkeyPatch):extractor = CSVExtractor("dummy.csv", autodetect_encoding=True)def always_raise(*args, **kwargs):@@ -86,7 +86,7 @@ class TestCSVExtractor:assert extractor.extract() == []- def test_read_from_file_re_raises_csv_error(self, monkeypatch):+ def test_read_from_file_re_raises_csv_error(self, monkeypatch: pytest.MonkeyPatch):extractor = CSVExtractor("dummy.csv")monkeypatch.setattr(pd, "read_csv", lambda *args, **kwargs: (_ for _ in ()).throw(csv.Error("bad csv")))diff --git a/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.pyindex d2bcc1e2c4f..2b42adc7161 100644--- a/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_excel_extractor.py@@ -45,7 +45,7 @@ class _FakeWorkbook:class TestExcelExtractor:- def test_extract_xlsx_with_hyperlinks_and_sheet_skip(self, monkeypatch):+ def test_extract_xlsx_with_hyperlinks_and_sheet_skip(self, monkeypatch: pytest.MonkeyPatch):sheet_with_data = _FakeSheet(header_rows=[("Name", "Link")],data_rows=[@@ -68,7 +68,7 @@ class TestExcelExtractor:assert docs[1].page_content == '"Name":"";"Link":"123"'assert all(doc.metadata["source"] == "/tmp/sample.xlsx" for doc in docs)- def test_extract_xls_path(self, monkeypatch):+ def test_extract_xls_path(self, monkeypatch: pytest.MonkeyPatch):class FakeExcelFile:sheet_names = ["Sheet1"]diff --git a/api/tests/unit_tests/core/rag/extractor/test_extract_processor.py b/api/tests/unit_tests/core/rag/extractor/test_extract_processor.pyindex 5beed88971d..b4b08f57ec8 100644--- a/api/tests/unit_tests/core/rag/extractor/test_extract_processor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_extract_processor.py@@ -56,7 +56,7 @@ def _patch_all_extractors(monkeypatch) -> _ExtractorFactory:class TestExtractProcessorLoaders:- def test_load_from_upload_file_return_docs_and_text(self, monkeypatch):+ def test_load_from_upload_file_return_docs_and_text(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(processor_module, "ExtractSetting", lambda **kwargs: SimpleNamespace(**kwargs))monkeypatch.setattr(@@ -93,7 +93,9 @@ class TestExtractProcessorLoaders:),],)- def test_load_from_url_builds_temp_file_with_correct_suffix(self, monkeypatch, url, headers, expected_suffix):+ def test_load_from_url_builds_temp_file_with_correct_suffix(+ self, monkeypatch: pytest.MonkeyPatch, url, headers, expected_suffix+ ):response = SimpleNamespace(headers=headers, content=b"body")monkeypatch.setattr(processor_module.ssrf_proxy, "get", lambda *args, **kwargs: response)monkeypatch.setattr(processor_module, "ExtractSetting", lambda **kwargs: SimpleNamespace(**kwargs))@@ -119,11 +121,13 @@ class TestExtractProcessorLoaders:class TestExtractProcessorFileRouting:@pytest.fixture(autouse=True)- def _set_unstructured_config(self, monkeypatch):+ def _set_unstructured_config(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(processor_module.dify_config, "UNSTRUCTURED_API_URL", "https://unstructured")monkeypatch.setattr(processor_module.dify_config, "UNSTRUCTURED_API_KEY", "key")- def _run_extract_for_extension(self, monkeypatch, extension: str, etl_type: str, is_automatic: bool = False):+ def _run_extract_for_extension(+ self, monkeypatch: pytest.MonkeyPatch, extension: str, etl_type: str, is_automatic: bool = False+ ):factory = _patch_all_extractors(monkeypatch)monkeypatch.setattr(processor_module.dify_config, "ETL_TYPE", etl_type)@@ -167,7 +171,7 @@ class TestExtractProcessorFileRouting:],)def test_extract_routes_file_extensions_for_unstructured_mode(- self, monkeypatch, extension, expected_extractor, is_automatic+ self, monkeypatch: pytest.MonkeyPatch, extension, expected_extractor, is_automatic):extractor_name, args, kwargs = self._run_extract_for_extension(monkeypatch, extension, etl_type="Unstructured", is_automatic=is_automatic@@ -189,7 +193,9 @@ class TestExtractProcessorFileRouting:(".txt", "TextExtractor"),],)- def test_extract_routes_file_extensions_for_default_mode(self, monkeypatch, extension, expected_extractor):+ def test_extract_routes_file_extensions_for_default_mode(+ self, monkeypatch: pytest.MonkeyPatch, extension, expected_extractor+ ):extractor_name, _, _ = self._run_extract_for_extension(monkeypatch, extension, etl_type="SelfHosted")assert extractor_name == expected_extractor@@ -202,7 +208,7 @@ class TestExtractProcessorFileRouting:class TestExtractProcessorDatasourceRouting:- def test_extract_routes_notion_datasource(self, monkeypatch):+ def test_extract_routes_notion_datasource(self, monkeypatch: pytest.MonkeyPatch):factory = _patch_all_extractors(monkeypatch)notion_info = SimpleNamespace(@@ -228,7 +234,9 @@ class TestExtractProcessorDatasourceRouting:("jinareader", "JinaReaderWebExtractor"),],)- def test_extract_routes_website_datasource_providers(self, monkeypatch, provider: str, expected: str):+ def test_extract_routes_website_datasource_providers(+ self, monkeypatch: pytest.MonkeyPatch, provider: str, expected: str+ ):factory = _patch_all_extractors(monkeypatch)website_info = SimpleNamespace(diff --git a/api/tests/unit_tests/core/rag/extractor/test_helpers.py b/api/tests/unit_tests/core/rag/extractor/test_helpers.pyindex 74387f749dd..1c6f97ec53c 100644--- a/api/tests/unit_tests/core/rag/extractor/test_helpers.py+++ b/api/tests/unit_tests/core/rag/extractor/test_helpers.py@@ -21,7 +21,7 @@ class TestHelpers:# Assert the language field for full coverageassert encodings[0].language is not None- def test_detect_file_encodings_timeout(self, monkeypatch):+ def test_detect_file_encodings_timeout(self, monkeypatch: pytest.MonkeyPatch):class FakeFuture:def result(self, timeout=None):raise helpers.concurrent.futures.TimeoutError()@@ -41,7 +41,7 @@ class TestHelpers:with pytest.raises(TimeoutError, match="Timeout reached while detecting encoding"):detect_file_encodings("file.txt", timeout=1)- def test_detect_file_encodings_raises_when_encoding_not_detected(self, monkeypatch):+ def test_detect_file_encodings_raises_when_encoding_not_detected(self, monkeypatch: pytest.MonkeyPatch):class FakeResult:encoding = Nonecoherence = 0.0diff --git a/api/tests/unit_tests/core/rag/extractor/test_markdown_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_markdown_extractor.pyindex 7e78c86c7d1..8ede44ec047 100644--- a/api/tests/unit_tests/core/rag/extractor/test_markdown_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_markdown_extractor.py@@ -74,7 +74,7 @@ afterassert "[link]" not in tups[1][1]assert "img.png" not in tups[1][1]- def test_parse_tups_autodetects_encoding_after_decode_error(self, monkeypatch):+ def test_parse_tups_autodetects_encoding_after_decode_error(self, monkeypatch: pytest.MonkeyPatch):extractor = MarkdownExtractor(file_path="dummy_path", autodetect_encoding=True)calls: list[str | None] = []@@ -99,7 +99,7 @@ afterassert len(tups) == 2assert calls == [None, "bad-encoding", "utf-8"]- def test_parse_tups_decode_error_with_autodetect_disabled_raises(self, monkeypatch):+ def test_parse_tups_decode_error_with_autodetect_disabled_raises(self, monkeypatch: pytest.MonkeyPatch):extractor = MarkdownExtractor(file_path="dummy_path", autodetect_encoding=False)def raise_decode(self, encoding=None):@@ -110,7 +110,7 @@ afterwith pytest.raises(RuntimeError, match="Error loading dummy_path"):extractor.parse_tups("dummy_path")- def test_parse_tups_other_exceptions_are_wrapped(self, monkeypatch):+ def test_parse_tups_other_exceptions_are_wrapped(self, monkeypatch: pytest.MonkeyPatch):extractor = MarkdownExtractor(file_path="dummy_path")def raise_other(self, encoding=None):@@ -121,7 +121,7 @@ afterwith pytest.raises(RuntimeError, match="Error loading dummy_path"):extractor.parse_tups("dummy_path")- def test_extract_builds_documents_for_header_and_non_header(self, monkeypatch):+ def test_extract_builds_documents_for_header_and_non_header(self, monkeypatch: pytest.MonkeyPatch):extractor = MarkdownExtractor(file_path="dummy_path")monkeypatch.setattr(extractor, "parse_tups", lambda _: [(None, "plain"), ("Header", "value")])diff --git a/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.pyindex 808e41867ed..49f7b592dcc 100644--- a/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_notion_extractor.py@@ -28,7 +28,7 @@ class TestNotionExtractorInitAndPublicMethods:assert extractor._notion_access_token == "token"- def test_init_falls_back_to_env_token_when_credential_lookup_fails(self, monkeypatch):+ def test_init_falls_back_to_env_token_when_credential_lookup_fails(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(notion_extractor.NotionExtractor,"_get_access_token",@@ -46,7 +46,7 @@ class TestNotionExtractorInitAndPublicMethods:assert extractor._notion_access_token == "env-token"- def test_init_raises_if_no_credential_and_no_env_token(self, monkeypatch):+ def test_init_raises_if_no_credential_and_no_env_token(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(notion_extractor.NotionExtractor,"_get_access_token",@@ -63,7 +63,7 @@ class TestNotionExtractorInitAndPublicMethods:credential_id="cred",)- def test_extract_updates_last_edited_and_loads_documents(self, monkeypatch):+ def test_extract_updates_last_edited_and_loads_documents(self, monkeypatch: pytest.MonkeyPatch):extractor = notion_extractor.NotionExtractor(notion_workspace_id="ws",notion_obj_id="obj",@@ -83,7 +83,7 @@ class TestNotionExtractorInitAndPublicMethods:load_mock.assert_called_once_with("obj", "page")assert len(docs) == 1- def test_load_data_as_documents_page_database_and_invalid(self, monkeypatch):+ def test_load_data_as_documents_page_database_and_invalid(self, monkeypatch: pytest.MonkeyPatch):extractor = notion_extractor.NotionExtractor(notion_workspace_id="ws",notion_obj_id="obj",@@ -394,7 +394,7 @@ class TestNotionMetadataAndCredentialMethods:assert extractor.update_last_edited_time(None) is None- def test_update_last_edited_time_updates_document_and_commits(self, monkeypatch):+ def test_update_last_edited_time_updates_document_and_commits(self, monkeypatch: pytest.MonkeyPatch):extractor = notion_extractor.NotionExtractor(notion_workspace_id="ws",notion_obj_id="obj",@@ -479,7 +479,7 @@ class TestNotionMetadataAndCredentialMethods:with pytest.raises(AssertionError, match="Notion access token is required"):extractor.get_notion_last_edited_time()- def test_get_access_token_success_and_errors(self, monkeypatch):+ def test_get_access_token_success_and_errors(self, monkeypatch: pytest.MonkeyPatch):with pytest.raises(Exception, match="No credential id found"):notion_extractor.NotionExtractor._get_access_token("tenant", None)diff --git a/api/tests/unit_tests/core/rag/extractor/test_pdf_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_pdf_extractor.pyindex 47222a23a20..f2caf02d5e2 100644--- a/api/tests/unit_tests/core/rag/extractor/test_pdf_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_pdf_extractor.py@@ -7,7 +7,7 @@ import core.rag.extractor.pdf_extractor as pe@pytest.fixture-def mock_dependencies(monkeypatch):+def mock_dependencies(monkeypatch: pytest.MonkeyPatch):# Mock storagesaves = []@@ -61,7 +61,9 @@ def mock_dependencies(monkeypatch):(b"\x89PNG\r\n\x1a\n some png", "image/png", "png", "test_file_id_png"),],)-def test_extract_images_formats(mock_dependencies, monkeypatch, image_bytes, expected_mime, expected_ext, file_id):+def test_extract_images_formats(+ mock_dependencies, monkeypatch: pytest.MonkeyPatch, image_bytes, expected_mime, expected_ext, file_id+):saves = mock_dependencies.savesdb_stub = mock_dependencies.db@@ -122,7 +124,7 @@ def test_extract_images_get_objects_scenarios(mock_dependencies, get_objects_sidassert result == ""-def test_extract_calls_extract_images(mock_dependencies, monkeypatch):+def test_extract_calls_extract_images(mock_dependencies, monkeypatch: pytest.MonkeyPatch):# Mock pypdfium2mock_pdf_doc = MagicMock()mock_page = MagicMock()diff --git a/api/tests/unit_tests/core/rag/extractor/test_text_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_text_extractor.pyindex fb3c6e52c62..71046d73af4 100644--- a/api/tests/unit_tests/core/rag/extractor/test_text_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_text_extractor.py@@ -19,7 +19,7 @@ class TestTextExtractor:assert docs[0].page_content == "hello world"assert docs[0].metadata == {"source": str(file_path)}- def test_extract_autodetect_success_after_decode_error(self, monkeypatch):+ def test_extract_autodetect_success_after_decode_error(self, monkeypatch: pytest.MonkeyPatch):extractor = TextExtractor("dummy.txt", autodetect_encoding=True)calls = []@@ -44,7 +44,7 @@ class TestTextExtractor:assert docs[0].page_content == "decoded text"assert calls == [None, "bad", "utf-8"]- def test_extract_autodetect_all_fail_raises_runtime_error(self, monkeypatch):+ def test_extract_autodetect_all_fail_raises_runtime_error(self, monkeypatch: pytest.MonkeyPatch):extractor = TextExtractor("dummy.txt", autodetect_encoding=True)def always_decode_error(self, encoding=None):@@ -56,7 +56,7 @@ class TestTextExtractor:with pytest.raises(RuntimeError, match="all detected encodings failed"):extractor.extract()- def test_extract_decode_error_without_autodetect_raises_runtime_error(self, monkeypatch):+ def test_extract_decode_error_without_autodetect_raises_runtime_error(self, monkeypatch: pytest.MonkeyPatch):extractor = TextExtractor("dummy.txt", autodetect_encoding=False)def always_decode_error(self, encoding=None):@@ -67,7 +67,7 @@ class TestTextExtractor:with pytest.raises(RuntimeError, match="specified encoding failed"):extractor.extract()- def test_extract_wraps_non_decode_exceptions(self, monkeypatch):+ def test_extract_wraps_non_decode_exceptions(self, monkeypatch: pytest.MonkeyPatch):extractor = TextExtractor("dummy.txt")def raise_other(self, encoding=None):diff --git a/api/tests/unit_tests/core/rag/extractor/test_word_extractor.py b/api/tests/unit_tests/core/rag/extractor/test_word_extractor.pyindex b9f2449cfb0..513d232d7fa 100644--- a/api/tests/unit_tests/core/rag/extractor/test_word_extractor.py+++ b/api/tests/unit_tests/core/rag/extractor/test_word_extractor.py@@ -61,7 +61,7 @@ def test_parse_row():assert extractor._parse_row(row, {}, 3) == gt[idx]-def test_init_downloads_via_ssrf_proxy(monkeypatch):+def test_init_downloads_via_ssrf_proxy(monkeypatch: pytest.MonkeyPatch):doc = Document()doc.add_paragraph("hello")buf = io.BytesIO()@@ -97,7 +97,7 @@ def test_init_downloads_via_ssrf_proxy(monkeypatch):extractor.temp_file.close()-def test_extract_images_from_docx(monkeypatch):+def test_extract_images_from_docx(monkeypatch: pytest.MonkeyPatch):external_bytes = b"ext-bytes"internal_bytes = b"int-bytes"@@ -210,7 +210,7 @@ def test_extract_images_from_docx_uses_internal_files_url():dify_config.INTERNAL_FILES_URL = original_internal_files_url-def test_extract_hyperlinks(monkeypatch):+def test_extract_hyperlinks(monkeypatch: pytest.MonkeyPatch):# Mock db and storage to avoid issues during image extraction (even if no images are present)monkeypatch.setattr(we, "storage", SimpleNamespace(save=lambda k, d: None))db_stub = SimpleNamespace(session=SimpleNamespace(add=lambda o: None, commit=lambda: None))@@ -255,7 +255,7 @@ def test_extract_hyperlinks(monkeypatch):os.remove(tmp_path)-def test_extract_legacy_hyperlinks(monkeypatch):+def test_extract_legacy_hyperlinks(monkeypatch: pytest.MonkeyPatch):# Mock db and storagemonkeypatch.setattr(we, "storage", SimpleNamespace(save=lambda k, d: None))db_stub = SimpleNamespace(session=SimpleNamespace(add=lambda o: None, commit=lambda: None))@@ -317,7 +317,7 @@ def test_extract_legacy_hyperlinks(monkeypatch):os.remove(tmp_path)-def test_init_rejects_invalid_url_status(monkeypatch):+def test_init_rejects_invalid_url_status(monkeypatch: pytest.MonkeyPatch):class FakeResponse:status_code = 404content = b""@@ -392,7 +392,7 @@ def test_close_closes_awaitable_close_result():extractor.temp_file.close.assert_called_once()-def test_extract_images_handles_invalid_external_cases(monkeypatch):+def test_extract_images_handles_invalid_external_cases(monkeypatch: pytest.MonkeyPatch):class FakeTargetRef:def __contains__(self, item):return item == "image"@@ -437,7 +437,7 @@ def test_extract_images_handles_invalid_external_cases(monkeypatch):db_stub.session.commit.assert_called_once()-def test_table_to_markdown_and_parse_helpers(monkeypatch):+def test_table_to_markdown_and_parse_helpers(monkeypatch: pytest.MonkeyPatch):extractor = object.__new__(WordExtractor)table = SimpleNamespace(@@ -500,7 +500,7 @@ def test_table_to_markdown_and_parse_helpers(monkeypatch):assert extractor._parse_cell(cell, image_map) == "EXT-IMGINT-IMGplain"-def test_parse_docx_covers_drawing_shapes_hyperlink_error_and_table_branch(monkeypatch):+def test_parse_docx_covers_drawing_shapes_hyperlink_error_and_table_branch(monkeypatch: pytest.MonkeyPatch):extractor = object.__new__(WordExtractor)ext_image_id = "ext-image"diff --git a/api/tests/unit_tests/core/rag/extractor/unstructured/test_unstructured_extractors.py b/api/tests/unit_tests/core/rag/extractor/unstructured/test_unstructured_extractors.pyindex 26ce333e113..19fb385a6d9 100644--- a/api/tests/unit_tests/core/rag/extractor/unstructured/test_unstructured_extractors.py+++ b/api/tests/unit_tests/core/rag/extractor/unstructured/test_unstructured_extractors.py@@ -45,7 +45,7 @@ def _install_chunk_by_title(monkeypatch: pytest.MonkeyPatch, chunks: list[Simpleclass TestUnstructuredMarkdownMsgXml:- def test_markdown_extractor_without_api(self, monkeypatch):+ def test_markdown_extractor_without_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text=" chunk-1 "), SimpleNamespace(text=" chunk-2 ")])_register_module(monkeypatch, "unstructured.partition.md", partition_md=lambda filename: [SimpleNamespace(text="x")]@@ -55,7 +55,7 @@ class TestUnstructuredMarkdownMsgXml:assert [doc.page_content for doc in docs] == ["chunk-1", "chunk-2"]- def test_markdown_extractor_with_api(self, monkeypatch):+ def test_markdown_extractor_with_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text=" via-api ")])calls = {}@@ -70,7 +70,7 @@ class TestUnstructuredMarkdownMsgXml:assert docs[0].page_content == "via-api"assert calls == {"filename": "/tmp/file.md", "api_url": "https://u", "api_key": "k"}- def test_msg_extractor_local(self, monkeypatch):+ def test_msg_extractor_local(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text="msg-doc")])_register_module(monkeypatch, "unstructured.partition.msg", partition_msg=lambda filename: [SimpleNamespace(text="x")]@@ -78,7 +78,7 @@ class TestUnstructuredMarkdownMsgXml:assert UnstructuredMsgExtractor("/tmp/file.msg").extract()[0].page_content == "msg-doc"- def test_msg_extractor_with_api(self, monkeypatch):+ def test_msg_extractor_with_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text="msg-doc")])calls = {}@@ -94,7 +94,7 @@ class TestUnstructuredMarkdownMsgXml:)assert calls["filename"] == "/tmp/file.msg"- def test_xml_extractor_local_and_api(self, monkeypatch):+ def test_xml_extractor_local_and_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text="xml-doc")])xml_calls = {}@@ -124,7 +124,7 @@ class TestUnstructuredMarkdownMsgXml:class TestUnstructuredEmailAndEpub:- def test_email_extractor_local_decodes_html_and_suppresses_decode_errors(self, monkeypatch):+ def test_email_extractor_local_decodes_html_and_suppresses_decode_errors(self, monkeypatch: pytest.MonkeyPatch):_register_unstructured_packages(monkeypatch)captured = {}@@ -150,7 +150,7 @@ class TestUnstructuredEmailAndEpub:assert "Hello Email" in chunk_elements[0].textassert chunk_elements[1].text == bad_base64- def test_email_extractor_with_api(self, monkeypatch):+ def test_email_extractor_with_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text="api-email")])_register_module(monkeypatch,@@ -162,7 +162,7 @@ class TestUnstructuredEmailAndEpub:assert docs[0].page_content == "api-email"- def test_epub_extractor_local_and_api(self, monkeypatch):+ def test_epub_extractor_local_and_api(self, monkeypatch: pytest.MonkeyPatch):_install_chunk_by_title(monkeypatch, [SimpleNamespace(text="epub-doc")])calls = {"download": 0, "partition": 0}@@ -198,7 +198,7 @@ class TestUnstructuredPPTAndPPTX:with pytest.raises(NotImplementedError, match="Unstructured API Url is not configured"):UnstructuredPPTExtractor("/tmp/file.ppt").extract()- def test_ppt_extractor_groups_text_by_page(self, monkeypatch):+ def test_ppt_extractor_groups_text_by_page(self, monkeypatch: pytest.MonkeyPatch):_register_unstructured_packages(monkeypatch)_register_module(monkeypatch,@@ -215,7 +215,7 @@ class TestUnstructuredPPTAndPPTX:assert [doc.page_content for doc in docs] == ["A\nB", "C"]- def test_pptx_extractor_local_and_api(self, monkeypatch):+ def test_pptx_extractor_local_and_api(self, monkeypatch: pytest.MonkeyPatch):_register_unstructured_packages(monkeypatch)_register_module(monkeypatch,@@ -244,7 +244,7 @@ class TestUnstructuredPPTAndPPTX:class TestUnstructuredWord:- def _install_doc_modules(self, monkeypatch, version: str, filetype_value):+ def _install_doc_modules(self, monkeypatch: pytest.MonkeyPatch, version: str, filetype_value):_register_unstructured_packages(monkeypatch)class FileType:@@ -276,13 +276,13 @@ class TestUnstructuredWord:],)- def test_word_extractor_rejects_doc_on_old_unstructured_version(self, monkeypatch):+ def test_word_extractor_rejects_doc_on_old_unstructured_version(self, monkeypatch: pytest.MonkeyPatch):self._install_doc_modules(monkeypatch, version="0.4.10", filetype_value="doc")with pytest.raises(ValueError, match="Partitioning .doc files is only supported"):UnstructuredWordExtractor("/tmp/file.doc", "https://u", "k").extract()- def test_word_extractor_doc_and_docx_paths(self, monkeypatch):+ def test_word_extractor_doc_and_docx_paths(self, monkeypatch: pytest.MonkeyPatch):self._install_doc_modules(monkeypatch, version="0.4.11", filetype_value="doc")docs = UnstructuredWordExtractor("/tmp/file.doc", "https://u", "k").extract()@@ -292,7 +292,7 @@ class TestUnstructuredWord:docs = UnstructuredWordExtractor("/tmp/file.docx", "https://u", "k").extract()assert [doc.page_content for doc in docs] == ["chunk-1", "chunk-2"]- def test_word_extractor_magic_import_error_fallback_to_extension(self, monkeypatch):+ def test_word_extractor_magic_import_error_fallback_to_extension(self, monkeypatch: pytest.MonkeyPatch):self._install_doc_modules(monkeypatch, version="0.4.10", filetype_value="not-used")monkeypatch.setitem(sys.modules, "magic", None)diff --git a/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py b/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.pyindex d758be218ad..95878fc688b 100644--- a/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py+++ b/api/tests/unit_tests/core/rag/extractor/watercrawl/test_watercrawl.py@@ -59,7 +59,7 @@ class TestWaterCrawlExceptions:class TestBaseAPIClient:- def test_init_session_builds_expected_headers(self, monkeypatch):+ def test_init_session_builds_expected_headers(self, monkeypatch: pytest.MonkeyPatch):captured = {}def fake_client(**kwargs):@@ -74,7 +74,7 @@ class TestBaseAPIClient:assert captured["headers"]["X-API-Key"] == "k"assert captured["headers"]["User-Agent"] == "WaterCrawl-Plugin"- def test_request_stream_and_non_stream_paths(self, monkeypatch):+ def test_request_stream_and_non_stream_paths(self, monkeypatch: pytest.MonkeyPatch):class FakeSession:def __init__(self):self.request_calls = []@@ -106,7 +106,7 @@ class TestBaseAPIClient:assert fake_session.build_callsassert fake_session.send_calls[0][1] is True- def test_http_method_helpers_delegate_to_request(self, monkeypatch):+ def test_http_method_helpers_delegate_to_request(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(BaseAPIClient, "init_session", lambda self: MagicMock())client = BaseAPIClient(api_key="k", base_url="https://watercrawl.dev")@@ -127,7 +127,7 @@ class TestBaseAPIClient:class TestWaterCrawlAPIClient:- def test_process_eventstream_and_download(self, monkeypatch):+ def test_process_eventstream_and_download(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")response = MagicMock()@@ -174,7 +174,7 @@ class TestWaterCrawlAPIClient:client.process_response(_response(200, content_type="application/octet-stream", content=b"bin")) == b"bin")- def test_process_response_event_stream_returns_generator(self, monkeypatch):+ def test_process_response_event_stream_returns_generator(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")generator = (item for item in [{"type": "result", "data": {}}])monkeypatch.setattr(client, "process_eventstream", lambda response, download=False: generator)@@ -193,7 +193,7 @@ class TestWaterCrawlAPIClient:with pytest.raises(RuntimeError, match="http error"):client.process_response(response)- def test_endpoint_wrappers(self, monkeypatch):+ def test_endpoint_wrappers(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")monkeypatch.setattr(client, "process_response", lambda resp: "processed")@@ -208,7 +208,7 @@ class TestWaterCrawlAPIClient:assert client.download_crawl_request("id") == "processed"assert client.get_crawl_request_results("id") == "processed"- def test_monitor_crawl_request_generator_and_validation(self, monkeypatch):+ def test_monitor_crawl_request_generator_and_validation(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")monkeypatch.setattr(client, "process_response", lambda _: (x for x in [{"type": "result", "data": 1}]))@@ -221,7 +221,7 @@ class TestWaterCrawlAPIClient:with pytest.raises(ValueError, match="Generator expected"):list(client.monitor_crawl_request("job-1"))- def test_scrape_url_sync_and_async(self, monkeypatch):+ def test_scrape_url_sync_and_async(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")monkeypatch.setattr(client, "create_crawl_request", lambda **kwargs: {"uuid": "job-1"})@@ -238,7 +238,7 @@ class TestWaterCrawlAPIClient:sync_result = client.scrape_url("https://example.com", sync=True)assert sync_result == {"url": "https://example.com"}- def test_download_result_fetches_json_and_closes(self, monkeypatch):+ def test_download_result_fetches_json_and_closes(self, monkeypatch: pytest.MonkeyPatch):client = WaterCrawlAPIClient(api_key="k")response = _response(200, {"markdown": "body"})@@ -251,7 +251,7 @@ class TestWaterCrawlAPIClient:class TestWaterCrawlProvider:- def test_crawl_url_builds_options_and_min_wait_time(self, monkeypatch):+ def test_crawl_url_builds_options_and_min_wait_time(self, monkeypatch: pytest.MonkeyPatch):provider = WaterCrawlProvider(api_key="k")captured_kwargs = {}@@ -290,7 +290,7 @@ class TestWaterCrawlProvider:assert captured_kwargs["page_options"]["only_main_content"] is Falseassert captured_kwargs["page_options"]["wait_time"] == 1000- def test_get_crawl_status_active_and_completed(self, monkeypatch):+ def test_get_crawl_status_active_and_completed(self, monkeypatch: pytest.MonkeyPatch):provider = WaterCrawlProvider(api_key="k")monkeypatch.setattr(@@ -327,7 +327,7 @@ class TestWaterCrawlProvider:assert completed["status"] == "completed"assert completed["data"] == [{"url": "u"}]- def test_get_crawl_url_data_and_scrape(self, monkeypatch):+ def test_get_crawl_url_data_and_scrape(self, monkeypatch: pytest.MonkeyPatch):provider = WaterCrawlProvider(api_key="k")monkeypatch.setattr(provider, "scrape_url", lambda url: {"source_url": url})@@ -339,7 +339,7 @@ class TestWaterCrawlProvider:monkeypatch.setattr(provider, "_get_results", lambda job_id, query_params=None: iter([]))assert provider.get_crawl_url_data("job", "u1") is None- def test_structure_data_validation_and_get_results_pagination(self, monkeypatch):+ def test_structure_data_validation_and_get_results_pagination(self, monkeypatch: pytest.MonkeyPatch):provider = WaterCrawlProvider(api_key="k")with pytest.raises(ValueError, match="Invalid result object"):@@ -380,7 +380,7 @@ class TestWaterCrawlProvider:assert len(results) == 1assert results[0]["source_url"] == "https://a"- def test_scrape_url_uses_client_and_structure(self, monkeypatch):+ def test_scrape_url_uses_client_and_structure(self, monkeypatch: pytest.MonkeyPatch):provider = WaterCrawlProvider(api_key="k")monkeypatch.setattr(provider.client, "scrape_url", lambda **kwargs: {"result": {"metadata": {}, "markdown": "m"}, "url": "u"}@@ -392,7 +392,7 @@ class TestWaterCrawlProvider:class TestWaterCrawlWebExtractor:- def test_extract_crawl_and_scrape_modes(self, monkeypatch):+ def test_extract_crawl_and_scrape_modes(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.rag.extractor.watercrawl.extractor.WebsiteService.get_crawl_url_data",lambda job_id, provider, url, tenant_id: {@@ -418,7 +418,7 @@ class TestWaterCrawlWebExtractor:assert crawl_extractor.extract()[0].page_content == "crawl"assert scrape_extractor.extract()[0].page_content == "scrape"- def test_extract_crawl_returns_empty_when_service_returns_none(self, monkeypatch):+ def test_extract_crawl_returns_empty_when_service_returns_none(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("core.rag.extractor.watercrawl.extractor.WebsiteService.get_crawl_url_data",lambda job_id, provider, url, tenant_id: None,diff --git a/api/tests/unit_tests/core/telemetry/test_facade.py b/api/tests/unit_tests/core/telemetry/test_facade.pyindex 36e8e1bbb13..95d653f55be 100644--- a/api/tests/unit_tests/core/telemetry/test_facade.py+++ b/api/tests/unit_tests/core/telemetry/test_facade.py@@ -14,7 +14,7 @@ from core.telemetry.events import TelemetryContext, TelemetryEvent@pytest.fixture-def telemetry_test_setup(monkeypatch):+def telemetry_test_setup(monkeypatch: pytest.MonkeyPatch):module_name = "core.ops.ops_trace_manager"ops_stub = types.ModuleType(module_name)diff --git a/api/tests/unit_tests/core/tools/test_builtin_tool_provider.py b/api/tests/unit_tests/core/tools/test_builtin_tool_provider.pyindex ad6d5906aee..b21a5c3e24a 100644--- a/api/tests/unit_tests/core/tools/test_builtin_tool_provider.py+++ b/api/tests/unit_tests/core/tools/test_builtin_tool_provider.py@@ -78,7 +78,7 @@ def _tool_yaml() -> dict[str, Any]:}-def test_builtin_tool_provider_init_load_tools_and_basic_accessors(monkeypatch):+def test_builtin_tool_provider_init_load_tools_and_basic_accessors(monkeypatch: pytest.MonkeyPatch):yaml_payloads = [_provider_yaml(), _tool_yaml()]def _load_yaml(*args, **kwargs):diff --git a/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py b/api/tests/unit_tests/core/tools/test_builtin_tools_extra.pyindex c7829fc0d71..3f6b1ec1545 100644--- a/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py+++ b/api/tests/unit_tests/core/tools/test_builtin_tools_extra.py@@ -115,7 +115,7 @@ def test_weekday_tool():list(weekday_tool.invoke(user_id="u", tool_parameters={"year": 2024, "day": 1}))-def test_simple_code_valid_execution(monkeypatch):+def test_simple_code_valid_execution(monkeypatch: pytest.MonkeyPatch):simple_code = _build_builtin_tool(SimpleCode)monkeypatch.setattr(@@ -138,7 +138,7 @@ def test_simple_code_invalid_language():list(simple_code.invoke(user_id="u", tool_parameters={"language": "go", "code": "fmt.Println(1)"}))-def test_simple_code_execution_error(monkeypatch):+def test_simple_code_execution_error(monkeypatch: pytest.MonkeyPatch):simple_code = _build_builtin_tool(SimpleCode)monkeypatch.setattr(@@ -155,14 +155,14 @@ def test_webscraper_empty_url():assert empty == "Please input url"-def test_webscraper_fetch(monkeypatch):+def test_webscraper_fetch(monkeypatch: pytest.MonkeyPatch):webscraper = _build_builtin_tool(WebscraperTool)monkeypatch.setattr("core.tools.builtin_tool.providers.webscraper.tools.webscraper.get_url", lambda *a, **k: "page")full = list(webscraper.invoke(user_id="u", tool_parameters={"url": "https://example.com"}))[0].message.textassert full == "page"-def test_webscraper_summary(monkeypatch):+def test_webscraper_summary(monkeypatch: pytest.MonkeyPatch):webscraper = _build_builtin_tool(WebscraperTool)monkeypatch.setattr("core.tools.builtin_tool.providers.webscraper.tools.webscraper.get_url", lambda *a, **k: "page")monkeypatch.setattr(webscraper, "summary", lambda user_id, content: "summary")@@ -175,7 +175,7 @@ def test_webscraper_summary(monkeypatch):assert summarized == "summary"-def test_webscraper_fetch_error(monkeypatch):+def test_webscraper_fetch_error(monkeypatch: pytest.MonkeyPatch):webscraper = _build_builtin_tool(WebscraperTool)monkeypatch.setattr("core.tools.builtin_tool.providers.webscraper.tools.webscraper.get_url",@@ -192,7 +192,7 @@ def test_asr_invalid_file():assert "not a valid audio file" in invalid_file-def test_asr_valid_file_invocation(monkeypatch):+def test_asr_valid_file_invocation(monkeypatch: pytest.MonkeyPatch):asr = _build_builtin_tool(ASRTool)model_instance = type("M", (), {"invoke_speech2text": lambda self, file: "transcript"})()model_manager = type("Mgr", (), {"get_model_instance": lambda *a, **k: model_instance})()@@ -209,7 +209,7 @@ def test_asr_valid_file_invocation(monkeypatch):assert captured_manager_kwargs == {"tenant_id": "tenant-1", "user_id": "u"}-def test_asr_available_models_and_runtime_parameters(monkeypatch):+def test_asr_available_models_and_runtime_parameters(monkeypatch: pytest.MonkeyPatch):asr = _build_builtin_tool(ASRTool)provider_model = type("PM", (), {"provider": "p", "models": [type("Model", (), {"model": "m"})()]})()monkeypatch.setattr(@@ -220,7 +220,7 @@ def test_asr_available_models_and_runtime_parameters(monkeypatch):assert asr.get_runtime_parameters()[0].name == "model"-def test_tts_invoke_returns_messages(monkeypatch):+def test_tts_invoke_returns_messages(monkeypatch: pytest.MonkeyPatch):tts = _build_builtin_tool(TTSTool)captured_manager_kwargs = {}voices_model_instance = type(@@ -280,7 +280,7 @@ def test_tts_tool_raises_when_voice_unavailable(monkeypatch, voices):list(tts.invoke(user_id="u", tool_parameters={"model": "p#m", "text": "hello"}))-def test_tts_tool_get_available_models_and_runtime_parameters(monkeypatch):+def test_tts_tool_get_available_models_and_runtime_parameters(monkeypatch: pytest.MonkeyPatch):tts = _build_builtin_tool(TTSTool)model_1 = SimpleNamespace(@@ -307,7 +307,7 @@ def test_tts_tool_get_available_models_and_runtime_parameters(monkeypatch):assert runtime_parameters[1].name == "voice#provider-a#model-a"-def test_provider_classes_and_builtin_sort(monkeypatch):+def test_provider_classes_and_builtin_sort(monkeypatch: pytest.MonkeyPatch):# Use object.__new__ to avoid YAML-loading __init__; only pass-through validation is exercised.# Ensure pass-through _validate_credentials methods are executed.AudioToolProvider._validate_credentials(object.__new__(AudioToolProvider), "u", {})diff --git a/api/tests/unit_tests/core/tools/test_custom_tool.py b/api/tests/unit_tests/core/tools/test_custom_tool.pyindex f35546b0251..f525baeaf23 100644--- a/api/tests/unit_tests/core/tools/test_custom_tool.py+++ b/api/tests/unit_tests/core/tools/test_custom_tool.py@@ -47,7 +47,7 @@ def test_parsed_response_to_string():assert ParsedResponse("ok", False).to_string() == "ok"-def test_api_tool_fork_runtime_and_validate_credentials(monkeypatch):+def test_api_tool_fork_runtime_and_validate_credentials(monkeypatch: pytest.MonkeyPatch):tool = _build_tool()forked = tool.fork_tool_runtime(ToolRuntime(tenant_id="tenant-2"))assert isinstance(forked, ApiTool)@@ -184,7 +184,7 @@ def test_get_parameter_value_and_type_conversion_helpers():assert tool._convert_body_property_type({"anyOf": [{"type": "integer"}]}, "2") == 2-def test_do_http_request_builds_arguments_and_handles_invalid_method(monkeypatch):+def test_do_http_request_builds_arguments_and_handles_invalid_method(monkeypatch: pytest.MonkeyPatch):openapi = {"parameters": [{"name": "id", "in": "path", "required": True, "schema": {"type": "string"}},@@ -236,7 +236,7 @@ def test_do_http_request_builds_arguments_and_handles_invalid_method(monkeypatchinvalid_method_tool.do_http_request("https://api.example.com", "TRACE", headers={}, parameters={})-def test_do_http_request_handles_file_upload_and_invoke_paths(monkeypatch):+def test_do_http_request_handles_file_upload_and_invoke_paths(monkeypatch: pytest.MonkeyPatch):openapi = {"parameters": [],"requestBody": {diff --git a/api/tests/unit_tests/core/tools/test_tool_manager.py b/api/tests/unit_tests/core/tools/test_tool_manager.pyindex c9b3dfb186f..7c7d6eec2d9 100644--- a/api/tests/unit_tests/core/tools/test_tool_manager.py+++ b/api/tests/unit_tests/core/tools/test_tool_manager.py@@ -648,7 +648,7 @@ def test_list_default_builtin_providers_for_postgres_and_mysql():assert providers == provider_records-def test_list_providers_from_api_covers_builtin_api_workflow_and_mcp(monkeypatch):+def test_list_providers_from_api_covers_builtin_api_workflow_and_mcp(monkeypatch: pytest.MonkeyPatch):hardcoded_controller = SimpleNamespace(entity=SimpleNamespace(identity=SimpleNamespace(name="hardcoded")))plugin_controller = object.__new__(PluginToolProviderController)plugin_controller.entity = SimpleNamespace(identity=SimpleNamespace(name="plugin-provider"))diff --git a/api/tests/unit_tests/core/tools/utils/test_configuration.py b/api/tests/unit_tests/core/tools/utils/test_configuration.pyindex ae5638784c4..9e179536dec 100644--- a/api/tests/unit_tests/core/tools/utils/test_configuration.py+++ b/api/tests/unit_tests/core/tools/utils/test_configuration.py@@ -4,6 +4,8 @@ from collections.abc import Generatorfrom typing import Anyfrom unittest.mock import patch+import pytest+from core.app.entities.app_invoke_entities import InvokeFromfrom core.helper.tool_parameter_cache import ToolParameterCachefrom core.tools.__base.tool import Tool@@ -110,7 +112,7 @@ def test_encrypt_tool_parameters():assert encrypted["plain"] == "x"-def test_decrypt_tool_parameters_cache_hit_and_miss(monkeypatch):+def test_decrypt_tool_parameters_cache_hit_and_miss(monkeypatch: pytest.MonkeyPatch):manager = _build_manager()with (@@ -139,7 +141,7 @@ def test_delete_tool_parameters_cache():mock_delete.assert_called_once()-def test_configuration_manager_decrypt_suppresses_errors(monkeypatch):+def test_configuration_manager_decrypt_suppresses_errors(monkeypatch: pytest.MonkeyPatch):manager = _build_manager()with (patch.object(ToolParameterCache, "get", return_value=None),diff --git a/api/tests/unit_tests/core/tools/utils/test_message_transformer.py b/api/tests/unit_tests/core/tools/utils/test_message_transformer.pyindex 5f34135af4b..354b3955042 100644--- a/api/tests/unit_tests/core/tools/utils/test_message_transformer.py+++ b/api/tests/unit_tests/core/tools/utils/test_message_transformer.py@@ -42,7 +42,7 @@ class _FakeToolFileManager:@pytest.fixture(autouse=True)-def _patch_tool_file_manager(monkeypatch):+def _patch_tool_file_manager(monkeypatch: pytest.MonkeyPatch):# Patch the manager used inside the transformer modulemonkeypatch.setattr(mt, "ToolFileManager", _FakeToolFileManager)# also ensure predictable URL generation (no need to patch; uses id and extension only)diff --git a/api/tests/unit_tests/core/tools/utils/test_system_oauth_encryption.py b/api/tests/unit_tests/core/tools/utils/test_system_oauth_encryption.pyindex 6bb86ebe78c..081b1897455 100644--- a/api/tests/unit_tests/core/tools/utils/test_system_oauth_encryption.py+++ b/api/tests/unit_tests/core/tools/utils/test_system_oauth_encryption.py@@ -34,7 +34,7 @@ def test_system_encrypter_raises_error_for_invalid_ciphertext():encrypter.decrypt_params("not-base64")-def test_system_helpers_use_global_cached_instance(monkeypatch):+def test_system_helpers_use_global_cached_instance(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(encryption, "_encrypter", None)monkeypatch.setattr("core.tools.utils.system_encryption.dify_config.SECRET_KEY", "global-secret")diff --git a/api/tests/unit_tests/core/variables/test_segment_type.py b/api/tests/unit_tests/core/variables/test_segment_type.pyindex d4e862220ae..baa2ac2dc76 100644--- a/api/tests/unit_tests/core/variables/test_segment_type.py+++ b/api/tests/unit_tests/core/variables/test_segment_type.py@@ -233,7 +233,7 @@ class TestSegmentTypeAdditionalMethods:assert SegmentType.GROUP.is_valid([StringSegment(value="b")]) is Trueassert SegmentType.GROUP.is_valid(["not-segment"]) is False- def test_unreachable_assertion_branch(self, monkeypatch):+ def test_unreachable_assertion_branch(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(SegmentType, "is_array_type", lambda self: False)with pytest.raises(AssertionError, match="unreachable"):diff --git a/api/tests/unit_tests/core/workflow/nodes/datasource/test_datasource_node.py b/api/tests/unit_tests/core/workflow/nodes/datasource/test_datasource_node.pyindex d7ef7817329..a18a36a0992 100644--- a/api/tests/unit_tests/core/workflow/nodes/datasource/test_datasource_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/datasource/test_datasource_node.py@@ -1,3 +1,5 @@+from pytest_mock import MockerFixture+from core.app.entities.app_invoke_entities import DIFY_RUN_CONTEXT_KEYfrom core.workflow.nodes.datasource.datasource_node import DatasourceNodefrom core.workflow.nodes.datasource.entities import DatasourceNodeData@@ -44,7 +46,7 @@ class _GraphParams:call_depth = 0-def test_datasource_node_delegates_to_manager_stream(mocker):+def test_datasource_node_delegates_to_manager_stream(mocker: MockerFixture):# prepare sys variablessys_vars = {"sys": {diff --git a/api/tests/unit_tests/core/workflow/nodes/knowledge_index/test_knowledge_index_node.py b/api/tests/unit_tests/core/workflow/nodes/knowledge_index/test_knowledge_index_node.pyindex f254fc3d09a..89433b34e63 100644--- a/api/tests/unit_tests/core/workflow/nodes/knowledge_index/test_knowledge_index_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/knowledge_index/test_knowledge_index_node.py@@ -3,6 +3,7 @@ import uuidfrom unittest.mock import Mockimport pytest+from pytest_mock import MockerFixturefrom core.app.entities.app_invoke_entities import InvokeFrom, UserFromfrom core.rag.index_processor.constant.index_type import IndexTechniqueType@@ -50,7 +51,7 @@ def mock_graph_runtime_state():@pytest.fixture-def mock_index_processor(mocker):+def mock_index_processor(mocker: MockerFixture):"""Create mock IndexProcessorProtocol."""mock_processor = Mock(spec=IndexProcessorProtocol)mocker.patch(@@ -61,7 +62,7 @@ def mock_index_processor(mocker):@pytest.fixture-def mock_summary_index_service(mocker):+def mock_summary_index_service(mocker: MockerFixture):"""Create mock SummaryIndexServiceProtocol."""mock_service = Mock(spec=SummaryIndexServiceProtocol)mocker.patch(diff --git a/api/tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py b/api/tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.pyindex e923ee761ba..d77a2ce363d 100644--- a/api/tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/knowledge_retrieval/test_knowledge_retrieval_node.py@@ -3,6 +3,7 @@ import uuidfrom unittest.mock import Mockimport pytest+from pytest_mock import MockerFixturefrom core.app.entities.app_invoke_entities import InvokeFrom, UserFromfrom core.workflow.nodes.knowledge_retrieval.entities import (@@ -56,7 +57,7 @@ def mock_graph_runtime_state():@pytest.fixture-def mock_rag_retrieval(mocker):+def mock_rag_retrieval(mocker: MockerFixture):"""Create mock RAGRetrievalProtocol."""mock_retrieval = Mock(spec=RAGRetrievalProtocol)mock_retrieval.knowledge_retrieval.return_value = []diff --git a/api/tests/unit_tests/core/workflow/nodes/llm/test_node.py b/api/tests/unit_tests/core/workflow/nodes/llm/test_node.pyindex c707cf28cde..c09f2d3fb69 100644--- a/api/tests/unit_tests/core/workflow/nodes/llm/test_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/llm/test_node.py@@ -222,7 +222,7 @@ def llm_node(@pytest.fixture-def model_config(monkeypatch):+def model_config(monkeypatch: pytest.MonkeyPatch):from tests.integration_tests.model_runtime.__mock.plugin_model import MockModelClassdef mock_model_providers(_self):@@ -1276,7 +1276,7 @@ class TestSaveMultimodalOutputAndConvertResultToMarkdown:mock_file_saver.save_binary_string.assert_not_called()mock_file_saver.save_remote_url.assert_not_called()- def test_image_content_with_inline_data(self, llm_node_for_multimodal, monkeypatch):+ def test_image_content_with_inline_data(self, llm_node_for_multimodal, monkeypatch: pytest.MonkeyPatch):llm_node, mock_file_saver = llm_node_for_multimodalimage_raw_data = b"PNG_DATA"diff --git a/api/tests/unit_tests/core/workflow/test_node_factory.py b/api/tests/unit_tests/core/workflow/test_node_factory.pyindex 1821f72e0cf..e93a7c7ccd3 100644--- a/api/tests/unit_tests/core/workflow/test_node_factory.py+++ b/api/tests/unit_tests/core/workflow/test_node_factory.py@@ -88,7 +88,7 @@ class TestFetchMemory:assert result is None- def test_returns_none_when_conversation_does_not_exist(self, monkeypatch):+ def test_returns_none_when_conversation_does_not_exist(self, monkeypatch: pytest.MonkeyPatch):class FakeSelect:def where(self, *_args):return self@@ -119,7 +119,7 @@ class TestFetchMemory:assert result is None- def test_builds_token_buffer_memory_for_existing_conversation(self, monkeypatch):+ def test_builds_token_buffer_memory_for_existing_conversation(self, monkeypatch: pytest.MonkeyPatch):conversation = sentinel.conversationmemory = sentinel.memory@@ -189,7 +189,7 @@ class TestDifyGraphInitContext:class TestDefaultWorkflowCodeExecutor:- def test_execute_delegates_to_code_executor(self, monkeypatch):+ def test_execute_delegates_to_code_executor(self, monkeypatch: pytest.MonkeyPatch):executor = node_factory.DefaultWorkflowCodeExecutor()execute_workflow_code_template = MagicMock(return_value={"answer": "ok"})monkeypatch.setattr(@@ -219,7 +219,7 @@ class TestDefaultWorkflowCodeExecutor:class TestCodeExecutorJinja2TemplateRenderer:- def test_render_template_delegates_to_code_executor(self, monkeypatch):+ def test_render_template_delegates_to_code_executor(self, monkeypatch: pytest.MonkeyPatch):renderer = workflow_template_rendering.CodeExecutorJinja2TemplateRenderer()execute_workflow_code_template = MagicMock(return_value={"result": "Hello workflow"})monkeypatch.setattr(@@ -237,7 +237,7 @@ class TestCodeExecutorJinja2TemplateRenderer:inputs={"name": "workflow"},)- def test_render_template_wraps_code_execution_errors(self, monkeypatch):+ def test_render_template_wraps_code_execution_errors(self, monkeypatch: pytest.MonkeyPatch):renderer = workflow_template_rendering.CodeExecutorJinja2TemplateRenderer()monkeypatch.setattr(workflow_template_rendering.CodeExecutor,@@ -434,7 +434,7 @@ class TestDifyNodeFactoryCreateNode:with pytest.raises(ValueError, match="No class mapping found for node type: missing"):factory.create_node({"id": "node-id", "data": {"type": "missing"}})- def test_rejects_missing_class_mapping(self, monkeypatch, factory):+ def test_rejects_missing_class_mapping(self, monkeypatch: pytest.MonkeyPatch, factory):monkeypatch.setattr(factory,"_resolve_node_class",@@ -444,7 +444,7 @@ class TestDifyNodeFactoryCreateNode:with pytest.raises(ValueError, match="No class mapping found for node type: start"):factory.create_node({"id": "node-id", "data": {"type": BuiltinNodeTypes.START}})- def test_rejects_missing_latest_class(self, monkeypatch, factory):+ def test_rejects_missing_latest_class(self, monkeypatch: pytest.MonkeyPatch, factory):monkeypatch.setattr(factory,"_resolve_node_class",@@ -454,7 +454,7 @@ class TestDifyNodeFactoryCreateNode:with pytest.raises(ValueError, match="No latest version class found for node type: start"):factory.create_node({"id": "node-id", "data": {"type": BuiltinNodeTypes.START}})- def test_uses_version_specific_class_when_available(self, monkeypatch, factory):+ def test_uses_version_specific_class_when_available(self, monkeypatch: pytest.MonkeyPatch, factory):matched_node = sentinel.matched_nodelatest_node_class = _node_constructor(return_value=sentinel.latest_node)matched_node_class = _node_constructor(return_value=matched_node)@@ -475,7 +475,9 @@ class TestDifyNodeFactoryCreateNode:assert kwargs["graph_runtime_state"] is factory.graph_runtime_statelatest_node_class.assert_not_called()- def test_falls_back_to_latest_class_when_version_specific_mapping_is_missing(self, monkeypatch, factory):+ def test_falls_back_to_latest_class_when_version_specific_mapping_is_missing(+ self, monkeypatch: pytest.MonkeyPatch, factory+ ):latest_node = sentinel.latest_nodelatest_node_class = _node_constructor(return_value=latest_node)monkeypatch.setattr(@@ -507,7 +509,7 @@ class TestDifyNodeFactoryCreateNode:(BuiltinNodeTypes.DOCUMENT_EXTRACTOR, "DocumentExtractorNode"),],)- def test_creates_specialized_nodes(self, monkeypatch, factory, node_type, constructor_name):+ def test_creates_specialized_nodes(self, monkeypatch: pytest.MonkeyPatch, factory, node_type, constructor_name):created_node = object()constructor = _node_constructor(return_value=created_node)constructor._mock_name = constructor_name@@ -597,7 +599,9 @@ class TestDifyNodeFactoryCreateNode:prepared_llm.assert_called_once_with(sentinel.model_instance)assert kwargs["model_instance"] is wrapped_model_instance- def test_create_node_passes_alias_preserving_llm_config_to_constructor(self, monkeypatch, factory):+ def test_create_node_passes_alias_preserving_llm_config_to_constructor(+ self, monkeypatch: pytest.MonkeyPatch, factory+ ):created_node = object()constructor = _node_constructor(return_value=created_node)monkeypatch.setattr(factory, "_resolve_node_class", MagicMock(return_value=constructor))@@ -665,7 +669,7 @@ class TestDifyNodeFactoryCreateNode:)def test_creates_model_backed_nodes(self,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,factory,node_type,constructor_name,@@ -726,7 +730,7 @@ class TestDifyNodeFactoryModelInstance:factory._llm_model_factory = sentinel.model_factoryreturn factory- def test_delegates_to_fetch_model_config(self, monkeypatch, factory):+ def test_delegates_to_fetch_model_config(self, monkeypatch: pytest.MonkeyPatch, factory):node_data_model = SimpleNamespace(provider="provider",name="model",@@ -755,7 +759,7 @@ class TestDifyNodeFactoryModelInstance:model_factory=sentinel.model_factory,)- def test_propagates_fetch_model_config_errors(self, monkeypatch, factory):+ def test_propagates_fetch_model_config_errors(self, monkeypatch: pytest.MonkeyPatch, factory):fetch_model_config = MagicMock(side_effect=ValueError("broken model config"))monkeypatch.setattr(node_factory, "fetch_model_config", fetch_model_config)@@ -780,7 +784,7 @@ class TestDifyNodeFactoryMemory:assert result is Nonefactory.graph_runtime_state.variable_pool.get.assert_not_called()- def test_uses_string_segment_conversation_id(self, monkeypatch, factory):+ def test_uses_string_segment_conversation_id(self, monkeypatch: pytest.MonkeyPatch, factory):memory_config = sentinel.memory_configfactory.graph_runtime_state.variable_pool.get.return_value = StringSegment(value="conversation-id")fetch_memory = MagicMock(return_value=sentinel.memory)@@ -800,7 +804,7 @@ class TestDifyNodeFactoryMemory:model_instance=sentinel.model_instance,)- def test_ignores_non_string_segment_conversation_ids(self, monkeypatch, factory):+ def test_ignores_non_string_segment_conversation_ids(self, monkeypatch: pytest.MonkeyPatch, factory):memory_config = sentinel.memory_configfactory.graph_runtime_state.variable_pool.get.return_value = sentinel.segmentfetch_memory = MagicMock(return_value=sentinel.memory)diff --git a/api/tests/unit_tests/core/workflow/test_workflow_entry.py b/api/tests/unit_tests/core/workflow/test_workflow_entry.pyindex 041c5cc6128..2e9e3468fd8 100644--- a/api/tests/unit_tests/core/workflow/test_workflow_entry.py+++ b/api/tests/unit_tests/core/workflow/test_workflow_entry.py@@ -19,7 +19,7 @@ from graphon.variables.variables import StringVariable@pytest.fixture(autouse=True)-def _mock_ssrf_head(monkeypatch):+def _mock_ssrf_head(monkeypatch: pytest.MonkeyPatch):"""Avoid any real network requests during tests.factories.file_factory.remote.get_remote_file_info() uses ssrf_proxy.headdiff --git a/api/tests/unit_tests/core/workflow/test_workflow_entry_helpers.py b/api/tests/unit_tests/core/workflow/test_workflow_entry_helpers.pyindex 270d0bf90dd..3978cbb1a0a 100644--- a/api/tests/unit_tests/core/workflow/test_workflow_entry_helpers.py+++ b/api/tests/unit_tests/core/workflow/test_workflow_entry_helpers.py@@ -603,7 +603,7 @@ class TestWorkflowEntryHelpers:user_inputs={},)- def test_run_free_node_rejects_missing_node_class(self, monkeypatch):+ def test_run_free_node_rejects_missing_node_class(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(workflow_entry,"resolve_workflow_node_class",@@ -619,7 +619,9 @@ class TestWorkflowEntryHelpers:user_inputs={},)- def test_run_free_node_uses_empty_mapping_when_selector_extraction_is_not_implemented(self, monkeypatch):+ def test_run_free_node_uses_empty_mapping_when_selector_extraction_is_not_implemented(+ self, monkeypatch: pytest.MonkeyPatch+ ):class FakeNodeClass:@staticmethoddef extract_variable_selector_to_variable_mapping(**_kwargs):@@ -707,7 +709,7 @@ class TestWorkflowEntryHelpers:tenant_id="tenant-id",)- def test_run_free_node_wraps_execution_failures(self, monkeypatch):+ def test_run_free_node_wraps_execution_failures(self, monkeypatch: pytest.MonkeyPatch):class FakeNodeClass:@staticmethoddef extract_variable_selector_to_variable_mapping(**_kwargs):diff --git a/api/tests/unit_tests/extensions/test_ext_request_logging.py b/api/tests/unit_tests/extensions/test_ext_request_logging.pyindex dcb457c8067..03479686bbe 100644--- a/api/tests/unit_tests/extensions/test_ext_request_logging.py+++ b/api/tests/unit_tests/extensions/test_ext_request_logging.py@@ -71,7 +71,7 @@ def enable_request_logging(monkeypatch: pytest.MonkeyPatch):class TestRequestLoggingExtension:def test_receiver_should_not_be_invoked_if_configuration_is_disabled(self,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,mock_request_receiver,mock_response_receiver,):@@ -266,7 +266,9 @@ class TestResponseUnmodified:class TestRequestFinishedInfoAccessLine:- def test_info_access_log_includes_method_path_status_duration_trace_id(self, monkeypatch, caplog):+ def test_info_access_log_includes_method_path_status_duration_trace_id(+ self, monkeypatch: pytest.MonkeyPatch, caplog+ ):"""Ensure INFO access line contains expected fields with computed duration and trace id."""app = _get_test_app()# Push a real request context so flask.request and g are available@@ -299,7 +301,7 @@ class TestRequestFinishedInfoAccessLine:assert "123.456" in msg # rounded to 3 decimalsassert "trace-xyz" in msg- def test_info_access_log_uses_dash_without_start_timestamp(self, monkeypatch, caplog):+ def test_info_access_log_uses_dash_without_start_timestamp(self, monkeypatch: pytest.MonkeyPatch, caplog):app = _get_test_app()with app.test_request_context("/bar", method="POST"):# No g.__request_started_ts set -> duration should be '-'diff --git a/api/tests/unit_tests/extensions/test_pubsub_channel.py b/api/tests/unit_tests/extensions/test_pubsub_channel.pyindex 926c406ad47..24bbf55cb3a 100644--- a/api/tests/unit_tests/extensions/test_pubsub_channel.py+++ b/api/tests/unit_tests/extensions/test_pubsub_channel.py@@ -1,10 +1,12 @@+import pytest+from configs import dify_configfrom extensions import ext_redisfrom libs.broadcast_channel.redis.channel import BroadcastChannel as RedisBroadcastChannelfrom libs.broadcast_channel.redis.sharded_channel import ShardedRedisBroadcastChannel-def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch):+def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub")monkeypatch.setattr(ext_redis, "_pubsub_redis_client", object())@@ -13,7 +15,7 @@ def test_get_pubsub_broadcast_channel_defaults_to_pubsub(monkeypatch):assert isinstance(channel, RedisBroadcastChannel)-def test_get_pubsub_broadcast_channel_sharded(monkeypatch):+def test_get_pubsub_broadcast_channel_sharded(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "sharded")monkeypatch.setattr(ext_redis, "_pubsub_redis_client", object())diff --git a/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py b/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.pyindex 8bef01c1ede..7c7f20374ee 100644--- a/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py+++ b/api/tests/unit_tests/libs/broadcast_channel/redis/test_channel_unit_tests.py@@ -673,7 +673,7 @@ class TestRedisShardedSubscription:"""Test cases for the _RedisShardedSubscription class."""@pytest.fixture(autouse=True)- def patch_sharded_redis_type(self, monkeypatch):+ def patch_sharded_redis_type(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("libs.broadcast_channel.redis.sharded_channel.Redis", FakeRedisClient)@pytest.fixture@@ -889,7 +889,9 @@ class TestRedisShardedSubscription:assert not sharded_subscription._queue.empty()assert sharded_subscription._queue.get_nowait() == b"test sharded payload"- def test_get_message_uses_target_node_for_cluster_client(self, mock_pubsub: MagicMock, monkeypatch):+ def test_get_message_uses_target_node_for_cluster_client(+ self, mock_pubsub: MagicMock, monkeypatch: pytest.MonkeyPatch+ ):"""Test that cluster clients use target_node for sharded messages."""class DummyRedisCluster:@@ -1177,7 +1179,7 @@ class TestRedisSubscriptionCommon:return request.param@pytest.fixture(autouse=True)- def patch_sharded_redis_type(self, monkeypatch):+ def patch_sharded_redis_type(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr("libs.broadcast_channel.redis.sharded_channel.Redis", FakeRedisClient)@pytest.fixturediff --git a/api/tests/unit_tests/libs/test_archive_storage.py b/api/tests/unit_tests/libs/test_archive_storage.pyindex de3c9c47374..4363c235716 100644--- a/api/tests/unit_tests/libs/test_archive_storage.py+++ b/api/tests/unit_tests/libs/test_archive_storage.py@@ -34,7 +34,7 @@ def _client_error(code: str) -> ClientError:return ClientError({"Error": {"Code": code}}, "Operation")-def _mock_client(monkeypatch):+def _mock_client(monkeypatch: pytest.MonkeyPatch):client = MagicMock()client.head_bucket.return_value = None# Configure put_object to return a proper ETag that matches the MD5 hash@@ -56,19 +56,19 @@ def _mock_client(monkeypatch):return client, boto_client-def test_init_disabled(monkeypatch):+def test_init_disabled(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch, ARCHIVE_STORAGE_ENABLED=False)with pytest.raises(ArchiveStorageNotConfiguredError, match="not enabled"):ArchiveStorage(bucket=BUCKET_NAME)-def test_init_missing_config(monkeypatch):+def test_init_missing_config(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch, ARCHIVE_STORAGE_ENDPOINT=None)with pytest.raises(ArchiveStorageNotConfiguredError, match="incomplete"):ArchiveStorage(bucket=BUCKET_NAME)-def test_init_bucket_not_found(monkeypatch):+def test_init_bucket_not_found(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.head_bucket.side_effect = _client_error("404")@@ -77,7 +77,7 @@ def test_init_bucket_not_found(monkeypatch):ArchiveStorage(bucket=BUCKET_NAME)-def test_init_bucket_access_denied(monkeypatch):+def test_init_bucket_access_denied(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.head_bucket.side_effect = _client_error("403")@@ -86,7 +86,7 @@ def test_init_bucket_access_denied(monkeypatch):ArchiveStorage(bucket=BUCKET_NAME)-def test_init_bucket_other_error(monkeypatch):+def test_init_bucket_other_error(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.head_bucket.side_effect = _client_error("500")@@ -95,7 +95,7 @@ def test_init_bucket_other_error(monkeypatch):ArchiveStorage(bucket=BUCKET_NAME)-def test_init_sets_client(monkeypatch):+def test_init_sets_client(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, boto_client = _mock_client(monkeypatch)@@ -113,7 +113,7 @@ def test_init_sets_client(monkeypatch):assert storage.bucket == BUCKET_NAME-def test_put_object_returns_checksum(monkeypatch):+def test_put_object_returns_checksum(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)storage = ArchiveStorage(bucket=BUCKET_NAME)@@ -132,7 +132,7 @@ def test_put_object_returns_checksum(monkeypatch):assert checksum == expected_md5-def test_put_object_raises_on_error(monkeypatch):+def test_put_object_raises_on_error(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)storage = ArchiveStorage(bucket=BUCKET_NAME)@@ -142,7 +142,7 @@ def test_put_object_raises_on_error(monkeypatch):storage.put_object("key", b"data")-def test_get_object_returns_bytes(monkeypatch):+def test_get_object_returns_bytes(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)body = MagicMock()@@ -153,7 +153,7 @@ def test_get_object_returns_bytes(monkeypatch):assert storage.get_object("key") == b"payload"-def test_get_object_missing(monkeypatch):+def test_get_object_missing(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.get_object.side_effect = _client_error("NoSuchKey")@@ -163,7 +163,7 @@ def test_get_object_missing(monkeypatch):storage.get_object("missing")-def test_get_object_stream(monkeypatch):+def test_get_object_stream(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)body = MagicMock()@@ -174,7 +174,7 @@ def test_get_object_stream(monkeypatch):assert list(storage.get_object_stream("key")) == [b"a", b"b"]-def test_get_object_stream_missing(monkeypatch):+def test_get_object_stream_missing(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.get_object.side_effect = _client_error("NoSuchKey")@@ -184,7 +184,7 @@ def test_get_object_stream_missing(monkeypatch):list(storage.get_object_stream("missing"))-def test_object_exists(monkeypatch):+def test_object_exists(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)storage = ArchiveStorage(bucket=BUCKET_NAME)@@ -194,7 +194,7 @@ def test_object_exists(monkeypatch):assert storage.object_exists("missing") is False-def test_delete_object_error(monkeypatch):+def test_delete_object_error(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.delete_object.side_effect = _client_error("500")@@ -204,7 +204,7 @@ def test_delete_object_error(monkeypatch):storage.delete_object("key")-def test_list_objects(monkeypatch):+def test_list_objects(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)paginator = MagicMock()@@ -219,7 +219,7 @@ def test_list_objects(monkeypatch):paginator.paginate.assert_called_once_with(Bucket="archive-bucket", Prefix="prefix")-def test_list_objects_error(monkeypatch):+def test_list_objects_error(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)paginator = MagicMock()@@ -231,7 +231,7 @@ def test_list_objects_error(monkeypatch):storage.list_objects("prefix")-def test_generate_presigned_url(monkeypatch):+def test_generate_presigned_url(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.generate_presigned_url.return_value = "http://signed-url"@@ -247,7 +247,7 @@ def test_generate_presigned_url(monkeypatch):assert url == "http://signed-url"-def test_generate_presigned_url_error(monkeypatch):+def test_generate_presigned_url_error(monkeypatch: pytest.MonkeyPatch):_configure_storage(monkeypatch)client, _ = _mock_client(monkeypatch)client.generate_presigned_url.side_effect = _client_error("500")diff --git a/api/tests/unit_tests/libs/test_pandas.py b/api/tests/unit_tests/libs/test_pandas.pyindex 21c2f0781d8..a4739dbbc2b 100644--- a/api/tests/unit_tests/libs/test_pandas.py+++ b/api/tests/unit_tests/libs/test_pandas.py@@ -1,7 +1,8 @@import pandas as pd+import pytest-def test_pandas_csv(tmp_path, monkeypatch):+def test_pandas_csv(tmp_path, monkeypatch: pytest.MonkeyPatch):monkeypatch.chdir(tmp_path)data = {"col1": [1, 2.2, -3.3, 4.0, 5], "col2": ["A", "B", "C", "D", "E"]}df1 = pd.DataFrame(data)@@ -16,7 +17,7 @@ def test_pandas_csv(tmp_path, monkeypatch):assert df2[df2.columns[1]].to_list() == data["col2"]-def test_pandas_xlsx(tmp_path, monkeypatch):+def test_pandas_xlsx(tmp_path, monkeypatch: pytest.MonkeyPatch):monkeypatch.chdir(tmp_path)data = {"col1": [1, 2.2, -3.3, 4.0, 5], "col2": ["A", "B", "C", "D", "E"]}df1 = pd.DataFrame(data)@@ -31,7 +32,7 @@ def test_pandas_xlsx(tmp_path, monkeypatch):assert df2[df2.columns[1]].to_list() == data["col2"]-def test_pandas_xlsx_with_sheets(tmp_path, monkeypatch):+def test_pandas_xlsx_with_sheets(tmp_path, monkeypatch: pytest.MonkeyPatch):monkeypatch.chdir(tmp_path)data1 = {"col1": [1, 2, 3, 4, 5], "col2": ["A", "B", "C", "D", "E"]}df1 = pd.DataFrame(data1)diff --git a/api/tests/unit_tests/libs/test_rate_limiter.py b/api/tests/unit_tests/libs/test_rate_limiter.pyindex 9d44b07b5ef..5052033db87 100644--- a/api/tests/unit_tests/libs/test_rate_limiter.py+++ b/api/tests/unit_tests/libs/test_rate_limiter.py@@ -1,5 +1,7 @@from unittest.mock import MagicMock+import pytest+from libs import helper as helper_module@@ -31,7 +33,7 @@ class _FakeRedis:return True-def test_rate_limiter_counts_attempts_within_same_second(monkeypatch):+def test_rate_limiter_counts_attempts_within_same_second(monkeypatch: pytest.MonkeyPatch):fake_redis = _FakeRedis()monkeypatch.setattr(helper_module.time, "time", lambda: 1000)@@ -48,7 +50,7 @@ def test_rate_limiter_counts_attempts_within_same_second(monkeypatch):assert limiter.is_rate_limited("203.0.113.10") is True-def test_rate_limiter_uses_injected_redis(monkeypatch):+def test_rate_limiter_uses_injected_redis(monkeypatch: pytest.MonkeyPatch):redis_client = MagicMock()redis_client.zcard.return_value = 1monkeypatch.setattr(helper_module.time, "time", lambda: 1000)diff --git a/api/tests/unit_tests/libs/test_token.py b/api/tests/unit_tests/libs/test_token.pyindex 6a65b5faa03..734568d37b3 100644--- a/api/tests/unit_tests/libs/test_token.py+++ b/api/tests/unit_tests/libs/test_token.py@@ -1,5 +1,6 @@from unittest.mock import MagicMock+import pytestfrom werkzeug.wrappers import Responsefrom constants import COOKIE_NAME_ACCESS_TOKEN, COOKIE_NAME_WEBAPP_ACCESS_TOKEN@@ -30,7 +31,7 @@ def test_extract_access_token():assert extract_webapp_access_token(request) == expected_webapp # pyright: ignore[reportArgumentType]-def test_real_cookie_name_uses_host_prefix_without_domain(monkeypatch):+def test_real_cookie_name_uses_host_prefix_without_domain(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(token.dify_config, "CONSOLE_WEB_URL", "https://console.example.com", raising=False)monkeypatch.setattr(token.dify_config, "CONSOLE_API_URL", "https://api.example.com", raising=False)monkeypatch.setattr(token.dify_config, "COOKIE_DOMAIN", "", raising=False)@@ -38,7 +39,7 @@ def test_real_cookie_name_uses_host_prefix_without_domain(monkeypatch):assert token._real_cookie_name("csrf_token") == "__Host-csrf_token"-def test_real_cookie_name_without_host_prefix_when_domain_present(monkeypatch):+def test_real_cookie_name_without_host_prefix_when_domain_present(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(token.dify_config, "CONSOLE_WEB_URL", "https://console.example.com", raising=False)monkeypatch.setattr(token.dify_config, "CONSOLE_API_URL", "https://api.example.com", raising=False)monkeypatch.setattr(token.dify_config, "COOKIE_DOMAIN", ".example.com", raising=False)@@ -46,7 +47,7 @@ def test_real_cookie_name_without_host_prefix_when_domain_present(monkeypatch):assert token._real_cookie_name("csrf_token") == "csrf_token"-def test_set_csrf_cookie_includes_domain_when_configured(monkeypatch):+def test_set_csrf_cookie_includes_domain_when_configured(monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(token.dify_config, "CONSOLE_WEB_URL", "https://console.example.com", raising=False)monkeypatch.setattr(token.dify_config, "CONSOLE_API_URL", "https://api.example.com", raising=False)monkeypatch.setattr(token.dify_config, "COOKIE_DOMAIN", ".example.com", raising=False)diff --git a/api/tests/unit_tests/services/plugin/conftest.py b/api/tests/unit_tests/services/plugin/conftest.pyindex 80c6077b0cd..9dc4fa03909 100644--- a/api/tests/unit_tests/services/plugin/conftest.py+++ b/api/tests/unit_tests/services/plugin/conftest.py@@ -21,7 +21,7 @@ def make_features(@pytest.fixture-def mock_installer(monkeypatch):+def mock_installer(monkeypatch: pytest.MonkeyPatch):"""Patch PluginInstaller at the service import site."""mock = MagicMock()monkeypatch.setattr("services.plugin.plugin_service.PluginInstaller", lambda: mock)diff --git a/api/tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py b/api/tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.pyindex 1a2d0622089..287391c24c4 100644--- a/api/tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py+++ b/api/tests/unit_tests/services/rag_pipeline/test_rag_pipeline_task_proxy.py@@ -2,12 +2,13 @@ from types import SimpleNamespacefrom unittest.mock import Mockimport pytest+from pytest_mock import MockerFixturefrom services.rag_pipeline.rag_pipeline_task_proxy import RagPipelineTaskProxy@pytest.fixture-def proxy(mocker):+def proxy(mocker: MockerFixture):"""Create a RagPipelineTaskProxy with mocked dependencies."""mocker.patch("services.rag_pipeline.rag_pipeline_task_proxy.TenantIsolatedTaskQueue")entity = Mock()diff --git a/api/tests/unit_tests/services/test_app_generate_service.py b/api/tests/unit_tests/services/test_app_generate_service.pyindex d3f9c5dd9f1..216c5d9db65 100644--- a/api/tests/unit_tests/services/test_app_generate_service.py+++ b/api/tests/unit_tests/services/test_app_generate_service.py@@ -20,6 +20,7 @@ from contextlib import contextmanagerfrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport services.app_generate_service as ags_modulefrom core.app.entities.app_invoke_entities import InvokeFrom@@ -96,7 +97,7 @@ def _noop_rate_limit_context(rate_limit, request_id):class TestBuildStreamingTaskOnSubscribe:"""Tests for AppGenerateService._build_streaming_task_on_subscribe."""- def test_streams_mode_starts_immediately(self, monkeypatch):+ def test_streams_mode_starts_immediately(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "streams")called = []cb = AppGenerateService._build_streaming_task_on_subscribe(lambda: called.append(1))@@ -106,7 +107,7 @@ class TestBuildStreamingTaskOnSubscribe:cb()assert called == [1] # not called again- def test_pubsub_mode_starts_on_subscribe(self, monkeypatch):+ def test_pubsub_mode_starts_on_subscribe(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub")monkeypatch.setattr(ags_module, "SSE_TASK_START_FALLBACK_MS", 60_000) # large to prevent timercalled = []@@ -118,7 +119,7 @@ class TestBuildStreamingTaskOnSubscribe:cb()assert called == [1]- def test_sharded_mode_starts_on_subscribe(self, monkeypatch):+ def test_sharded_mode_starts_on_subscribe(self, monkeypatch: pytest.MonkeyPatch):"""sharded is treated like pubsub (i.e. not 'streams')."""monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "sharded")monkeypatch.setattr(ags_module, "SSE_TASK_START_FALLBACK_MS", 60_000)@@ -128,7 +129,7 @@ class TestBuildStreamingTaskOnSubscribe:cb()assert called == [1]- def test_pubsub_fallback_timer_fires(self, monkeypatch):+ def test_pubsub_fallback_timer_fires(self, monkeypatch: pytest.MonkeyPatch):"""When nobody subscribes fast enough the fallback timer fires."""monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub")monkeypatch.setattr(ags_module, "SSE_TASK_START_FALLBACK_MS", 50) # 50 ms@@ -137,7 +138,7 @@ class TestBuildStreamingTaskOnSubscribe:time.sleep(0.2) # give the timer time to fireassert called == [1]- def test_exception_in_start_task_returns_false(self, monkeypatch):+ def test_exception_in_start_task_returns_false(self, monkeypatch: pytest.MonkeyPatch):"""When start_task raises, _try_start returns False and next call retries."""monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "streams")call_count = 0@@ -154,7 +155,7 @@ class TestBuildStreamingTaskOnSubscribe:cb()assert call_count == 2- def test_concurrent_subscribe_only_starts_once(self, monkeypatch):+ def test_concurrent_subscribe_only_starts_once(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "PUBSUB_REDIS_CHANNEL_TYPE", "pubsub")monkeypatch.setattr(ags_module, "SSE_TASK_START_FALLBACK_MS", 60_000)call_count = 0@@ -176,31 +177,31 @@ class TestBuildStreamingTaskOnSubscribe:# _get_max_active_requests# ---------------------------------------------------------------------------class TestGetMaxActiveRequests:- def test_both_zero_returns_zero(self, monkeypatch):+ def test_both_zero_returns_zero(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "APP_MAX_ACTIVE_REQUESTS", 0)monkeypatch.setattr(ags_module.dify_config, "APP_DEFAULT_ACTIVE_REQUESTS", 0)app = _make_app(AppMode.CHAT, max_active_requests=0)assert AppGenerateService._get_max_active_requests(app) == 0- def test_app_limit_only(self, monkeypatch):+ def test_app_limit_only(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "APP_MAX_ACTIVE_REQUESTS", 0)monkeypatch.setattr(ags_module.dify_config, "APP_DEFAULT_ACTIVE_REQUESTS", 0)app = _make_app(AppMode.CHAT, max_active_requests=5)assert AppGenerateService._get_max_active_requests(app) == 5- def test_config_limit_only(self, monkeypatch):+ def test_config_limit_only(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "APP_MAX_ACTIVE_REQUESTS", 10)monkeypatch.setattr(ags_module.dify_config, "APP_DEFAULT_ACTIVE_REQUESTS", 0)app = _make_app(AppMode.CHAT, max_active_requests=0)assert AppGenerateService._get_max_active_requests(app) == 10- def test_both_non_zero_returns_min(self, monkeypatch):+ def test_both_non_zero_returns_min(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "APP_MAX_ACTIVE_REQUESTS", 20)monkeypatch.setattr(ags_module.dify_config, "APP_DEFAULT_ACTIVE_REQUESTS", 0)app = _make_app(AppMode.CHAT, max_active_requests=5)assert AppGenerateService._get_max_active_requests(app) == 5- def test_default_active_requests_used_when_app_has_none(self, monkeypatch):+ def test_default_active_requests_used_when_app_has_none(self, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "APP_MAX_ACTIVE_REQUESTS", 0)monkeypatch.setattr(ags_module.dify_config, "APP_DEFAULT_ACTIVE_REQUESTS", 15)app = _make_app(AppMode.CHAT, max_active_requests=0)@@ -214,7 +215,7 @@ class TestGenerate:"""Tests for AppGenerateService.generate covering each mode."""@pytest.fixture(autouse=True)- def _common(self, mocker, monkeypatch):+ def _common(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "BILLING_ENABLED", False)mocker.patch("services.app_generate_service.RateLimit", _DummyRateLimit)# Prevent AppExecutionParams.new from touching real models via isinstance@@ -224,7 +225,7 @@ class TestGenerate:)# -- COMPLETION ---------------------------------------------------------- def test_completion_mode(self, mocker):+ def test_completion_mode(self, mocker: MockerFixture):gen_spy = mocker.patch("services.app_generate_service.CompletionAppGenerator.generate",return_value={"result": "ok"},@@ -244,7 +245,7 @@ class TestGenerate:gen_spy.assert_called_once()# -- AGENT_CHAT via mode ------------------------------------------------- def test_agent_chat_mode(self, mocker):+ def test_agent_chat_mode(self, mocker: MockerFixture):gen_spy = mocker.patch("services.app_generate_service.AgentChatAppGenerator.generate",return_value={"result": "agent"},@@ -264,7 +265,7 @@ class TestGenerate:gen_spy.assert_called_once()# -- AGENT_CHAT via is_agent flag (non-AGENT_CHAT mode) ------------------ def test_agent_via_is_agent_flag(self, mocker):+ def test_agent_via_is_agent_flag(self, mocker: MockerFixture):gen_spy = mocker.patch("services.app_generate_service.AgentChatAppGenerator.generate",return_value={"result": "agent-via-flag"},@@ -285,7 +286,7 @@ class TestGenerate:gen_spy.assert_called_once()# -- CHAT ---------------------------------------------------------------- def test_chat_mode(self, mocker):+ def test_chat_mode(self, mocker: MockerFixture):gen_spy = mocker.patch("services.app_generate_service.ChatAppGenerator.generate",return_value={"result": "chat"},@@ -306,7 +307,7 @@ class TestGenerate:gen_spy.assert_called_once()# -- ADVANCED_CHAT blocking ---------------------------------------------- def test_advanced_chat_blocking(self, mocker):+ def test_advanced_chat_blocking(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)@@ -333,7 +334,7 @@ class TestGenerate:retrieve_spy.assert_not_called()# -- ADVANCED_CHAT streaming --------------------------------------------- def test_advanced_chat_streaming(self, mocker, monkeypatch):+ def test_advanced_chat_streaming(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)mocker.patch(@@ -365,7 +366,7 @@ class TestGenerate:delay_spy.assert_called_once()# -- WORKFLOW blocking --------------------------------------------------- def test_workflow_blocking(self, mocker):+ def test_workflow_blocking(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)gen_spy = mocker.patch(@@ -390,7 +391,7 @@ class TestGenerate:assert call_kwargs["pause_state_config"].state_owner_user_id == "owner-id"# -- WORKFLOW streaming -------------------------------------------------- def test_workflow_streaming(self, mocker, monkeypatch):+ def test_workflow_streaming(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)mocker.patch(@@ -422,7 +423,7 @@ class TestGenerate:delay_spy.assert_called_once()# -- Invalid mode -------------------------------------------------------- def test_invalid_mode_raises(self, mocker):+ def test_invalid_mode_raises(self, mocker: MockerFixture):app = _make_app("invalid-mode", is_agent=False)with pytest.raises(ValueError, match="Invalid app mode"):AppGenerateService.generate(@@ -439,14 +440,14 @@ class TestGenerate:# ---------------------------------------------------------------------------class TestGenerateBilling:@pytest.fixture(autouse=True)- def _common(self, mocker, monkeypatch):+ def _common(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):mocker.patch("services.app_generate_service.RateLimit", _DummyRateLimit)mocker.patch("services.app_generate_service.rate_limit_context",_noop_rate_limit_context,)- def test_billing_enabled_consumes_quota(self, mocker, monkeypatch):+ def test_billing_enabled_consumes_quota(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "BILLING_ENABLED", True)quota_charge = MagicMock()reserve_mock = mocker.patch(@@ -472,7 +473,9 @@ class TestGenerateBilling:reserve_mock.assert_called_once_with(QuotaType.WORKFLOW, "tenant-id")quota_charge.commit.assert_called_once()- def test_billing_quota_exceeded_raises_rate_limit_error(self, mocker, monkeypatch):+ def test_billing_quota_exceeded_raises_rate_limit_error(+ self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch+ ):from services.errors.app import QuotaExceededErrorfrom services.errors.llm import InvokeRateLimitError@@ -491,7 +494,7 @@ class TestGenerateBilling:streaming=False,)- def test_exception_refunds_quota_and_exits_rate_limit(self, mocker, monkeypatch):+ def test_exception_refunds_quota_and_exits_rate_limit(self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch):monkeypatch.setattr(ags_module.dify_config, "BILLING_ENABLED", True)quota_charge = MagicMock()mocker.patch(@@ -517,7 +520,9 @@ class TestGenerateBilling:)quota_charge.refund.assert_called_once()- def test_rate_limit_exit_called_in_finally_for_blocking(self, mocker, monkeypatch):+ def test_rate_limit_exit_called_in_finally_for_blocking(+ self, mocker: MockerFixture, monkeypatch: pytest.MonkeyPatch+ ):"""For non-streaming (blocking) calls, rate_limit.exit should be called in finally."""monkeypatch.setattr(ags_module.dify_config, "BILLING_ENABLED", False)@@ -552,7 +557,7 @@ class TestGenerateBilling:# _get_workflow# ---------------------------------------------------------------------------class TestGetWorkflow:- def test_debugger_fetches_draft(self, mocker):+ def test_debugger_fetches_draft(self, mocker: MockerFixture):draft_wf = _make_workflow()ws = MagicMock()ws.get_draft_workflow.return_value = draft_wf@@ -562,7 +567,7 @@ class TestGetWorkflow:assert result is draft_wfws.get_draft_workflow.assert_called_once()- def test_debugger_raises_when_no_draft(self, mocker):+ def test_debugger_raises_when_no_draft(self, mocker: MockerFixture):ws = MagicMock()ws.get_draft_workflow.return_value = Nonemocker.patch("services.app_generate_service.WorkflowService", return_value=ws)@@ -570,7 +575,7 @@ class TestGetWorkflow:with pytest.raises(ValueError, match="Workflow not initialized"):AppGenerateService._get_workflow(_make_app(AppMode.WORKFLOW), InvokeFrom.DEBUGGER)- def test_non_debugger_fetches_published(self, mocker):+ def test_non_debugger_fetches_published(self, mocker: MockerFixture):pub_wf = _make_workflow()ws = MagicMock()ws.get_published_workflow.return_value = pub_wf@@ -580,7 +585,7 @@ class TestGetWorkflow:assert result is pub_wfws.get_published_workflow.assert_called_once()- def test_non_debugger_raises_when_no_published(self, mocker):+ def test_non_debugger_raises_when_no_published(self, mocker: MockerFixture):ws = MagicMock()ws.get_published_workflow.return_value = Nonemocker.patch("services.app_generate_service.WorkflowService", return_value=ws)@@ -588,7 +593,7 @@ class TestGetWorkflow:with pytest.raises(ValueError, match="Workflow not published"):AppGenerateService._get_workflow(_make_app(AppMode.WORKFLOW), InvokeFrom.SERVICE_API)- def test_specific_workflow_id_valid_uuid(self, mocker):+ def test_specific_workflow_id_valid_uuid(self, mocker: MockerFixture):valid_uuid = str(uuid.uuid4())specific_wf = _make_workflow(workflow_id=valid_uuid)ws = MagicMock()@@ -601,7 +606,7 @@ class TestGetWorkflow:assert result is specific_wfws.get_published_workflow_by_id.assert_called_once()- def test_specific_workflow_id_invalid_uuid(self, mocker):+ def test_specific_workflow_id_invalid_uuid(self, mocker: MockerFixture):ws = MagicMock()mocker.patch("services.app_generate_service.WorkflowService", return_value=ws)@@ -610,7 +615,7 @@ class TestGetWorkflow:_make_app(AppMode.WORKFLOW), InvokeFrom.SERVICE_API, workflow_id="not-a-uuid")- def test_specific_workflow_id_not_found(self, mocker):+ def test_specific_workflow_id_not_found(self, mocker: MockerFixture):valid_uuid = str(uuid.uuid4())ws = MagicMock()ws.get_published_workflow_by_id.return_value = None@@ -626,7 +631,7 @@ class TestGetWorkflow:# generate_single_iteration# ---------------------------------------------------------------------------class TestGenerateSingleIteration:- def test_advanced_chat_mode(self, mocker):+ def test_advanced_chat_mode(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)gen_spy = mocker.patch(@@ -644,7 +649,7 @@ class TestGenerateSingleIteration:iter_spy.assert_called_once()assert result == {"event": "iteration"}- def test_workflow_mode(self, mocker):+ def test_workflow_mode(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)mocker.patch(@@ -662,7 +667,7 @@ class TestGenerateSingleIteration:iter_spy.assert_called_once()assert result == {"event": "wf-iteration"}- def test_invalid_mode_raises(self, mocker):+ def test_invalid_mode_raises(self, mocker: MockerFixture):app = _make_app(AppMode.CHAT)with pytest.raises(ValueError, match="Invalid app mode"):AppGenerateService.generate_single_iteration(app_model=app, user=_make_user(), node_id="n1", args={})@@ -672,7 +677,7 @@ class TestGenerateSingleIteration:# generate_single_loop# ---------------------------------------------------------------------------class TestGenerateSingleLoop:- def test_advanced_chat_mode(self, mocker):+ def test_advanced_chat_mode(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)mocker.patch(@@ -690,7 +695,7 @@ class TestGenerateSingleLoop:loop_spy.assert_called_once()assert result == {"event": "loop"}- def test_workflow_mode(self, mocker):+ def test_workflow_mode(self, mocker: MockerFixture):workflow = _make_workflow()mocker.patch.object(AppGenerateService, "_get_workflow", return_value=workflow)mocker.patch(@@ -708,7 +713,7 @@ class TestGenerateSingleLoop:loop_spy.assert_called_once()assert result == {"event": "wf-loop"}- def test_invalid_mode_raises(self, mocker):+ def test_invalid_mode_raises(self, mocker: MockerFixture):app = _make_app(AppMode.COMPLETION)with pytest.raises(ValueError, match="Invalid app mode"):AppGenerateService.generate_single_loop(app_model=app, user=_make_user(), node_id="n1", args=MagicMock())@@ -718,7 +723,7 @@ class TestGenerateSingleLoop:# generate_more_like_this# ---------------------------------------------------------------------------class TestGenerateMoreLikeThis:- def test_delegates_to_completion_generator(self, mocker):+ def test_delegates_to_completion_generator(self, mocker: MockerFixture):gen_spy = mocker.patch("services.app_generate_service.CompletionAppGenerator.generate_more_like_this",return_value={"result": "similar"},@@ -739,7 +744,7 @@ class TestGenerateMoreLikeThis:# get_response_generator# ---------------------------------------------------------------------------class TestGetResponseGenerator:- def test_non_ended_workflow_run(self, mocker):+ def test_non_ended_workflow_run(self, mocker: MockerFixture):app = _make_app(AppMode.ADVANCED_CHAT)workflow_run = MagicMock()workflow_run.id = "run-1"@@ -756,7 +761,7 @@ class TestGetResponseGenerator:result = AppGenerateService.get_response_generator(app_model=app, workflow_run=workflow_run)gen_instance.retrieve_events.assert_called_once()- def test_ended_workflow_run_still_returns_generator(self, mocker):+ def test_ended_workflow_run_still_returns_generator(self, mocker: MockerFixture):"""Even when the run is ended, the current code still returns a generator (TODO branch)."""app = _make_app(AppMode.WORKFLOW)workflow_run = MagicMock()diff --git a/api/tests/unit_tests/services/test_app_generate_service_streaming_integration.py b/api/tests/unit_tests/services/test_app_generate_service_streaming_integration.pyindex 30aa359b455..4293be8f726 100644--- a/api/tests/unit_tests/services/test_app_generate_service_streaming_integration.py+++ b/api/tests/unit_tests/services/test_app_generate_service_streaming_integration.py@@ -89,7 +89,7 @@ class _FakeStreams:@pytest.fixture-def _patch_get_channel_streams(monkeypatch):+def _patch_get_channel_streams(monkeypatch: pytest.MonkeyPatch):from libs.broadcast_channel.redis.streams_channel import StreamsBroadcastChannelfake = _FakeStreams()@@ -108,7 +108,7 @@ def _patch_get_channel_streams(monkeypatch):@pytest.fixture-def _patch_get_channel_pubsub(monkeypatch):+def _patch_get_channel_pubsub(monkeypatch: pytest.MonkeyPatch):from libs.broadcast_channel.redis.channel import BroadcastChannel as RedisBroadcastChannelstore: dict[str, deque[bytes]] = defaultdict(deque)@@ -163,7 +163,7 @@ def test_streams_full_flow_prepublish_and_replay():@pytest.mark.usefixtures("_patch_get_channel_pubsub")-def test_pubsub_full_flow_start_on_subscribe_gated(monkeypatch):+def test_pubsub_full_flow_start_on_subscribe_gated(monkeypatch: pytest.MonkeyPatch):# Speed up any potential timer if it accidentally triggersmonkeypatch.setattr("services.app_generate_service.SSE_TASK_START_FALLBACK_MS", 50)diff --git a/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py b/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.pyindex 9a513c3fe64..f5879d973d6 100644--- a/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py+++ b/api/tests/unit_tests/services/test_dataset_service_lock_not_owned.py@@ -22,7 +22,7 @@ class FakeLock:@pytest.fixture-def fake_current_user(monkeypatch):+def fake_current_user(monkeypatch: pytest.MonkeyPatch):user = create_autospec(Account, instance=True)user.id = "user-1"user.current_tenant_id = "tenant-1"@@ -31,7 +31,7 @@ def fake_current_user(monkeypatch):@pytest.fixture-def fake_features(monkeypatch):+def fake_features(monkeypatch: pytest.MonkeyPatch):"""Features.billing.enabled == False to skip quota logic."""features = types.SimpleNamespace(billing=types.SimpleNamespace(enabled=False, subscription=types.SimpleNamespace(plan="ENTERPRISE")),@@ -45,7 +45,7 @@ def fake_features(monkeypatch):@pytest.fixture-def fake_lock(monkeypatch):+def fake_lock(monkeypatch: pytest.MonkeyPatch):"""Patch redis_client.lock to always raise LockNotOwnedError on enter."""def _fake_lock(name, timeout=None, *args, **kwargs):@@ -61,7 +61,7 @@ def fake_lock(monkeypatch):def test_save_document_with_dataset_id_ignores_lock_not_owned(- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,fake_current_user,fake_features,fake_lock,@@ -118,7 +118,7 @@ def test_save_document_with_dataset_id_ignores_lock_not_owned(def test_add_segment_ignores_lock_not_owned(- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,fake_current_user,fake_lock,):@@ -161,7 +161,7 @@ def test_add_segment_ignores_lock_not_owned(def test_multi_create_segment_ignores_lock_not_owned(- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,fake_current_user,fake_lock,):diff --git a/api/tests/unit_tests/services/test_human_input_service.py b/api/tests/unit_tests/services/test_human_input_service.pyindex 55af5648219..9fc818f789e 100644--- a/api/tests/unit_tests/services/test_human_input_service.py+++ b/api/tests/unit_tests/services/test_human_input_service.py@@ -3,6 +3,7 @@ from datetime import datetime, timedeltafrom unittest.mock import MagicMockimport pytest+from pytest_mock import MockerFixtureimport services.human_input_service as human_input_service_modulefrom core.repositories.human_input_repository import (@@ -177,7 +178,9 @@ def test_get_form_definition_by_token_for_console_uses_repository(sample_form_reassert form.get_definition() == console_record.definition-def test_submit_form_by_token_calls_repository_and_enqueue(sample_form_record, mock_session_factory, mocker):+def test_submit_form_by_token_calls_repository_and_enqueue(+ sample_form_record, mock_session_factory, mocker: MockerFixture+):session_factory, _ = mock_session_factoryrepo = MagicMock(spec=HumanInputFormSubmissionRepository)repo.get_by_token.return_value = sample_form_record@@ -204,7 +207,9 @@ def test_submit_form_by_token_calls_repository_and_enqueue(sample_form_record, menqueue_spy.assert_called_once_with(sample_form_record.workflow_run_id)-def test_submit_form_by_token_skips_enqueue_for_delivery_test(sample_form_record, mock_session_factory, mocker):+def test_submit_form_by_token_skips_enqueue_for_delivery_test(+ sample_form_record, mock_session_factory, mocker: MockerFixture+):session_factory, _ = mock_session_factoryrepo = MagicMock(spec=HumanInputFormSubmissionRepository)test_record = dataclasses.replace(@@ -227,7 +232,9 @@ def test_submit_form_by_token_skips_enqueue_for_delivery_test(sample_form_recordenqueue_spy.assert_not_called()-def test_submit_form_by_token_passes_submission_user_id(sample_form_record, mock_session_factory, mocker):+def test_submit_form_by_token_passes_submission_user_id(+ sample_form_record, mock_session_factory, mocker: MockerFixture+):session_factory, _ = mock_session_factoryrepo = MagicMock(spec=HumanInputFormSubmissionRepository)repo.get_by_token.return_value = sample_form_record@@ -314,7 +321,7 @@ def test_form_submitted_error_init():assert error.code == 412-def test_human_input_service_init_with_engine(mocker):+def test_human_input_service_init_with_engine(mocker: MockerFixture):engine = MagicMock(spec=human_input_service_module.Engine)sessionmaker_mock = mocker.patch("services.human_input_service.sessionmaker")@@ -371,7 +378,7 @@ def test_submit_form_by_token_delivery_not_enabled(mock_session_factory):service.submit_form_by_token(RecipientType.STANDALONE_WEB_APP, "token", "action", {})-def test_submit_form_by_token_no_workflow_run_id(sample_form_record, mock_session_factory, mocker):+def test_submit_form_by_token_no_workflow_run_id(sample_form_record, mock_session_factory, mocker: MockerFixture):session_factory, _ = mock_session_factoryrepo = MagicMock(spec=HumanInputFormSubmissionRepository)repo.get_by_token.return_value = sample_form_recorddiff --git a/api/tests/unit_tests/services/test_message_service.py b/api/tests/unit_tests/services/test_message_service.pyindex 7adc15d63ee..51f8b3ef5b6 100644--- a/api/tests/unit_tests/services/test_message_service.py+++ b/api/tests/unit_tests/services/test_message_service.py@@ -906,7 +906,7 @@ class TestMessageServiceSuggestedQuestions:):"""Test successful suggested questions generation in basic Chat mode."""# Arrange- app = factory.create_app_mock(mode=AppMode.CHAT.value)+ app = factory.create_app_mock(mode=AppMode.CHAT)user = factory.create_end_user_mock()message = factory.create_message_mock()mock_get_message.return_value = message@@ -953,7 +953,7 @@ class TestMessageServiceSuggestedQuestions:"""Test suggested question generation uses frontend configured model and prompt."""from core.app.entities.app_invoke_entities import InvokeFrom- app = factory.create_app_mock(mode=AppMode.CHAT.value)+ app = factory.create_app_mock(mode=AppMode.CHAT)app.tenant_id = "tenant-123"user = factory.create_end_user_mock()message = factory.create_message_mock()@@ -1024,7 +1024,7 @@ class TestMessageServiceSuggestedQuestions:factory,):"""Test invalid frontend configured model falls back to tenant default model."""- app = factory.create_app_mock(mode=AppMode.CHAT.value)+ app = factory.create_app_mock(mode=AppMode.CHAT)app.tenant_id = "tenant-123"user = factory.create_end_user_mock()message = factory.create_message_mock()diff --git a/api/tests/unit_tests/services/test_model_load_balancing_service.py b/api/tests/unit_tests/services/test_model_load_balancing_service.pyindex 3119af40a27..beecf73caa4 100644--- a/api/tests/unit_tests/services/test_model_load_balancing_service.py+++ b/api/tests/unit_tests/services/test_model_load_balancing_service.py@@ -104,7 +104,7 @@ def test_enable_disable_model_load_balancing_should_call_provider_configuration_service.provider_manager.get_configurations.return_value = {"openai": provider_configuration}# Act- getattr(service, method_name)("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value)+ getattr(service, method_name)("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM)# Assertgetattr(provider_configuration, expected_provider_method).assert_called_once_with(@@ -125,7 +125,7 @@ def test_enable_disable_model_load_balancing_should_raise_value_error_when_provi# Act + Assertwith pytest.raises(ValueError, match="Provider openai does not exist"):- getattr(service, method_name)("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value)+ getattr(service, method_name)("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM)def test_get_load_balancing_configs_should_raise_value_error_when_provider_missing(@@ -136,7 +136,7 @@ def test_get_load_balancing_configs_should_raise_value_error_when_provider_missi# Act + Assertwith pytest.raises(ValueError, match="Provider openai does not exist"):- service.get_load_balancing_configs("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value)+ service.get_load_balancing_configs("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM)def test_get_load_balancing_configs_should_insert_inherit_config_when_missing_for_custom_provider(@@ -177,7 +177,7 @@ def test_get_load_balancing_configs_should_insert_inherit_config_when_missing_fo"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,)# Assert@@ -238,7 +238,7 @@ def test_get_load_balancing_configs_should_reorder_existing_inherit_and_tolerate"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,config_from="predefined-model",)@@ -259,7 +259,7 @@ def test_get_load_balancing_config_should_raise_value_error_when_provider_missin# Act + Assertwith pytest.raises(ValueError, match="Provider openai does not exist"):- service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value, "cfg-1")+ service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM, "cfg-1")def test_get_load_balancing_config_should_return_none_when_config_not_found(@@ -272,7 +272,7 @@ def test_get_load_balancing_config_should_return_none_when_config_not_found(mock_db.session.scalar.return_value = None# Act- result = service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value, "cfg-1")+ result = service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM, "cfg-1")# Assertassert result is None@@ -292,7 +292,7 @@ def test_get_load_balancing_config_should_return_obfuscated_payload_when_config_mock_db.session.scalar.return_value = config# Act- result = service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM.value, "cfg-1")+ result = service.get_load_balancing_config("tenant-1", "openai", "gpt-4o-mini", ModelType.LLM, "cfg-1")# Assertassert result == {@@ -335,7 +335,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_provider_mi"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[],"custom-model",)@@ -354,7 +354,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_configs_is_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,cast(list[dict[str, object]], "invalid-configs"),"custom-model",)@@ -375,7 +375,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_config_item"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,cast(list[dict[str, object]], ["bad-item"]),"custom-model",)@@ -397,7 +397,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_credential_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"credential_id": "cred-1", "enabled": True}],"predefined-model",)@@ -418,7 +418,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_name_or_ena"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"enabled": True}],"custom-model",)@@ -428,7 +428,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_name_or_ena"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"name": "cfg-without-enabled"}],"custom-model",)@@ -450,7 +450,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_existing_co"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"id": "cfg-2", "name": "invalid", "enabled": True}],"custom-model",)@@ -472,7 +472,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_credentials"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"id": "cfg-1", "name": "new", "enabled": True, "credentials": "bad"}],"custom-model",)@@ -482,7 +482,7 @@ def test_update_load_balancing_configs_should_raise_value_error_when_credentials"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"name": "new-config", "enabled": True, "credentials": "bad"}],"custom-model",)@@ -519,7 +519,7 @@ def test_update_load_balancing_configs_should_update_existing_create_new_and_del"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"id": "cfg-1", "name": "updated-name", "enabled": False, "credentials": {"api_key": "plain"}},{"name": "new-config", "enabled": True, "credentials": {"api_key": "plain"}},@@ -553,7 +553,7 @@ def test_update_load_balancing_configs_should_raise_value_error_for_invalid_new_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"name": "__inherit__", "enabled": True, "credentials": {"api_key": "x"}}],"custom-model",)@@ -563,7 +563,7 @@ def test_update_load_balancing_configs_should_raise_value_error_for_invalid_new_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"name": "new", "enabled": True}],"custom-model",)@@ -585,7 +585,7 @@ def test_update_load_balancing_configs_should_create_from_existing_provider_cred"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,[{"credential_id": "cred-1", "enabled": True}],"predefined-model",)@@ -611,7 +611,7 @@ def test_validate_load_balancing_credentials_should_raise_value_error_when_provi"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,{"api_key": "plain"},)@@ -631,7 +631,7 @@ def test_validate_load_balancing_credentials_should_raise_value_error_when_confi"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,{"api_key": "plain"},config_id="cfg-1",)@@ -654,7 +654,7 @@ def test_validate_load_balancing_credentials_should_delegate_to_custom_validate_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,{"api_key": "plain"},config_id="cfg-1",)@@ -662,7 +662,7 @@ def test_validate_load_balancing_credentials_should_delegate_to_custom_validate_"tenant-1","openai","gpt-4o-mini",- ModelType.LLM.value,+ ModelType.LLM,{"api_key": "plain"},)diff --git a/api/tests/unit_tests/services/test_model_provider_service.py b/api/tests/unit_tests/services/test_model_provider_service.pyindex 28d459eac95..9e4eeb2d6ed 100644--- a/api/tests/unit_tests/services/test_model_provider_service.py+++ b/api/tests/unit_tests/services/test_model_provider_service.py@@ -90,7 +90,7 @@ class TestModelProviderServiceConfiguration:)manager.get_configurations.return_value = {"openai": allowed, "embedding": filtered}- result = service.get_provider_list(tenant_id="tenant-1", model_type=ModelType.LLM.value)+ result = service.get_provider_list(tenant_id="tenant-1", model_type=ModelType.LLM)assert len(result) == 1assert result[0].provider == "openai"@@ -232,7 +232,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credential_id": "cred-1",},@@ -245,7 +245,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credentials": {"api_key": "x"},},@@ -258,7 +258,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credentials": {"api_key": "x"},"credential_name": "cred-a",@@ -277,7 +277,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credentials": {"api_key": "x"},"credential_id": "cred-1",@@ -298,7 +298,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credential_id": "cred-1",},@@ -311,7 +311,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credential_id": "cred-1",},@@ -324,7 +324,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o","credential_id": "cred-1",},@@ -337,7 +337,7 @@ class TestModelProviderServiceDelegation:{"tenant_id": "tenant-1","provider": "openai",- "model_type": ModelType.LLM.value,+ "model_type": ModelType.LLM,"model": "gpt-4o",},"delete_custom_model",@@ -425,7 +425,7 @@ class TestModelProviderServiceListingsAndDefaults:provider_configurations = SimpleNamespace(get_models=MagicMock(return_value=models))manager.get_configurations.return_value = provider_configurations- result = service.get_models_by_model_type(tenant_id="tenant-1", model_type=ModelType.LLM.value)+ result = service.get_models_by_model_type(tenant_id="tenant-1", model_type=ModelType.LLM)provider_configurations.get_models.assert_called_once_with(model_type=ModelType.LLM, only_active=True)assert len(result) == 1@@ -495,7 +495,7 @@ class TestModelProviderServiceListingsAndDefaults:),)- result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM.value)+ result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM)assert result is not Noneassert result.model == "gpt-4o"@@ -506,7 +506,7 @@ class TestModelProviderServiceListingsAndDefaults:service, manager = _create_service_with_mocked_manager()manager.get_default_model.return_value = None- result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM.value)+ result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM)assert result is None@@ -514,7 +514,7 @@ class TestModelProviderServiceListingsAndDefaults:service, manager = _create_service_with_mocked_manager()manager.get_default_model.side_effect = RuntimeError("boom")- result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM.value)+ result = service.get_default_model_of_model_type(tenant_id="tenant-1", model_type=ModelType.LLM)assert result is None@@ -523,7 +523,7 @@ class TestModelProviderServiceListingsAndDefaults:service.update_default_model_of_model_type(tenant_id="tenant-1",- model_type=ModelType.LLM.value,+ model_type=ModelType.LLM,provider="openai",model="gpt-4o",)@@ -593,7 +593,7 @@ class TestModelProviderServiceListingsAndDefaults:tenant_id="tenant-1",provider="openai",model="gpt-4o",- model_type=ModelType.LLM.value,+ model_type=ModelType.LLM,)getattr(provider_configuration, provider_method_name).assert_called_once_with(diff --git a/api/tests/unit_tests/services/test_trigger_provider_service.py b/api/tests/unit_tests/services/test_trigger_provider_service.pyindex 6eba60e5f10..4da4af2d939 100644--- a/api/tests/unit_tests/services/test_trigger_provider_service.py+++ b/api/tests/unit_tests/services/test_trigger_provider_service.py@@ -325,7 +325,7 @@ def test_update_trigger_subscription_should_raise_error_when_name_conflicts(id="sub-1",name="old",provider_id="langgenius/github/github",- credential_type=CredentialType.API_KEY.value,+ credential_type=CredentialType.API_KEY,)mock_session.scalar.side_effect = [subscription, object()] # found sub, name conflict_mock_get_trigger_provider(mocker, provider_controller)@@ -350,7 +350,7 @@ def test_update_trigger_subscription_should_update_fields_and_clear_cache(properties={"project": "enc-old"},parameters={"event": "old"},credentials={"api_key": "enc-old"},- credential_type=CredentialType.API_KEY.value,+ credential_type=CredentialType.API_KEY,credential_expires_at=0,expires_at=0,)@@ -456,7 +456,7 @@ def test_delete_trigger_provider_should_delete_and_clear_cache_even_if_unsubscriid="sub-1",user_id="user-1",provider_id=str(provider_id),- credential_type=CredentialType.OAUTH2.value,+ credential_type=CredentialType.OAUTH2,credentials={"token": "enc"},to_entity=lambda: SimpleNamespace(id="sub-1"),)@@ -492,7 +492,7 @@ def test_delete_trigger_provider_should_skip_unsubscribe_for_unauthorized(id="sub-2",user_id="user-1",provider_id=str(provider_id),- credential_type=CredentialType.UNAUTHORIZED.value,+ credential_type=CredentialType.UNAUTHORIZED,credentials={},to_entity=lambda: SimpleNamespace(id="sub-2"),)@@ -527,7 +527,7 @@ def test_refresh_oauth_token_should_raise_error_for_non_oauth_credentials(mocker: MockerFixture, mock_session: MagicMock) -> None:# Arrange- subscription = SimpleNamespace(credential_type=CredentialType.API_KEY.value)+ subscription = SimpleNamespace(credential_type=CredentialType.API_KEY)mock_session.scalar.return_value = subscription# Act + Assert@@ -545,7 +545,7 @@ def test_refresh_oauth_token_should_refresh_and_persist_new_credentials(subscription = SimpleNamespace(provider_id=str(provider_id),user_id="user-1",- credential_type=CredentialType.OAUTH2.value,+ credential_type=CredentialType.OAUTH2,credentials={"access_token": "enc"},credential_expires_at=0,)@@ -613,7 +613,7 @@ def test_refresh_subscription_should_refresh_and_persist_properties(parameters={"event": "push"},properties={"p": "enc"},credentials={"c": "enc"},- credential_type=CredentialType.API_KEY.value,+ credential_type=CredentialType.API_KEY,)mock_session.scalar.return_value = subscription_mock_get_trigger_provider(mocker, provider_controller)@@ -989,7 +989,7 @@ def test_verify_subscription_credentials_should_raise_when_api_key_validation_faprovider_controller: MagicMock,) -> None:# Arrange- subscription = SimpleNamespace(credential_type=CredentialType.API_KEY.value, credentials={"api_key": "old"})+ subscription = SimpleNamespace(credential_type=CredentialType.API_KEY, credentials={"api_key": "old"})_mock_get_trigger_provider(mocker, provider_controller)mocker.patch.object(TriggerProviderService, "get_subscription_by_id", return_value=subscription)provider_controller.validate_credentials.side_effect = RuntimeError("bad credentials")@@ -1012,7 +1012,7 @@ def test_verify_subscription_credentials_should_return_verified_when_api_key_valprovider_controller: MagicMock,) -> None:# Arrange- subscription = SimpleNamespace(credential_type=CredentialType.API_KEY.value, credentials={"api_key": "old"})+ subscription = SimpleNamespace(credential_type=CredentialType.API_KEY, credentials={"api_key": "old"})_mock_get_trigger_provider(mocker, provider_controller)mocker.patch.object(TriggerProviderService, "get_subscription_by_id", return_value=subscription)@@ -1036,7 +1036,7 @@ def test_verify_subscription_credentials_should_return_verified_for_non_api_key_provider_controller: MagicMock,) -> None:# Arrange- subscription = SimpleNamespace(credential_type=CredentialType.OAUTH2.value, credentials={})+ subscription = SimpleNamespace(credential_type=CredentialType.OAUTH2, credentials={})_mock_get_trigger_provider(mocker, provider_controller)mocker.patch.object(TriggerProviderService, "get_subscription_by_id", return_value=subscription)@@ -1100,7 +1100,7 @@ def test_rebuild_trigger_subscription_should_raise_for_unsupported_credential_typrovider_controller: MagicMock,) -> None:# Arrange- subscription = SimpleNamespace(credential_type=CredentialType.UNAUTHORIZED.value)+ subscription = SimpleNamespace(credential_type=CredentialType.UNAUTHORIZED)_mock_get_trigger_provider(mocker, provider_controller)mocker.patch.object(TriggerProviderService, "get_subscription_by_id", return_value=subscription)@@ -1126,7 +1126,7 @@ def test_rebuild_trigger_subscription_should_raise_when_unsubscribe_fails(id="sub-1",user_id="user-1",endpoint_id="endpoint-1",- credential_type=CredentialType.API_KEY.value,+ credential_type=CredentialType.API_KEY,credentials={"api_key": "old"},to_entity=lambda: SimpleNamespace(id="sub-1"),)@@ -1159,7 +1159,7 @@ def test_rebuild_trigger_subscription_should_resubscribe_and_update_existing_subid="sub-1",user_id="user-1",endpoint_id="endpoint-1",- credential_type=CredentialType.API_KEY.value,+ credential_type=CredentialType.API_KEY,credentials={"api_key": "old-key"},to_entity=lambda: SimpleNamespace(id="sub-1"),)diff --git a/api/tests/unit_tests/services/test_webhook_service.py b/api/tests/unit_tests/services/test_webhook_service.pyindex ffdcc046f98..95edc436d73 100644--- a/api/tests/unit_tests/services/test_webhook_service.py+++ b/api/tests/unit_tests/services/test_webhook_service.py@@ -140,7 +140,7 @@ class TestWebhookServiceUnit:assert args[1] == "text/plain"assert args[2] is webhook_trigger- def test_detect_binary_mimetype_uses_magic(self, monkeypatch):+ def test_detect_binary_mimetype_uses_magic(self, monkeypatch: pytest.MonkeyPatch):"""python-magic output should be used when available."""fake_magic = MagicMock()fake_magic.from_buffer.return_value = "image/png"@@ -151,7 +151,7 @@ class TestWebhookServiceUnit:assert result == "image/png"fake_magic.from_buffer.assert_called_once()- def test_detect_binary_mimetype_fallback_without_magic(self, monkeypatch):+ def test_detect_binary_mimetype_fallback_without_magic(self, monkeypatch: pytest.MonkeyPatch):"""Fallback MIME type should be used when python-magic is unavailable."""monkeypatch.setattr("services.trigger.webhook_service.magic", None)@@ -159,7 +159,7 @@ class TestWebhookServiceUnit:assert result == "application/octet-stream"- def test_detect_binary_mimetype_handles_magic_exception(self, monkeypatch):+ def test_detect_binary_mimetype_handles_magic_exception(self, monkeypatch: pytest.MonkeyPatch):"""Fallback MIME type should be used when python-magic raises an exception."""try:import magic as real_magicdiff --git a/api/tests/unit_tests/services/test_workflow_service.py b/api/tests/unit_tests/services/test_workflow_service.pyindex feafada59af..08c6ec76e28 100644--- a/api/tests/unit_tests/services/test_workflow_service.py+++ b/api/tests/unit_tests/services/test_workflow_service.py@@ -61,7 +61,7 @@ class TestWorkflowAssociatedDataFactory:def create_app_mock(app_id: str = "app-123",tenant_id: str = "tenant-456",- mode: str = AppMode.WORKFLOW.value,+ mode: str = AppMode.WORKFLOW,workflow_id: str | None = None,**kwargs,) -> MagicMock:@@ -93,7 +93,7 @@ class TestWorkflowAssociatedDataFactory:tenant_id: str = "tenant-456",app_id: str = "app-123",version: str = Workflow.VERSION_DRAFT,- workflow_type: str = WorkflowType.WORKFLOW.value,+ workflow_type: str = WorkflowType.WORKFLOW,graph: dict[str, Any] | None = None,features: dict[str, Any] | None = None,unique_hash: str | None = None,@@ -584,7 +584,7 @@ class TestWorkflowService:id="published-workflow-id",tenant_id=app.tenant_id,app_id=app.id,- type=WorkflowType.WORKFLOW.value,+ type=WorkflowType.WORKFLOW,version="2026-03-19T00:00:00",graph=json.dumps(TestWorkflowAssociatedDataFactory.create_valid_workflow_graph()),features=json.dumps(legacy_features),@@ -597,7 +597,7 @@ class TestWorkflowService:id="draft-workflow-id",tenant_id=app.tenant_id,app_id=app.id,- type=WorkflowType.WORKFLOW.value,+ type=WorkflowType.WORKFLOW,version=Workflow.VERSION_DRAFT,graph=json.dumps({"nodes": [], "edges": []}),features=json.dumps({}),@@ -685,7 +685,7 @@ class TestWorkflowService:Different app modes have different feature configurations.This ensures the features match the expected schema for workflow apps."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW)features = {"file_upload": {"enabled": False}}with patch("services.workflow_service.WorkflowAppConfigManager.config_validate") as mock_validate:@@ -696,7 +696,7 @@ class TestWorkflowService:def test_validate_features_structure_advanced_chat_mode(self, workflow_service):"""Test validate_features_structure for advanced chat mode."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.ADVANCED_CHAT.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.ADVANCED_CHAT)features = {"opening_statement": "Hello"}with patch("services.workflow_service.AdvancedChatAppConfigManager.config_validate") as mock_validate:@@ -707,7 +707,7 @@ class TestWorkflowService:def test_validate_features_structure_invalid_mode_raises_error(self, workflow_service):"""Test validate_features_structure raises error for invalid mode."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.COMPLETION.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.COMPLETION)features = {}with pytest.raises(ValueError, match="Invalid app mode"):@@ -1326,7 +1326,7 @@ class TestWorkflowService:The conversion creates equivalent workflow nodes from the chat configuration,giving users more control and customization options."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.CHAT.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.CHAT)account = TestWorkflowAssociatedDataFactory.create_account_mock()args = {"name": "Converted Workflow",@@ -1337,7 +1337,7 @@ class TestWorkflowService:with patch("services.workflow_service.WorkflowConverter") as MockConverter:mock_converter = MockConverter.return_value- mock_new_app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW.value)+ mock_new_app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW)mock_converter.convert_to_workflow.return_value = mock_new_appresult = workflow_service.convert_to_workflow(app, account, args)@@ -1353,13 +1353,13 @@ class TestWorkflowService:Completion apps are simpler (single prompt-response), so theconversion creates a basic workflow with fewer nodes."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.COMPLETION.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.COMPLETION)account = TestWorkflowAssociatedDataFactory.create_account_mock()args = {"name": "Converted Workflow"}with patch("services.workflow_service.WorkflowConverter") as MockConverter:mock_converter = MockConverter.return_value- mock_new_app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW.value)+ mock_new_app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW)mock_converter.convert_to_workflow.return_value = mock_new_appresult = workflow_service.convert_to_workflow(app, account, args)@@ -1373,7 +1373,7 @@ class TestWorkflowService:Only chat and completion apps can be converted to workflows.Apps that are already workflows or have other modes cannot be converted."""- app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW.value)+ app = TestWorkflowAssociatedDataFactory.create_app_mock(mode=AppMode.WORKFLOW)account = TestWorkflowAssociatedDataFactory.create_account_mock()args = {}@@ -2087,7 +2087,7 @@ class TestSetupVariablePool:This helper initialises the VariablePool used for single-step workflow execution."""- def _make_workflow(self, workflow_type: str = WorkflowType.WORKFLOW.value) -> MagicMock:+ def _make_workflow(self, workflow_type: str = WorkflowType.WORKFLOW) -> MagicMock:wf = MagicMock(spec=Workflow)wf.app_id = "app-1"wf.id = "wf-1"@@ -2176,7 +2176,7 @@ class TestSetupVariablePool:from models.workflow import WorkflowType# Arrange- workflow = self._make_workflow(workflow_type=WorkflowType.CHAT.value)+ workflow = self._make_workflow(workflow_type=WorkflowType.CHAT)# Actwith (diff --git a/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py b/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.pyindex 663eec6a06d..b5b9f0bd976 100644--- a/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py+++ b/api/tests/unit_tests/services/workflow/test_workflow_draft_variable_service.py@@ -398,7 +398,7 @@ class TestWorkflowDraftVariableService:self,mock_engine,mock_session,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,):"""Test resetting a node variable when execution record doesn't exist"""mock_repo_session = Mock(spec=Session)@@ -435,7 +435,7 @@ class TestWorkflowDraftVariableService:def test_reset_node_variable_with_valid_execution_record(self,mock_session,- monkeypatch,+ monkeypatch: pytest.MonkeyPatch,):"""Test resetting a node variable with valid execution record - should restore from execution"""mock_repo_session = Mock(spec=Session)diff --git a/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service.py b/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service.pyindex dfdbd9acd6a..17e9a077d62 100644--- a/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service.py+++ b/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service.py@@ -414,8 +414,8 @@ def test_parse_event_message_should_parse_only_json_object(def test_is_terminal_event_should_recognize_finished_and_optional_paused_events() -> None:# Arrange- finished_event = {"event": StreamEvent.WORKFLOW_FINISHED.value}- paused_event = {"event": StreamEvent.WORKFLOW_PAUSED.value}+ finished_event = {"event": StreamEvent.WORKFLOW_FINISHED}+ paused_event = {"event": StreamEvent.WORKFLOW_PAUSED}# Actis_finished = service_module._is_terminal_event(finished_event, close_on_pause=False)@@ -426,7 +426,7 @@ def test_is_terminal_event_should_recognize_finished_and_optional_paused_events(assert is_finished is Trueassert paused_without_flag is Falseassert paused_with_flag is True- assert service_module._is_terminal_event(StreamEvent.PING.value, close_on_pause=True) is False+ assert service_module._is_terminal_event(StreamEvent.PING, close_on_pause=True) is Falsedef test_apply_message_context_should_update_payload_when_context_exists() -> None:@@ -569,7 +569,7 @@ def test_build_workflow_event_stream_should_emit_ping_and_terminal_snapshot_evenmonkeypatch.setattr(service_module,"_build_snapshot_events",- MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED.value, "task_id": "task-1"}]),+ MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED, "task_id": "task-1"}]),)# Act@@ -584,9 +584,9 @@ def test_build_workflow_event_stream_should_emit_ping_and_terminal_snapshot_even)# Assert- assert events[0] == StreamEvent.PING.value+ assert events[0] == StreamEvent.PINGfinished_event = cast(Mapping[str, Any], events[1])- assert finished_event["event"] == StreamEvent.WORKFLOW_FINISHED.value+ assert finished_event["event"] == StreamEvent.WORKFLOW_FINISHEDassert buffer_state.stop_event.is_set() is Truenode_repo.get_execution_snapshots_by_workflow_run.assert_called_once()called_kwargs = node_repo.get_execution_snapshots_by_workflow_run.call_args.kwargs@@ -643,7 +643,7 @@ def test_build_workflow_event_stream_should_emit_periodic_ping_and_stop_after_id)# Assert- assert events == [StreamEvent.PING.value, StreamEvent.PING.value]+ assert events == [StreamEvent.PING, StreamEvent.PING]assert buffer_state.stop_event.is_set() is True@@ -686,7 +686,7 @@ def test_build_workflow_event_stream_should_exit_when_buffer_done_and_empty()# Assert- assert events == [StreamEvent.PING.value]+ assert events == [StreamEvent.PING]assert buffer_state.stop_event.is_set() is True@@ -706,7 +706,7 @@ def test_build_workflow_event_stream_should_continue_when_pause_loading_fails(monkeypatch.setattr(service_module.MessageGenerator, "get_response_topic", MagicMock(return_value=topic))monkeypatch.setattr(service_module, "_load_resumption_context", MagicMock(return_value=None))monkeypatch.setattr(service_module, "_resolve_task_id", MagicMock(return_value="task-1"))- snapshot_builder = MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED.value}])+ snapshot_builder = MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED}])monkeypatch.setattr(service_module, "_build_snapshot_events", snapshot_builder)buffer_state = BufferState(queue=queue.Queue(),@@ -729,7 +729,7 @@ def test_build_workflow_event_stream_should_continue_when_pause_loading_fails()# Assert- assert events[0] == StreamEvent.PING.value+ assert events[0] == StreamEvent.PINGassert snapshot_builder.call_args.kwargs["pause_entity"] is None@@ -779,7 +779,7 @@ def test_build_snapshot_events_preserves_public_form_token(monkeypatch: pytest.Msession_maker=cast(sessionmaker[Session], session_maker),)- assert events[-2]["event"] == StreamEvent.HUMAN_INPUT_REQUIRED.value+ assert events[-2]["event"] == StreamEvent.HUMAN_INPUT_REQUIREDassert events[-2]["data"]["form_token"] == "wtok"assert events[-2]["data"]["expiration_time"] == int(datetime(2024, 1, 1, tzinfo=UTC).timestamp())pause_data = events[-1]["data"]@@ -837,6 +837,6 @@ def test_build_workflow_event_stream_loads_pause_tokens_without_flask_app_contex)pause_event = cast(Mapping[str, Any], events[-1])- assert pause_event["event"] == StreamEvent.WORKFLOW_PAUSED.value+ assert pause_event["event"] == StreamEvent.WORKFLOW_PAUSEDassert pause_event["data"]["reasons"][0]["form_token"] == "wtok"assert pause_event["data"]["reasons"][0]["expiration_time"] == int(datetime(2024, 1, 1, tzinfo=UTC).timestamp())diff --git a/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service_additional.py b/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service_additional.pyindex d2634d7d7b9..4d711f1bf83 100644--- a/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service_additional.py+++ b/api/tests/unit_tests/services/workflow/test_workflow_event_snapshot_service_additional.py@@ -215,8 +215,8 @@ class TestWorkflowEventSnapshotHelpers:assert result == expecteddef test_is_terminal_event_should_recognize_finished_and_optional_paused_events(self) -> None:- finished_event = {"event": StreamEvent.WORKFLOW_FINISHED.value}- paused_event = {"event": StreamEvent.WORKFLOW_PAUSED.value}+ finished_event = {"event": StreamEvent.WORKFLOW_FINISHED}+ paused_event = {"event": StreamEvent.WORKFLOW_PAUSED}is_finished = service_module._is_terminal_event(finished_event, include_paused=False)paused_without_flag = service_module._is_terminal_event(paused_event, include_paused=False)@@ -225,7 +225,7 @@ class TestWorkflowEventSnapshotHelpers:assert is_finished is Trueassert paused_without_flag is Falseassert paused_with_flag is True- assert service_module._is_terminal_event(StreamEvent.PING.value, include_paused=True) is False+ assert service_module._is_terminal_event(StreamEvent.PING, include_paused=True) is Falsedef test_apply_message_context_should_update_payload_when_context_exists(self) -> None:payload: dict[str, Any] = {"event": "workflow_started"}@@ -352,7 +352,7 @@ class TestBuildWorkflowEventStream:monkeypatch.setattr(service_module,"_build_snapshot_events",- MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED.value, "task_id": "task-1"}]),+ MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED, "task_id": "task-1"}]),)events = list(@@ -365,9 +365,9 @@ class TestBuildWorkflowEventStream:))- assert events[0] == StreamEvent.PING.value+ assert events[0] == StreamEvent.PINGfinished_event = cast(Mapping[str, Any], events[1])- assert finished_event["event"] == StreamEvent.WORKFLOW_FINISHED.value+ assert finished_event["event"] == StreamEvent.WORKFLOW_FINISHEDassert buffer_state.stop_event.is_set() is Truenode_repo.get_execution_snapshots_by_workflow_run.assert_called_once()called_kwargs = node_repo.get_execution_snapshots_by_workflow_run.call_args.kwargs@@ -421,7 +421,7 @@ class TestBuildWorkflowEventStream:))- assert events == [StreamEvent.PING.value, StreamEvent.PING.value]+ assert events == [StreamEvent.PING, StreamEvent.PING]assert buffer_state.stop_event.is_set() is Truedef test_build_workflow_event_stream_should_exit_when_buffer_done_and_empty(@@ -461,7 +461,7 @@ class TestBuildWorkflowEventStream:))- assert events == [StreamEvent.PING.value]+ assert events == [StreamEvent.PING]assert buffer_state.stop_event.is_set() is Truedef test_build_workflow_event_stream_should_continue_when_pause_loading_fails(@@ -480,7 +480,7 @@ class TestBuildWorkflowEventStream:monkeypatch.setattr(service_module.MessageGenerator, "get_response_topic", MagicMock(return_value=topic))monkeypatch.setattr(service_module, "_load_resumption_context", MagicMock(return_value=None))monkeypatch.setattr(service_module, "_resolve_task_id", MagicMock(return_value="task-1"))- snapshot_builder = MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED.value}])+ snapshot_builder = MagicMock(return_value=[{"event": StreamEvent.WORKFLOW_FINISHED}])monkeypatch.setattr(service_module, "_build_snapshot_events", snapshot_builder)buffer_state = BufferState(queue=queue.Queue(),@@ -501,5 +501,5 @@ class TestBuildWorkflowEventStream:))- assert events[0] == StreamEvent.PING.value+ assert events[0] == StreamEvent.PINGassert snapshot_builder.call_args.kwargs["pause_entity"] is Nonediff --git a/api/tests/unit_tests/tasks/test_workflow_execute_task.py b/api/tests/unit_tests/tasks/test_workflow_execute_task.pyindex 72508bef526..2544c9d61a9 100644--- a/api/tests/unit_tests/tasks/test_workflow_execute_task.py+++ b/api/tests/unit_tests/tasks/test_workflow_execute_task.py@@ -122,7 +122,7 @@ def test_resume_app_execution_queries_message_by_conversation_and_workflow_run(mworkflow_run = SimpleNamespace(workflow_id="wf-id",app_id="app-id",- created_by_role=CreatorUserRole.ACCOUNT.value,+ created_by_role=CreatorUserRole.ACCOUNT,created_by="account-id",tenant_id="tenant-id",)@@ -208,7 +208,7 @@ def test_resume_app_execution_returns_early_when_advanced_chat_missing_conversatworkflow_run = SimpleNamespace(workflow_id="wf-id",app_id="app-id",- created_by_role=CreatorUserRole.ACCOUNT.value,+ created_by_role=CreatorUserRole.ACCOUNT,created_by="account-id",tenant_id="tenant-id",)