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(api): clear remaining ruff debt in strict unit tests (#44049)
Eddy ZHANGc7bf876988f0
diff --git a/api/tests/unit_tests/.ruff.toml b/api/tests/unit_tests/.ruff.tomlindex da7ddcb1ae3..80c77dd8ecd 100644--- a/api/tests/unit_tests/.ruff.toml+++ b/api/tests/unit_tests/.ruff.toml@@ -8,7 +8,6 @@ extend-select = ["ANN401", "ARG"][lint.per-file-ignores]"clients/agent_backend/test_request_builder.py" = ["TID251"]"commands/test_archive_workflow_runs.py" = ["ARG005"]-"commands/test_data_migration_wizard.py" = ["ARG005"]"commands/test_legacy_model_type_migration.py" = ["ARG001", "ARG002", "ARG005"]"repositories/test_app_definition_query_repository_agent.py" = ["ARG005", "TID251"]"controllers/common/test_app_access.py" = ["ARG005"]@@ -39,7 +38,6 @@ extend-select = ["ANN401", "ARG"]"controllers/console/datasets/test_datasets_document_download.py" = ["ARG005"]"controllers/console/datasets/test_datasets_segments.py" = ["TID251"]"controllers/console/datasets/test_external.py" = ["TID251"]-"controllers/console/datasets/test_wraps.py" = ["ARG001"]"controllers/console/explore/test_trial.py" = ["ANN401", "ARG001", "ARG005", "TID251"]"controllers/console/explore/test_wraps.py" = ["ARG001"]"controllers/console/snippets/test_snippet_workflow.py" = ["ARG001"]@@ -47,11 +45,9 @@ extend-select = ["ANN401", "ARG"]"controllers/console/test_files.py" = ["ARG001", "ARG002"]"controllers/console/test_human_input_form.py" = ["ARG001", "ARG005"]"controllers/console/test_wraps.py" = ["ARG001", "ARG002"]-"controllers/console/workspace/test_load_balancing_config.py" = ["ARG001"]"controllers/console/workspace/test_plugin.py" = ["ARG002", "TID251"]"controllers/console/workspace/test_snippets.py" = ["ARG002"]"controllers/console/workspace/test_tool_providers.py" = ["ARG001", "ARG005"]-"controllers/console/workspace/test_trigger_providers.py" = ["ARG001"]"controllers/inner_api/plugin/test_plugin.py" = ["ARG002"]"controllers/inner_api/plugin/test_plugin_wraps.py" = ["ARG001", "ARG002", "ARG003", "TID251"]"controllers/inner_api/test_runtime_credentials.py" = ["ARG001"]@@ -249,11 +245,8 @@ extend-select = ["ANN401", "ARG"]"extensions/otel/decorators/handlers/test_generate_handler.py" = ["ARG001", "ARG002"]"extensions/otel/decorators/handlers/test_workflow_app_runner_handler.py" = ["ARG001"]"extensions/otel/test_retrieval_tracing.py" = ["ARG001"]-"extensions/test_ext_request_logging.py" = ["ARG002"]-"extensions/test_redis.py" = ["ARG001"]"factories/test_build_from_mapping.py" = ["ARG001"]"factories/test_file_factory.py" = ["ARG001"]-"factories/test_variable_factory.py" = ["TID251"]"fields/test_file_fields.py" = ["ARG005"]"libs/_human_input/support.py" = ["TID251"]"libs/broadcast_channel/redis/test_channel_unit_tests.py" = ["ARG002", "ARG005"]@@ -261,12 +254,10 @@ extend-select = ["ANN401", "ARG"]"libs/test_cron_compatibility.py" = ["S110"]"libs/test_email_i18n.py" = ["ANN401", "TID251"]"libs/test_oauth_bearer_rate_limit_ordering.py" = ["ARG001"]-"libs/test_pyrefly_type_coverage.py" = ["TID251"]"libs/test_schedule_utils_enhanced.py" = ["S110"]"libs/test_sendgrid_client.py" = ["ARG001", "TID251"]"libs/test_smtp_client.py" = ["TID251"]"models/test_dataset_models.py" = ["ARG005"]-"models/test_plugin_entities.py" = ["TID251"]"oss/__mock/aliyun_oss.py" = ["ARG002"]"oss/__mock/baidu_obs.py" = ["ARG002"]"oss/__mock/base.py" = ["ARG002"]@@ -332,7 +323,6 @@ extend-select = ["ANN401", "ARG"]"tasks/test_clean_document_task.py" = ["ARG002"]"tasks/test_dataset_indexing_task.py" = ["ARG001", "ARG002"]"tasks/test_document_indexing_sync_task.py" = ["ARG002"]-"tasks/test_duplicate_document_indexing_task.py" = ["ARG002"]"tasks/test_human_input_timeout_tasks.py" = ["ARG001", "ARG002", "ARG005", "TID251"]"tasks/test_initialize_created_app_rbac_access_task.py" = ["ARG005"]"tasks/test_mail_send_task.py" = ["ARG002"]diff --git a/api/tests/unit_tests/commands/test_data_migration_wizard.py b/api/tests/unit_tests/commands/test_data_migration_wizard.pyindex 8a342072db2..8d524cb914d 100644--- a/api/tests/unit_tests/commands/test_data_migration_wizard.py+++ b/api/tests/unit_tests/commands/test_data_migration_wizard.py@@ -71,7 +71,7 @@ def test_prompt_tool_category_marks_auto_discovered_tools(monkeypatch: pytest.Mooutput_lines: list[str] = []monkeypatch.setattr("commands.data_migration.click.echo", output_lines.append)- monkeypatch.setattr("commands.data_migration.click.prompt", lambda *args, **kwargs: "")+ monkeypatch.setattr("commands.data_migration.click.prompt", lambda *_args, **_kwargs: "")selected = _prompt_tool_category("Custom API tools",@@ -126,7 +126,7 @@ def test_prompt_output_file_shows_default(monkeypatch: pytest.MonkeyPatch) -> Nodef test_prompt_tool_category_marks_auto_by_detail_and_supports_multi_select(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setattr("commands.data_migration.click.echo", lambda *_args, **_kwargs: None)- monkeypatch.setattr("commands.data_migration.click.prompt", lambda *args, **kwargs: "1,2")+ monkeypatch.setattr("commands.data_migration.click.prompt", lambda *_args, **_kwargs: "1,2")selected = _prompt_tool_category("Workflow tools",@@ -145,7 +145,7 @@ def test_prompt_tool_category_marks_auto_by_value() -> None:original_echo = data_migration.click.echooriginal_prompt = data_migration.click.promptdata_migration.click.echo = output_lines.append # pyrefly: ignore[bad-assignment]- data_migration.click.prompt = lambda *args, **kwargs: ""+ data_migration.click.prompt = lambda *_args, **_kwargs: ""try:_prompt_tool_category("Workflow tools",@@ -263,7 +263,7 @@ def test_prompt_output_file_rejects_yes_no_typo(monkeypatch: pytest.MonkeyPatch)import clickimport pytest- monkeypatch.setattr("commands.data_migration.click.prompt", lambda *args, **kwargs: "y")+ monkeypatch.setattr("commands.data_migration.click.prompt", lambda *_args, **_kwargs: "y")with pytest.raises(click.ClickException, match="Output path must be a file path"):_prompt_output_file()@@ -302,7 +302,7 @@ def test_confirm_wizard_summary_shows_final_deduplicated_tool_selection(monkeypaoutput_lines: list[str] = []monkeypatch.setattr("commands.data_migration.click.echo", output_lines.append)- monkeypatch.setattr("commands.data_migration.click.confirm", lambda *args, **kwargs: True)+ monkeypatch.setattr("commands.data_migration.click.confirm", lambda *_args, **_kwargs: True)_confirm_wizard_summary(tenant_name="admin's Workspace",diff --git a/api/tests/unit_tests/controllers/console/datasets/test_wraps.py b/api/tests/unit_tests/controllers/console/datasets/test_wraps.pyindex 503f6e3d559..2ebbc93114a 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_wraps.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_wraps.py@@ -32,7 +32,7 @@ def current_account() -> Account:class TestGetRagPipeline:def test_missing_pipeline_id(self) -> None:@get_rag_pipeline- def dummy_view(**kwargs: object) -> str:+ def dummy_view(**_kwargs: object) -> str:return "ok"with pytest.raises(ValueError, match="missing pipeline_id"):@@ -45,7 +45,7 @@ class TestGetRagPipeline:current_account: Account,) -> None:@get_rag_pipeline- def dummy_view(**kwargs: object) -> str:+ def dummy_view(**_kwargs: object) -> str:return "ok"mocker.patch(diff --git a/api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.py b/api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.pyindex 7c476f35d6c..b6c5f7651a2 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_load_balancing_config.py@@ -45,7 +45,7 @@ def load_balancing_module(monkeypatch: pytest.MonkeyPatch) -> ModuleType:monkeypatch.setattr(wraps, "setup_required", _noop)monkeypatch.setattr(wraps, "account_initialization_required", _noop)- def _noop_route[**P](*args: P.args, **kwargs: P.kwargs): # type: ignore[override]+ def _noop_route(*_args: object, **_kwargs: object): # type: ignore[override]def _decorator(cls: type) -> type:return clsdiff --git a/api/tests/unit_tests/controllers/console/workspace/test_trigger_providers.py b/api/tests/unit_tests/controllers/console/workspace/test_trigger_providers.pyindex 34de5c05f93..660b275ce03 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_trigger_providers.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_trigger_providers.py@@ -51,7 +51,8 @@ def test_delete_subscription_uses_sqlite_transaction(flask_sqlite_engine: Engineassert provider_session.get_bind() is flask_sqlite_engine-def test_delete_subscription_translates_value_error(flask_sqlite_engine: Engine) -> None:[email protected]("flask_sqlite_engine")+def test_delete_subscription_translates_value_error() -> None:api = TriggerSubscriptionDeleteApi()method = unwrap(api.post)diff --git a/api/tests/unit_tests/extensions/test_ext_request_logging.py b/api/tests/unit_tests/extensions/test_ext_request_logging.pyindex fc0752128a1..c7512fc6914 100644--- a/api/tests/unit_tests/extensions/test_ext_request_logging.py+++ b/api/tests/unit_tests/extensions/test_ext_request_logging.py@@ -95,9 +95,9 @@ class TestRequestLoggingExtension:mock_request_receiver.assert_not_called()mock_response_receiver.assert_not_called()+ @pytest.mark.usefixtures("enable_request_logging")def test_receiver_should_be_called_if_enabled(self,- enable_request_logging: None,mock_request_receiver: MagicMock,mock_response_receiver: MagicMock,) -> None:@@ -117,9 +117,7 @@ class TestRequestLoggingExtension:class TestLoggingLevel:@pytest.mark.usefixtures("enable_request_logging")- def test_logging_should_be_skipped_if_level_is_above_debug(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture- ) -> None:+ def test_logging_should_be_skipped_if_level_is_above_debug(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.INFO, logger=ext_request_logging.logger.name)app = _get_test_app()init_app(app)@@ -130,10 +128,8 @@ class TestLoggingLevel:class TestRequestReceiverLogging:- @pytest.mark.usefixtures("enable_request_logging")- def test_non_json_request(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_non_json_request(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()init_app(app)@@ -147,10 +143,8 @@ class TestRequestReceiverLogging:assert record.args == ("POST", "/")assert "Request Body" not in record.msg- @pytest.mark.usefixtures("enable_request_logging")- def test_json_request(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_json_request(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()init_app(app)@@ -167,10 +161,8 @@ class TestRequestReceiverLogging:assert args[1] == "/"assert _KEY_NEEDLE in args[2]- @pytest.mark.usefixtures("enable_request_logging")- def test_json_request_with_empty_body(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_json_request_with_empty_body(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()init_app(app)@@ -185,10 +177,8 @@ class TestRequestReceiverLogging:assert "Request Body" not in record.msgassert record.args == ("POST", "/")- @pytest.mark.usefixtures("enable_request_logging")- def test_json_request_with_invalid_json_as_body(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_json_request_with_invalid_json_as_body(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()init_app(app)@@ -207,7 +197,7 @@ class TestRequestReceiverLogging:class TestResponseReceiverLogging:@pytest.mark.usefixtures("enable_request_logging")- def test_non_json_response(self, enable_request_logging: None, caplog: pytest.LogCaptureFixture) -> None:+ def test_non_json_response(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()response = Response(@@ -224,10 +214,8 @@ class TestResponseReceiverLogging:assert args[1] == "text/plain"assert "Response Body" not in record.msg- @pytest.mark.usefixtures("enable_request_logging")- def test_json_response(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_json_response(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()response = Response(@@ -245,10 +233,8 @@ class TestResponseReceiverLogging:assert args[1] == "application/json"assert _KEY_NEEDLE in args[2]- @pytest.mark.usefixtures("enable_request_logging")- def test_json_request_with_invalid_json_as_body(- self, enable_request_logging: None, caplog: pytest.LogCaptureFixture, mock_response_receiver: mock.Mock- ) -> None:+ @pytest.mark.usefixtures("enable_request_logging", "mock_response_receiver")+ def test_json_request_with_invalid_json_as_body(self, caplog: pytest.LogCaptureFixture) -> None:caplog.set_level(logging.DEBUG, logger=ext_request_logging.logger.name)app = _get_test_app()@@ -278,7 +264,7 @@ class TestResponseUnmodified:assert response.status_code == 200@pytest.mark.usefixtures("enable_request_logging")- def test_when_request_logging_enabled(self, enable_request_logging: None) -> None:+ def test_when_request_logging_enabled(self) -> None:app = _get_test_app()init_app(app)diff --git a/api/tests/unit_tests/extensions/test_redis.py b/api/tests/unit_tests/extensions/test_redis.pyindex 3ea0de346d9..bf2858f72ce 100644--- a/api/tests/unit_tests/extensions/test_redis.py+++ b/api/tests/unit_tests/extensions/test_redis.py@@ -157,18 +157,26 @@ class TestRedisFallback:assert test_func() is Nonedef test_redis_fallback_with_args(self) -> None:+ received: list[tuple[int, int]] = []+@redis_fallback(default_return=0)def test_func(x: int, y: int) -> None:+ received.append((x, y))raise RedisError("Redis error")assert test_func(1, 2) == 0+ assert received == [(1, 2)]def test_redis_fallback_with_kwargs(self) -> None:+ received: list[tuple[int | None, int | None]] = []+@redis_fallback(default_return=dict[str, object]())def test_func(x: int | None = None, y: int | None = None) -> None:+ received.append((x, y))raise RedisError("Redis error")assert test_func(x=1, y=2) == {}+ assert received == [(1, 2)]def test_redis_fallback_preserves_function_metadata(self) -> None:@redis_fallback(default_return=None)diff --git a/api/tests/unit_tests/factories/test_variable_factory.py b/api/tests/unit_tests/factories/test_variable_factory.pyindex 5214b0febe2..00847bb058f 100644--- a/api/tests/unit_tests/factories/test_variable_factory.py+++ b/api/tests/unit_tests/factories/test_variable_factory.py@@ -1,7 +1,6 @@import mathfrom collections.abc import Iteratorfrom dataclasses import dataclass-from typing import Anyfrom uuid import uuid4import pytest@@ -197,7 +196,7 @@ def test_array_number_variable() -> None:def test_build_segment_scalar_values() -> None:@dataclassclass TestCase:- value: Any+ value: objectexpected: Segmentdescription: str@@ -821,7 +820,7 @@ class TestBuildSegmentValueErrors:name: strdescription: str- test_value: Any+ test_value: objectdef _get_test_cases(self) -> list[ValueErrorTestCase]:"""Get all test cases for ValueError scenarios."""diff --git a/api/tests/unit_tests/libs/test_pyrefly_type_coverage.py b/api/tests/unit_tests/libs/test_pyrefly_type_coverage.pyindex cad9d47bba6..da8b2833ab3 100644--- a/api/tests/unit_tests/libs/test_pyrefly_type_coverage.py+++ b/api/tests/unit_tests/libs/test_pyrefly_type_coverage.py@@ -1,5 +1,4 @@import json-from typing import Anyfrom libs.pyrefly_type_coverage import (CoverageSummary,@@ -9,11 +8,11 @@ from libs.pyrefly_type_coverage import ()-def _make_report(summary: dict[str, Any]) -> str:+def _make_report(summary: dict[str, object]) -> str:return json.dumps({"module_reports": [], "summary": summary})-_SAMPLE_SUMMARY: dict[str, Any] = {+_SAMPLE_SUMMARY: dict[str, object] = {"n_modules": 100,"n_typable": 1000,"n_typed": 400,diff --git a/api/tests/unit_tests/models/test_plugin_entities.py b/api/tests/unit_tests/models/test_plugin_entities.pyindex 453425e128b..ace30618f0b 100644--- a/api/tests/unit_tests/models/test_plugin_entities.py+++ b/api/tests/unit_tests/models/test_plugin_entities.py@@ -1,6 +1,5 @@import binasciifrom collections.abc import Mapping-from typing import Anyfrom core.plugin.entities.request import TriggerDispatchResponse@@ -8,14 +7,14 @@ from core.plugin.entities.request import TriggerDispatchResponsedef test_trigger_dispatch_response() -> None:raw_http_response = b'HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n{"message": "Hello, world!"}'- data: Mapping[str, Any] = {+ data: Mapping[str, object] = {"user_id": "123","events": ["event1", "event2"],"response": binascii.hexlify(raw_http_response).decode(),"payload": {"key": "value"},}- response = TriggerDispatchResponse(**data)+ response = TriggerDispatchResponse.model_validate(data)assert response.response.status_code == 200assert response.response.headers["Content-Type"] == "application/json"diff --git a/api/tests/unit_tests/tasks/test_duplicate_document_indexing_task.py b/api/tests/unit_tests/tasks/test_duplicate_document_indexing_task.pyindex 87106c6dd79..bb1481e942a 100644--- a/api/tests/unit_tests/tasks/test_duplicate_document_indexing_task.py+++ b/api/tests/unit_tests/tasks/test_duplicate_document_indexing_task.py@@ -2,11 +2,12 @@import jsonimport uuid-from unittest.mock import MagicMock, Mock, patch+from unittest.mock import MagicMock, Mock, create_autospec, patchimport pytestfrom tasks.duplicate_document_indexing_task import (+ _duplicate_document_indexing_task,_duplicate_document_indexing_task_with_tenant_queue,duplicate_document_indexing_task,normal_duplicate_document_indexing_task,@@ -62,10 +63,10 @@ class TestDuplicateDocumentIndexingTaskWithTenantQueue:"""Tests for _duplicate_document_indexing_task_with_tenant_queue function."""@patch("tasks.duplicate_document_indexing_task._duplicate_document_indexing_task", autospec=True)+ @pytest.mark.usefixtures("tenant_queue_commands")def test_tenant_queue_wrapper_calls_core_function(self,mock_core_func: MagicMock,- tenant_queue_commands: MagicMock,tenant_id: str,dataset_id: str,document_ids: list[str],@@ -80,10 +81,12 @@ class TestDuplicateDocumentIndexingTaskWithTenantQueue:# Assertmock_core_func.assert_called_once_with(dataset_id, document_ids)- @patch("tasks.duplicate_document_indexing_task._duplicate_document_indexing_task", autospec=True)+ @patch(+ "tasks.duplicate_document_indexing_task._duplicate_document_indexing_task",+ new=create_autospec(_duplicate_document_indexing_task),+ )def test_tenant_queue_wrapper_deletes_key_when_no_tasks(self,- mock_core_func: MagicMock,tenant_queue_commands: MagicMock,tenant_id: str,dataset_id: str,@@ -100,10 +103,12 @@ class TestDuplicateDocumentIndexingTaskWithTenantQueue:# Asserttenant_queue_commands.assert_any_call("DEL", f"tenant_duplicate_document_indexing_task:{tenant_id}")- @patch("tasks.duplicate_document_indexing_task._duplicate_document_indexing_task", autospec=True)+ @patch(+ "tasks.duplicate_document_indexing_task._duplicate_document_indexing_task",+ new=create_autospec(_duplicate_document_indexing_task),+ )def test_tenant_queue_wrapper_processes_next_tasks(self,- mock_core_func: MagicMock,tenant_queue_commands: MagicMock,tenant_id: str,dataset_id: str,