Skip to content

armgit / dify

Public Imported from GitHub
0

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

refactor(api): enable strict typing for tools/libs test files (#44819)

Felix Shibbe282a9a550
diff --git a/api/tests/unit_tests/core/tools/entities/test_api_entities.py b/api/tests/unit_tests/core/tools/entities/test_api_entities.py
index 34f87ca6fab..5d1e174fcbc 100644
--- a/api/tests/unit_tests/core/tools/entities/test_api_entities.py
+++ b/api/tests/unit_tests/core/tools/entities/test_api_entities.py
@@ -14,7 +14,7 @@ from core.tools.entities.tool_entities import ToolProviderType
class TestToolProviderApiEntityWorkflowAppId:
"""Test suite for ToolProviderApiEntity workflow_app_id field."""
- def test_workflow_app_id_field_default_none(self):
+ def test_workflow_app_id_field_default_none(self) -> None:
"""Test that workflow_app_id defaults to None when not provided."""
entity = ToolProviderApiEntity(
id="test_id",
@@ -28,7 +28,7 @@ class TestToolProviderApiEntityWorkflowAppId:
assert entity.workflow_app_id is None
- def test_to_dict_includes_workflow_app_id_when_workflow_type_and_has_value(self):
+ def test_to_dict_includes_workflow_app_id_when_workflow_type_and_has_value(self) -> None:
"""Test that to_dict() includes workflow_app_id when type is WORKFLOW and value is set."""
workflow_app_id = "app_123"
entity = ToolProviderApiEntity(
@@ -47,7 +47,7 @@ class TestToolProviderApiEntityWorkflowAppId:
assert "workflow_app_id" in result
assert result["workflow_app_id"] == workflow_app_id
- def test_to_dict_excludes_workflow_app_id_when_workflow_type_and_none(self):
+ def test_to_dict_excludes_workflow_app_id_when_workflow_type_and_none(self) -> None:
"""Test that to_dict() excludes workflow_app_id when type is WORKFLOW but value is None."""
entity = ToolProviderApiEntity(
id="test_id",
@@ -64,7 +64,7 @@ class TestToolProviderApiEntityWorkflowAppId:
assert "workflow_app_id" not in result
- def test_to_dict_excludes_workflow_app_id_when_not_workflow_type(self):
+ def test_to_dict_excludes_workflow_app_id_when_not_workflow_type(self) -> None:
"""Test that to_dict() excludes workflow_app_id when type is not WORKFLOW."""
workflow_app_id = "app_123"
entity = ToolProviderApiEntity(
@@ -82,7 +82,7 @@ class TestToolProviderApiEntityWorkflowAppId:
assert "workflow_app_id" not in result
- def test_to_dict_includes_workflow_app_id_for_workflow_type_with_empty_string(self):
+ def test_to_dict_includes_workflow_app_id_for_workflow_type_with_empty_string(self) -> None:
"""Test that to_dict() excludes workflow_app_id when value is empty string (falsy)."""
entity = ToolProviderApiEntity(
id="test_id",
diff --git a/api/tests/unit_tests/core/tools/plugin_tool/test_provider.py b/api/tests/unit_tests/core/tools/plugin_tool/test_provider.py
index c903b8aa6e4..7f54f5fb501 100644
--- a/api/tests/unit_tests/core/tools/plugin_tool/test_provider.py
+++ b/api/tests/unit_tests/core/tools/plugin_tool/test_provider.py
@@ -49,7 +49,7 @@ def _build_controller() -> PluginToolProviderController:
)
-def test_plugin_tool_provider_controller_basic_behaviors():
+def test_plugin_tool_provider_controller_basic_behaviors() -> None:
controller = _build_controller()
assert controller.provider_type == ToolProviderType.PLUGIN
@@ -66,7 +66,7 @@ def test_plugin_tool_provider_controller_basic_behaviors():
@pytest.mark.parametrize("valid", [True, False])
-def test_validate_credentials(monkeypatch: pytest.MonkeyPatch, valid: bool):
+def test_validate_credentials(monkeypatch: pytest.MonkeyPatch, valid: bool) -> None:
controller = _build_controller()
requests: list[httpx.Request] = []
diff --git a/api/tests/unit_tests/core/tools/utils/test_workflow_configuration_sync.py b/api/tests/unit_tests/core/tools/utils/test_workflow_configuration_sync.py
index f1de66fd644..8280d9e0a0d 100644
--- a/api/tests/unit_tests/core/tools/utils/test_workflow_configuration_sync.py
+++ b/api/tests/unit_tests/core/tools/utils/test_workflow_configuration_sync.py
@@ -5,7 +5,7 @@ from core.tools.utils.workflow_configuration_sync import WorkflowToolConfigurati
from graphon.variables.input_entities import VariableEntity, VariableEntityType
-def test_get_workflow_graph_variables_and_outputs():
+def test_get_workflow_graph_variables_and_outputs() -> None:
graph = {
"nodes": [
{
@@ -58,7 +58,7 @@ def test_get_workflow_graph_variables_and_outputs():
assert no_start == []
-def test_check_is_synced_validation():
+def test_check_is_synced_validation() -> None:
variables = [
VariableEntity(
variable="query",
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.toml
index 06aff8b7366..b99f7352a73 100644
--- a/api/tests/unit_tests/pyrefly.toml
+++ b/api/tests/unit_tests/pyrefly.toml
@@ -292,7 +292,6 @@ project-excludes = [
"core/test_model_manager.py",
"core/test_provider_manager.py",
"core/trigger/debug/test_event_selectors.py",
- "core/tools/entities/test_api_entities.py",
"core/tools/__base/test_tool.py",
"core/tools/builtin_tool/test_tool.py",
"core/tools/builtin_tool/test_provider.py",
@@ -303,7 +302,6 @@ project-excludes = [
"core/tools/mcp_tool/test_tool.py",
"core/tools/mcp_tool/test_provider.py",
"core/tools/plugin_tool/test_tool.py",
- "core/tools/plugin_tool/test_provider.py",
"core/tools/test_tool_engine.py",
"core/tools/entities/test_tool_entities.py",
"core/tools/test_tool_file_manager.py",
@@ -316,7 +314,6 @@ project-excludes = [
"core/tools/utils/test_model_invocation_utils.py",
"core/tools/utils/test_parser.py",
"core/tools/utils/test_web_reader_tool.py",
- "core/tools/utils/test_workflow_configuration_sync.py",
"core/tools/workflow_as_tool/test_provider.py",
"core/tools/workflow_as_tool/test_tool.py",
"core/trigger/utils/test_encryption.py",
@@ -414,7 +411,6 @@ project-excludes = [
"libs/test_helper.py",
"libs/test_json_in_md_parser.py",
"libs/test_login.py",
- "libs/test_oauth_bearer.py",
"libs/test_orjson.py",
"libs/test_pagination.py",
"../e2e_tests/contracts/libs/test_pandas.py",