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
test(api): strictly type four controller unit tests (#45332)
Felix Shia8631e5bfe0e
diff --git a/api/tests/unit_tests/controllers/console/app/test_annotation.py b/api/tests/unit_tests/controllers/console/app/test_annotation.pyindex c5fabba4677..4ca97d8cd23 100644--- a/api/tests/unit_tests/controllers/console/app/test_annotation.py+++ b/api/tests/unit_tests/controllers/console/app/test_annotation.py@@ -3,7 +3,7 @@ from controllers.console.app import annotation as annotation_modulefrom tasks.annotation.batch_import_annotations_task import batch_import_annotations_task-def test_annotation_reply_payload_valid():+def test_annotation_reply_payload_valid() -> None:"""Test AnnotationReplyPayload with valid data."""payload = annotation_module.AnnotationReplyPayload(score_threshold=0.5,@@ -15,7 +15,7 @@ def test_annotation_reply_payload_valid():assert payload.embedding_model_name == "text-embedding-3-small"-def test_annotation_setting_update_payload_valid():+def test_annotation_setting_update_payload_valid() -> None:"""Test AnnotationSettingUpdatePayload with valid data."""payload = annotation_module.AnnotationSettingUpdatePayload(score_threshold=0.75,@@ -23,7 +23,7 @@ def test_annotation_setting_update_payload_valid():assert payload.score_threshold == 0.75-def test_annotation_list_query_defaults():+def test_annotation_list_query_defaults() -> None:"""Test AnnotationListQuery with default parameters."""query = annotation_module.AnnotationListQuery()assert query.page == 1@@ -31,20 +31,20 @@ def test_annotation_list_query_defaults():assert query.keyword == ""-def test_annotation_list_query_custom_page():+def test_annotation_list_query_custom_page() -> None:"""Test AnnotationListQuery with custom page."""query = annotation_module.AnnotationListQuery(page=3, limit=50)assert query.page == 3assert query.limit == 50-def test_annotation_list_query_with_keyword():+def test_annotation_list_query_with_keyword() -> None:"""Test AnnotationListQuery with keyword."""query = annotation_module.AnnotationListQuery(keyword="test")assert query.keyword == "test"-def test_create_annotation_payload_with_message_id():+def test_create_annotation_payload_with_message_id() -> None:"""Test CreateAnnotationPayload with message ID."""payload = annotation_module.CreateAnnotationPayload(message_id="550e8400-e29b-41d4-a716-446655440000",@@ -54,7 +54,7 @@ def test_create_annotation_payload_with_message_id():assert payload.question == "What is AI?"-def test_create_annotation_payload_with_text():+def test_create_annotation_payload_with_text() -> None:"""Test CreateAnnotationPayload with text content."""payload = annotation_module.CreateAnnotationPayload(question="What is ML?",@@ -64,7 +64,7 @@ def test_create_annotation_payload_with_text():assert payload.answer == "Machine learning is..."-def test_update_annotation_payload():+def test_update_annotation_payload() -> None:"""Test UpdateAnnotationPayload."""payload = annotation_module.UpdateAnnotationPayload(question="Updated question",@@ -74,19 +74,19 @@ def test_update_annotation_payload():assert payload.answer == "Updated answer"-def test_annotation_reply_status_query_enable():+def test_annotation_reply_status_query_enable() -> None:"""Test AnnotationReplyStatusQuery with enable action."""query = annotation_module.AnnotationReplyStatusQuery(action="enable")assert query.action == "enable"-def test_annotation_reply_status_query_disable():+def test_annotation_reply_status_query_disable() -> None:"""Test AnnotationReplyStatusQuery with disable action."""query = annotation_module.AnnotationReplyStatusQuery(action="disable")assert query.action == "disable"-def test_annotation_file_payload_valid():+def test_annotation_file_payload_valid() -> None:"""Test AnnotationFilePayload with valid message ID."""payload = annotation_module.AnnotationFilePayload(message_id="550e8400-e29b-41d4-a716-446655440000")assert payload.message_id == "550e8400-e29b-41d4-a716-446655440000"@@ -95,15 +95,16 @@ def test_annotation_file_payload_valid():class TestAnnotationImportTaskOptimization:"""Test optimizations in batch import task."""- def test_task_is_registered_with_queue(self):+ def test_task_is_registered_with_queue(self) -> None:"""Test that task is registered with the correct queue."""- assert batch_import_annotations_task.queue == "dataset"+ # Celery sets `queue` on the registered task at runtime; the Task type does not declare it.+ assert batch_import_annotations_task.queue == "dataset" # pyrefly: ignore[missing-attribute]class TestConfigurationValues:"""Test that security configuration values are properly set."""- def test_rate_limit_configs_exist(self):+ def test_rate_limit_configs_exist(self) -> None:"""Test that rate limit configurations are defined."""assert hasattr(dify_config, "ANNOTATION_IMPORT_RATE_LIMIT_PER_MINUTE")assert hasattr(dify_config, "ANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR")@@ -111,13 +112,13 @@ class TestConfigurationValues:assert dify_config.ANNOTATION_IMPORT_RATE_LIMIT_PER_MINUTE > 0assert dify_config.ANNOTATION_IMPORT_RATE_LIMIT_PER_HOUR > 0- def test_file_size_limit_config_exists(self):+ def test_file_size_limit_config_exists(self) -> None:"""Test that file size limit configuration is defined."""assert hasattr(dify_config, "ANNOTATION_IMPORT_FILE_SIZE_LIMIT")assert dify_config.ANNOTATION_IMPORT_FILE_SIZE_LIMIT > 0assert dify_config.ANNOTATION_IMPORT_FILE_SIZE_LIMIT <= 10 # Reasonable max (10MB)- def test_record_limit_configs_exist(self):+ def test_record_limit_configs_exist(self) -> None:"""Test that record limit configurations are defined."""assert hasattr(dify_config, "ANNOTATION_IMPORT_MAX_RECORDS")assert hasattr(dify_config, "ANNOTATION_IMPORT_MIN_RECORDS")@@ -126,7 +127,7 @@ class TestConfigurationValues:assert dify_config.ANNOTATION_IMPORT_MIN_RECORDS > 0assert dify_config.ANNOTATION_IMPORT_MIN_RECORDS < dify_config.ANNOTATION_IMPORT_MAX_RECORDS- def test_concurrency_limit_config_exists(self):+ def test_concurrency_limit_config_exists(self) -> None:"""Test that concurrency limit configuration is defined."""assert hasattr(dify_config, "ANNOTATION_IMPORT_MAX_CONCURRENT")assert dify_config.ANNOTATION_IMPORT_MAX_CONCURRENT > 0diff --git a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_content_preview.py b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_content_preview.pyindex 74f3ee45dce..958bd7dc91d 100644--- a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_content_preview.py+++ b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_content_preview.py@@ -20,14 +20,14 @@ def make_account() -> Account:class TestDataSourceContentPreviewApi:- def _valid_payload(self):+ def _valid_payload(self) -> dict[str, object]:return {"inputs": {"query": "hello"},"datasource_type": "notion","credential_id": "cred-1",}- def test_post_success(self, app: Flask):+ def test_post_success(self, app: Flask) -> None:api = DataSourceContentPreviewApi()method = unwrap(api.post)@@ -66,7 +66,7 @@ class TestDataSourceContentPreviewApi:assert status == 200assert response == preview_result- def test_post_invalid_payload(self, app: Flask):+ def test_post_invalid_payload(self, app: Flask) -> None:api = DataSourceContentPreviewApi()method = unwrap(api.post)@@ -85,7 +85,7 @@ class TestDataSourceContentPreviewApi:with pytest.raises(ValueError, match=r"datasource_type\n\s+Field required"):method(api, DatasourceContentPreviewPayload.model_validate(payload), account, pipeline, "node-1")- def test_post_without_credential_id(self, app: Flask):+ def test_post_without_credential_id(self, app: Flask) -> None:api = DataSourceContentPreviewApi()method = unwrap(api.post)diff --git a/api/tests/unit_tests/controllers/service_api/test_index.py b/api/tests/unit_tests/controllers/service_api/test_index.pyindex f43f3e3babb..86e3ce9b0c5 100644--- a/api/tests/unit_tests/controllers/service_api/test_index.py+++ b/api/tests/unit_tests/controllers/service_api/test_index.py@@ -22,7 +22,7 @@ def _get_index_response(app: Flask, version: str) -> dict[str, str]:class TestIndexApi:"""Test suite for IndexApi resource."""- def test_get_returns_api_info(self, app: Flask):+ def test_get_returns_api_info(self, app: Flask) -> None:"""Test that GET returns API metadata with correct structure."""# Actresponse = _get_index_response(app, "1.0.0-test")@@ -32,7 +32,7 @@ class TestIndexApi:assert response["api_version"] == "v1"assert response["server_version"] == "1.0.0-test"- def test_get_response_has_required_fields(self, app: Flask):+ def test_get_response_has_required_fields(self, app: Flask) -> None:"""Test that response contains all required fields."""# Actresponse = _get_index_response(app, "1.11.4")@@ -46,7 +46,7 @@ class TestIndexApi:assert isinstance(response["server_version"], str)@pytest.mark.parametrize("version", ["0.0.1", "1.0.0", "2.0.0-beta", "1.11.4"])- def test_get_returns_correct_version(self, app: Flask, version):+ def test_get_returns_correct_version(self, app: Flask, version: str) -> None:"""Test that server_version matches config version."""# Actresponse = _get_index_response(app, version)@@ -54,7 +54,7 @@ class TestIndexApi:# Assertassert response["server_version"] == version- def test_root_route_returns_public_api_info(self):+ def test_root_route_returns_public_api_info(self) -> None:"""Exercise the registered blueprint so Flask-RESTX cannot shadow the resource."""app = Flask(__name__)app.config["TESTING"] = True@@ -72,7 +72,7 @@ class TestIndexApi:root_rules = [rule for rule in app.url_map.iter_rules() if rule.rule == "/v1/"]assert [rule.endpoint for rule in root_rules] == ["service_api.root"]- def test_datasource_credentials_route_is_not_registered(self):+ def test_datasource_credentials_route_is_not_registered(self) -> None:app = Flask(__name__)app.config["TESTING"] = Trueapp.register_blueprint(service_api_bp)diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.tomlindex adf9c351a8a..730683f27ab 100644--- a/api/tests/unit_tests/pyrefly.toml+++ b/api/tests/unit_tests/pyrefly.toml@@ -15,11 +15,9 @@ project-excludes = ["controllers/common/test_errors.py","controllers/common/test_file_response.py","controllers/console/app/test_agent_config_inspector.py",- "controllers/console/app/test_annotation.py","controllers/console/app/test_app.py","controllers/console/app/test_app_import.py","controllers/console/app/test_audio.py",- "controllers/console/app/test_conversation.py","libs/test_validators.py","controllers/console/app/test_generator.py","controllers/console/app/test_mcp_server.py",@@ -33,7 +31,6 @@ project-excludes = ["controllers/console/auth/test_activate.py","controllers/console/auth/test_email_register.py","controllers/console/datasets/rag_pipeline/test_datasource_auth.py",- "controllers/console/datasets/rag_pipeline/test_datasource_content_preview.py","controllers/console/datasets/rag_pipeline/test_rag_pipeline.py","controllers/console/datasets/rag_pipeline/test_rag_pipeline_draft_variable.py","controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.py",@@ -77,7 +74,6 @@ project-excludes = ["controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py","controllers/service_api/dataset/test_segment.py","controllers/service_api/dataset/test_document.py",- "controllers/service_api/test_index.py","controllers/service_api/test_wraps.py","controllers/service_api/test___init__.py","controllers/trigger/test_trigger.py",