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.

test(api): annotate eight contract and helper files for strict pyrefly (#45456)

Felix Shifff098a2cf76
diff --git a/api/tests/e2e_tests/contracts/core/test_file.py b/api/tests/e2e_tests/contracts/core/test_file.py
index dff4a7f3efc..a230028790b 100644
--- a/api/tests/e2e_tests/contracts/core/test_file.py
+++ b/api/tests/e2e_tests/contracts/core/test_file.py
@@ -5,7 +5,7 @@ from models.workflow import Workflow
from models.workflow import WorkflowType as ModelWorkflowType
-def test_file_to_dict():
+def test_file_to_dict() -> None:
file = File(
file_id="file1",
tenant_id="tenant1",
@@ -20,7 +20,7 @@ def test_file_to_dict():
assert "url" in file_dict
-def test_workflow_features_with_image():
+def test_workflow_features_with_image() -> None:
# Create a feature dict that mimics the old structure with image config
features = {
"file_upload": {
diff --git a/api/tests/e2e_tests/contracts/core/workflow/graph_engine/test_tool_in_chatflow.py b/api/tests/e2e_tests/contracts/core/workflow/graph_engine/test_tool_in_chatflow.py
index 5cf9b1e518c..73bf820a84c 100644
--- a/api/tests/e2e_tests/contracts/core/workflow/graph_engine/test_tool_in_chatflow.py
+++ b/api/tests/e2e_tests/contracts/core/workflow/graph_engine/test_tool_in_chatflow.py
@@ -9,7 +9,7 @@ from tests.helpers.workflow.mock_config import MockConfigBuilder
from tests.helpers.workflow.table_runner import TableTestRunner
-def test_tool_in_chatflow():
+def test_tool_in_chatflow() -> None:
runner = TableTestRunner()
# Load the workflow configuration
@@ -42,7 +42,7 @@ def test_tool_in_chatflow():
assert success_events[-1].outputs["answer"] == "hello, dify!"
-def test_answer_can_render_llm_structured_output_in_chatflow():
+def test_answer_can_render_llm_structured_output_in_chatflow() -> None:
runner = TableTestRunner()
fixture_data = runner.workflow_runner.load_fixture("basic_chatflow")
diff --git a/api/tests/e2e_tests/contracts/core/workflow/nodes/answer/test_answer.py b/api/tests/e2e_tests/contracts/core/workflow/nodes/answer/test_answer.py
index 1e6248fba5c..c0ed7b432c0 100644
--- a/api/tests/e2e_tests/contracts/core/workflow/nodes/answer/test_answer.py
+++ b/api/tests/e2e_tests/contracts/core/workflow/nodes/answer/test_answer.py
@@ -1,5 +1,6 @@
import time
import uuid
+from typing import Any
from core.app.entities.app_invoke_entities import InvokeFrom, UserFrom
from core.workflow.system_variables import build_system_variables
@@ -18,7 +19,7 @@ def _build_variable_pool() -> VariablePool:
def _build_answer_node(*, answer: str, variable_pool: VariablePool) -> AnswerNode:
- graph_config = {
+ graph_config: dict[str, Any] = {
"edges": [],
"nodes": [
{
diff --git a/api/tests/e2e_tests/contracts/core/workflow/nodes/template_transform/test_template_transform_node.py b/api/tests/e2e_tests/contracts/core/workflow/nodes/template_transform/test_template_transform_node.py
index feb45995bf5..30dc80352b7 100644
--- a/api/tests/e2e_tests/contracts/core/workflow/nodes/template_transform/test_template_transform_node.py
+++ b/api/tests/e2e_tests/contracts/core/workflow/nodes/template_transform/test_template_transform_node.py
@@ -7,7 +7,7 @@ from tests.helpers.unit.core.workflow.nodes.template_transform.template_transfor
)
-def test_extract_variable_selector_to_variable_mapping_accepts_mixed_valid_entries():
+def test_extract_variable_selector_to_variable_mapping_accepts_mixed_valid_entries() -> None:
mapping = TemplateTransformNode._extract_variable_selector_to_variable_mapping(
graph_config={"ignored": True},
node_id="node_123",
diff --git a/api/tests/e2e_tests/contracts/core/workflow/test_node_mapping_bootstrap.py b/api/tests/e2e_tests/contracts/core/workflow/test_node_mapping_bootstrap.py
index 0c798e29fb2..38dede952df 100644
--- a/api/tests/e2e_tests/contracts/core/workflow/test_node_mapping_bootstrap.py
+++ b/api/tests/e2e_tests/contracts/core/workflow/test_node_mapping_bootstrap.py
@@ -5,7 +5,7 @@ import textwrap
from pathlib import Path
-def test_moved_core_nodes_resolve_after_importing_production_entrypoints():
+def test_moved_core_nodes_resolve_after_importing_production_entrypoints() -> None:
api_root = Path(__file__).resolve().parents[5]
# `PYTHONSAFEPATH=1` enables Python's safe-path mode, which suppresses the
diff --git a/api/tests/e2e_tests/contracts/libs/test_pandas.py b/api/tests/e2e_tests/contracts/libs/test_pandas.py
index 3eec25815a1..7e201660c86 100644
--- a/api/tests/e2e_tests/contracts/libs/test_pandas.py
+++ b/api/tests/e2e_tests/contracts/libs/test_pandas.py
@@ -4,7 +4,7 @@ import pandas as pd
import pytest
-def test_pandas_csv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
+def test_pandas_csv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(tmp_path)
data = {"col1": [1, 2.2, -3.3, 4.0, 5], "col2": ["A", "B", "C", "D", "E"]}
df1 = pd.DataFrame(data)
@@ -19,7 +19,7 @@ def test_pandas_csv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
assert df2[df2.columns[1]].to_list() == data["col2"]
-def test_pandas_xlsx(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
+def test_pandas_xlsx(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(tmp_path)
data = {"col1": [1, 2.2, -3.3, 4.0, 5], "col2": ["A", "B", "C", "D", "E"]}
df1 = pd.DataFrame(data)
@@ -34,7 +34,7 @@ def test_pandas_xlsx(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
assert df2[df2.columns[1]].to_list() == data["col2"]
-def test_pandas_xlsx_with_sheets(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
+def test_pandas_xlsx_with_sheets(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
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/e2e_tests/contracts/test_makefile_backend_tests.py b/api/tests/e2e_tests/contracts/test_makefile_backend_tests.py
index c4fc0b2e619..7a3f997f78b 100644
--- a/api/tests/e2e_tests/contracts/test_makefile_backend_tests.py
+++ b/api/tests/e2e_tests/contracts/test_makefile_backend_tests.py
@@ -2,7 +2,7 @@ import subprocess
from pathlib import Path
-def test_default_make_test_runs_backend_unit_suites():
+def test_default_make_test_runs_backend_unit_suites() -> None:
repo_root = Path(__file__).resolve().parents[4]
completed = subprocess.run(["make", "-n", "test"], cwd=repo_root, check=True, capture_output=True, text=True)
@@ -20,7 +20,7 @@ def test_default_make_test_runs_backend_unit_suites():
assert "api/providers/vdb/vdb-chroma/tests/e2e_tests" not in dry_run_output
-def test_make_test_all_runs_backend_pytest_suites():
+def test_make_test_all_runs_backend_pytest_suites() -> None:
repo_root = Path(__file__).resolve().parents[4]
completed = subprocess.run(["make", "-n", "test-all"], cwd=repo_root, check=True, capture_output=True, text=True)
diff --git a/api/tests/helpers/workflow/mock_config.py b/api/tests/helpers/workflow/mock_config.py
index a876f813365..745d0efcf4f 100644
--- a/api/tests/helpers/workflow/mock_config.py
+++ b/api/tests/helpers/workflow/mock_config.py
@@ -48,7 +48,7 @@ class MockConfig:
default_tool_response: dict[str, Any] = field(default_factory=lambda: {"result": "mocked tool output"})
default_retrieval_response: str = "This is mocked retrieval content"
default_http_response: dict[str, Any] = field(
- default_factory=lambda: {"status_code": 200, "body": "mocked response", "headers": {}}
+ default_factory=lambda: {"status_code": 200, "body": "mocked response", "headers": dict[str, str]()}
)
default_template_transform_response: str = "This is mocked template transform output"
default_code_response: dict[str, Any] = field(default_factory=lambda: {"result": "mocked code execution result"})
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.toml
index ee0de4a9dec..e49aaeecc69 100644
--- a/api/tests/unit_tests/pyrefly.toml
+++ b/api/tests/unit_tests/pyrefly.toml
@@ -185,7 +185,6 @@ project-excludes = [
"core/repositories/test_human_input_repository.py",
"core/repositories/test_sqlalchemy_workflow_execution_repository.py",
"core/repositories/test_sqlalchemy_workflow_node_execution_repository.py",
- "../e2e_tests/contracts/core/test_file.py",
"core/test_model_manager.py",
"core/test_provider_manager.py",
"core/trigger/debug/test_event_selectors.py",
@@ -216,12 +215,10 @@ project-excludes = [
"core/workflow/generator/prompts/test_planner_prompts.py",
"core/workflow/generator/test_runner.py",
"core/app/workflow/layers/conftest.py",
- "../helpers/workflow/mock_config.py",
"../helpers/workflow/mock_factory.py",
"../helpers/workflow/mock_nodes.py",
"../e2e_tests/contracts/core/workflow/graph_engine/test_parallel_human_input_join_resume.py",
"../helpers/workflow/table_runner.py",
- "../e2e_tests/contracts/core/workflow/graph_engine/test_tool_in_chatflow.py",
"core/workflow/nodes/agent/test_runtime_support.py",
"core/workflow/nodes/agent_v2/test_agent_node.py",
"core/workflow/nodes/agent_v2/test_binding_resolver.py",
@@ -229,7 +226,6 @@ project-excludes = [
"core/workflow/nodes/agent_v2/test_output_adapter.py",
"core/workflow/nodes/agent_v2/test_runtime_request_builder.py",
"core/workflow/nodes/agent_v2/test_validators.py",
- "../e2e_tests/contracts/core/workflow/nodes/answer/test_answer.py",
"../e2e_tests/contracts/core/workflow/nodes/base/test_base_node.py",
"../helpers/unit/core/workflow/nodes/code/code_node_spec.py",
"core/workflow/nodes/datasource/test_datasource_node.py",
@@ -244,7 +240,6 @@ project-excludes = [
"../e2e_tests/contracts/core/workflow/nodes/llm/test_node.py",
"../e2e_tests/contracts/core/workflow/nodes/parameter_extractor/test_parameter_extractor_node.py",
"../helpers/unit/core/workflow/nodes/template_transform/template_transform_node_spec.py",
- "../e2e_tests/contracts/core/workflow/nodes/template_transform/test_template_transform_node.py",
"../e2e_tests/contracts/core/workflow/nodes/test_base_node.py",
"../e2e_tests/contracts/core/workflow/nodes/test_document_extractor_node.py",
"../e2e_tests/contracts/core/workflow/nodes/test_if_else.py",
@@ -257,7 +252,6 @@ project-excludes = [
"core/workflow/nodes/human_input/test_pause_reason.py",
"core/workflow/nodes/human_input/test_callback.py",
"core/workflow/test_human_input_forms.py",
- "../e2e_tests/contracts/core/workflow/test_node_mapping_bootstrap.py",
"core/workflow/test_workflow_entry.py",
"dev/test_generate_knowledge_fs_contract.py",
"enterprise/telemetry/test_contracts.py",
@@ -284,7 +278,6 @@ project-excludes = [
"libs/test_archive_storage.py",
"libs/test_schedule_utils.py",
"libs/test_external_api.py",
- "../e2e_tests/contracts/libs/test_pandas.py",
"migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py",
"models/test_account.py",
"models/test_agent.py",
@@ -349,7 +342,6 @@ project-excludes = [
"tasks/test_enable_segments_to_index_task.py",
"tasks/test_human_input_timeout_tasks.py",
"tasks/app_generate/test_workflow_execute_task.py",
- "../e2e_tests/contracts/test_makefile_backend_tests.py",
"../e2e_tests/contracts/test_pytest_dify.py",
]