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
refactor(api): enable strict typing for tasks test files (#44879)
Felix Shi802360e16382
diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.tomlindex d4ce535d022..d4a8c53f9cc 100644--- a/api/tests/unit_tests/pyrefly.toml+++ b/api/tests/unit_tests/pyrefly.toml@@ -467,8 +467,6 @@ project-excludes = ["services/test_workflow_event_snapshot_service.py","services/workflow/test_workflow_event_snapshot_service_additional.py","services/test_workflow_restore.py",- "tasks/test_async_workflow_tasks.py",- "tasks/test_batch_clean_document_task.py","tasks/test_clean_dataset_task.py","tasks/test_clean_document_task.py","tasks/test_document_indexing_task.py",@@ -476,12 +474,7 @@ project-excludes = ["tasks/test_document_indexing_update_task.py","tasks/test_enable_segments_to_index_task.py","tasks/test_human_input_timeout_tasks.py",- "tasks/test_initialize_created_app_rbac_access_task.py",- "tasks/test_ops_trace_task.py",- "tasks/test_process_tenant_plugin_autoupgrade_check_task.py",- "tasks/test_remove_app_and_related_data_task.py","tasks/test_resume_agent_app_task.py",- "tasks/test_generate_summary_index_task.py","tasks/app_generate/test_workflow_execute_task.py","../e2e_tests/contracts/test_makefile_backend_tests.py","../e2e_tests/contracts/test_pytest_dify.py",diff --git a/api/tests/unit_tests/tasks/test_async_workflow_tasks.py b/api/tests/unit_tests/tasks/test_async_workflow_tasks.pyindex 9eabbb889f1..6ab9f43d861 100644--- a/api/tests/unit_tests/tasks/test_async_workflow_tasks.py+++ b/api/tests/unit_tests/tasks/test_async_workflow_tasks.py@@ -5,7 +5,7 @@ from services.errors.app import WorkflowNotFoundErrorfrom tasks import async_workflow_tasks-def test_workflow_not_found_error_message_is_a_single_formatted_string():+def test_workflow_not_found_error_message_is_a_single_formatted_string() -> None:# Regression: previously raised with printf-style positional args# ("...%s...", id1, id2), which made Exception store them as a tuple# and str(exc) rendered the literal tuple instead of a readable message.@@ -23,7 +23,7 @@ def test_workflow_not_found_error_message_is_a_single_formatted_string():assert exc.args == ("Workflow not found: workflow_run_id=wr-123, workflow_id=wf-456",)-def test_app_not_found_error_message_is_a_single_formatted_string():+def test_app_not_found_error_message_is_a_single_formatted_string() -> None:# Same regression check for the _AppNotFoundError raise site in the same# function (resume_workflow_execution).app_id = "app-789"@@ -58,7 +58,7 @@ def _collect_raise_calls_in(func_name: str) -> list[ast.Call]:return raises-def test_resume_workflow_execution_raises_do_not_use_printf_positional_args():+def test_resume_workflow_execution_raises_do_not_use_printf_positional_args() -> None:"""Regression: ``resume_workflow_execution`` previously raised``WorkflowNotFoundError("Workflow not found: workflow_run_id=%s, ...", run_id, wf_id)``and ``_AppNotFoundError("App not found: app_id=%s, ...", app_id, run_id)``.diff --git a/api/tests/unit_tests/tasks/test_batch_clean_document_task.py b/api/tests/unit_tests/tasks/test_batch_clean_document_task.pyindex d619dc1c058..835627d9174 100644--- a/api/tests/unit_tests/tasks/test_batch_clean_document_task.py+++ b/api/tests/unit_tests/tasks/test_batch_clean_document_task.py@@ -49,7 +49,7 @@ def cleanup_rows(sqlite_session: Session, monkeypatch: pytest.MonkeyPatch) -> tureturn dataset_id, document_id, tenant_id-def test_successful_vector_cleanup_schedules_billing_refresh(cleanup_rows: tuple[str, str, str]):+def test_successful_vector_cleanup_schedules_billing_refresh(cleanup_rows: tuple[str, str, str]) -> None:dataset_id, document_id, tenant_id = cleanup_rowswith (@@ -68,7 +68,7 @@ def test_successful_vector_cleanup_schedules_billing_refresh(cleanup_rows: tupleschedule_refresh.assert_called_once_with(tenant_id)-def test_failed_vector_cleanup_does_not_schedule_billing_refresh(cleanup_rows: tuple[str, str, str]):+def test_failed_vector_cleanup_does_not_schedule_billing_refresh(cleanup_rows: tuple[str, str, str]) -> None:dataset_id, document_id, _tenant_id = cleanup_rowswith (@@ -164,7 +164,9 @@ def test_batch_cleanup_keeps_only_the_leased_legacy_source_file(storage.delete.assert_called_once_with(deletable_file_key)-def test_cleans_segment_attachment_bindings_and_files(cleanup_rows: tuple[str, str, str], sqlite_session: Session):+def test_cleans_segment_attachment_bindings_and_files(+ cleanup_rows: tuple[str, str, str], sqlite_session: Session+) -> None:dataset_id, document_id, tenant_id = cleanup_rowssegment = sqlite_session.query(DocumentSegment).filter_by(document_id=document_id).one()attachment = UploadFile(diff --git a/api/tests/unit_tests/tasks/test_generate_summary_index_task.py b/api/tests/unit_tests/tasks/test_generate_summary_index_task.pyindex f6632e0a8a1..51450b09aa2 100644--- a/api/tests/unit_tests/tasks/test_generate_summary_index_task.py+++ b/api/tests/unit_tests/tasks/test_generate_summary_index_task.py@@ -15,7 +15,7 @@ SUMMARY_QUEUE = "dataset_summary"INDEXING_QUEUE = "dataset"-def _task_queue(task) -> str | None:+def _task_queue(task: object) -> str | None:# Celery's @shared_task(queue=...) stores the routing key on the task instance# at runtime, but type stubs don't declare it; use getattr to stay type-clean.return getattr(task, "queue", None)@@ -28,7 +28,7 @@ def _task_queue(task) -> str | None:(regenerate_summary_index_task, "regenerate_summary_index_task"),],)-def test_summary_task_uses_dedicated_queue(task, task_name):+def test_summary_task_uses_dedicated_queue(task: object, task_name: str) -> None:"""Summary tasks must use the dataset_summary queue, not the shared dataset queue.Summary generation is LLM-heavy and will block document indexing if placeddiff --git a/api/tests/unit_tests/tasks/test_ops_trace_task.py b/api/tests/unit_tests/tasks/test_ops_trace_task.pyindex e82849abe71..46196ca01f0 100644--- a/api/tests/unit_tests/tasks/test_ops_trace_task.py+++ b/api/tests/unit_tests/tasks/test_ops_trace_task.py@@ -1,6 +1,7 @@import jsonimport sys-from contextlib import contextmanager, nullcontext+from collections.abc import Generator+from contextlib import AbstractContextManager, contextmanager, nullcontextfrom types import ModuleTypefrom unittest.mock import MagicMock, patch@@ -28,12 +29,12 @@ def _application_tracing_disabled(monkeypatch: pytest.MonkeyPatch) -> None:@contextmanager-def fake_app_context():+def fake_app_context() -> Generator[None]:yieldclass FakeCurrentApp:- def app_context(self):+ def app_context(self) -> AbstractContextManager[None]:return fake_app_context()@@ -51,9 +52,9 @@ def _install_trace_manager(return trace_instancetelemetry_module = ModuleType("extensions.ext_enterprise_telemetry")- telemetry_module.is_enabled = lambda: enterprise_enabled+ telemetry_module.is_enabled = lambda: enterprise_enabled # pyrefly: ignore[missing-attribute]- ops_trace_manager_module.OpsTraceManager = StubOpsTraceManager+ ops_trace_manager_module.OpsTraceManager = StubOpsTraceManager # pyrefly: ignore[missing-attribute]modules = {"core.ops.ops_trace_manager": ops_trace_manager_module,"extensions.ext_enterprise_telemetry": telemetry_module,@@ -62,7 +63,7 @@ def _install_trace_manager(enterprise_module = ModuleType("enterprise")enterprise_telemetry_module = ModuleType("enterprise.telemetry")enterprise_trace_module = ModuleType("enterprise.telemetry.enterprise_trace")- enterprise_trace_module.EnterpriseOtelTrace = enterprise_trace_cls+ enterprise_trace_module.EnterpriseOtelTrace = enterprise_trace_cls # pyrefly: ignore[missing-attribute]modules.update({"enterprise": enterprise_module,@@ -88,7 +89,7 @@ def _retryable_dispatch_error() -> RetryableTraceDispatchError:def _run_task(file_info: dict[str, str], retries: int = 0) -> None:- process_trace_tasks.push_request(retries=retries)+ process_trace_tasks.push_request(retries=retries) # pyrefly: ignore[unexpected-keyword, missing-argument]try:process_trace_tasks.run(file_info)finally:@@ -138,7 +139,7 @@ def test_process_trace_tasks_retries_only_confirmed_retryable_dispatch_failures(mock_incr.assert_not_called()-def test_process_trace_tasks_marks_enterprise_trace_dispatched_before_retryable_dispatch_retry():+def test_process_trace_tasks_marks_enterprise_trace_dispatched_before_retryable_dispatch_retry() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()pending_error = _retryable_dispatch_error()@@ -178,7 +179,7 @@ def test_process_trace_tasks_marks_enterprise_trace_dispatched_before_retryable_mock_incr.assert_not_called()-def test_process_trace_tasks_does_not_mark_failed_enterprise_trace_as_dispatched_before_retry():+def test_process_trace_tasks_does_not_mark_failed_enterprise_trace_as_dispatched_before_retry() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()pending_error = _retryable_dispatch_error()@@ -217,7 +218,7 @@ def test_process_trace_tasks_does_not_mark_failed_enterprise_trace_as_dispatchedmock_incr.assert_not_called()-def test_process_trace_tasks_skips_enterprise_trace_when_retry_payload_was_already_dispatched():+def test_process_trace_tasks_skips_enterprise_trace_when_retry_payload_was_already_dispatched() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()enterprise_trace_cls = MagicMock()@@ -247,14 +248,13 @@ def test_process_trace_tasks_skips_enterprise_trace_when_retry_payload_was_alreamock_incr.assert_not_called()-def test_process_trace_tasks_default_retry_window_covers_workflow_and_export_grace_period():- assert (- process_trace_tasks.max_retries * process_trace_tasks.default_retry_delay- >= dify_config.WORKFLOW_MAX_EXECUTION_TIME + 300- )+def test_process_trace_tasks_default_retry_window_covers_workflow_and_export_grace_period() -> None:+ max_retries = process_trace_tasks.max_retries+ assert max_retries is not None+ assert max_retries * process_trace_tasks.default_retry_delay >= dify_config.WORKFLOW_MAX_EXECUTION_TIME + 300-def test_process_trace_tasks_deletes_payload_on_success():+def test_process_trace_tasks_deletes_payload_on_success() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()@@ -272,7 +272,7 @@ def test_process_trace_tasks_deletes_payload_on_success():mock_incr.assert_not_called()-def test_process_trace_tasks_deletes_payload_and_counts_terminal_failure():+def test_process_trace_tasks_deletes_payload_and_counts_terminal_failure() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()trace_instance.trace.side_effect = RuntimeError("trace failed")@@ -290,7 +290,7 @@ def test_process_trace_tasks_deletes_payload_and_counts_terminal_failure():mock_incr.assert_called_once_with(f"{OPS_TRACE_FAILED_KEY}_app-id")-def test_process_trace_tasks_treats_retry_enqueue_failure_as_terminal_failure():+def test_process_trace_tasks_treats_retry_enqueue_failure_as_terminal_failure() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()pending_error = _retryable_dispatch_error()@@ -315,7 +315,7 @@ def test_process_trace_tasks_treats_retry_enqueue_failure_as_terminal_failure():mock_incr.assert_called_once_with(f"{OPS_TRACE_FAILED_KEY}_app-id")-def test_process_trace_tasks_deletes_payload_and_counts_exhausted_retryable_dispatch_failure():+def test_process_trace_tasks_deletes_payload_and_counts_exhausted_retryable_dispatch_failure() -> None:file_info = {"app_id": "app-id", "file_id": "file-id"}trace_instance = MagicMock()pending_error = _retryable_dispatch_error()@@ -329,14 +329,18 @@ def test_process_trace_tasks_deletes_payload_and_counts_exhausted_retryable_disppatch("tasks.ops_trace_task.redis_client.incr") as mock_incr,patch.object(process_trace_tasks, "retry") as mock_retry,):- _run_task(file_info, retries=process_trace_tasks.max_retries)+ max_retries = process_trace_tasks.max_retries+ assert max_retries is not None+ _run_task(file_info, retries=max_retries)mock_retry.assert_not_called()mock_delete.assert_called_once_with("ops_trace/app-id/file-id.json")mock_incr.assert_called_once_with(f"{OPS_TRACE_FAILED_KEY}_app-id")-def test_managed_application_capture_receives_restored_info_and_preserves_enterprise(monkeypatch: pytest.MonkeyPatch):+def test_managed_application_capture_receives_restored_info_and_preserves_enterprise(+ monkeypatch: pytest.MonkeyPatch,+) -> None:from core.ops.entities.trace_entity import MessageTraceInfoapply_config_overrides(monkeypatch, OPS_AGENT_TRACE_ENABLED=True)@@ -394,7 +398,7 @@ def test_managed_application_capture_receives_restored_info_and_preserves_enterp@pytest.mark.parametrize("enabled", [False, True])def test_nonmanaged_task_uses_legacy_and_disabled_gate_never_calls_collector(monkeypatch: pytest.MonkeyPatch, enabled: bool-):+) -> None:apply_config_overrides(monkeypatch, OPS_AGENT_TRACE_ENABLED=enabled)legacy_calls: list[object] = []@@ -426,7 +430,7 @@ def test_nonmanaged_task_uses_legacy_and_disabled_gate_never_calls_collector(lookup.assert_called_once_with("app-id")-def test_capture_persistence_failure_preserves_payload_without_legacy_export(monkeypatch: pytest.MonkeyPatch):+def test_capture_persistence_failure_preserves_payload_without_legacy_export(monkeypatch: pytest.MonkeyPatch) -> None:apply_config_overrides(monkeypatch, OPS_AGENT_TRACE_ENABLED=True)pending_error = RetryableTraceDispatchError("database busy")calls: list[BaseTraceInfo] = []diff --git a/api/tests/unit_tests/tasks/test_process_tenant_plugin_autoupgrade_check_task.py b/api/tests/unit_tests/tasks/test_process_tenant_plugin_autoupgrade_check_task.pyindex 97e8db5fcc8..15615c8ba38 100644--- a/api/tests/unit_tests/tasks/test_process_tenant_plugin_autoupgrade_check_task.py+++ b/api/tests/unit_tests/tasks/test_process_tenant_plugin_autoupgrade_check_task.py@@ -17,9 +17,9 @@ MODULE = "tasks.process_tenant_plugin_autoupgrade_check_task"def _make_plugin(plugin_id: str,version: str,- source=PluginInstallationSource.Marketplace,+ source: PluginInstallationSource = PluginInstallationSource.Marketplace,category: PluginCategory = PluginCategory.Tool,-):+) -> SimpleNamespace:"""Build a minimal stand-in for a PluginInstallation entry returned by manager.list_plugins."""return SimpleNamespace(plugin_id=plugin_id,@@ -43,14 +43,14 @@ def _make_manifest(plugin_id: str, latest_version: str) -> MarketplacePluginSnapdef _run_task(*,- plugins: list,+ plugins: list[SimpleNamespace],manifests: list[MarketplacePluginSnapshot],- strategy_setting=TenantPluginAutoUpgradeStrategySetting.LATEST,- upgrade_mode=TenantPluginAutoUpgradeMode.ALL,- exclude_plugins=None,- include_plugins=None,- category=None,-):+ strategy_setting: TenantPluginAutoUpgradeStrategySetting = TenantPluginAutoUpgradeStrategySetting.LATEST,+ upgrade_mode: TenantPluginAutoUpgradeMode = TenantPluginAutoUpgradeMode.ALL,+ exclude_plugins: list[str] | None = None,+ include_plugins: list[str] | None = None,+ category: PluginCategory | str | None = None,+) -> tuple[MagicMock, list[tuple[str, str, str]]]:"""Execute the celery task synchronously with mocks for the plugin manager,the marketplace cache and PluginService.upgrade_plugin_with_marketplace.@@ -61,7 +61,7 @@ def _run_task(upgrade_calls: list[tuple[str, str, str]] = []- def _record_upgrade(tenant_id, original, new):+ def _record_upgrade(tenant_id: str, original: str, new: str) -> None:upgrade_calls.append((tenant_id, original, new))with (@@ -97,7 +97,7 @@ class TestUpgradeCallsMarketplaceService:"package file not found" and the upgrade silently never completed."""- def test_upgrade_routes_through_plugin_service(self):+ def test_upgrade_routes_through_plugin_service(self) -> None:plugin = _make_plugin("acme/foo", "1.0.0")manifest = _make_manifest("acme/foo", "1.0.1")@@ -106,7 +106,7 @@ class TestUpgradeCallsMarketplaceService:upgrade_mock.assert_called_once()assert calls == [("tenant-1", plugin.plugin_unique_identifier, manifest.latest_package_identifier)]- def test_does_not_call_manager_upgrade_plugin_directly(self):+ def test_does_not_call_manager_upgrade_plugin_directly(self) -> None:"""Locks in that we never go back to the broken path that bypassed download/upload."""plugin = _make_plugin("acme/foo", "1.0.0")manifest = _make_manifest("acme/foo", "1.0.1")@@ -136,7 +136,7 @@ class TestUpgradeCallsMarketplaceService:class TestStrategySetting:- def test_disabled_strategy_skips_everything(self):+ def test_disabled_strategy_skips_everything(self) -> None:upgrade_mock, _ = _run_task(plugins=[_make_plugin("acme/foo", "1.0.0")],manifests=[_make_manifest("acme/foo", "1.0.1")],@@ -144,7 +144,7 @@ class TestStrategySetting:)upgrade_mock.assert_not_called()- def test_fix_only_upgrades_patch_version(self):+ def test_fix_only_upgrades_patch_version(self) -> None:upgrade_mock, calls = _run_task(plugins=[_make_plugin("acme/foo", "1.0.0")],manifests=[_make_manifest("acme/foo", "1.0.5")],@@ -153,7 +153,7 @@ class TestStrategySetting:upgrade_mock.assert_called_once()assert calls[0][2].endswith(":1.0.5@cafe1234")- def test_fix_only_skips_minor_bump(self):+ def test_fix_only_skips_minor_bump(self) -> None:upgrade_mock, _ = _run_task(plugins=[_make_plugin("acme/foo", "1.0.0")],manifests=[_make_manifest("acme/foo", "1.1.0")],@@ -161,7 +161,7 @@ class TestStrategySetting:)upgrade_mock.assert_not_called()- def test_fix_only_skips_major_bump(self):+ def test_fix_only_skips_major_bump(self) -> None:upgrade_mock, _ = _run_task(plugins=[_make_plugin("acme/foo", "1.0.0")],manifests=[_make_manifest("acme/foo", "2.0.0")],@@ -169,7 +169,7 @@ class TestStrategySetting:)upgrade_mock.assert_not_called()- def test_latest_strategy_skips_when_versions_equal(self):+ def test_latest_strategy_skips_when_versions_equal(self) -> None:upgrade_mock, _ = _run_task(plugins=[_make_plugin("acme/foo", "1.0.0")],manifests=[_make_manifest("acme/foo", "1.0.0")],@@ -179,7 +179,7 @@ class TestStrategySetting:class TestUpgradeMode:- def test_mode_all_upgrades_every_marketplace_plugin(self):+ def test_mode_all_upgrades_every_marketplace_plugin(self) -> None:plugins = [_make_plugin("acme/foo", "1.0.0"),_make_plugin("acme/bar", "2.0.0"),@@ -199,7 +199,7 @@ class TestUpgradeMode:upgraded_ids = sorted(c[1] for c in calls)assert upgraded_ids == sorted(p.plugin_unique_identifier for p in plugins)- def test_mode_all_skips_non_marketplace_sources(self):+ def test_mode_all_skips_non_marketplace_sources(self) -> None:plugins = [_make_plugin("acme/foo", "1.0.0"),_make_plugin("acme/bar", "2.0.0", source=PluginInstallationSource.Github),@@ -218,7 +218,7 @@ class TestUpgradeMode:assert upgrade_mock.call_count == 1assert calls[0][1] == plugins[0].plugin_unique_identifier- def test_mode_partial_only_upgrades_included_plugins(self):+ def test_mode_partial_only_upgrades_included_plugins(self) -> None:plugins = [_make_plugin("acme/foo", "1.0.0"),_make_plugin("acme/bar", "2.0.0"),@@ -238,7 +238,7 @@ class TestUpgradeMode:assert upgrade_mock.call_count == 1assert calls[0][1] == plugins[0].plugin_unique_identifier- def test_mode_exclude_skips_excluded_plugins(self):+ def test_mode_exclude_skips_excluded_plugins(self) -> None:plugins = [_make_plugin("acme/foo", "1.0.0"),_make_plugin("acme/bar", "2.0.0"),@@ -258,7 +258,7 @@ class TestUpgradeMode:assert upgrade_mock.call_count == 1assert calls[0][1] == plugins[0].plugin_unique_identifier- def test_category_strategy_only_upgrades_matching_category(self):+ def test_category_strategy_only_upgrades_matching_category(self) -> None:plugins = [_make_plugin("acme/model-provider", "1.0.0", category=PluginCategory.Model),_make_plugin("acme/tool-provider", "1.0.0", category=PluginCategory.Tool),@@ -280,7 +280,7 @@ class TestUpgradeMode:class TestErrorIsolation:- def test_one_plugin_failure_does_not_block_others(self):+ def test_one_plugin_failure_does_not_block_others(self) -> None:plugins = [_make_plugin("acme/foo", "1.0.0"),_make_plugin("acme/bar", "2.0.0"),@@ -294,7 +294,7 @@ class TestErrorIsolation:seen: list[str] = []- def _upgrade(tenant_id, original, new):+ def _upgrade(tenant_id: str, original: str, new: str) -> None:seen.append(original)if "foo" in original:raise RuntimeError("boom")@@ -321,7 +321,7 @@ class TestErrorIsolation:assert any("bar" in s for s in seen)-def _make_declaration(plugin_id: str, latest_version: str):+def _make_declaration(plugin_id: str, latest_version: str) -> SimpleNamespace:"""Minimal stand-in for a MarketplacePluginDeclaration returned by the batch API."""org, name = plugin_id.split("/", 1)return SimpleNamespace(@@ -339,7 +339,14 @@ class TestManifestCacheFallback:the check must fall back to the batch API instead of silently skipping the upgrade."""- def _fetch(self, plugin_ids, *, cached, declarations=None, batch_error=None):+ def _fetch(+ self,+ plugin_ids: list[str],+ *,+ cached: dict[str, str],+ declarations: list[SimpleNamespace] | None = None,+ batch_error: Exception | None = None,+ ) -> tuple[list[MarketplacePluginSnapshot], MagicMock, MagicMock]:from tasks.process_tenant_plugin_autoupgrade_check_task import (marketplace_batch_fetch_plugin_manifests,)@@ -361,7 +368,7 @@ class TestManifestCacheFallback:return result, batch_mock, redis_mock- def test_cache_hits_do_not_touch_the_marketplace(self):+ def test_cache_hits_do_not_touch_the_marketplace(self) -> None:"""The whole point of the snapshot: a warm cache must not generate any request."""key = "plugin_autoupgrade_check_task:cached_plugin_snapshot:langgenius/foo"cached = {key: _make_manifest("langgenius/foo", "1.1.0").model_dump_json()}@@ -371,7 +378,7 @@ class TestManifestCacheFallback:assert [r.latest_version for r in result] == ["1.1.0"]batch_mock.assert_not_called()- def test_empty_snapshot_falls_back_to_batch_api(self):+ def test_empty_snapshot_falls_back_to_batch_api(self) -> None:"""Regression: an empty global snapshot used to skip every plugin silently."""result, batch_mock, _ = self._fetch(["langgenius/foo"],@@ -383,7 +390,7 @@ class TestManifestCacheFallback:assert [r.plugin_id for r in result] == ["langgenius/foo"]assert [r.latest_version for r in result] == ["1.2.0"]- def test_fallback_results_are_cached(self):+ def test_fallback_results_are_cached(self) -> None:_, _, redis_mock = self._fetch(["langgenius/foo"],cached={},@@ -393,7 +400,7 @@ class TestManifestCacheFallback:cached_keys = [call.args[0] for call in redis_mock.setex.call_args_list]assert "plugin_autoupgrade_check_task:cached_plugin_snapshot:langgenius/foo" in cached_keys- def test_plugins_unknown_to_the_marketplace_are_negatively_cached(self):+ def test_plugins_unknown_to_the_marketplace_are_negatively_cached(self) -> None:"""Avoid re-asking about a plugin the marketplace does not serve on every cycle."""_, _, redis_mock = self._fetch(["langgenius/ghost"], cached={}, declarations=[])@@ -402,7 +409,7 @@ class TestManifestCacheFallback:assert key == "plugin_autoupgrade_check_task:cached_plugin_snapshot:langgenius/ghost"assert value == "null"- def test_negatively_cached_plugins_are_not_refetched(self):+ def test_negatively_cached_plugins_are_not_refetched(self) -> None:key = "plugin_autoupgrade_check_task:cached_plugin_snapshot:langgenius/ghost"result, batch_mock, _ = self._fetch(["langgenius/ghost"], cached={key: "null"})@@ -410,7 +417,7 @@ class TestManifestCacheFallback:assert result == []batch_mock.assert_not_called()- def test_marketplace_failure_keeps_cached_results(self):+ def test_marketplace_failure_keeps_cached_results(self) -> None:"""A failing batch call must not lose the plugins the snapshot did cover."""key = "plugin_autoupgrade_check_task:cached_plugin_snapshot:langgenius/foo"cached = {key: _make_manifest("langgenius/foo", "1.1.0").model_dump_json()}diff --git a/api/tests/unit_tests/tasks/test_remove_app_and_related_data_task.py b/api/tests/unit_tests/tasks/test_remove_app_and_related_data_task.pyindex eabaab82567..ed473d616c1 100644--- a/api/tests/unit_tests/tasks/test_remove_app_and_related_data_task.py+++ b/api/tests/unit_tests/tasks/test_remove_app_and_related_data_task.py@@ -264,7 +264,7 @@ def test_parent_retries_before_local_cleanup_when_binding_schedule_fails(class TestDeleteDraftVariablesBatch:- def test_delete_draft_variables_batch_invalid_batch_size(self):+ def test_delete_draft_variables_batch_invalid_batch_size(self) -> None:"""Test that invalid batch size raises ValueError."""app_id = "test-app-id"@@ -275,7 +275,7 @@ class TestDeleteDraftVariablesBatch:delete_draft_variables_batch(app_id, 0)@patch("tasks.remove_app_and_related_data_task.delete_draft_variables_batch")- def test_delete_draft_variables_calls_batch_function(self, mock_batch_delete):+ def test_delete_draft_variables_calls_batch_function(self, mock_batch_delete: MagicMock) -> None:"""Test that _delete_draft_variables calls the batch function correctly."""app_id = "test-app-id"expected_return = 42@@ -347,7 +347,7 @@ class _FakeSessionFactory:class TestDeleteDraftVariableOffloadData:"""Test the Offload data cleanup functionality."""- def test_delete_draft_variable_offload_data_empty_file_ids(self):+ def test_delete_draft_variable_offload_data_empty_file_ids(self) -> None:"""An empty file_ids list must not open a session or touch object storage."""with (patch("tasks.remove_app_and_related_data_task.session_factory") as mock_session_factory,@@ -359,7 +359,7 @@ class TestDeleteDraftVariableOffloadData:mock_session_factory.create_session.assert_not_called()mock_storage.delete.assert_not_called()- def test_delete_draft_variable_offload_data_database_failure(self, caplog: pytest.LogCaptureFixture):+ def test_delete_draft_variable_offload_data_database_failure(self, caplog: pytest.LogCaptureFixture) -> None:"""Test handling of database operation failures."""mock_session_factory = MagicMock()mock_session_factory.create_session.return_value.__enter__.return_value.execute.side_effect = Exception(@@ -373,7 +373,7 @@ class TestDeleteDraftVariableOffloadData:assert result == 0assert "Error deleting draft variable offload data:" in caplog.text- def test_storage_delete_runs_with_no_open_transaction(self, monkeypatch: pytest.MonkeyPatch):+ def test_storage_delete_runs_with_no_open_transaction(self, monkeypatch: pytest.MonkeyPatch) -> None:"""Object storage cleanup must not run while a database transaction is open."""factory = _FakeSessionFactory([_FakeResult([("vf-1", "key-1", "uf-1"), ("vf-2", "key-2", "uf-2")])])mock_storage = MagicMock()@@ -391,7 +391,7 @@ class TestDeleteDraftVariableOffloadData:def test_storage_failure_is_logged_and_not_counted(self, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture- ):+ ) -> None:"""A failing object is logged and not counted, and the DB cleanup still runs."""factory = _FakeSessionFactory([_FakeResult([("vf-1", "key-1", "uf-1"), ("vf-2", "key-2", "uf-2")])])mock_storage = MagicMock()@@ -407,7 +407,7 @@ class TestDeleteDraftVariableOffloadData:assert "Failed to delete storage object key-1" in caplog.textassert factory.open_count == 0- def test_file_ids_with_no_matching_rows_delete_nothing(self, monkeypatch: pytest.MonkeyPatch):+ def test_file_ids_with_no_matching_rows_delete_nothing(self, monkeypatch: pytest.MonkeyPatch) -> None:"""file_ids that no longer resolve to rows must not raise or touch storage."""factory = _FakeSessionFactory([_FakeResult([])])mock_storage = MagicMock()@@ -425,7 +425,7 @@ class TestDeleteDraftVariableOffloadData:class TestDeleteDraftVariablesBatchTransactionScope:"""The batch loop must not hold a transaction while object storage is cleaned up."""- def test_offload_cleanup_is_called_with_no_session_open(self, monkeypatch: pytest.MonkeyPatch):+ def test_offload_cleanup_is_called_with_no_session_open(self, monkeypatch: pytest.MonkeyPatch) -> None:factory = _FakeSessionFactory([_FakeResult([("var-1", "vf-1")]), _FakeResult([], rowcount=1)])observed_open_counts: list[int] = []@@ -442,7 +442,7 @@ class TestDeleteDraftVariablesBatchTransactionScope:assert observed_open_counts == [0]assert factory.open_count == 0- def test_rows_without_offloaded_files_skip_cleanup(self, monkeypatch: pytest.MonkeyPatch):+ def test_rows_without_offloaded_files_skip_cleanup(self, monkeypatch: pytest.MonkeyPatch) -> None:"""A batch whose rows carry no file_id must not invoke the offload cleanup."""factory = _FakeSessionFactory([_FakeResult([("var-1", None)]), _FakeResult([], rowcount=1)])cleanup = MagicMock(return_value=0)@@ -462,8 +462,8 @@ class TestDeleteWorkflowArchiveLogs:@patch("tasks.remove_app_and_related_data_task._delete_records")@patch("tasks.remove_app_and_related_data_task.db")def test_delete_app_workflow_archive_logs_calls_delete_records(- self, mock_db, mock_delete_records, sqlite_session: Session- ):+ self, mock_db: MagicMock, mock_delete_records: MagicMock, sqlite_session: Session+ ) -> None:tenant_id = "tenant-1"app_id = "app-1"@@ -510,7 +510,9 @@ class TestDeleteWorkflowArchiveLogs:class TestDeleteAppStars:@pytest.mark.parametrize("sqlite_session", [(AppStar,)], indirect=True)@patch("tasks.remove_app_and_related_data_task._delete_records")- def test_delete_app_stars_calls_delete_records(self, mock_delete_records, sqlite_session: Session):+ def test_delete_app_stars_calls_delete_records(+ self, mock_delete_records: MagicMock, sqlite_session: Session+ ) -> None:tenant_id = "tenant-1"app_id = "app-1"@@ -536,8 +538,8 @@ class TestDeleteAppStars:class TestDeleteArchivedWorkflowRunFiles:@patch("tasks.remove_app_and_related_data_task.get_archive_storage")def test_delete_archived_workflow_run_files_not_configured(- self, mock_get_storage, caplog: pytest.LogCaptureFixture- ):+ self, mock_get_storage: MagicMock, caplog: pytest.LogCaptureFixture+ ) -> None:mock_get_storage.side_effect = ArchiveStorageNotConfiguredError("missing config")with caplog.at_level(logging.INFO, logger="tasks.remove_app_and_related_data_task"):@@ -546,7 +548,9 @@ class TestDeleteArchivedWorkflowRunFiles:assert caplog.text.count("Archive storage not configured") == 1@patch("tasks.remove_app_and_related_data_task.get_archive_storage")- def test_delete_archived_workflow_run_files_list_failure(self, mock_get_storage, caplog: pytest.LogCaptureFixture):+ def test_delete_archived_workflow_run_files_list_failure(+ self, mock_get_storage: MagicMock, caplog: pytest.LogCaptureFixture+ ) -> None:storage = MagicMock()storage.list_objects.side_effect = Exception("list failed")mock_get_storage.return_value = storage@@ -559,7 +563,9 @@ class TestDeleteArchivedWorkflowRunFiles:assert "Failed to list archive files for app app-1" in caplog.text@patch("tasks.remove_app_and_related_data_task.get_archive_storage")- def test_delete_archived_workflow_run_files_success(self, mock_get_storage, caplog: pytest.LogCaptureFixture):+ def test_delete_archived_workflow_run_files_success(+ self, mock_get_storage: MagicMock, caplog: pytest.LogCaptureFixture+ ) -> None:storage = MagicMock()storage.list_objects.return_value = ["key-1", "key-2"]mock_get_storage.return_value = storage