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): annotate three model and task test modules for strict pyrefly (#45627)
yetuge2ba1b2965bb1
diff --git a/api/tests/unit_tests/models/test_agent.py b/api/tests/unit_tests/models/test_agent.pyindex 6dff7dcb7bf..150ff5fbdda 100644--- a/api/tests/unit_tests/models/test_agent.py+++ b/api/tests/unit_tests/models/test_agent.py@@ -139,7 +139,7 @@ def test_agent_models_require_fields_and_generate_ids(model(**incomplete_values)-def test_agent_enums_match_prd_boundaries():+def test_agent_enums_match_prd_boundaries() -> None:assert AgentKind.DIFY_AGENT.value == "dify_agent"assert AgentIconType.EMOJI.value == "emoji"assert AgentScope.ROSTER.value == "roster"@@ -158,7 +158,7 @@ def test_agent_enums_match_prd_boundaries():assert WorkflowAgentBindingType.INLINE_AGENT.value == "inline_agent"-def test_agent_table_uses_db_unique_constraint_for_active_roster_names():+def test_agent_table_uses_db_unique_constraint_for_active_roster_names() -> None:agent_table = cast(sa.Table, Agent.__table__)unique_constraints = {str(constraint.name): tuple(column.name for column in constraint.columns)@@ -181,7 +181,7 @@ def test_agent_table_uses_db_unique_constraint_for_active_roster_names():def test_active_roster_agent_name_unique_constraint_allows_archived_and_workflow_only_duplicates(sqlite_engine: sa.Engine,-):+) -> None:engine = sqlite_engineagent_table = cast(sa.Table, Agent.__table__)insert_agent = agent_table.insert()@@ -235,7 +235,7 @@ def test_active_roster_agent_name_unique_constraint_allows_archived_and_workflow)-def test_current_snapshot_stores_agent_soul_snapshot_as_long_text_json():+def test_current_snapshot_stores_agent_soul_snapshot_as_long_text_json() -> None:config_snapshot = AgentSoulConfig.model_validate({"schema_version": 1,@@ -257,7 +257,7 @@ def test_current_snapshot_stores_agent_soul_snapshot_as_long_text_json():assert version.config_snapshot_dict["env"]["secret_refs"][0]["provider_credential_id"] == "cred-1"-def test_agent_config_draft_stores_editable_agent_soul_as_long_text_json():+def test_agent_config_draft_stores_editable_agent_soul_as_long_text_json() -> None:config_snapshot = AgentSoulConfig.model_validate({"prompt": {"system_prompt": "draft prompt"}})draft = AgentConfigDraft(tenant_id="tenant-1",@@ -274,7 +274,7 @@ def test_agent_config_draft_stores_editable_agent_soul_as_long_text_json():assert draft.config_snapshot_dict["prompt"]["system_prompt"] == "draft prompt"-def test_workflow_binding_stores_node_job_config_separately_from_agent_soul():+def test_workflow_binding_stores_node_job_config_separately_from_agent_soul() -> None:node_job_config = {"schema_version": 1,"workflow_prompt": "Review the bid and identify clarification questions.",@@ -300,7 +300,7 @@ def test_workflow_binding_stores_node_job_config_separately_from_agent_soul():assert "prompt" not in binding.node_job_config_dict-def test_long_text_columns_do_not_use_mysql_incompatible_server_defaults():+def test_long_text_columns_do_not_use_mysql_incompatible_server_defaults() -> None:for column in (Agent.__table__.c.description,):assert isinstance(column.type, LongText)assert column.server_default is None@@ -309,7 +309,7 @@ def test_long_text_columns_do_not_use_mysql_incompatible_server_defaults():assert WorkflowAgentNodeBinding.__table__.c.node_job_config.server_default is None-def test_agent_config_revision_links_previous_and_current_snapshots():+def test_agent_config_revision_links_previous_and_current_snapshots() -> None:revision = AgentConfigRevision(tenant_id="tenant-1",agent_id="agent-1",diff --git a/api/tests/unit_tests/pyrefly.toml b/api/tests/unit_tests/pyrefly.tomlindex 35b743d4df3..017191be198 100644--- a/api/tests/unit_tests/pyrefly.toml+++ b/api/tests/unit_tests/pyrefly.toml@@ -266,7 +266,6 @@ project-excludes = ["libs/test_external_api.py","migrations/versions/test_2025_07_02_2332-1c9ba48be8e4_add_uuidv7_function_in_sql.py","models/test_account.py",- "models/test_agent.py","models/test_model.py","models/test_dataset.py","models/test_tools.py",@@ -316,9 +315,7 @@ project-excludes = ["services/workflow/test_workflow_converter.py","services/test_workflow_event_snapshot_service.py","tasks/test_clean_dataset_task.py",- "tasks/test_clean_document_task.py","tasks/test_document_indexing_task.py",- "tasks/test_document_indexing_sync_task.py","tasks/test_document_indexing_update_task.py","tasks/test_enable_segments_to_index_task.py","tasks/test_human_input_timeout_tasks.py",diff --git a/api/tests/unit_tests/tasks/test_clean_document_task.py b/api/tests/unit_tests/tasks/test_clean_document_task.pyindex 36aa6c59581..0137261a141 100644--- a/api/tests/unit_tests/tasks/test_clean_document_task.py+++ b/api/tests/unit_tests/tasks/test_clean_document_task.py@@ -6,8 +6,9 @@ starts from the production incident shape: the caller has already deleted the"""import uuid+from collections.abc import Generatorfrom datetime import UTC, datetime, timedelta-from unittest.mock import patch+from unittest.mock import MagicMock, patchimport pytestfrom sqlalchemy import select@@ -67,14 +68,14 @@ def bind_task_sessions(monkeypatch: pytest.MonkeyPatch, sqlite_session: Session)@pytest.fixture-def mock_storage():+def mock_storage() -> Generator[MagicMock]:with patch("tasks.clean_document_task.storage", autospec=True) as mock:mock.delete.return_value = Noneyield mock@pytest.fixture-def mock_index_cleanup(tenant_id: str):+def mock_index_cleanup(tenant_id: str) -> Generator[MagicMock]:"""Keep task resilience tests independent of the external index backend."""with patch("tasks.clean_document_task.clean_document_indexes", return_value=tenant_id) as cleanup:yield cleanup@@ -201,8 +202,8 @@ class TestVectorCleanupResilience:tenant_id: str,sqlite_session: Session,bind_task_sessions: None,- mock_storage,- mock_index_cleanup,+ mock_storage: MagicMock,+ mock_index_cleanup: MagicMock,) -> None:"""A transient billing failure leaves only the unrelated document's rows."""other_document_id, survivor_segment_id = _persist_deleted_document_state(@@ -241,8 +242,8 @@ def test_active_upgrade_lease_keeps_the_legacy_source_file(tenant_id: str,sqlite_session: Session,bind_task_sessions: None,- mock_storage,- mock_index_cleanup,+ mock_storage: MagicMock,+ mock_index_cleanup: MagicMock,) -> None:del bind_task_sessions, mock_index_cleanup_persist_deleted_document_state(@@ -312,8 +313,8 @@ class TestVectorCleanupSuccessPaths:tenant_id: str,sqlite_session: Session,bind_task_sessions: None,- mock_storage,- mock_index_cleanup,+ mock_storage: MagicMock,+ mock_index_cleanup: MagicMock,) -> None:"""The happy path calls the index boundary and completes scoped cleanup."""other_document_id, survivor_segment_id = _persist_deleted_document_state(@@ -357,8 +358,8 @@ class TestVectorCleanupSuccessPaths:tenant_id: str,sqlite_session: Session,bind_task_sessions: None,- mock_storage,- mock_index_cleanup,+ mock_storage: MagicMock,+ mock_index_cleanup: MagicMock,) -> None:"""Cleanup checks for orphan summaries even when no segments remain."""mock_index_cleanup.return_value = Nonediff --git a/api/tests/unit_tests/tasks/test_document_indexing_sync_task.py b/api/tests/unit_tests/tasks/test_document_indexing_sync_task.pyindex be8e8b3c022..69d6042bbd2 100644--- a/api/tests/unit_tests/tasks/test_document_indexing_sync_task.py+++ b/api/tests/unit_tests/tasks/test_document_indexing_sync_task.py@@ -6,6 +6,7 @@ Notion extraction, index cleanup, and indexing remain mocked I/O boundaries.import jsonimport uuid+from collections.abc import Generatorfrom unittest.mock import ANY, MagicMock, patchimport pytest@@ -124,7 +125,7 @@ def _bind_sqlite_session_factory(monkeypatch: pytest.MonkeyPatch, sqlite_session@pytest.fixture-def mock_datasource_provider_service():+def mock_datasource_provider_service() -> Generator[MagicMock]:"""Mock datasource credential provider."""with patch("tasks.document_indexing_sync_task.build_data_source_credentials", autospec=True) as mock_service_class:mock_service = MagicMock()@@ -134,7 +135,7 @@ def mock_datasource_provider_service():@pytest.fixture-def mock_notion_extractor():+def mock_notion_extractor() -> Generator[dict[str, MagicMock]]:"""Mock notion extractor class and instance."""with patch("tasks.document_indexing_sync_task.NotionExtractor", autospec=True) as mock_extractor_class:mock_extractor = MagicMock()@@ -148,14 +149,14 @@ class TestDocumentIndexingSyncTaskCollaboratorParams:def test_notion_extractor_initialized_with_correct_params(self,- mock_datasource_provider_service,- mock_notion_extractor,+ mock_datasource_provider_service: MagicMock,+ mock_notion_extractor: dict[str, MagicMock],document: Document,dataset_id: str,document_id: str,notion_workspace_id: str,notion_page_id: str,- ):+ ) -> None:"""Test that NotionExtractor is initialized with expected arguments."""# Arrangeexpected_token = "test_token"@@ -175,13 +176,13 @@ class TestDocumentIndexingSyncTaskCollaboratorParams:def test_datasource_credentials_requested_correctly(self,- mock_datasource_provider_service,- mock_notion_extractor,+ mock_datasource_provider_service: MagicMock,+ mock_notion_extractor: dict[str, MagicMock],document: Document,dataset_id: str,document_id: str,credential_id: str,- ):+ ) -> None:"""Test that datasource credentials are requested with expected identifiers."""# Arrangeexpected_tenant_id = document.tenant_id@@ -199,13 +200,13 @@ class TestDocumentIndexingSyncTaskCollaboratorParams:def test_credential_id_missing_uses_none(self,- mock_datasource_provider_service,- mock_notion_extractor,+ mock_datasource_provider_service: MagicMock,+ mock_notion_extractor: dict[str, MagicMock],document: Document,sqlite_session: Session,dataset_id: str,document_id: str,- ):+ ) -> None:"""Test that missing credential_id is forwarded as None."""# Arrangedocument.data_source_info = json.dumps(@@ -244,7 +245,7 @@ class TestDataSourceInfoSerialization:sqlite_session: Session,dataset_id: str,document_id: str,- ):+ ) -> None:"""data_source_info must be serialized with json.dumps before DB write."""with (patch("tasks.document_indexing_sync_task.build_data_source_credentials") as mock_service_class,