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): bring workflow-run retention and inspector tests under strict pyrefly (#45328)

Felix Shib1b3d36f5560
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.toml
index a40ef62033a..634f8366f81 100644
--- a/api/tests/unit_tests/pyrefly.toml
+++ b/api/tests/unit_tests/pyrefly.toml
@@ -313,8 +313,6 @@ project-excludes = [
"services/rag_pipeline/test_rag_pipeline_task_proxy.py",
"services/rag_pipeline/test_rag_pipeline_transform_service.py",
"services/retention/workflow_run/test_archive_download_preparation.py",
- "services/retention/workflow_run/test_archive_download_task_cache.py",
- "services/retention/workflow_run/test_archive_log_service.py",
"services/retention/workflow_run/test_clear_free_plan_expired_workflow_run_logs.py",
"services/retention/workflow_run/test_restore_archived_workflow_run.py",
"services/test_agent_config_service.py",
@@ -345,11 +343,9 @@ project-excludes = [
"services/data_source/test_website_service.py",
"services/test_workflow_collaboration_service.py",
"services/test_workflow_node_execution_trace_service.py",
- "services/test_workflow_run_service.py",
"services/test_workflow_service.py",
"services/tools/test_tools_transform_service.py",
"services/test_workflow_draft_variable_service.py",
- "services/workflow/test_node_output_inspector_service.py",
"services/workflow/test_workflow_converter.py",
"services/test_workflow_event_snapshot_service.py",
"tasks/test_clean_dataset_task.py",
diff --git a/api/tests/unit_tests/services/retention/workflow_run/test_archive_download_task_cache.py b/api/tests/unit_tests/services/retention/workflow_run/test_archive_download_task_cache.py
index bafd609f8e8..2498128bd45 100644
--- a/api/tests/unit_tests/services/retention/workflow_run/test_archive_download_task_cache.py
+++ b/api/tests/unit_tests/services/retention/workflow_run/test_archive_download_task_cache.py
@@ -1,5 +1,5 @@
import datetime
-from contextlib import nullcontext
+from contextlib import AbstractContextManager, nullcontext
import pytest
@@ -46,7 +46,7 @@ class FakeRedis:
name: str,
timeout: float | None = None,
blocking_timeout: float | None = None,
- ):
+ ) -> AbstractContextManager[None]:
self.lock_calls.append((name, timeout, blocking_timeout))
return nullcontext()
@@ -121,7 +121,8 @@ def test_build_archive_download_id_rejects_empty_bundle_refs() -> None:
def test_archive_download_task_cache_round_trips_with_ttl() -> None:
redis = FakeRedis()
- cache = WorkflowRunArchiveDownloadTaskCache(redis=redis)
+ # FakeRedis implements the subset of RedisClientWrapper that the cache uses.
+ cache = WorkflowRunArchiveDownloadTaskCache(redis=redis) # pyrefly: ignore[bad-argument-type]
task = build_pending_archive_download_task(
tenant_id="tenant-1",
requested_by="account-1",
@@ -144,7 +145,8 @@ def test_archive_download_task_cache_round_trips_with_ttl() -> None:
def test_archive_download_task_cache_uses_per_download_lock() -> None:
redis = FakeRedis()
- cache = WorkflowRunArchiveDownloadTaskCache(redis=redis)
+ # FakeRedis implements the subset of RedisClientWrapper that the cache uses.
+ cache = WorkflowRunArchiveDownloadTaskCache(redis=redis) # pyrefly: ignore[bad-argument-type]
with cache.lock(tenant_id="tenant-1", download_id="download-1"):
pass
@@ -160,7 +162,8 @@ def test_archive_download_task_cache_uses_per_download_lock() -> None:
def test_archive_download_task_cache_delete_removes_entry() -> None:
redis = FakeRedis()
- cache = WorkflowRunArchiveDownloadTaskCache(redis=redis)
+ # FakeRedis implements the subset of RedisClientWrapper that the cache uses.
+ cache = WorkflowRunArchiveDownloadTaskCache(redis=redis) # pyrefly: ignore[bad-argument-type]
task = WorkflowRunArchiveDownloadTask(
download_id="download-1",
tenant_id="tenant-1",
@@ -185,7 +188,8 @@ def test_archive_download_task_cache_delete_removes_entry() -> None:
def test_archive_download_task_cache_ignores_malformed_json() -> None:
redis = FakeRedis()
- cache = WorkflowRunArchiveDownloadTaskCache(redis=redis)
+ # FakeRedis implements the subset of RedisClientWrapper that the cache uses.
+ cache = WorkflowRunArchiveDownloadTaskCache(redis=redis) # pyrefly: ignore[bad-argument-type]
redis.setex("workflow_run_archive_download:tenant-1:download-1", 3600, "{")
assert cache.get(tenant_id="tenant-1", download_id="download-1") is None
diff --git a/api/tests/unit_tests/services/retention/workflow_run/test_archive_log_service.py b/api/tests/unit_tests/services/retention/workflow_run/test_archive_log_service.py
index fdb75337978..dbb67fc3417 100644
--- a/api/tests/unit_tests/services/retention/workflow_run/test_archive_log_service.py
+++ b/api/tests/unit_tests/services/retention/workflow_run/test_archive_log_service.py
@@ -2,7 +2,7 @@ import datetime
import json
import logging
from collections.abc import Sequence
-from contextlib import nullcontext
+from contextlib import AbstractContextManager, nullcontext
import pytest
@@ -92,7 +92,7 @@ class FakeTaskStore:
self.fail_reads = fail_reads
self.lock_calls: list[tuple[str, str]] = []
- def lock(self, *, tenant_id: str, download_id: str):
+ def lock(self, *, tenant_id: str, download_id: str) -> AbstractContextManager[None]:
self.lock_calls.append((tenant_id, download_id))
return nullcontext()
@@ -334,7 +334,7 @@ def test_create_download_marks_matching_claim_failed_when_dispatch_fails() -> No
records = (_bundle(shard="00-of-01", bundle_id="bundle-a", archive_bytes=1024),)
task_store = FakeTaskStore()
- def dispatch(_task: WorkflowRunArchiveDownloadTask) -> None:
+ def dispatch(task: WorkflowRunArchiveDownloadTask) -> None:
raise RuntimeError("broker unavailable")
result = _service(records=records, tasks=task_store, dispatcher=dispatch).create_download(
@@ -393,7 +393,7 @@ def test_create_download_claims_dispatch_once() -> None:
dispatched_tasks.append(task)
concurrent_results.append(service.create_download(_CONTEXT, year=2025, month=3))
- def sign_download_url(_storage_key: str, *, expires_in: int, filename: str) -> str:
+ def sign_download_url(storage_key: str, *, expires_in: int, filename: str) -> str:
assert expires_in > 0
assert filename
return "unused"
diff --git a/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py b/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py
index 3ec90c25966..857901e4743 100644
--- a/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py
+++ b/api/tests/unit_tests/services/workflow/test_node_output_inspector_service.py
@@ -179,7 +179,7 @@ def session_for(sqlite_session: Session) -> SessionFor:
return create_session
-def _stub_binding_resolver(*, declared_outputs: list[DeclaredOutputConfig]):
+def _stub_binding_resolver(*, declared_outputs: list[DeclaredOutputConfig]) -> MagicMock:
"""Build a fake ``WorkflowAgentBindingResolver`` whose ``.resolve`` returns
a binding with ``node_job_config_dict.declared_outputs``."""
binding = WorkflowAgentNodeBinding(
@@ -527,7 +527,7 @@ def test_file_output_preview_endpoint_returns_full_value_with_signed_url(session
assert preview.value["preview_url"] == "https://signed.example/x.pdf"
-def test_resolve_preview_url_uses_standard_file_factory():
+def test_resolve_preview_url_uses_standard_file_factory() -> None:
file_payload = {
"transfer_method": "tool_file",
"reference": build_file_reference(record_id="550e8400-e29b-41d4-a716-446655440000"),