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
ci: enable Ruff PT011 (#44122)
Asuka Minatod8b37884d8f0
diff --git a/api/.ruff.toml b/api/.ruff.tomlindex 2f91e4dded1..571603bf0f5 100644--- a/api/.ruff.toml+++ b/api/.ruff.toml@@ -63,7 +63,6 @@ ignore = ["B901", # allow return in yield"B904", # raise-without-from-inside-except"N815", # mixed-case-variable-in-class-scope- "PT011", # pytest-raises-too-broad"SIM102", # collapsible-if"SIM117", # multiple-with-statements]diff --git a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.pyindex b1c31a93787..e07c12e64d9 100644--- a/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py+++ b/api/providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_vector.py@@ -138,7 +138,13 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):mock_conn.cursor.return_value = mock_cursormock_cursor.fetchone.side_effect = [{"VERSION()": "8.0.35"}, {"vector_support": False}]- with pytest.raises(ValueError) as context:+ with pytest.raises(+ ValueError,+ match=(+ "RDS MySQL Vector functions are not available\\. Please ensure you're "+ "using RDS MySQL 8\\.0\\.36\\+ with Vector support\\."+ ),+ ) as context:AlibabaCloudMySQLVector(self.collection_name, self.config)assert "RDS MySQL Vector functions are not available" in str(context.value)@@ -157,7 +163,13 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):mock_cursor.fetchone.return_value = {"VERSION()": "8.0.36"}mock_cursor.execute.side_effect = [None, MySQLError(errno=1305, msg="FUNCTION VEC_FromText does not exist")]- with pytest.raises(ValueError) as context:+ with pytest.raises(+ ValueError,+ match=(+ "RDS MySQL Vector functions are not available\\. Please ensure you're "+ "using RDS MySQL 8\\.0\\.36\\+ with Vector support\\."+ ),+ ) as context:AlibabaCloudMySQLVector(self.collection_name, self.config)assert "RDS MySQL Vector functions are not available" in str(context.value)@@ -516,10 +528,10 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):vector_store = AlibabaCloudMySQLVector(self.collection_name, self.config)query_vector = [0.1, 0.2, 0.3, 0.4]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="top_k must be a positive integer"):vector_store.search_by_vector(query_vector, top_k=0)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="top_k must be a positive integer"):vector_store.search_by_vector(query_vector, top_k="invalid")@patch("dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.mysql.connector.pooling.MySQLConnectionPool")@@ -590,10 +602,10 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):vector_store = AlibabaCloudMySQLVector(self.collection_name, self.config)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="top_k must be a positive integer"):vector_store.search_by_full_text("test", top_k=0)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="top_k must be a positive integer"):vector_store.search_by_full_text("test", top_k="invalid")@patch("dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.mysql.connector.pooling.MySQLConnectionPool")@@ -623,7 +635,9 @@ class TestAlibabaCloudMySQLVector(unittest.TestCase):def test_unsupported_distance_function(self, mock_pool_class):"""Test that Pydantic validation rejects unsupported distance functions."""# Test that creating config with unsupported distance function raises ValidationError- with pytest.raises(ValueError) as context:+ with pytest.raises(+ ValueError, match="1 validation error for AlibabaCloudMySQLVectorConfig\\\ndistance_function"+ ) as context:AlibabaCloudMySQLVectorConfig(host="localhost",port=3306,@@ -677,7 +691,23 @@ def test_config_validation_parametrized(invalid_config_override):}config.update(invalid_config_override)- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for AlibabaCloudMySQLVectorConfig\\\n Value "+ "error, config ALIBABACLOUD_MYSQL_HOST is required "+ "\\[type=value_error, input_value=\\{'host': '', 'port': "+ "3306\\.\\.\\.t', 'max_connection': 5\\}, input_type=dict\\]|1 "+ "validation error for AlibabaCloudMySQLVectorConfig\\\n Value error, "+ "config ALIBABACLOUD_MYSQL_MAX_CONNECTION is required "+ "\\[type=value_error, input_value=\\{'host': 'localhost', "+ "'po\\.\\.\\.t', 'max_connection': 0\\}, input_type=dict\\]|1 "+ "validation error for AlibabaCloudMySQLVectorConfig\\\n Value error, "+ "config ALIBABACLOUD_MYSQL_PORT is required \\[type=value_error, "+ "input_value=\\{'host': 'localhost', 'po\\.\\.\\.t', 'max_connection': "+ "5\\}, input_type=dict\\])"+ ),+ ):AlibabaCloudMySQLVectorConfig(**config)diff --git a/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py b/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.pyindex eb3a6580888..de4a71a2137 100644--- a/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py+++ b/api/providers/vdb/vdb-pgvector/tests/unit_tests/test_pgvector.py@@ -321,7 +321,38 @@ def test_config_validation_parametrized(invalid_config_override):}config.update(invalid_config_override)- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for PGVectorConfig\\\n Value error, config "+ "PGVECTOR_DATABASE is required \\[type=value_error, "+ "input_value=\\{'host': 'localhost', 'po\\.\\.\\. 1, 'max_connection': "+ "5\\}, input_type=dict\\]|1 validation error for PGVectorConfig\\\n "+ "Value error, config PGVECTOR_HOST is required \\[type=value_error, "+ "input_value=\\{'host': '', 'port': 5432\\.\\.\\. 1, 'max_connection': "+ "5\\}, input_type=dict\\]|1 validation error for PGVectorConfig\\\n "+ "Value error, config PGVECTOR_MAX_CONNECTION is required "+ "\\[type=value_error, input_value=\\{'host': 'localhost', 'po\\.\\.\\. "+ "1, 'max_connection': 0\\}, input_type=dict\\]|1 validation error for "+ "PGVectorConfig\\\n Value error, config PGVECTOR_MIN_CONNECTION is "+ "required \\[type=value_error, input_value=\\{'host': 'localhost', "+ "'po\\.\\.\\. 0, 'max_connection': 5\\}, input_type=dict\\]|1 "+ "validation error for PGVectorConfig\\\n Value error, config "+ "PGVECTOR_MIN_CONNECTION should less than PGVECTOR_MAX_CONNECTION "+ "\\[type=value_error, input_value=\\{'host': 'localhost', "+ "'po\\.\\.\\.10, 'max_connection': 5\\}, input_type=dict\\]|1 "+ "validation error for PGVectorConfig\\\n Value error, config "+ "PGVECTOR_PASSWORD is required \\[type=value_error, "+ "input_value=\\{'host': 'localhost', 'po\\.\\.\\. 1, 'max_connection': "+ "5\\}, input_type=dict\\]|1 validation error for PGVectorConfig\\\n "+ "Value error, config PGVECTOR_PORT is required \\[type=value_error, "+ "input_value=\\{'host': 'localhost', 'po\\.\\.\\. 1, 'max_connection': "+ "5\\}, input_type=dict\\]|1 validation error for PGVectorConfig\\\n "+ "Value error, config PGVECTOR_USER is required \\[type=value_error, "+ "input_value=\\{'host': 'localhost', 'po\\.\\.\\. 1, 'max_connection': "+ "5\\}, input_type=dict\\])"+ ),+ ):PGVectorConfig(**config)diff --git a/api/tests/test_containers_integration_tests/factories/test_storage_key_loader.py b/api/tests/test_containers_integration_tests/factories/test_storage_key_loader.pyindex 26b80cebbb6..e4f68ea3264 100644--- a/api/tests/test_containers_integration_tests/factories/test_storage_key_loader.py+++ b/api/tests/test_containers_integration_tests/factories/test_storage_key_loader.py@@ -233,7 +233,7 @@ class TestStorageKeyLoader:loader = StorageKeyLoader(db_session_with_containers, tenant_id, access_controller=DatabaseFileAccessController())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Upload file not found for id:"):loader.load_storage_keys([file])def test_load_storage_keys_nonexistent_tool_file_records(self, db_session_with_containers: Session):@@ -244,7 +244,7 @@ class TestStorageKeyLoader:loader = StorageKeyLoader(db_session_with_containers, tenant_id, access_controller=DatabaseFileAccessController())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Tool file not found for id:"):loader.load_storage_keys([file])def test_load_storage_keys_invalid_uuid(self, db_session_with_containers: Session):@@ -259,7 +259,7 @@ class TestStorageKeyLoader:loader = StorageKeyLoader(db_session_with_containers, tenant_id, access_controller=DatabaseFileAccessController())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="badly formed hexadecimal UUID string"):loader.load_storage_keys([file])def test_load_storage_keys_batch_efficiency(self, db_session_with_containers: Session):@@ -385,5 +385,5 @@ class TestStorageKeyLoader:tenant_id,access_controller=DatabaseFileAccessController(),)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Upload file not found for id:"):other_loader.load_storage_keys([file])diff --git a/api/tests/test_containers_integration_tests/models/test_types_enum_text.py b/api/tests/test_containers_integration_tests/models/test_types_enum_text.pyindex cb114537e63..bed53975308 100644--- a/api/tests/test_containers_integration_tests/models/test_types_enum_text.py+++ b/api/tests/test_containers_integration_tests/models/test_types_enum_text.py@@ -1,3 +1,4 @@+import refrom collections.abc import Callable, Iterablefrom enum import StrEnumfrom typing import Any, NamedTuple@@ -204,7 +205,7 @@ class TestEnumText:session.execute(sa.text(insertion_sql))session.commit()- with pytest.raises(ValueError) as exc:+ with pytest.raises(ValueError, match="'invalid' is not a valid _UserType") as exc:with Session(engine_with_containers) as session:_user = session.scalar(select(_User).where(_User.id == 1).limit(1))@@ -222,7 +223,7 @@ class TestEnumText:session.commit()for record_id, legacy_value in enumerate(("text-generation", "embeddings", "reranking"), 1):- with pytest.raises(ValueError) as exc:+ with pytest.raises(ValueError, match=re.escape(f"'{legacy_value}' is not a valid ModelType")) as exc:with Session(engine_with_containers) as session:session.scalar(select(_LegacyModelTypeRecord).where(_LegacyModelTypeRecord.id == record_id))diff --git a/api/tests/test_containers_integration_tests/services/test_annotation_service.py b/api/tests/test_containers_integration_tests/services/test_annotation_service.pyindex ddf1fe25c97..c0a5d213fac 100644--- a/api/tests/test_containers_integration_tests/services/test_annotation_service.py+++ b/api/tests/test_containers_integration_tests/services/test_annotation_service.py@@ -241,7 +241,7 @@ class TestAnnotationService:"answer": fake.text(max_nb_chars=200),}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'question' is required"):AppAnnotationService.insert_app_annotation_directly(annotation_args, app.id, db_session_with_containers)def test_insert_app_annotation_directly_app_not_found(diff --git a/api/tests/test_containers_integration_tests/services/test_app_generate_service.py b/api/tests/test_containers_integration_tests/services/test_app_generate_service.pyindex a7eec53a182..879335d27fc 100644--- a/api/tests/test_containers_integration_tests/services/test_app_generate_service.py+++ b/api/tests/test_containers_integration_tests/services/test_app_generate_service.py@@ -680,7 +680,7 @@ class TestAppGenerateService:args = {"inputs": {"query": fake.text(max_nb_chars=50)}, "response_mode": "streaming"}# Execute the method under test and expect ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Workflow not initialized") as exc_info:AppGenerateService.generate(app_model=app,user=account,@@ -711,7 +711,7 @@ class TestAppGenerateService:args = {"inputs": {"query": fake.text(max_nb_chars=50)}, "response_mode": "streaming"}# Execute the method under test and expect ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Workflow not published") as exc_info:AppGenerateService.generate(app_model=app,user=account,@@ -803,7 +803,7 @@ class TestAppGenerateService:args = {"inputs": {"query": fake.text(max_nb_chars=50)}}# Execute the method under test and expect ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Invalid app mode") as exc_info:AppGenerateService.generate_single_iteration(app_model=app,user=account,@@ -893,7 +893,7 @@ class TestAppGenerateService:args = {"inputs": {"query": fake.text(max_nb_chars=50)}}# Execute the method under test and expect ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Invalid app mode") as exc_info:AppGenerateService.generate_single_loop(app_model=app,user=account,@@ -1058,7 +1058,7 @@ class TestAppGenerateService:args = {"inputs": {"query": fake.text(max_nb_chars=50)}, "response_mode": "streaming"}# Execute the method under test and expect exception- with pytest.raises(Exception) as exc_info:+ with pytest.raises(Exception, match="Test exception") as exc_info:AppGenerateService.generate(app_model=app,user=account,diff --git a/api/tests/test_containers_integration_tests/services/test_app_service.py b/api/tests/test_containers_integration_tests/services/test_app_service.pyindex 72cb9314a44..9fa1170e70e 100644--- a/api/tests/test_containers_integration_tests/services/test_app_service.py+++ b/api/tests/test_containers_integration_tests/services/test_app_service.py@@ -813,7 +813,7 @@ class TestAppService:mock_current_user.current_tenant_id = account.current_tenant_idwith patch("services.app_service.current_user", mock_current_user):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'' is not a valid IconType"):app_service.update_app(app,{diff --git a/api/tests/test_containers_integration_tests/services/test_dataset_service_update_dataset.py b/api/tests/test_containers_integration_tests/services/test_dataset_service_update_dataset.pyindex ebf6fa0f54d..fc67f0a4c65 100644--- a/api/tests/test_containers_integration_tests/services/test_dataset_service_update_dataset.py+++ b/api/tests/test_containers_integration_tests/services/test_dataset_service_update_dataset.py@@ -220,7 +220,7 @@ class TestDatasetServiceUpdateDataset:update_data = {"name": "new_name", "external_knowledge_api_id": str(uuid4())}- with pytest.raises(ValueError) as context:+ with pytest.raises(ValueError, match="External knowledge id is required") as context:DatasetService.update_dataset(dataset.id, update_data, user, session=db_session_with_containers)assert "External knowledge id is required" in str(context.value)@@ -244,7 +244,7 @@ class TestDatasetServiceUpdateDataset:update_data = {"name": "new_name", "external_knowledge_id": "knowledge_id"}- with pytest.raises(ValueError) as context:+ with pytest.raises(ValueError, match="External knowledge api id is required") as context:DatasetService.update_dataset(dataset.id, update_data, user, session=db_session_with_containers)assert "External knowledge api id is required" in str(context.value)@@ -271,7 +271,7 @@ class TestDatasetServiceUpdateDataset:"external_knowledge_api_id": external_api.id,}- with pytest.raises(ValueError) as context:+ with pytest.raises(ValueError, match="External knowledge binding not found") as context:DatasetService.update_dataset(dataset.id, update_data, user, session=db_session_with_containers)assert "External knowledge binding not found" in str(context.value)@@ -544,7 +544,7 @@ class TestDatasetServiceUpdateDataset:user, _ = DatasetUpdateTestDataFactory.create_account_with_tenant(db_session_with_containers)update_data = {"name": "new_name"}- with pytest.raises(ValueError) as context:+ with pytest.raises(ValueError, match="Dataset not found") as context:DatasetService.update_dataset(str(uuid4()), update_data, user, session=db_session_with_containers)assert "Dataset not found" in str(context.value)@@ -594,7 +594,7 @@ class TestDatasetServiceUpdateDataset:):mock_model_manager.return_value.get_model_instance.side_effect = Exception("No Embedding Model available")- with pytest.raises(Exception) as context:+ with pytest.raises(Exception, match="(?i)No Embedding Model available") as context:DatasetService.update_dataset(dataset.id, update_data, user, session=db_session_with_containers)assert "No Embedding Model available".lower() in str(context.value).lower()diff --git a/api/tests/test_containers_integration_tests/services/test_model_load_balancing_service.py b/api/tests/test_containers_integration_tests/services/test_model_load_balancing_service.pyindex c435af52a06..d5d058195a2 100644--- a/api/tests/test_containers_integration_tests/services/test_model_load_balancing_service.py+++ b/api/tests/test_containers_integration_tests/services/test_model_load_balancing_service.py@@ -260,7 +260,7 @@ class TestModelLoadBalancingService:# Act & Assert: Verify proper error handlingservice = ModelLoadBalancingService()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Provider nonexistent_provider does not exist\\.") as exc_info:service.enable_model_load_balancing(tenant_id=tenant.id, provider="nonexistent_provider", model="gpt-3.5-turbo", model_type="llm")@@ -383,7 +383,7 @@ class TestModelLoadBalancingService:# Act & Assert: Verify proper error handlingservice = ModelLoadBalancingService()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Provider nonexistent_provider does not exist\\.") as exc_info:service.get_load_balancing_configs(tenant_id=tenant.id,provider="nonexistent_provider",diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.pyindex caaa7ea54c6..0ed46ad66d4 100644--- a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py+++ b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py@@ -976,7 +976,7 @@ class TestWorkflowAppLogQueryService:assert all(log.created_by_role == CreatorUserRole.ACCOUNT for log in result_with_new_email["data"])# Old email unbound, is unexpected input, should raise ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Account not found") as exc_info:service.get_paginate_workflow_app_logs(session=db_session_with_containers, app_model=app, created_by_account=original_email, page=1, limit=20)@@ -996,7 +996,7 @@ class TestWorkflowAppLogQueryService:assert result_no_session["total"] == 0# Test filtering by non-existent account email, is unexpected input, should raise ValueError- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Account not found") as exc_info:service.get_paginate_workflow_app_logs(session=db_session_with_containers,app_model=app,@@ -1250,7 +1250,7 @@ class TestWorkflowAppLogQueryService:assert len(result_no_session["data"]) == 0# Test with account email that doesn't exist- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Account not found") as exc_info:service.get_paginate_workflow_app_logs(session=db_session_with_containers,app_model=app,diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_service.pyindex 4c47037dfca..8582a2d546c 100644--- a/api/tests/test_containers_integration_tests/services/test_workflow_service.py+++ b/api/tests/test_containers_integration_tests/services/test_workflow_service.py@@ -1620,7 +1620,7 @@ class TestWorkflowService:# Act# Since start nodes are not supported in run_free_node, we expect an error- with pytest.raises(Exception) as exc_info:+ with pytest.raises(Exception, match="Node type start not supported") as exc_info:workflow_service.run_free_workflow_node(node_data=node_data, tenant_id=tenant_id, user_id=user_id, node_id=node_id, user_inputs=user_inputs)diff --git a/api/tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py b/api/tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.pyindex 5039875d62e..87c3c750ed4 100644--- a/api/tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py+++ b/api/tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py@@ -1,5 +1,6 @@import inspectimport json+import refrom collections.abc import Iteratorfrom unittest.mock import MagicMock, patch@@ -193,7 +194,7 @@ class TestApiToolManageService:invalid_schema = "invalid json schema"# Act & Assert: Verify proper error handling- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="invalid schema") as exc_info:ApiToolManageService.parser_api_schema(invalid_schema)assert "invalid schema" in str(exc_info.value)@@ -216,7 +217,7 @@ class TestApiToolManageService:malformed_schema = '{"openapi": "3.0.0", "info": {"title": "Test", "version": "1.0.0"}, "paths": {}}'# Act & Assert: Verify proper error handling- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="invalid schema") as exc_info:ApiToolManageService.parser_api_schema(malformed_schema)assert "invalid schema" in str(exc_info.value)@@ -301,7 +302,7 @@ class TestApiToolManageService:invalid_schema = "invalid schema content"# Act & Assert: Verify proper error handling- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="invalid schema") as exc_info:ApiToolManageService.convert_schema_to_tool_bundles(invalid_schema)assert "invalid schema" in str(exc_info.value)@@ -421,7 +422,7 @@ class TestApiToolManageService:)# Act & Assert: Try to create duplicate provider- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match=re.escape(f"provider {provider_name} already exists")) as exc_info:ApiToolManageService.create_api_tool_provider(user_id=account.id,tenant_id=tenant.id,@@ -502,7 +503,7 @@ class TestApiToolManageService:labels = ["test"]# Act & Assert: Try to create provider with missing auth type- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="auth_type is required") as exc_info:ApiToolManageService.create_api_tool_provider(user_id=account.id,tenant_id=tenant.id,diff --git a/api/tests/test_containers_integration_tests/services/tools/test_workflow_tools_manage_service.py b/api/tests/test_containers_integration_tests/services/tools/test_workflow_tools_manage_service.pyindex 80dc32ec3fa..7397b5bb4b7 100644--- a/api/tests/test_containers_integration_tests/services/tools/test_workflow_tools_manage_service.py+++ b/api/tests/test_containers_integration_tests/services/tools/test_workflow_tools_manage_service.py@@ -1,4 +1,5 @@import json+import refrom unittest.mock import patchimport pytest@@ -264,7 +265,9 @@ class TestWorkflowToolManageService:# Attempt to create second workflow tool with same namesecond_tool_parameters = self._create_test_workflow_tool_parameters()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match=re.escape(f"Tool with name {first_tool_name} or app_id {app.id} already exists")+ ) as exc_info:WorkflowToolManageService.create_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,@@ -314,7 +317,7 @@ class TestWorkflowToolManageService:# Attempt to create workflow tool with non-existent apptool_parameters = self._create_test_workflow_tool_parameters()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match=re.escape(f"App {non_existent_app_id} not found")) as exc_info:WorkflowToolManageService.create_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,@@ -431,7 +434,9 @@ class TestWorkflowToolManageService:# Attempt to create second workflow tool with same app_id but different namesecond_tool_name = fake.word()second_tool_parameters = self._create_test_workflow_tool_parameters()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match=re.escape(f"Tool with name {second_tool_name} or app_id {app.id} already exists")+ ) as exc_info:WorkflowToolManageService.create_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,@@ -483,7 +488,7 @@ class TestWorkflowToolManageService:# Attempt to create workflow tool for app without workflowtool_parameters = self._create_test_workflow_tool_parameters()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match=re.escape(f"Workflow not found for app {app.id}")) as exc_info:WorkflowToolManageService.create_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,@@ -749,7 +754,7 @@ class TestWorkflowToolManageService:# Attempt to update non-existent workflow tooltool_parameters = self._create_test_workflow_tool_parameters()- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match=re.escape(f"Tool {non_existent_tool_id} not found")) as exc_info:WorkflowToolManageService.update_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,@@ -1020,7 +1025,7 @@ class TestWorkflowToolManageService:)# Attempt to create workflow tool (will fail at validation stage)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Validation failed") as exc_info:WorkflowToolManageService.create_workflow_tool(user_id=account.id,tenant_id=account.current_tenant.id,diff --git a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.pyindex b9bd0721643..edb4fce268d 100644--- a/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py+++ b/api/tests/test_containers_integration_tests/tasks/test_create_segment_to_index_task.py@@ -745,7 +745,7 @@ class TestCreateSegmentToIndexTask:# Mock Redis to raise exception in finally blockwith patch.object(redis_client, "delete", side_effect=Exception("Redis connection failed"), autospec=True):# Act: Execute the task - Redis failure should not prevent completion- with pytest.raises(Exception) as exc_info:+ with pytest.raises(Exception, match="Redis connection failed") as exc_info:create_segment_to_index_task(segment.id)# Verify the exception contains the expected Redis error messagediff --git a/api/tests/unit_tests/controllers/common/test_schema.py b/api/tests/unit_tests/controllers/common/test_schema.pyindex 3af43405d7e..18c09f53c82 100644--- a/api/tests/unit_tests/controllers/common/test_schema.py+++ b/api/tests/unit_tests/controllers/common/test_schema.py@@ -439,7 +439,7 @@ def test_query_params_from_request_raises_for_malformed_ints_by_default():app = Flask(__name__)with app.test_request_context("/?page=bad&limit="):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="2 validation errors for HelperQueryModel\\\npage"):query_params_from_request(HelperQueryModel, list_fields=("status",))diff --git a/api/tests/unit_tests/controllers/console/app/test_annotation_security.py b/api/tests/unit_tests/controllers/console/app/test_annotation_security.pyindex 9d0f6c33cc5..2cfa372a388 100644--- a/api/tests/unit_tests/controllers/console/app/test_annotation_security.py+++ b/api/tests/unit_tests/controllers/console/app/test_annotation_security.py@@ -75,7 +75,13 @@ class TestAnnotationImportRateLimiting:return "success"# Should abort with 429- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=(+ "429 Too Many Requests: Too many annotation import requests\\. Maximum "+ "5 requests per minute allowed\\. Please try again later\\."+ ),+ ) as exc_info:dummy_view()# Verify it's a rate limit error@@ -95,7 +101,13 @@ class TestAnnotationImportRateLimiting:return "success"# Should abort with 429- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=(+ "429 Too Many Requests: Too many annotation import requests\\. Maximum "+ "20 requests per hour allowed\\. Please try again later\\."+ ),+ ) as exc_info:dummy_view()assert "429" in str(exc_info.value) or "Too many" in str(exc_info.value)@@ -146,7 +158,14 @@ class TestAnnotationImportConcurrencyControl:return "success"# Should abort with 429- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=(+ "429 Too Many Requests: Too many concurrent import tasks\\. Maximum 2 "+ "concurrent imports allowed per workspace\\. Please wait for existing "+ "imports to complete\\."+ ),+ ) as exc_info:dummy_view()assert "429" in str(exc_info.value) or "concurrent" in str(exc_info.value).lower()diff --git a/api/tests/unit_tests/controllers/console/app/test_app_apis.py b/api/tests/unit_tests/controllers/console/app/test_app_apis.pyindex d371be2ec66..bdbd6282f7c 100644--- a/api/tests/unit_tests/controllers/console/app/test_app_apis.py+++ b/api/tests/unit_tests/controllers/console/app/test_app_apis.py@@ -834,7 +834,7 @@ class TestMCPServerEndpoints:class TestErrorHandling:def test_annotation_list_query_validation(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for AnnotationListQuery\\\npage"):annotation_module.AnnotationListQuery(page=0)diff --git a/api/tests/unit_tests/controllers/console/app/test_console_app_api.py b/api/tests/unit_tests/controllers/console/app/test_console_app_api.pyindex 5b6d2adf702..06f44f45955 100644--- a/api/tests/unit_tests/controllers/console/app/test_console_app_api.py+++ b/api/tests/unit_tests/controllers/console/app/test_console_app_api.py@@ -245,7 +245,7 @@ def test_export_closes_archive_when_send_file_fails(raise OSError("delivery failed")monkeypatch.setattr(controller, "send_file", fail)- with app.test_request_context("/"), pytest.raises(OSError):+ with app.test_request_context("/"), pytest.raises(OSError, match="delivery failed"):invoke(controller.AppExportApi, controller.AppExportApi.get, app_id=APP_ID)assert archive.closeddiff --git a/api/tests/unit_tests/controllers/console/app/test_description_validation.py b/api/tests/unit_tests/controllers/console/app/test_description_validation.pyindex dcc408a21c5..ea3fd14ab59 100644--- a/api/tests/unit_tests/controllers/console/app/test_description_validation.py+++ b/api/tests/unit_tests/controllers/console/app/test_description_validation.py@@ -30,19 +30,19 @@ class TestDescriptionValidationUnit:"""Test validation function with invalid descriptions."""# 401 characters should failjust_over = "x" * 401- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\.") as exc_info:validate_description_length(just_over)assert "Description cannot exceed 400 characters." in str(exc_info.value)# 500 characters should failway_over = "x" * 500- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\.") as exc_info:validate_description_length(way_over)assert "Description cannot exceed 400 characters." in str(exc_info.value)# 1000 characters should failvery_long = "x" * 1000- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\.") as exc_info:validate_description_length(very_long)assert "Description cannot exceed 400 characters." in str(exc_info.value)@@ -66,7 +66,7 @@ class TestDescriptionValidationUnit:assert validate_description_length(test_desc) == test_descelse:# Should raise ValueError- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\."):validate_description_length(test_desc)def test_special_characters(self):@@ -86,7 +86,7 @@ class TestDescriptionValidationUnit:if len(mixed_desc) <= 400:assert validate_description_length(mixed_desc) == mixed_descelif len(mixed_desc) > 400:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\."):validate_description_length(mixed_desc)def test_whitespace_handling(self):@@ -103,5 +103,5 @@ class TestDescriptionValidationUnit:# Only whitespace over limitonly_spaces = " " * 401- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Description cannot exceed 400 characters\\."):validate_description_length(only_spaces)diff --git a/api/tests/unit_tests/controllers/console/app/test_generator_api.py b/api/tests/unit_tests/controllers/console/app/test_generator_api.pyindex f268f9a3869..4e20e384f44 100644--- a/api/tests/unit_tests/controllers/console/app/test_generator_api.py+++ b/api/tests/unit_tests/controllers/console/app/test_generator_api.py@@ -297,7 +297,7 @@ def test_instruction_template_invalid_type(app: Flask) -> None:method="POST",json={"type": "unknown"},):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Invalid type: unknown"):method(api, InstructionTemplatePayload.model_validate(request.get_json()))diff --git a/api/tests/unit_tests/controllers/console/app/test_workflow_human_input_debug_api.py b/api/tests/unit_tests/controllers/console/app/test_workflow_human_input_debug_api.pyindex f223228048d..be86ef6dc52 100644--- a/api/tests/unit_tests/controllers/console/app/test_workflow_human_input_debug_api.py+++ b/api/tests/unit_tests/controllers/console/app/test_workflow_human_input_debug_api.py@@ -231,7 +231,7 @@ def test_human_input_delivery_test_maps_validation_error(app: Flask, monkeypatchmethod="POST",json={"delivery_method_id": "bad"},):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="bad delivery method"):workflow_module.WorkflowDraftHumanInputDeliveryTestApi().post(app_id=app_model.id, node_id="node-1")diff --git a/api/tests/unit_tests/controllers/console/app/test_wraps.py b/api/tests/unit_tests/controllers/console/app/test_wraps.pyindex f090f14a51b..6336e071620 100644--- a/api/tests/unit_tests/controllers/console/app/test_wraps.py+++ b/api/tests/unit_tests/controllers/console/app/test_wraps.py@@ -59,7 +59,7 @@ def test_get_app_model_requires_app_id() -> None:def handler(app_model):return app_model.id- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="missing app_id in path parameters"):handler()diff --git a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_auth.py b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_auth.pyindex a57f5e8338a..2e9df086729 100644--- a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_auth.py+++ b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_datasource_auth.py@@ -188,7 +188,7 @@ class TestDatasourcePluginOAuthAuthorizationUrl:return_value=None,),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="No OAuth Client Config for notion"):method(api, "tenant-1", user, "notion")def test_get_without_credential_id_sets_cookie(self, app: Flask):@@ -466,7 +466,7 @@ class TestDatasourceAuth:side_effect=CredentialsValidateFailedError("invalid"),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="invalid"):method(api, DatasourceCredentialPayload.model_validate(payload), "tenant-1", "notion")def test_get_success(self, app: Flask):@@ -497,7 +497,7 @@ class TestDatasourceAuth:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasourceCredentialPayload\\\ncredentials"):method(api, DatasourceCredentialPayload.model_validate(payload), "tenant-1", "notion")def test_get_empty_list(self, app: Flask):@@ -558,7 +558,9 @@ class TestDatasourceAuthDeleteApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match="1 validation error for DatasourceCredentialDeletePayload\\\ncredential_id"+ ):method(api, DatasourceCredentialDeletePayload.model_validate(payload), "tenant-1", "notion")@@ -880,7 +882,7 @@ class TestDatasourceAuthDefaultApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasourceDefaultPayload\\\nid"):method(api, DatasourceDefaultPayload.model_validate(payload), "tenant-1", "notion")@@ -924,7 +926,7 @@ class TestDatasourceUpdateProviderNameApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasourceUpdateNamePayload\\\nname"):method(api, DatasourceUpdateNamePayload.model_validate(payload), "tenant-1", "notion")def test_update_name_missing_credential_id(self, app: Flask):@@ -937,5 +939,5 @@ class TestDatasourceUpdateProviderNameApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasourceUpdateNamePayload\\\ncredential_id"):method(api, DatasourceUpdateNamePayload.model_validate(payload), "tenant-1", "notion")diff --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 6db24797f4a..74f3ee45dce 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@@ -82,7 +82,7 @@ class TestDataSourceContentPreviewApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ 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):diff --git a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_datasets.py b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_datasets.pyindex 34762805286..2b28b23d9c7 100644--- a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_datasets.py+++ b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_datasets.py@@ -171,7 +171,9 @@ class TestCreateRagPipelineDatasetApi:app.test_request_context("/", json=payload),patch.object(type(console_ns), "payload", payload),):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match="1 validation error for RagPipelineDatasetImportPayload\\\nyaml_content"+ ):method(api, RagPipelineDatasetImportPayload.model_validate(payload), "tenant-1", user)diff --git a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow_apis.py b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow_apis.pyindex 02c162e39af..141614f07b1 100644--- a/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow_apis.py+++ b/api/tests/unit_tests/controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow_apis.py@@ -490,7 +490,7 @@ class TestDraftNodeRun:return_value=service,),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Workflow node execution not found"):method(api, NodeRunRequiredPayload(inputs={}), user, pipeline, "node")@@ -616,7 +616,7 @@ class TestDefaultBlockConfigApi:pipeline = make_pipeline()with app.test_request_context("/?q=bad-json"):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Invalid filters"):method(api, DefaultBlockConfigQuery(q="bad-json"), pipeline, "llm")diff --git a/api/tests/unit_tests/controllers/console/datasets/test_datasets.py b/api/tests/unit_tests/controllers/console/datasets/test_datasets.pyindex d6f494365a8..50d48b039e4 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_datasets.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_datasets.py@@ -208,7 +208,12 @@ def test_website_estimate_parses_boolean_values(value: str | bool, expected: boo@pytest.mark.parametrize("values", [{"only_main_content": "invalid"}, {"urls": [42]}])def test_website_estimate_rejects_invalid_field_types(values: dict[str, object]) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for WebsiteInfo\\\nonly_main_content|1 validation error for WebsiteInfo\\\nurls\\.0)"+ ),+ ):_new_estimate_sources({"data_source_type": "website_crawl",@@ -249,7 +254,15 @@ def test_new_estimate_sources_deduplicates_upload_ids_without_reordering() -> No],)def test_new_estimate_sources_rejects_malformed_transport_shapes(info_list: dict[str, object]) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for FileInfo\\\nfile_ids|1 validation error for "+ "list\\[NotionEstimateWorkspacePayload\\]\\\n0\\.pages\\.0\\.type|2 "+ "validation errors for list\\[NotionEstimateWorkspacePayload\\]\\\n0\\."+ "credential_id|Data source type not support)"+ ),+ ):_new_estimate_sources(info_list)diff --git a/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py b/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.pyindex b0bc71d2e64..0a0d37e74ca 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_datasets_segments.py@@ -285,7 +285,11 @@ def test_batch_import_status_preserves_missing_job_contract(app: Flask) -> None:method = unwrap(DatasetDocumentSegmentBatchImportStatusApi.get)segments.get_batch_import_status.side_effect = SegmentBatchImportNotFoundError("The job does not exist.")- with app.test_request_context("/"), _patch_services(segments), pytest.raises(ValueError):+ with (+ app.test_request_context("/"),+ _patch_services(segments),+ pytest.raises(ValueError, match="The job does not exist\\."),+ ):method(DatasetDocumentSegmentBatchImportStatusApi(), _context(), "job-1")segments.get_batch_import_status.side_effect = Nonediff --git a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.pyindex 8054d21b633..68a0944ada7 100644--- a/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py+++ b/api/tests/unit_tests/controllers/console/datasets/test_hit_testing_base.py@@ -148,7 +148,7 @@ class TestParseArgs:def test_parse_args_invalid(self):payload = {"query": "x" * 300}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for HitTestingPayload\\\nquery"):DatasetsHitTestingBase.parse_args(payload)def test_parse_args_ignores_unknown_fields_for_compatibility(self):diff --git a/api/tests/unit_tests/controllers/console/workspace/test_accounts.py b/api/tests/unit_tests/controllers/console/workspace/test_accounts.pyindex d8ff65f993f..4b8bbc74a39 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_accounts.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_accounts.py@@ -372,7 +372,13 @@ class TestAccountProfilePatchApi:@pytest.mark.parametrize("payload", [{"name": None}, {"unexpected": "value"}])def test_rejects_null_or_unknown_changes(self, payload: dict[str, object]):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for AccountProfilePatchPayload\\\nname|1 "+ "validation error for AccountProfilePatchPayload\\\nunexpected)"+ ),+ ):AccountProfilePatchPayload.model_validate(payload)diff --git a/api/tests/unit_tests/controllers/console/workspace/test_endpoint.py b/api/tests/unit_tests/controllers/console/workspace/test_endpoint.pyindex be72754d231..1f5abb0fc5c 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_endpoint.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_endpoint.py@@ -144,7 +144,7 @@ class TestEndpointCollectionApi:side_effect=PluginPermissionDeniedError("denied"),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="denied"):method(api, req_data, "t1", "u1")def test_create_validation_error(self, app: Flask):@@ -160,7 +160,7 @@ class TestEndpointCollectionApi:with (app.test_request_context("/", json=payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointCreatePayload\\\nname"):method(api, EndpointCreatePayload(**payload), "t1", "u1")@@ -231,7 +231,7 @@ class TestEndpointListApi:with (app.test_request_context("/?page=0&page_size=10"),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointListQuery\\\npage"):method(api, EndpointListQuery(page=0, page_size=10), "t1", "u1")@@ -260,7 +260,7 @@ class TestEndpointListForSinglePluginApi:with (app.test_request_context("/?page=1&page_size=10"),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointListForPluginQuery\\\nplugin_id"):method(api, EndpointListForPluginQuery(page=1, page_size=10), "t1", "u1")@@ -332,7 +332,7 @@ class TestEndpointItemApi:with (app.test_request_context("/", method="PATCH", json=payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointUpdatePayload\\\nname"):method(api, EndpointUpdatePayload(**payload), "t1", "u1", "e1")def test_update_service_failure(self, app: Flask):@@ -379,7 +379,7 @@ class TestDeprecatedEndpointDeleteApi:with (app.test_request_context("/", json={}),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointIdPayload\\\nendpoint_id"):method(api, EndpointIdPayload(), "t1", "u1")def test_delete_service_failure(self, app: Flask):@@ -429,7 +429,7 @@ class TestDeprecatedEndpointUpdateApi:with (app.test_request_context("/", json=payload),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for LegacyEndpointUpdatePayload\\\nname"):method(api, LegacyEndpointUpdatePayload(**payload), "t1", "u1")def test_update_service_failure(self, app: Flask):@@ -513,7 +513,7 @@ class TestEndpointEnableApi:with (app.test_request_context("/", json={}),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointIdPayload\\\nendpoint_id"):method(api, EndpointIdPayload(), "t1", "u1")def test_enable_service_failure(self, app: Flask):@@ -557,5 +557,5 @@ class TestEndpointDisableApi:with (app.test_request_context("/", json={}),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for EndpointIdPayload\\\nendpoint_id"):method(api, EndpointIdPayload(), "t1", "u1")diff --git a/api/tests/unit_tests/controllers/console/workspace/test_model_providers.py b/api/tests/unit_tests/controllers/console/workspace/test_model_providers.pyindex dd247132ec2..d9c6249028c 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_model_providers.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_model_providers.py@@ -395,7 +395,7 @@ class TestModelProviderCredentialApi:side_effect=CredentialsValidateFailedError("bad"),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="bad"):method(api, ParserCredentialCreate.model_validate(_payload()), "tenant1", provider="openai")def test_put_update_success(self, app: Flask):@@ -557,7 +557,7 @@ class TestModelProviderIconApi:return_value=(None, None),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="icon not found for provider openai, icon_type logo, lang en"):api.get("t1", "openai", "logo", "en")@@ -621,7 +621,7 @@ class TestModelProviderPaymentCheckoutUrlApi:method = unwrap(api.get)with app.test_request_context("/"):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="provider name openai is invalid"):method(api, "tenant1", make_account(), provider="openai")def test_checkout_rejects_non_privileged_role(self, app: Flask):diff --git a/api/tests/unit_tests/controllers/console/workspace/test_plugin.py b/api/tests/unit_tests/controllers/console/workspace/test_plugin.pyindex 612b0042589..ed2ae031615 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_plugin.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_plugin.py@@ -656,7 +656,7 @@ class TestPluginUploadFromPkgApi:config_overrides_context(PLUGIN_MAX_PACKAGE_SIZE=0),patch("controllers.console.workspace.plugin.PluginService.upload_pkg") as upload_pkg_mock,):- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="File size exceeds the maximum allowed size") as exc_info:method(api, "t1")assert "File size exceeds the maximum allowed size" in str(exc_info.value)@@ -943,7 +943,7 @@ class TestPluginUploadFromBundleApi:config_overrides_context(PLUGIN_MAX_BUNDLE_SIZE=0),patch("controllers.console.workspace.plugin.PluginService.upload_bundle") as upload_bundle_mock,):- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="File size exceeds the maximum allowed size") as exc_info:method(api, "t1")assert "File size exceeds the maximum allowed size" in str(exc_info.value)diff --git a/api/tests/unit_tests/controllers/console/workspace/test_tool_provider_apis.py b/api/tests/unit_tests/controllers/console/workspace/test_tool_provider_apis.pyindex 1d078671a53..ebfc88c2a68 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_tool_provider_apis.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_tool_provider_apis.py@@ -310,7 +310,7 @@ class TestBuiltinProviderApis:with (app.test_request_context("/", json={"credentials": empty_mapping(), "type": "invalid"}),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for BuiltinToolAddPayload\\\ntype"):method(api,BuiltinToolAddPayload(credentials=empty_mapping(), type="invalid"),@@ -612,7 +612,13 @@ class TestWorkflowApis:with (app.test_request_context("/"),):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for WorkflowToolGetQuery\\\n Value error, "+ "workflow_tool_id or workflow_app_id is required"+ ),+ ):method(api, "t", make_account())diff --git a/api/tests/unit_tests/controllers/console/workspace/test_trigger_provider_apis.py b/api/tests/unit_tests/controllers/console/workspace/test_trigger_provider_apis.pyindex bf5ab7485af..ae0f77dc9b1 100644--- a/api/tests/unit_tests/controllers/console/workspace/test_trigger_provider_apis.py+++ b/api/tests/unit_tests/controllers/console/workspace/test_trigger_provider_apis.py@@ -241,7 +241,7 @@ class TestTriggerSubscriptionBuilderApis:side_effect=Exception("err"),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="err"):method(api,TriggerSubscriptionBuilderVerifyPayload(credentials={}),@@ -523,7 +523,7 @@ class TestTriggerOAuthApis:return_value=MagicMock(credentials=None, expires_at=None),),):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Failed to get OAuth credentials from the provider\\."):method(api, "github")diff --git a/api/tests/unit_tests/controllers/files/test_plugin_file_upload.py b/api/tests/unit_tests/controllers/files/test_plugin_file_upload.pyindex 704afa30878..323f13f28a6 100644--- a/api/tests/unit_tests/controllers/files/test_plugin_file_upload.py+++ b/api/tests/unit_tests/controllers/files/test_plugin_file_upload.py@@ -211,7 +211,7 @@ class TestPluginUploadFileApi:monkeypatch.setattr(module, "request", _fake_request(_valid_args(), file=DummyFile()))application_services.return_value.plugin_file_uploads.upload.side_effect = storage_error- with pytest.raises(OSError) as error_info:+ with pytest.raises(OSError, match="storage unavailable") as error_info:unwrap(module.PluginUploadFileApi().post)(module.PluginUploadFileApi())assert error_info.value is storage_errordiff --git a/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py b/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.pyindex 44482d46611..478b17e5f6a 100644--- a/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py+++ b/api/tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py@@ -354,7 +354,7 @@ class TestPluginData:# Act & Assert - Malformed JSON triggers ValueErrorwith app.test_request_context(data="not valid json", content_type="application/json"):- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="invalid json") as exc_info:protected_view()# PEP 3134: the re-raised ValueError must chain the underlying JSON parse failure.assert exc_info.value.__cause__ is not Nonediff --git a/api/tests/unit_tests/controllers/inner_api/test_agent_files.py b/api/tests/unit_tests/controllers/inner_api/test_agent_files.pyindex efda15a4ef5..d55b6d5f343 100644--- a/api/tests/unit_tests/controllers/inner_api/test_agent_files.py+++ b/api/tests/unit_tests/controllers/inner_api/test_agent_files.py@@ -74,9 +74,9 @@ def test_upload_request_payload_requires_non_negative_max_size() -> None:"mimetype": "application/pdf",}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for AgentFileUploadRequestPayload\\\nmax_size"):AgentFileUploadRequestPayload.model_validate(payload)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for AgentFileUploadRequestPayload\\\nmax_size"):AgentFileUploadRequestPayload.model_validate({**payload, "max_size": -1})assert AgentFileUploadRequestPayload.model_validate({**payload, "max_size": 0}).max_size == 0diff --git a/api/tests/unit_tests/controllers/service_api/app/test_annotation.py b/api/tests/unit_tests/controllers/service_api/app/test_annotation.pyindex 71aa6e222b8..a7b7a8e813b 100644--- a/api/tests/unit_tests/controllers/service_api/app/test_annotation.py+++ b/api/tests/unit_tests/controllers/service_api/app/test_annotation.py@@ -224,7 +224,7 @@ class TestAnnotationReplyActionStatusApi:api = AnnotationReplyActionStatusApi()handler = unwrap(api.get)app_model = _app()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="The job does not exist\\."):handler(api, app_model=app_model, job_id="j1", action="enable")def test_error(self, monkeypatch: pytest.MonkeyPatch) -> None:diff --git a/api/tests/unit_tests/controllers/service_api/app/test_completion.py b/api/tests/unit_tests/controllers/service_api/app/test_completion.pyindex 1042fab9f05..c5fc2f92999 100644--- a/api/tests/unit_tests/controllers/service_api/app/test_completion.py+++ b/api/tests/unit_tests/controllers/service_api/app/test_completion.py@@ -196,7 +196,9 @@ class TestChatRequestPayload:def test_payload_rejects_invalid_uuid_conversation_id(self):"""Test that invalid UUID format raises ValueError."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ChatRequestPayload\\\nconversation_id"+ ) as exc_info:ChatRequestPayload(inputs={}, query="test", conversation_id="not-a-uuid")assert "valid UUID" in str(exc_info.value)diff --git a/api/tests/unit_tests/controllers/service_api/app/test_conversation.py b/api/tests/unit_tests/controllers/service_api/app/test_conversation.pyindex 2e8a6f5e1b6..f461dabfc8f 100644--- a/api/tests/unit_tests/controllers/service_api/app/test_conversation.py+++ b/api/tests/unit_tests/controllers/service_api/app/test_conversation.py@@ -124,12 +124,12 @@ class TestConversationListQuery:def test_query_rejects_limit_below_minimum(self):"""Test query rejects limit < 1."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ConversationListQuery\\\nlimit"):ConversationListQuery(limit=0)def test_query_rejects_limit_above_maximum(self):"""Test query rejects limit > 100."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ConversationListQuery\\\nlimit"):ConversationListQuery(limit=101)@pytest.mark.parametrize(@@ -164,18 +164,36 @@ class TestConversationRenamePayload:def test_payload_requires_name_when_auto_generate_false(self):"""Test that name is required when auto_generate is False."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ConversationRenamePayload\\\n Value error, "+ "name is required when auto_generate is false"+ ),+ ) as exc_info:ConversationRenamePayload(auto_generate=False)assert "name is required when auto_generate is false" in str(exc_info.value)def test_payload_requires_non_empty_name_when_auto_generate_false(self):"""Test that empty string name is rejected."""- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ConversationRenamePayload\\\n Value error, "+ "name is required when auto_generate is false"+ ),+ ):ConversationRenamePayload(name="", auto_generate=False)def test_payload_requires_non_whitespace_name_when_auto_generate_false(self):"""Test that whitespace-only name is rejected."""- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ConversationRenamePayload\\\n Value error, "+ "name is required when auto_generate is false"+ ),+ ):ConversationRenamePayload(name=" ", auto_generate=False)def test_payload_name_with_special_characters(self):@@ -221,37 +239,49 @@ class TestConversationVariablesQuery:def test_query_rejects_sql_injection_single_quote(self):"""Test that single quotes are rejected (SQL injection prevention)."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name="'; DROP TABLE users;--")assert "can only contain" in str(exc_info.value)def test_query_rejects_sql_injection_double_quote(self):"""Test that double quotes are rejected."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name='name"test')assert "can only contain" in str(exc_info.value)def test_query_rejects_sql_injection_semicolon(self):"""Test that semicolons are rejected."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name="name;malicious")assert "can only contain" in str(exc_info.value)def test_query_rejects_sql_injection_comment(self):"""Test that SQL comments are rejected."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name="name--comment")assert "invalid characters" in str(exc_info.value)def test_query_rejects_special_characters(self):"""Test that special characters are rejected."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name="name@domain")assert "can only contain" in str(exc_info.value)def test_query_rejects_backticks(self):"""Test that backticks are rejected (SQL injection prevention)."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"+ ) as exc_info:ConversationVariablesQuery(variable_name="`table`")assert "can only contain" in str(exc_info.value)@@ -537,11 +567,17 @@ class TestConversationService:class TestConversationPayloadsController:def test_rename_requires_name(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ConversationRenamePayload\\\n Value error, "+ "name is required when auto_generate is false"+ ),+ ):ConversationRenamePayload(auto_generate=False, name="")def test_variables_query_invalid_name(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ConversationVariablesQuery\\\nvariable_name"):ConversationVariablesQuery(variable_name="bad;")diff --git a/api/tests/unit_tests/controllers/service_api/app/test_message.py b/api/tests/unit_tests/controllers/service_api/app/test_message.pyindex 6d4770b30d4..b5cab07f6c2 100644--- a/api/tests/unit_tests/controllers/service_api/app/test_message.py+++ b/api/tests/unit_tests/controllers/service_api/app/test_message.py@@ -121,13 +121,13 @@ class TestMessageListQuery:def test_query_rejects_limit_below_minimum(self):"""Test query rejects limit < 1."""conversation_id = str(uuid.uuid4())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for MessageListQuery\\\nlimit"):MessageListQuery(conversation_id=conversation_id, limit=0) # pyrefly: ignore[bad-argument-type]def test_query_rejects_limit_above_maximum(self):"""Test query rejects limit > 100."""conversation_id = str(uuid.uuid4())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for MessageListQuery\\\nlimit"):MessageListQuery(conversation_id=conversation_id, limit=101) # pyrefly: ignore[bad-argument-type]@@ -198,7 +198,7 @@ class TestFeedbackListQuery:def test_query_rejects_page_below_minimum(self):"""Test query rejects page < 1."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for FeedbackListQuery\\\npage"):FeedbackListQuery(page=0) # pyrefly: ignore[bad-argument-type]def test_query_limit_boundaries(self):@@ -211,12 +211,12 @@ class TestFeedbackListQuery:def test_query_rejects_limit_below_minimum(self):"""Test query rejects limit < 1."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for FeedbackListQuery\\\nlimit"):FeedbackListQuery(limit=0) # pyrefly: ignore[bad-argument-type]def test_query_rejects_limit_above_maximum(self):"""Test query rejects limit > 101."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for FeedbackListQuery\\\nlimit"):FeedbackListQuery(limit=102) # pyrefly: ignore[bad-argument-type]diff --git a/api/tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py b/api/tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.pyindex 6a6d07ed1cd..b1b10993968 100644--- a/api/tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py+++ b/api/tests/unit_tests/controllers/service_api/dataset/rag_pipeline/test_rag_pipeline_workflow.py@@ -384,7 +384,7 @@ class TestPipelineRunApiEntity:def test_entity_missing_required_field(self):"""Test entity raises on missing required field."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="4 validation errors for PipelineRunApiEntity\\\ndatasource_info_list"):PipelineRunApiEntity.model_validate({"inputs": {},diff --git a/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_payloads.py b/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_payloads.pyindex d6755e957a6..dc88606fe94 100644--- a/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_payloads.py+++ b/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_payloads.py@@ -45,15 +45,15 @@ class TestDatasetCreatePayload:assert payload.embedding_model_provider == "openai"def test_payload_name_length_validation_min(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasetCreatePayload\\\nname"):DatasetCreatePayload(name="")def test_payload_name_length_validation_max(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasetCreatePayload\\\nname"):DatasetCreatePayload(name="A" * 41)def test_payload_description_max_length(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasetCreatePayload\\\ndescription"):DatasetCreatePayload(name="Dataset", description="A" * 401)@pytest.mark.parametrize("technique", ["high_quality", "economy"])@@ -93,9 +93,9 @@ class TestDatasetUpdatePayload:assert len(payload.partial_member_list) == 1def test_payload_name_length_validation(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasetUpdatePayload\\\nname"):DatasetUpdatePayload(name="")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for DatasetUpdatePayload\\\nname"):DatasetUpdatePayload(name="A" * 41)@@ -133,11 +133,11 @@ class TestTagCreatePayload:assert payload.name == "New Tag"def test_payload_name_length_min(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for TagCreatePayload\\\nname"):TagCreatePayload(name="")def test_payload_name_length_max(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for TagCreatePayload\\\nname"):TagCreatePayload(name="A" * 51)def test_payload_with_unicode_name(self) -> None:@@ -154,7 +154,7 @@ class TestTagUpdatePayload:assert payload.tag_id == "tag_123"def test_payload_requires_tag_id(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for TagUpdatePayload\\\ntag_id"):TagUpdatePayload.model_validate({"name": "Updated Tag"})@@ -166,7 +166,7 @@ class TestTagDeletePayload:assert payload.tag_id == "tag_to_delete"def test_payload_requires_tag_id(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for TagDeletePayload\\\ntag_id"):TagDeletePayload.model_validate({})@@ -179,7 +179,7 @@ class TestTagBindingPayload:assert payload.target_id == "dataset_123"def test_payload_rejects_empty_tag_ids(self) -> None:- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="1 validation error for TagBindingPayload\\\ntag_ids") as exc_info:TagBindingPayload(tag_ids=[], target_id="dataset_123")assert "Tag IDs is required" in str(exc_info.value)@@ -202,6 +202,9 @@ class TestTagUnbindingPayload:assert payload.target_id == "dataset_456"def test_payload_rejects_empty_tag_ids(self) -> None:- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=("1 validation error for TagUnbindingPayload\\\n Value error, Tag IDs is required\\."),+ ) as exc_info:TagUnbindingPayload(tag_ids=[], target_id="dataset_456")assert "Tag IDs is required" in str(exc_info.value)diff --git a/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py b/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.pyindex 96eb5c48afa..cffa59042d1 100644--- a/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py+++ b/api/tests/unit_tests/controllers/service_api/dataset/test_dataset_segment.py@@ -166,27 +166,27 @@ class TestSegmentCreatePayload:def test_payload_with_none_segments(self):"""Test payload with None segments is rejected."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for SegmentCreatePayload\\\nsegments"):SegmentCreatePayload.model_validate({"segments": None})def test_payload_with_empty_segments(self):"""Test payload with empty segments list is rejected."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for SegmentCreatePayload\\\nsegments"):SegmentCreatePayload.model_validate({"segments": []})def test_payload_requires_segments(self):"""Test payload requires a segments field."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for SegmentCreatePayload\\\nsegments"):SegmentCreatePayload.model_validate({})def test_payload_rejects_segment_without_content(self):"""Test each segment requires content."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for SegmentCreatePayload\\\nsegments\\.0\\.content"):SegmentCreatePayload.model_validate({"segments": [{"answer": "Answer only"}]})def test_payload_rejects_blank_content(self):"""Test content cannot be whitespace-only."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for SegmentCreateItemPayload\\\ncontent"):SegmentCreateItemPayload.model_validate({"content": " "})def test_payload_with_complex_segment_data(self):@@ -245,7 +245,7 @@ class TestChildChunkCreatePayload:def test_payload_requires_content(self):"""Test that content is required."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ChildChunkCreatePayload\\\ncontent"):ChildChunkCreatePayload.model_validate({})def test_payload_with_long_content(self):@@ -285,12 +285,12 @@ class TestChildChunkListQuery:def test_query_limit_minimum(self):"""Test query limit minimum validation."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ChildChunkListQuery\\\nlimit"):ChildChunkListQuery.model_validate({"limit": 0})def test_query_page_minimum(self):"""Test query page minimum validation."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for ChildChunkListQuery\\\npage"):ChildChunkListQuery.model_validate({"page": 0})def test_query_with_keyword(self):diff --git a/api/tests/unit_tests/controllers/service_api/dataset/test_hit_testing.py b/api/tests/unit_tests/controllers/service_api/dataset/test_hit_testing.pyindex 3083c9c1f60..5c853e53ddc 100644--- a/api/tests/unit_tests/controllers/service_api/dataset/test_hit_testing.py+++ b/api/tests/unit_tests/controllers/service_api/dataset/test_hit_testing.py@@ -101,7 +101,7 @@ class TestHitTestingPayload:def test_payload_query_too_long(self) -> None:"""Test payload rejects query over 250 characters."""- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for HitTestingPayload\\\nquery"):HitTestingPayload(query="x" * 251)def test_payload_query_at_max_length(self) -> None:diff --git a/api/tests/unit_tests/core/agent/strategy/test_plugin.py b/api/tests/unit_tests/core/agent/strategy/test_plugin.pyindex b08f81b4b06..d4459273e0e 100644--- a/api/tests/unit_tests/core/agent/strategy/test_plugin.py+++ b/api/tests/unit_tests/core/agent/strategy/test_plugin.py@@ -277,7 +277,7 @@ class TestInvoke:side_effect=ValueError("conversion failed"),)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="conversion failed"):list(strategy._invoke(params={}, user_id="user_1"))def test_invoke_manager_raises_exception(self, strategy: PluginAgentStrategy, mocker: MockerFixture) -> None:diff --git a/api/tests/unit_tests/core/agent/test_plugin_entities.py b/api/tests/unit_tests/core/agent/test_plugin_entities.pyindex edcf8f492a5..5530aa0f712 100644--- a/api/tests/unit_tests/core/agent/test_plugin_entities.py+++ b/api/tests/unit_tests/core/agent/test_plugin_entities.py@@ -109,7 +109,7 @@ class TestAgentStrategyParameterType:side_effect=ValueError("invalid"),)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="invalid"):enum_member.cast_value("bad")diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.pyindex 607732f0741..fe42c66dc40 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_dataset_manager.py@@ -221,7 +221,7 @@ class TestValidateAndSetDefaults:}}}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Dataset query variable is required when dataset is exist"):DatasetConfigManager.validate_and_set_defaults("tenant1", AppMode.COMPLETION, config, unbound_session)@@ -242,21 +242,21 @@ class TestExtractDatasetConfig:def test_extract_invalid_agent_mode_type(self, unbound_session: Session):config = {"agent_mode": "invalid"}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="agent_mode must be of object type"):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config, unbound_session)def test_extract_invalid_enabled_type(self, unbound_session: Session):config = {"agent_mode": {"enabled": "yes"}}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in agent_mode must be of boolean type"):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config, unbound_session)def test_extract_invalid_tools_type(self, unbound_session: Session):config = {"agent_mode": {"enabled": True, "tools": "invalid"}}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="tools in agent_mode must be a list of objects"):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config, unbound_session)@@ -270,7 +270,7 @@ class TestExtractDatasetConfig:"tools": [{"dataset": {"id": invalid_uuid, "enabled": True}}],}}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="id in dataset must be of UUID type"):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config, unbound_session)@@ -287,7 +287,7 @@ class TestExtractDatasetConfig:"tools": [{"dataset": {"id": valid_uuid, "enabled": True}}],}}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Dataset ID does not exist, please check your permission\\."):DatasetConfigManager.extract_dataset_config_for_legacy_compatibility("tenant1", AppMode.CHAT, config, unbound_session)diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.pyindex e5b581b6a09..d78d972356e 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_model_config_converter.py@@ -165,7 +165,7 @@ class TestModelConfigConverter:return_value=mock_manager,)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Model gpt\\-4 not exist\\."):ModelConfigConverter.convert(mock_app_config)@pytest.mark.parametrize(@@ -207,7 +207,7 @@ class TestModelConfigConverter:return_value=mock_manager,)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Model gpt\\-4 not exist\\."):ModelConfigConverter.convert(mock_app_config)# =============================diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.pyindex d78b2df66ef..7ebc10c5d6c 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_prompt_template_manager.py@@ -50,7 +50,7 @@ class TestPromptTemplateConfigManagerConvert:"chat_prompt_config": {"prompt": [message]},}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="(?:message role must be a string|message text must be a string)"):PromptTemplateConfigManager.convert(config)def test_convert_advanced_completion_with_roles(self):@@ -95,7 +95,10 @@ class TestValidateAndSetDefaults:def test_invalid_prompt_type_raises(self):config = {"prompt_type": "invalid", "model": self.valid_model}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("prompt_type must be in \\[<PromptType\\.SIMPLE: 'simple'>, <PromptType\\.ADVANCED: 'advanced'>\\]"),+ ):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_invalid_chat_prompt_config_type(self):@@ -105,7 +108,7 @@ class TestValidateAndSetDefaults:"model": self.valid_model,}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="chat_prompt_config must be of object type"):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_simple_mode_invalid_pre_prompt_type(self):@@ -115,7 +118,7 @@ class TestValidateAndSetDefaults:"model": self.valid_model,}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="pre_prompt must be of string type"):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_advanced_requires_one_config(self):@@ -126,7 +129,10 @@ class TestValidateAndSetDefaults:"model": {"mode": "chat"},}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("chat_prompt_config or completion_prompt_config is required when prompt_type is advanced"),+ ):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_advanced_invalid_model_mode(self):@@ -136,7 +142,9 @@ class TestValidateAndSetDefaults:"model": {"mode": "invalid"},}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match="model\\.mode must be in \\['completion', 'chat'\\] when prompt_type is advanced"+ ):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_advanced_chat_prompt_length_exceeds(self):@@ -146,7 +154,7 @@ class TestValidateAndSetDefaults:"model": {"mode": "chat"},}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="prompt messages must be less than 10"):PromptTemplateConfigManager.validate_and_set_defaults(AppMode.CHAT, config)def test_completion_prefix_defaults_set_when_empty(self):@@ -183,5 +191,5 @@ class TestValidatePostPrompt:def test_post_prompt_invalid_type(self):config = {"post_prompt": 123}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="post_prompt must be of string type"):PromptTemplateConfigManager.validate_post_prompt_and_set_defaults(config)diff --git a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.pyindex 77aaeb0a501..c6b57880048 100644--- a/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py+++ b/api/tests/unit_tests/core/app/app_config/easy_ui_based_app/test_variables_manager.py@@ -100,37 +100,40 @@ class TestValidateVariablesAndSetDefaults:def test_validate_user_input_form_not_list_raises(self):config = {"user_input_form": "invalid"}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="user_input_form must be a list of objects"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_invalid_key_raises(self):config = {"user_input_form": [{"invalid": {}}]}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match="Keys in user_input_form list can only be",+ ):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_missing_label_raises(self):config = {"user_input_form": [{VariableEntityType.TEXT_INPUT: {"variable": "name"}}]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="label is required in user_input_form"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_label_not_string_raises(self):config = {"user_input_form": [{VariableEntityType.TEXT_INPUT: {"variable": "name", "label": 123}}]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="label in user_input_form must be of string type"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_missing_variable_raises(self):config = {"user_input_form": [{VariableEntityType.TEXT_INPUT: {"label": "Name"}}]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="variable is required in user_input_form"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_variable_not_string_raises(self):config = {"user_input_form": [{VariableEntityType.TEXT_INPUT: {"label": "Name", "variable": 123}}]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="variable in user_input_form must be of string type"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)@pytest.mark.parametrize(@@ -149,7 +152,13 @@ class TestValidateVariablesAndSetDefaults:]}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:variable in user_input_form must be a string, and cannot start "+ "with a number|variable in user_input_form must be of string type)"+ ),+ ):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_required_default_and_type(self):@@ -181,7 +190,7 @@ class TestValidateVariablesAndSetDefaults:]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="required in user_input_form must be of boolean type"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_select_options_default_not_in_options_raises(self):@@ -198,7 +207,7 @@ class TestValidateVariablesAndSetDefaults:]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="default value in user_input_form must be in the options list"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)def test_validate_select_options_not_list_raises(self):@@ -214,7 +223,7 @@ class TestValidateVariablesAndSetDefaults:]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="options in user_input_form must be a list of strings"):BasicVariablesConfigManager.validate_variables_and_set_defaults(config)@@ -230,7 +239,7 @@ class TestValidateExternalDataToolsAndSetDefaults:def test_validate_external_data_tools_not_list_raises(self):config = {"external_data_tools": "invalid"}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="external_data_tools must be of list type"):BasicVariablesConfigManager.validate_external_data_tools_and_set_defaults("tenant", config)def test_validate_disabled_tool_skipped(self, mocker: MockerFixture):@@ -248,7 +257,7 @@ class TestValidateExternalDataToolsAndSetDefaults:def test_validate_enabled_tool_missing_type_raises(self):config = {"external_data_tools": [{"enabled": True, "config": {}}]}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="external_data_tools\\[\\]\\.type is required"):BasicVariablesConfigManager.validate_external_data_tools_and_set_defaults("tenant", config)def test_validate_enabled_tool_calls_factory(self, mocker: MockerFixture):diff --git a/api/tests/unit_tests/core/app/app_config/features/test_additional_feature_managers.py b/api/tests/unit_tests/core/app/app_config/features/test_additional_feature_managers.pyindex 12a4a86d86d..20d6827ee6e 100644--- a/api/tests/unit_tests/core/app/app_config/features/test_additional_feature_managers.py+++ b/api/tests/unit_tests/core/app/app_config/features/test_additional_feature_managers.py@@ -19,13 +19,13 @@ class TestAdditionalFeatureManagers:assert set(keys) == {"opening_statement", "suggested_questions"}def test_opening_statement_validate_types(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="opening_statement must be of string type"):OpeningStatementConfigManager.validate_and_set_defaults({"opening_statement": 123})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="suggested_questions must be of list type"):OpeningStatementConfigManager.validate_and_set_defaults({"opening_statement": "hi", "suggested_questions": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Elements in suggested_questions list must be of string type"):OpeningStatementConfigManager.validate_and_set_defaults({"opening_statement": "hi", "suggested_questions": [1]})@@ -42,9 +42,9 @@ class TestAdditionalFeatureManagers:assert config["retriever_resource"]["enabled"] is Falseassert keys == ["retriever_resource"]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="retriever_resource must be of dict type"):RetrievalResourceConfigManager.validate_and_set_defaults({"retriever_resource": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in retriever_resource must be of boolean type"):RetrievalResourceConfigManager.validate_and_set_defaults({"retriever_resource": {"enabled": "yes"}})def test_retrieval_resource_convert(self):@@ -56,9 +56,9 @@ class TestAdditionalFeatureManagers:assert config["speech_to_text"]["enabled"] is Falseassert keys == ["speech_to_text"]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="speech_to_text must be of dict type"):SpeechToTextConfigManager.validate_and_set_defaults({"speech_to_text": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in speech_to_text must be of boolean type"):SpeechToTextConfigManager.validate_and_set_defaults({"speech_to_text": {"enabled": "yes"}})assert SpeechToTextConfigManager.convert({"speech_to_text": {"enabled": True}}) is True@@ -69,15 +69,15 @@ class TestAdditionalFeatureManagers:assert config["suggested_questions_after_answer"]["enabled"] is Falseassert keys == ["suggested_questions_after_answer"]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="suggested_questions_after_answer must be of dict type"):SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in suggested_questions_after_answer must be of boolean type"):SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": {"enabled": "yes"}})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="prompt in suggested_questions_after_answer must be of string type"):SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": {"enabled": True, "prompt": 123}})@@ -89,11 +89,11 @@ class TestAdditionalFeatureManagers:SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": {"enabled": True, "prompt": "a" * 1001}})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="model in suggested_questions_after_answer must be of object type"):SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": {"enabled": True, "model": "bad"}})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="name in suggested_questions_after_answer\\.model must be of string type"):SuggestedQuestionsAfterAnswerConfigManager.validate_and_set_defaults({"suggested_questions_after_answer": {"enabled": True, "model": {"provider": "openai"}}})@@ -128,9 +128,9 @@ class TestAdditionalFeatureManagers:assert config["text_to_speech"]["enabled"] is Falseassert keys == ["text_to_speech"]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="text_to_speech must be of dict type"):TextToSpeechConfigManager.validate_and_set_defaults({"text_to_speech": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in text_to_speech must be of boolean type"):TextToSpeechConfigManager.validate_and_set_defaults({"text_to_speech": {"enabled": "yes"}})for field, value in (("voice", None), ("language", 42), ("autoPlay", "auto"), ("autoPlay", None)):with pytest.raises(ValueError, match=f"{field} in text_to_speech"):@@ -157,5 +157,8 @@ class TestAdditionalFeatureManagers:assert MoreLikeThisConfigManager.convert({"more_like_this": {"enabled": True}}) is Trueassert MoreLikeThisConfigManager.convert({"more_like_this": {"enabled": False}}) is False- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("more_like_this must be of dict type and enabled in more_like_this must be of boolean type"),+ ):MoreLikeThisConfigManager.validate_and_set_defaults({"more_like_this": "bad"})diff --git a/api/tests/unit_tests/core/app/app_config/test_entities.py b/api/tests/unit_tests/core/app/app_config/test_entities.pyindex b63fe414ee0..5822eaec0f7 100644--- a/api/tests/unit_tests/core/app/app_config/test_entities.py+++ b/api/tests/unit_tests/core/app/app_config/test_entities.py@@ -21,7 +21,7 @@ class TestAppConfigEntities:assert entity.options == []def test_variable_entity_rejects_invalid_json_schema(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for VariableEntity\\\njson_schema"):VariableEntity(variable="query",label="Query",@@ -31,7 +31,7 @@ class TestAppConfigEntities:def test_prompt_template_value_of(self) -> None:assert PromptTemplateEntity.PromptType.value_of("simple") == PromptTemplateEntity.PromptType.SIMPLE- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="invalid prompt type value missing"):PromptTemplateEntity.PromptType.value_of("missing")def test_dataset_retrieve_strategy_value_of(self) -> None:@@ -39,5 +39,5 @@ class TestAppConfigEntities:DatasetRetrieveConfigEntity.RetrieveStrategy.value_of("single")== DatasetRetrieveConfigEntity.RetrieveStrategy.SINGLE)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="invalid retrieve strategy value missing"):DatasetRetrieveConfigEntity.RetrieveStrategy.value_of("missing")diff --git a/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py b/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.pyindex 7c2cfbb5969..f73205b7dcc 100644--- a/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py+++ b/api/tests/unit_tests/core/app/app_config/workflow_ui_based_app/test_workflow_ui_based_app_manager.py@@ -104,7 +104,7 @@ class TestWorkflowVariablesConfigManagerConvert:mock_variable_entity.model_validate.side_effect = ValueError("validation error")# Act & Assert- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="validation error"):WorkflowVariablesConfigManager.convert(mock_workflow)def test_convert_normalizes_json_schema_string_to_dict(self, mock_workflow: Workflow) -> None:diff --git a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.pyindex 9f9e151e7bd..1584d15fc90 100644--- a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py+++ b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_config_manager.py@@ -238,7 +238,7 @@ class TestValidateAgentModeAndSetDefaults:["invalid", 123],)def test_agent_mode_type_validation(self, agent_mode):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="agent_mode must be of object type"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": agent_mode}, _session())@@ -250,31 +250,31 @@ class TestValidateAgentModeAndSetDefaults:assert updated["agent_mode"]["tools"] == []def test_enabled_must_be_bool(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in agent_mode must be of boolean type"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": {"enabled": "yes"}}, _session())def test_strategy_must_be_valid(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="strategy in agent_mode must be in the specified strategy list"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": {"enabled": True, "strategy": "invalid"}}, _session())def test_tools_must_be_list(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="tools in agent_mode must be a list of objects"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": {"enabled": True, "tools": "not-list"}}, _session())def test_old_tool_dataset_requires_id(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="id is required in dataset"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": {"enabled": True, "tools": [{"dataset": {"enabled": True}}]}}, _session())def test_old_tool_dataset_id_must_be_uuid(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="id in dataset must be of UUID type"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant",{"agent_mode": {"enabled": True, "tools": [{"dataset": {"enabled": True, "id": "bad"}}]}},@@ -287,7 +287,7 @@ class TestValidateAgentModeAndSetDefaults:return_value=False,)dataset_id = str(uuid.uuid4())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Dataset ID does not exist, please check your permission\\."):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant",{"agent_mode": {"enabled": True, "tools": [{"dataset": {"enabled": True, "id": dataset_id}}]}},@@ -295,7 +295,7 @@ class TestValidateAgentModeAndSetDefaults:)def test_old_tool_enabled_must_be_bool(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="enabled in agent_mode\\.tools must be of boolean type"):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant",{"agent_mode": {"enabled": True, "tools": [{"dataset": {"enabled": "yes", "id": str(uuid.uuid4())}}]}},@@ -306,7 +306,14 @@ class TestValidateAgentModeAndSetDefaults:def test_new_style_tool_requires_fields(self, missing_key):tool = {"enabled": True, "provider_type": "type", "provider_id": "id", "tool_name": "tool"}tool.pop(missing_key, None)- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:provider_id is required in agent_mode\\.tools|provider_type is "+ "required in agent_mode\\.tools|tool_name is required in "+ "agent_mode\\.tools|tool_parameters is required in agent_mode\\.tools)"+ ),+ ):AgentChatAppConfigManager.validate_agent_mode_and_set_defaults("tenant", {"agent_mode": {"enabled": True, "tools": [tool]}}, _session())diff --git a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.pyindex a4dbee5d7c1..db498ebaac6 100644--- a/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/agent_chat/test_agent_chat_app_generator.py@@ -119,7 +119,7 @@ class TestAgentChatAppGeneratorGenerate:def test_generate_rejects_blocking_mode(self, generator: AgentChatAppGenerator, sqlite_session: Session) -> None:app_model = _app()user = _account()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Agent Chat App does not support blocking mode"):generator.generate(session=sqlite_session,app_model=app_model,@@ -132,7 +132,7 @@ class TestAgentChatAppGeneratorGenerate:def test_generate_requires_query(self, generator: AgentChatAppGenerator, sqlite_session: Session) -> None:app_model = _app()user = _account()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="query is required"):generator.generate(session=sqlite_session,app_model=app_model,@@ -145,7 +145,7 @@ class TestAgentChatAppGeneratorGenerate:def test_generate_rejects_non_string_query(self, generator: AgentChatAppGenerator, sqlite_session: Session) -> None:app_model = _app()user = _account()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="query must be a string"):generator.generate(session=sqlite_session,app_model=app_model,@@ -162,7 +162,7 @@ class TestAgentChatAppGeneratorGenerate:user = _account()generator._get_app_model_config = CallRecorder(AppModelConfig(app_id="app1")) # type: ignore[method-assign]- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Only in App debug mode can override model config"):generator.generate(session=sqlite_session,app_model=app_model,diff --git a/api/tests/unit_tests/core/app/apps/chat/test_app_generator_and_runner.py b/api/tests/unit_tests/core/app/apps/chat/test_app_generator_and_runner.pyindex d2ee53ca43d..3802ab247cd 100644--- a/api/tests/unit_tests/core/app/apps/chat/test_app_generator_and_runner.py+++ b/api/tests/unit_tests/core/app/apps/chat/test_app_generator_and_runner.py@@ -121,7 +121,7 @@ def _bind_db_session(sqlite_session: Session, monkeypatch: pytest.MonkeyPatch):class TestChatAppGenerator:def test_generate_requires_query(self, unbound_session: Session):generator = ChatAppGenerator()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="query is required"):generator.generate(session=unbound_session,app_model=_app(),@@ -133,7 +133,7 @@ class TestChatAppGenerator:def test_generate_rejects_non_string_query(self, unbound_session: Session):generator = ChatAppGenerator()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="query must be a string"):generator.generate(session=unbound_session,app_model=_app(),@@ -233,7 +233,7 @@ class TestChatAppGenerator:def test_generate_rejects_model_config_override_for_non_debugger(self, unbound_session: Session):generator = ChatAppGenerator()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Only in App debug mode can override model config"):with (patch.object(ChatAppGenerator, "_get_app_model_config", return_value=AppModelConfig(app_id="app-1")),patch.object(AppModelConfig, "to_dict", return_value={}),@@ -300,7 +300,7 @@ class TestChatAppRunner:invoke_from=InvokeFrom.SERVICE_API,)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="App not found"):runner.run(app_generate_entity,DummyQueueManager(),diff --git a/api/tests/unit_tests/core/app/apps/common/test_graph_runtime_state_support.py b/api/tests/unit_tests/core/app/apps/common/test_graph_runtime_state_support.pyindex 201923e0e40..b373ecd3b6e 100644--- a/api/tests/unit_tests/core/app/apps/common/test_graph_runtime_state_support.py+++ b/api/tests/unit_tests/core/app/apps/common/test_graph_runtime_state_support.py@@ -43,7 +43,7 @@ def test_resolve_graph_runtime_state_reads_from_queue_when_cache_empty():def test_resolve_graph_runtime_state_raises_when_no_state_available():pipeline = _StubPipeline(cached_state=None, queue_state=None)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="graph runtime state not initialized\\."):pipeline._resolve_graph_runtime_state()@@ -60,5 +60,5 @@ def test_extract_workflow_run_id_raises_when_missing():state = _make_state(None)pipeline = _StubPipeline(cached_state=state, queue_state=None)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="workflow_execution_id missing from runtime state"):pipeline._extract_workflow_run_id(state)diff --git a/api/tests/unit_tests/core/app/apps/common/test_workflow_response_converter_truncation.py b/api/tests/unit_tests/core/app/apps/common/test_workflow_response_converter_truncation.pyindex e9780c817ce..b15f8500bc4 100644--- a/api/tests/unit_tests/core/app/apps/common/test_workflow_response_converter_truncation.py+++ b/api/tests/unit_tests/core/app/apps/common/test_workflow_response_converter_truncation.py@@ -401,7 +401,7 @@ class TestWorkflowResponseConverter:process_data={},)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="workflow_run_id missing before streaming workflow events"):converter.workflow_node_finish_to_stream_response(event=event,task_id="test-task-id",diff --git a/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py b/api/tests/unit_tests/core/app/apps/completion/test_app_runner.pyindex 1203f2c69d2..f337af850fb 100644--- a/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py+++ b/api/tests/unit_tests/core/app/apps/completion/test_app_runner.py@@ -260,7 +260,7 @@ class TestCompletionAppRunner:app_config = _build_app_config()app_generate_entity = _build_generate_entity(app_config)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="App not found"):runner.run(app_generate_entity, queue_manager, _message(), sqlite_session)def test_run_moderation_error_outputs_direct(diff --git a/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py b/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.pyindex 7fd35af82eb..04b359b045b 100644--- a/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/completion/test_completion_completion_app_generator.py@@ -135,7 +135,7 @@ def _persist_message(@pytest.mark.parametrize("sqlite_session", [TABLES], indirect=True)class TestCompletionAppGenerator:def test_generate_invalid_query_type(self, generator, sqlite_session: Session):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="query must be a string"):generator.generate(session=sqlite_session,app_model=_build_app_model(),@@ -146,7 +146,7 @@ class TestCompletionAppGenerator:)def test_generate_override_not_debugger(self, generator, sqlite_session: Session):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="^$"):generator.generate(session=sqlite_session,app_model=_build_app_model(),@@ -383,7 +383,7 @@ class TestCompletionAppGenerator:app_model.app_model_config_id = current_config.id_persist_message(sqlite_session)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Message app_model_config is None"):generator.generate_more_like_this(session=sqlite_session,app_model=app_model,diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.pyindex de16f2dc540..f702e0ed626 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_generator.py@@ -164,7 +164,7 @@ def _dummy_preserve[**P](*args: P.args, **kwargs: P.kwargs):def test_generate_dataset_missing(generator, sqlite_session: Session):pipeline = _build_pipeline()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Pipeline dataset is required"):generator.generate(session=sqlite_session,pipeline=pipeline,@@ -443,7 +443,7 @@ def test_generate_raises_when_workflow_not_found(generator, mocker: MockerFixtursession = sqlite_session- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Workflow not found: wf"):generator._generate(session=session,flask_app=flask_app,@@ -517,12 +517,12 @@ def test_generate_success_returns_converted(generator, mocker: MockerFixture, sqdef test_single_iteration_generate_validates_inputs(generator, sqlite_session: Session):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="node_id is required"):generator.single_iteration_generate(_build_pipeline(), _build_workflow(), "", _build_user(), {}, session=sqlite_session)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="inputs is required"):generator.single_iteration_generate(_build_pipeline(),_build_workflow(),@@ -536,7 +536,7 @@ def test_single_iteration_generate_validates_inputs(generator, sqlite_session: Sdef test_single_iteration_generate_dataset_required(generator, sqlite_session: Session):pipeline = _build_pipeline()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Pipeline dataset is required"):generator.single_iteration_generate(pipeline,_build_workflow(),@@ -684,7 +684,7 @@ def test_build_document_supports_online_drive_datasource_type(generator):def test_build_document_invalid_datasource_type(generator):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Unsupported datasource type: invalid"):generator._build_document(tenant_id="tenant",dataset_id="ds",@@ -715,7 +715,7 @@ def test_format_datasource_info_list_non_online_drive(generator):def test_format_datasource_info_list_missing_node_data(generator):workflow = _build_workflow()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Datasource node data not found"):generator._format_datasource_info_list(DatasourceProviderType.ONLINE_DRIVE,[],diff --git a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.pyindex ce8360eaada..64a354f2a45 100644--- a/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py+++ b/api/tests/unit_tests/core/app/apps/pipeline/test_pipeline_runner.py@@ -187,19 +187,19 @@ def test_get_workflow_returns_workflow(runner, sqlite_session: Session):def test_init_rag_pipeline_graph_invalid_config(mocker, runner):workflow = _workflow(graph={})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="nodes or edges not found in workflow graph"):runner._init_rag_pipeline_graph(workflow=workflow, graph_runtime_state=GraphRuntimeState(variable_pool=VariablePool(), start_at=0))workflow.graph = json.dumps({"nodes": "bad", "edges": []})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="nodes in workflow graph must be a list"):runner._init_rag_pipeline_graph(workflow=workflow, graph_runtime_state=GraphRuntimeState(variable_pool=VariablePool(), start_at=0))workflow.graph = json.dumps({"nodes": [], "edges": "bad"})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="edges in workflow graph must be a list"):runner._init_rag_pipeline_graph(workflow=workflow, graph_runtime_state=GraphRuntimeState(variable_pool=VariablePool(), start_at=0))@@ -209,7 +209,7 @@ def test_init_rag_pipeline_graph_not_found(mocker, runner):workflow = _workflow()mocker.patch.object(module.Graph, "init", return_value=None)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Unable to determine default root node ID from workflow graph"):runner._init_rag_pipeline_graph(workflow=workflow, graph_runtime_state=GraphRuntimeState(variable_pool=VariablePool(), start_at=0))@@ -277,7 +277,7 @@ def test_run_pipeline_not_found(sqlite_engine: Engine):runner = _build_runner(app_generate_entity, sqlite_engine, _workflow())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Pipeline not found"):runner.run()@@ -357,7 +357,7 @@ def test_run_workflow_not_initialized(sqlite_session: Session, sqlite_engine: Ensqlite_session.commit()runner = _build_runner(app_generate_entity, sqlite_engine, _workflow())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Workflow not initialized"):runner.run()diff --git a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py b/api/tests/unit_tests/core/app/apps/test_base_app_generator.pyindex e24fb7560fb..890d8edb5dd 100644--- a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py+++ b/api/tests/unit_tests/core/app/apps/test_base_app_generator.py@@ -58,7 +58,9 @@ def test_restore_workflow_run_graph_requires_persisted_snapshot(sqlite_session.add(workflow_run)sqlite_session.commit()- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match=("(?:Workflow run graph not found: run\\-id|Workflow run id is required when resuming)")+ ):BaseAppGenerator._restore_workflow_run_graph(session=sqlite_session,workflow=Workflow(graph="{}"),@@ -105,7 +107,7 @@ def test_validate_input_with_none_for_required_variable():)# Test with input None- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="test_var is required in input form") as exc_info:base_app_generator._validate_inputs(variable_entity=var,value=None,@@ -400,7 +402,7 @@ def test_validate_inputs_required_file_with_empty_string_fails():required=True,)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="test_file in input form must be a file") as exc_info:base_app_generator._validate_inputs(variable_entity=var_file,value="",diff --git a/api/tests/unit_tests/core/app/apps/test_base_app_queue_manager.py b/api/tests/unit_tests/core/app/apps/test_base_app_queue_manager.pyindex 52f47bfb79f..2debd2e3d8d 100644--- a/api/tests/unit_tests/core/app/apps/test_base_app_queue_manager.py+++ b/api/tests/unit_tests/core/app/apps/test_base_app_queue_manager.py@@ -30,7 +30,7 @@ def _redis_broken_pipe_error() -> RedisConnectionError:class TestBaseAppQueueManager:def test_init_requires_user_id(self):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="user is required"):DummyQueueManager(task_id="t1", user_id="", invoke_from=InvokeFrom.SERVICE_API)def test_publish_error_records_event(self):diff --git a/api/tests/unit_tests/core/app/features/rate_limiting/test_rate_limit.py b/api/tests/unit_tests/core/app/features/rate_limiting/test_rate_limit.pyindex 538b130cace..097fe7a28ed 100644--- a/api/tests/unit_tests/core/app/features/rate_limiting/test_rate_limit.py+++ b/api/tests/unit_tests/core/app/features/rate_limiting/test_rate_limit.py@@ -373,7 +373,7 @@ class TestRateLimitGenerator:wrapped_gen = rate_limit.generate(generator, request_id)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Test error"):list(wrapped_gen)redis_patch.hdel.assert_called_once_with("dify:rate_limit:test_client:active_requests", request_id)diff --git a/api/tests/unit_tests/core/app/task_pipeline/test_message_cycle_manager_optimization.py b/api/tests/unit_tests/core/app/task_pipeline/test_message_cycle_manager_optimization.pyindex 283e5159fab..3065022e93d 100644--- a/api/tests/unit_tests/core/app/task_pipeline/test_message_cycle_manager_optimization.py+++ b/api/tests/unit_tests/core/app/task_pipeline/test_message_cycle_manager_optimization.py@@ -528,7 +528,7 @@ class TestMessageCycleManagerOptimization:message_cycle_manager._application_generate_entity.app_config = SimpleNamespace(additional_features=None)message_cycle_manager._task_state = SimpleNamespace(metadata=TaskStateMetadata())- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Additional features not found"):message_cycle_manager.handle_retriever_resources(QueueRetrieverResourcesEvent(retriever_resources=[]))def test_handle_retriever_resources_skips_none_entries(self, message_cycle_manager):diff --git a/api/tests/unit_tests/core/app/workflow/test_node_factory.py b/api/tests/unit_tests/core/app/workflow/test_node_factory.pyindex 43888eca917..d6cc4dc391e 100644--- a/api/tests/unit_tests/core/app/workflow/test_node_factory.py+++ b/api/tests/unit_tests/core/app/workflow/test_node_factory.py@@ -80,14 +80,14 @@ class TestDifyNodeFactory:def test_create_node_unknown_type(self):factory = self._factory()- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="No class mapping found for node type: unknown"):factory.create_node({"id": "node-1", "data": {"type": "unknown"}})def test_create_node_missing_mapping(self, monkeypatch: pytest.MonkeyPatch):factory = self._factory()monkeypatch.setattr("core.workflow.node_factory.get_node_type_classes_mapping", lambda: {})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="No class mapping found for node type: start"):factory.create_node({"id": "node-1", "data": {"type": BuiltinNodeTypes.START}})def test_create_node_missing_latest_class(self, monkeypatch: pytest.MonkeyPatch):@@ -98,7 +98,7 @@ class TestDifyNodeFactory:)monkeypatch.setattr("core.workflow.node_factory.LATEST_VERSION", "latest")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="No latest version class found for node type: start"):factory.create_node({"id": "node-1", "data": {"type": BuiltinNodeTypes.START}})def test_create_node_selects_versioned_class(self, monkeypatch: pytest.MonkeyPatch):diff --git a/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py b/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.pyindex ea6451dc785..d55c4fc1a69 100644--- a/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py+++ b/api/tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py@@ -195,7 +195,7 @@ class TestDifyWorkflowCallbackHandler:bad_message.model_dump_json.side_effect = ValueError("JSON error")# Act & Assert- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="JSON error"):list(handler.on_tool_execution(tool_name=tool_name,diff --git a/api/tests/unit_tests/core/datasource/test_notion_provider.py b/api/tests/unit_tests/core/datasource/test_notion_provider.pyindex 6a137a1b7ca..bbbb24906d2 100644--- a/api/tests/unit_tests/core/datasource/test_notion_provider.py+++ b/api/tests/unit_tests/core/datasource/test_notion_provider.py@@ -201,7 +201,10 @@ class TestNotionExtractorAuthentication:providers = build_data_source_credentials(database_client=sqlite_session_factory).providers# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=("Must specify `integration_token` or set environment variable `NOTION_INTEGRATION_TOKEN`\\."),+ ) as exc_info:NotionExtractor(notion_workspace_id="workspace-123",notion_obj_id="page-456",@@ -386,7 +389,7 @@ class TestNotionExtractorPageRetrieval:mock_request.return_value = self._create_response({}, status_code=404)# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error fetching Notion block data: \\{\\}") as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)@@ -397,7 +400,7 @@ class TestNotionExtractorPageRetrieval:mock_request.return_value = self._create_response({"invalid": "structure"})# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error fetching Notion block data") as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)@@ -408,7 +411,7 @@ class TestNotionExtractorPageRetrieval:mock_request.side_effect = httpx.HTTPError("Network error")# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error fetching Notion block data") as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)@@ -1042,7 +1045,7 @@ class TestNotionExtractorIntegration:)# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="notion page type not supported") as exc_info:extractor.extract()assert "notion page type not supported" in str(exc_info.value)@@ -1205,7 +1208,7 @@ class TestNotionProviderController:)# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Datasource with name nonexistent_datasource not found") as exc_info:controller.get_datasource("nonexistent_datasource")assert "not found" in str(exc_info.value)@@ -1625,7 +1628,7 @@ class TestNotionExtractorErrorScenarios:mock_request.side_effect = error_value# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error fetching Notion block data") as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)@@ -1651,7 +1654,14 @@ class TestNotionExtractorErrorScenarios:mock_request.return_value = mock_response# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=(+ "(?:Error fetching Notion block data: Forbidden|Error fetching Notion "+ "block data: Not Found|Error fetching Notion block data: Rate limit "+ "exceeded|Error fetching Notion block data: Unauthorized)"+ ),+ ) as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)@@ -1677,7 +1687,7 @@ class TestNotionExtractorErrorScenarios:mock_request.return_value = mock_response# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error fetching Notion block data") as exc_info:extractor._get_notion_block_data("page-456")assert "Error fetching Notion block data" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/entities/test_entities_parameter_entities.py b/api/tests/unit_tests/core/entities/test_entities_parameter_entities.pyindex 0ba8805e4c8..bb7d05500d9 100644--- a/api/tests/unit_tests/core/entities/test_entities_parameter_entities.py+++ b/api/tests/unit_tests/core/entities/test_entities_parameter_entities.py@@ -18,7 +18,7 @@ def test_common_parameter_type_values_are_stable() -> None:assert CommonParameterType.OBJECT.value == "object"assert CommonParameterType.DATE.value == "date"assert CommonParameterType.DATE_RANGE.value == "date-range"- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'date\\-picker' is not a valid PluginParameterType"):PluginParameterType("date-picker")@@ -28,7 +28,14 @@ def test_cast_date_accepts_only_canonical_calendar_dates() -> None:assert cast_parameter_value(PluginParameterType.DATE, "2024-02-29") == "2024-02-29"for value in ("a", "2024-02-30", "20240229", 20240229):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:The date parameter must be a string in YYYY\\-MM\\-DD format\\.|"+ "The date parameter must be a valid date in YYYY\\-MM\\-DD format\\.|"+ "The date parameter must use YYYY\\-MM\\-DD format\\.)"+ ),+ ):cast_parameter_value(PluginParameterType.DATE, value)@@ -50,7 +57,15 @@ def test_cast_date_range_validates_optional_range() -> None:{"start": "2024-01-02", "end": "2024-01-01"},'{"start":"2024-01-02","end":"2024-01-01"}',):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:The date\\-range start date must not be after the end date\\.|The "+ "date\\-range start parameter must be a string in YYYY\\-MM\\-DD "+ "format\\.|The date\\-range start parameter must be a valid date in "+ "YYYY\\-MM\\-DD format\\.)"+ ),+ ):cast_parameter_value(PluginParameterType.DATE_RANGE, value)diff --git a/api/tests/unit_tests/core/helper/code_executor/jinja2/test_jinja2_sandbox.py b/api/tests/unit_tests/core/helper/code_executor/jinja2/test_jinja2_sandbox.pyindex 7ff7aa166c7..bb80c9c9800 100644--- a/api/tests/unit_tests/core/helper/code_executor/jinja2/test_jinja2_sandbox.py+++ b/api/tests/unit_tests/core/helper/code_executor/jinja2/test_jinja2_sandbox.py@@ -49,7 +49,14 @@ class TestJinja2TransformCallerSandbox:runner, preload = Jinja2TemplateTransformer.transform_caller(malicious_template, {})ns: dict = {}exec(compile(preload, "<preload>", "exec"), ns) # noqa: S102- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=(+ "(?:access to attribute '__class__' of 'str' object is unsafe\\.|"+ "access to attribute '__globals__' of 'function' object is unsafe\\.|"+ "access to attribute '__init__' of 'type' object is unsafe\\.)"+ ),+ ) as exc_info:exec(compile(runner, "<runner>", "exec"), ns) # noqa: S102assert "unsafe" in str(exc_info.value).lower() or "security" in str(exc_info.value).lower()diff --git a/api/tests/unit_tests/core/helper/test_encrypter.py b/api/tests/unit_tests/core/helper/test_encrypter.pyindex bab4747dc69..b99d599d108 100644--- a/api/tests/unit_tests/core/helper/test_encrypter.py+++ b/api/tests/unit_tests/core/helper/test_encrypter.py@@ -80,7 +80,7 @@ class TestEncryptToken:def test_tenant_not_found(self):"""Test error when tenant doesn't exist"""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Tenant with id invalid\\-tenant not found") as exc_info:encrypt_token("invalid-tenant", "test_token")assert "Tenant with id invalid-tenant not found" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/helper/test_ssrf_proxy.py b/api/tests/unit_tests/core/helper/test_ssrf_proxy.pyindex d522367f28e..b096a080042 100644--- a/api/tests/unit_tests/core/helper/test_ssrf_proxy.py+++ b/api/tests/unit_tests/core/helper/test_ssrf_proxy.py@@ -146,7 +146,7 @@ def test_retry_exceed_max_retries(mock_get_client, client_factory, monkeypatch:mock_client, send_calls = client_factory(mock_response)mock_get_client.return_value = mock_client- with pytest.raises(Exception) as e:+ with pytest.raises(Exception, match="Reached maximum retries \\(2\\) for URL http://example\\.com") as e:make_request("GET", "http://example.com", max_retries=SSRF_DEFAULT_MAX_RETRIES - 1)assert str(e.value) == f"Reached maximum retries ({SSRF_DEFAULT_MAX_RETRIES - 1}) for URL http://example.com"assert len(send_calls) == SSRF_DEFAULT_MAX_RETRIESdiff --git a/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py b/api/tests/unit_tests/core/mcp/auth/test_auth_flow.pyindex 594432dc613..3ff42fa7422 100644--- a/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py+++ b/api/tests/unit_tests/core/mcp/auth/test_auth_flow.py@@ -140,7 +140,7 @@ class TestRedisStateManagement:"""Test retrieving non-existent state from Redis."""mock_redis.get.return_value = None- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="State parameter has expired or does not exist") as exc_info:_retrieve_redis_state("nonexistent-key")assert "State parameter has expired or does not exist" in str(exc_info.value)@@ -150,7 +150,9 @@ class TestRedisStateManagement:"""Test retrieving invalid JSON state from Redis."""mock_redis.get.return_value = '{"invalid": json}'- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="Invalid state parameter: 1 validation error for OAuthCallbackState"+ ) as exc_info:_retrieve_redis_state("test-key")assert "Invalid state parameter" in str(exc_info.value)@@ -342,7 +344,9 @@ class TestAuthorizationFlow:)client_info = OAuthClientInformation(client_id="test-client-id")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="Incompatible auth server: does not support response type code"+ ) as exc_info:start_authorization("https://api.example.com",metadata,@@ -412,7 +416,7 @@ class TestAuthorizationFlow:client_info = OAuthClientInformation(client_id="test-client-id")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Token exchange failed: HTTP 400") as exc_info:exchange_authorization("https://api.example.com",None,@@ -525,7 +529,9 @@ class TestAuthorizationFlow:)client_metadata = OAuthClientMetadata(client_name="Dify", redirect_uris=["https://redirect.example.com"])- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match=('Client registration failed: HTTP 400, Response: \\{"error":"invalid_redirect_uri"\\}')+ ) as exc_info:register_client("https://api.example.com", metadata, client_metadata)message = str(exc_info.value)@@ -542,7 +548,9 @@ class TestAuthorizationFlow:)client_metadata = OAuthClientMetadata(client_name="Dify", redirect_uris=["https://redirect.example.com"])- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="Incompatible auth server: does not support dynamic client registration"+ ) as exc_info:register_client("https://api.example.com", metadata, client_metadata)assert "does not support dynamic client registration" in str(exc_info.value)@@ -709,7 +717,9 @@ class TestAuthOrchestration:provider.credentials["client_information"] = {"client_id": "existing-client"}- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="State parameter is required when exchanging authorization code"+ ) as exc_info:auth(provider, authorization_code="auth-code")assert "State parameter is required" in str(exc_info.value)@@ -780,7 +790,9 @@ class TestAuthOrchestration:provider.credentials.pop("client_information", None)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match=("Existing OAuth client information is required when exchanging an authorization code")+ ) as exc_info:auth(provider, authorization_code="auth-code")assert "Existing OAuth client information is required" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/mcp/test_mcp_client.py b/api/tests/unit_tests/core/mcp/test_mcp_client.pyindex 507ad07f20f..3a62d571047 100644--- a/api/tests/unit_tests/core/mcp/test_mcp_client.py+++ b/api/tests/unit_tests/core/mcp/test_mcp_client.py@@ -372,7 +372,7 @@ class TestMCPClient:"""Test list_tools when session not initialized."""client = MCPClient(server_url="http://test.example.com")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Session not initialized\\.") as exc_info:client.list_tools()assert "Session not initialized" in str(exc_info.value)@@ -403,7 +403,7 @@ class TestMCPClient:"""Test invoke_tool when session not initialized."""client = MCPClient(server_url="http://test.example.com")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Session not initialized\\.") as exc_info:client.invoke_tool("test-tool", {"arg": "value"})assert "Session not initialized" in str(exc_info.value)@@ -451,7 +451,7 @@ class TestMCPClient:client._session = Mock()client._initialized = True- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error during cleanup: Cleanup error") as exc_info:client.cleanup()assert "Error during cleanup: Cleanup error" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/ops/test_utils.py b/api/tests/unit_tests/core/ops/test_utils.pyindex ee4f6518892..313f345b2d8 100644--- a/api/tests/unit_tests/core/ops/test_utils.py+++ b/api/tests/unit_tests/core/ops/test_utils.py@@ -152,13 +152,13 @@ class TestValidateUrlWithPath:def test_restricted_scheme_rejects_http(self):"""Test https-only validation rejects http and names only https in the error"""- with pytest.raises(ValueError) as excinfo:+ with pytest.raises(ValueError, match="URL must start with https://") as excinfo:validate_url_with_path("http://langsmith.internal/api", "https://default.com", allowed_schemes=("https",))assert str(excinfo.value) == "URL must start with https://"def test_default_schemes_keep_original_error_message(self):"""Test the two-scheme default keeps the exact message existing providers assert on"""- with pytest.raises(ValueError) as excinfo:+ with pytest.raises(ValueError, match="URL must start with https:// or http://") as excinfo:validate_url_with_path("ftp://example.com", "https://default.com")assert str(excinfo.value) == "URL must start with https:// or http://"diff --git a/api/tests/unit_tests/core/plugin/test_endpoint_client.py b/api/tests/unit_tests/core/plugin/test_endpoint_client.pyindex 2ef2aeb1b45..082ba9b0c89 100644--- a/api/tests/unit_tests/core/plugin/test_endpoint_client.py+++ b/api/tests/unit_tests/core/plugin/test_endpoint_client.py@@ -292,7 +292,9 @@ class TestPluginEndpointClientDelete:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception, match="req_id: PluginDaemonUnauthorizedError: unauthorized access"+ ) as exc_info:endpoint_client.delete_endpoint(tenant_id=tenant_id,user_id=user_id,diff --git a/api/tests/unit_tests/core/plugin/test_plugin_manager.py b/api/tests/unit_tests/core/plugin/test_plugin_manager.pyindex 290c7301bbe..c08dda3d3b1 100644--- a/api/tests/unit_tests/core/plugin/test_plugin_manager.py+++ b/api/tests/unit_tests/core/plugin/test_plugin_manager.py@@ -460,7 +460,7 @@ class TestPluginValidation:def test_plugin_manifest_invalid_author_format(self):"""Test that invalid author format raises validation error."""# Arrange & Act & Assert: Creating a declaration with invalid author should fail- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for PluginDeclaration\\\nauthor"):PluginDeclaration(version="1.0.0",author="invalid author with spaces!@#", # Invalid author format@@ -478,7 +478,7 @@ class TestPluginValidation:def test_plugin_manifest_invalid_name_format(self):"""Test that invalid plugin name format raises validation error."""# Arrange & Act & Assert: Creating a declaration with invalid name should fail- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="1 validation error for PluginDeclaration\\\nname"):PluginDeclaration(version="1.0.0",author="test-author",diff --git a/api/tests/unit_tests/core/plugin/test_plugin_runtime.py b/api/tests/unit_tests/core/plugin/test_plugin_runtime.pyindex b72856395f9..922aed4567f 100644--- a/api/tests/unit_tests/core/plugin/test_plugin_runtime.py+++ b/api/tests/unit_tests/core/plugin/test_plugin_runtime.py@@ -549,7 +549,10 @@ class TestPluginRuntimeErrorHandling:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=("got unknown error from plugin daemon: UnknownErrorType, message: Unknown error occurred"),+ ) as exc_info:plugin_client._request_with_plugin_daemon_response("POST", "plugin/test-tenant/test", bool)assert "got unknown error from plugin daemon" in str(exc_info.value)@@ -572,7 +575,7 @@ class TestPluginRuntimeErrorHandling:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="got empty data from plugin daemon") as exc_info:plugin_client._request_with_plugin_daemon_response("GET", "plugin/test-tenant/test", bool)assert "got empty data from plugin daemon" in str(exc_info.value)@@ -996,7 +999,13 @@ class TestPluginRuntimeEdgeCases:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "Failed to parse response from plugin daemon to "+ "PluginDaemonBasicResponse \\[bool\\], url: plugin/test\\-tenant/test"+ ),+ ):plugin_client._request_with_plugin_daemon_response("GET", "plugin/test-tenant/test", bool)def test_invalid_response_structure(self, plugin_client, mock_config):@@ -1007,7 +1016,13 @@ class TestPluginRuntimeEdgeCases:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "Failed to parse response from plugin daemon to "+ "PluginDaemonBasicResponse \\[bool\\], url: plugin/test\\-tenant/test"+ ),+ ):plugin_client._request_with_plugin_daemon_response("GET", "plugin/test-tenant/test", bool)def test_streaming_with_invalid_json_line(self, plugin_client, mock_config):@@ -1035,7 +1050,7 @@ class TestPluginRuntimeEdgeCases:first_result = next(results)assert first_result.value == "valid"- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="\\{invalid json\\}"):next(results)def test_request_with_bytes_data(self, plugin_client, mock_config):@@ -1111,7 +1126,7 @@ class TestPluginRuntimeEdgeCases:with patch("httpx.request", return_value=mock_response, autospec=True):# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Plain text error message, code: \\-1") as exc_info:plugin_client._request_with_plugin_daemon_response("GET", "plugin/test-tenant/test", bool)assert "Plain text error message" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/plugin/utils/test_chunk_merger.py b/api/tests/unit_tests/core/plugin/utils/test_chunk_merger.pyindex 4e37e65b535..314f6bff026 100644--- a/api/tests/unit_tests/core/plugin/utils/test_chunk_merger.py+++ b/api/tests/unit_tests/core/plugin/utils/test_chunk_merger.py@@ -125,7 +125,9 @@ class TestChunkMerger:),)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError, match="File is too large which reached the limit of 0\\.00095367431640625MB"+ ) as exc_info:list(merge_blob_chunks(mock_generator(), max_file_size=1000))assert "File is too large" in str(exc_info.value)@@ -141,7 +143,7 @@ class TestChunkMerger:),)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="File chunk is too large which reached the limit of 8\\.0KB") as exc_info:list(merge_blob_chunks(mock_generator(), max_chunk_size=8192))assert "File chunk is too large" in str(exc_info.value)@@ -216,7 +218,7 @@ class TestChunkMerger:),)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="File is too large which reached the limit of 0\\.000286102294921875MB"):list(merge_blob_chunks(mock_generator2(), max_file_size=300))def test_merge_blob_chunks_data_integrity(self):diff --git a/api/tests/unit_tests/core/rag/datasource/vdb/test_field.py b/api/tests/unit_tests/core/rag/datasource/vdb/test_field.pyindex 6a614f07a1c..99fac5f10a5 100644--- a/api/tests/unit_tests/core/rag/datasource/vdb/test_field.py+++ b/api/tests/unit_tests/core/rag/datasource/vdb/test_field.py@@ -23,7 +23,12 @@ class TestParseMetadataJson:assert parse_metadata_json("{}") == {}def test_invalid_json_raises_value_error(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for dict\\[str,any\\]\\\n Invalid JSON: key must be a string at line 1 column 2"+ ),+ ):parse_metadata_json("{invalid json")def test_nested_metadata(self) -> None:diff --git a/api/tests/unit_tests/core/rag/docstore/test_dataset_docstore.py b/api/tests/unit_tests/core/rag/docstore/test_dataset_docstore.pyindex 813ea0709b6..e9b48cdff8b 100644--- a/api/tests/unit_tests/core/rag/docstore/test_dataset_docstore.py+++ b/api/tests/unit_tests/core/rag/docstore/test_dataset_docstore.py@@ -324,7 +324,7 @@ class TestDatasetDocumentStoreAddDocuments(_UsesSQLiteSession):)store = DatasetDocumentStore(dataset=_dataset(), user_id=USER_ID, document_id=DOCUMENT_ID)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="zip\\(\\) argument 2 is shorter than argument 1"):store.add_documents(session=sqlite_session, docs=[document], token_counts=[])assert sqlite_session.scalar(select(func.count()).select_from(DocumentSegment)) == 0diff --git a/api/tests/unit_tests/core/rag/embedding/test_cached_embedding.py b/api/tests/unit_tests/core/rag/embedding/test_cached_embedding.pyindex 89634c9e7c3..909fbbc85ac 100644--- a/api/tests/unit_tests/core/rag/embedding/test_cached_embedding.py+++ b/api/tests/unit_tests/core/rag/embedding/test_cached_embedding.py@@ -454,7 +454,7 @@ class TestCacheEmbeddingMultimodalQuery:mock_redis.get.return_value = Nonemock_model_instance.invoke_multimodal_embedding.return_value = embedding_result- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Normalized embedding is nan please try again") as exc_info:cache_embedding.embed_multimodal_query(document)assert "Normalized embedding is nan" in str(exc_info.value)@@ -471,7 +471,7 @@ class TestCacheEmbeddingMultimodalQuery:mock_redis.get.return_value = Nonemock_model_instance.invoke_multimodal_embedding.side_effect = Exception("API Error")- with pytest.raises(Exception) as exc_info:+ with pytest.raises(Exception, match="API Error") as exc_info:cache_embedding.embed_multimodal_query(document)assert "API Error" in str(exc_info.value)diff --git a/api/tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py b/api/tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.pyindex 461258033ee..9b1646e4f59 100644--- a/api/tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py+++ b/api/tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py@@ -1472,7 +1472,7 @@ class TestRetrievalService:mock_retrieve.side_effect = side_effect_with_exception# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Search failed") as exc_info:RetrievalService.retrieve(retrieval_method=RetrievalMethod.SEMANTIC_SEARCH,dataset_id=mock_dataset.id,@@ -4103,7 +4103,7 @@ class TestDatasetRetrievalAdditionalHelpers:assert prompt_messages_completion == ["prompt"]assert stop_completion == []- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'unknown\\-mode' is not a valid ModelMode"):retrieval._get_prompt_template(model_config=model_config_chat,mode="unknown-mode",@@ -4579,7 +4579,14 @@ class TestKnowledgeRetrievalCoverage:patch("core.rag.retrieval.dataset_retrieval.ModelManager.for_tenant") as mock_model_manager,):mock_model_manager.return_value.get_model_instance.return_value = model_instance- with pytest.raises(Exception) as exc_info:+ with pytest.raises(+ Exception,+ match=(+ "(?:Dify Hosted OpenAI gpt\\-4 currently not support\\.|Model gpt\\-4 "+ "credentials is not initialized\\.|Model provider openai quota "+ "exceeded\\.)"+ ),+ ) as exc_info:retrieval.knowledge_retrieval(self.orm_session, request)mock_model_manager.assert_called_once_with(tenant_id="tenant-1", user_id="user-1")assert error_cls in type(exc_info.value).__name__@@ -5830,7 +5837,7 @@ class TestInternalHooksCoverage:assert len(ranked) == 1assert ranked[0].metadata.get("score") == 0.0- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="metadata_model_config is required"):retrieval._automatic_metadata_filter_func(self.orm_session,dataset_ids=[str(uuid4())],diff --git a/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py b/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.pyindex 3fbe1993bd1..def06d9f0e9 100644--- a/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py+++ b/api/tests/unit_tests/core/trigger/debug/test_debug_event_selectors.py@@ -271,7 +271,7 @@ class TestCreateEventPoller:def test_raises_for_unknown_type(self) -> None:wf = _workflow_with_node(BuiltinNodeTypes.START)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="unable to create event poller for node type start") as exc_info:create_event_poller(wf, "t1", "u1", "a1", "n1")assert str(exc_info.value) == "unable to create event poller for node type start"@@ -281,7 +281,7 @@ class TestCreateEventPoller:with (patch.object(Workflow, "get_node_config_by_id", return_value=None),- pytest.raises(ValueError),+ pytest.raises(ValueError, match="\\('Node data not found for node %s', 'n1'\\)"),):create_event_poller(wf, "t1", "u1", "a1", "n1")diff --git a/api/tests/unit_tests/core/trigger/test_trigger_manager.py b/api/tests/unit_tests/core/trigger/test_trigger_manager.pyindex fbe8f09edbf..14b600fce6a 100644--- a/api/tests/unit_tests/core/trigger/test_trigger_manager.py+++ b/api/tests/unit_tests/core/trigger/test_trigger_manager.py@@ -169,7 +169,7 @@ class TestGetTriggerProvider:mock_ctx.plugin_trigger_providers_lock.get.return_value = Lock()mock_client.return_value.fetch_trigger_provider.return_value = None- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Trigger provider org/plug/missing not found"):TriggerManager.get_trigger_provider("t1", TriggerProviderID("org/plug/missing"))@patch("core.trigger.trigger_manager.PluginTriggerClient")@@ -179,7 +179,7 @@ class TestGetTriggerProvider:mock_ctx.plugin_trigger_providers_lock.get.return_value = Lock()mock_client.return_value.fetch_trigger_provider.side_effect = PluginNotFoundError("gone")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Trigger provider org/plug/miss not found"):TriggerManager.get_trigger_provider("t1", TriggerProviderID("org/plug/miss"))@patch("core.trigger.trigger_manager.PluginTriggerClient")diff --git a/api/tests/unit_tests/core/workflow/nodes/code/test_code_node_output_validation.py b/api/tests/unit_tests/core/workflow/nodes/code/test_code_node_output_validation.pyindex 18771ca3ee1..2cdd0c07ff8 100644--- a/api/tests/unit_tests/core/workflow/nodes/code/test_code_node_output_validation.py+++ b/api/tests/unit_tests/core/workflow/nodes/code/test_code_node_output_validation.py@@ -66,15 +66,19 @@ def test_transform_result_validates_nested_values_and_limits() -> None:"string_array_validator": [1],"object_validator": {"result": "1", "depth": {"depth": {"depth": "1"}}},}- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Output string_validator must be a string, got int instead\\."):node._transform_result(wrong_types, outputs)overlong = valid | {"string_validator": "1" * (dify_config.CODE_MAX_STRING_LENGTH + 1)}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match=("The length of output variable `string_validator` must be less than 400000 characters")+ ):node._transform_result(overlong, outputs)oversized_array = valid | {"number_array_validator": [1, 2, 3, 3.333] * 2000}- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match=("The length of output variable `number_array_validator` must be less than 1000 elements\\.")+ ):node._transform_result(oversized_array, outputs)@@ -83,7 +87,9 @@ def test_transform_result_validates_object_arrays() -> None:outputs = {"object_list": CodeNodeData.Output(type="array[object]")}node._transform_result({"object_list": [{"result": 1}, {"result": [1, 2, 3]}]}, outputs)- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match=("Output object_list\\[1\\] is not an object, got <class 'int'> instead at index 1\\.")+ ):node._transform_result({"object_list": [{"result": 1}, 1]}, outputs)diff --git a/api/tests/unit_tests/core/workflow/nodes/test_base_node.py b/api/tests/unit_tests/core/workflow/nodes/test_base_node.pyindex a05151f79b0..d9630f69676 100644--- a/api/tests/unit_tests/core/workflow/nodes/test_base_node.py+++ b/api/tests/unit_tests/core/workflow/nodes/test_base_node.py@@ -103,7 +103,7 @@ def test_node_accepts_invoke_from_enum():assert dify_ctx.user_from == UserFrom.ACCOUNTassert dify_ctx.invoke_from == InvokeFrom.DEBUGGERassert node.get_run_context_value("missing") is None- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="run_context missing required key: missing"):node.require_run_context_value("missing")diff --git a/api/tests/unit_tests/extensions/otel/decorators/test_base.py b/api/tests/unit_tests/extensions/otel/decorators/test_base.pyindex c9f05eb1d10..b6e644b8e95 100644--- a/api/tests/unit_tests/extensions/otel/decorators/test_base.py+++ b/api/tests/unit_tests/extensions/otel/decorators/test_base.py@@ -115,7 +115,7 @@ class TestTraceSpanWithMemoryExporter:def test_func() -> None:raise ValueError("test error")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="test error"):test_func()spans = memory_span_exporter.get_finished_spans()diff --git a/api/tests/unit_tests/extensions/otel/decorators/test_handler.py b/api/tests/unit_tests/extensions/otel/decorators/test_handler.pyindex 688b6d1f335..8e410b9c7e9 100644--- a/api/tests/unit_tests/extensions/otel/decorators/test_handler.py+++ b/api/tests/unit_tests/extensions/otel/decorators/test_handler.py@@ -207,7 +207,7 @@ class TestSpanHandlerWrapper:def test_func() -> None:raise ValueError("test error")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="test error"):handler.wrapper(tracer, test_func)spans = memory_span_exporter.get_finished_spans()diff --git a/api/tests/unit_tests/extensions/storage/test_clickzetta_volume_paths.py b/api/tests/unit_tests/extensions/storage/test_clickzetta_volume_paths.pyindex bc03add50cb..0d031763297 100644--- a/api/tests/unit_tests/extensions/storage/test_clickzetta_volume_paths.py+++ b/api/tests/unit_tests/extensions/storage/test_clickzetta_volume_paths.py@@ -28,13 +28,31 @@ def _table_storage() -> ClickZettaVolumeStorage:def test_config_validation() -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ClickZettaVolumeConfig\\\n Value error, "+ "CLICKZETTA_VOLUME_USERNAME or CLICKZETTA_USERNAME is required"+ ),+ ):ClickZettaVolumeConfig(username="", password="pass", instance="instance")- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ClickZettaVolumeConfig\\\n Value error, "+ "CLICKZETTA_VOLUME_TYPE must be one of: table, user, external"+ ),+ ):ClickZettaVolumeConfig(username="user", password="pass", instance="instance", volume_type="invalid_type")- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ClickZettaVolumeConfig\\\n Value error, "+ "CLICKZETTA_VOLUME_NAME is required for external volume type"+ ),+ ):ClickZettaVolumeConfig(username="user",password="pass",diff --git a/api/tests/unit_tests/factories/test_variable_factory.py b/api/tests/unit_tests/factories/test_variable_factory.pyindex 0f6569b6133..9ac5def1ddd 100644--- a/api/tests/unit_tests/factories/test_variable_factory.py+++ b/api/tests/unit_tests/factories/test_variable_factory.py@@ -928,9 +928,11 @@ class TestBuildSegmentValueErrors:# Use test value directlytest_value = test_case.test_value- with pytest.raises(ValueError) as exc_info: # noqa: PT012- segment = variable_factory.build_segment(test_value)- pytest.fail(f"Test case {index} ({test_case.name}) should raise ValueError but not, result={segment}")+ with pytest.raises(+ ValueError,+ match="not supported value",+ ) as exc_info:+ variable_factory.build_segment(test_value)error_message = str(exc_info.value)assert "not supported value" in error_message, (diff --git a/api/tests/unit_tests/libs/key_providers/test_azure_keyvault_key_provider.py b/api/tests/unit_tests/libs/key_providers/test_azure_keyvault_key_provider.pyindex cd8962e5b4f..fb39d84b5b0 100644--- a/api/tests/unit_tests/libs/key_providers/test_azure_keyvault_key_provider.py+++ b/api/tests/unit_tests/libs/key_providers/test_azure_keyvault_key_provider.py@@ -240,7 +240,13 @@ def test_decrypt_rejects_truncated_envelope_raises_value_error(truncate_at: int)encrypted = provider.encrypt("tenant-1", "secret")truncated = encrypted[:truncate_at]- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:Malformed Azure Key Vault envelope: truncated metadata|Malformed "+ "Azure Key Vault envelope: truncated metadata length)"+ ),+ ):provider.decrypt_with_decoding(truncated, "tenant-1")diff --git a/api/tests/unit_tests/libs/test_file_utils.py b/api/tests/unit_tests/libs/test_file_utils.pyindex 8d9b4e803a2..b2abc0fafa8 100644--- a/api/tests/unit_tests/libs/test_file_utils.py+++ b/api/tests/unit_tests/libs/test_file_utils.py@@ -1,3 +1,4 @@+import refrom pathlib import Pathimport pytest@@ -29,7 +30,12 @@ def test_search_file_upwards_found_in_current(tmp_path: Path):def test_search_file_upwards_not_found_raises(tmp_path: Path):base = tmp_path / "m" / "n"base.mkdir(parents=True)- with pytest.raises(ValueError) as exc:+ with pytest.raises(+ ValueError,+ match=re.escape(+ f"File 'missing.txt' not found in the directory '{base}' or its parent directories in depth of 3."+ ),+ ) as exc:search_file_upwards(base, "missing.txt", max_search_parent_depth=3)# error message should contain file name and base pathmsg = str(exc.value)@@ -39,7 +45,13 @@ def test_search_file_upwards_not_found_raises(tmp_path: Path):def test_search_file_upwards_root_breaks_and_raises():# Using filesystem root triggers the 'break' branch (parent == current)- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "File '__definitely_not_exists__\\.txt' not found in the directory '/' "+ "or its parent directories in depth of 1\\."+ ),+ ):search_file_upwards(Path("/"), "__definitely_not_exists__.txt", max_search_parent_depth=1)@@ -51,5 +63,10 @@ def test_search_file_upwards_depth_limit_raises(tmp_path: Path):# The file is 2 levels up from `c` (in `a`), but search depth is only 2.# The search path is `c` (depth 1) -> `b` (depth 2). The file is in `a` (would need depth 3).# So, this should not find the file and should raise an error.- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=re.escape(+ f"File 'target.txt' not found in the directory '{base}' or its parent directories in depth of 2."+ ),+ ):search_file_upwards(base, "target.txt", max_search_parent_depth=2)diff --git a/api/tests/unit_tests/libs/test_json_in_md_parser.py b/api/tests/unit_tests/libs/test_json_in_md_parser.pyindex 57a45e07669..40d454364f4 100644--- a/api/tests/unit_tests/libs/test_json_in_md_parser.py+++ b/api/tests/unit_tests/libs/test_json_in_md_parser.py@@ -36,7 +36,7 @@ def test_parse_json_markdown_braces_only():def test_parse_json_markdown_not_found():- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="could not find json block in the output\\."):parse_json_markdown("no json here")diff --git a/api/tests/unit_tests/libs/test_oauth_clients.py b/api/tests/unit_tests/libs/test_oauth_clients.pyindex 07a33f34109..60746e3dedb 100644--- a/api/tests/unit_tests/libs/test_oauth_clients.py+++ b/api/tests/unit_tests/libs/test_oauth_clients.py@@ -98,7 +98,7 @@ class TestGitHubOAuth(BaseOAuthTest):mock_post.return_value = httpx.Response(200, json=response_data)if should_raise:- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error in GitHub OAuth: \\{\\}") as exc_info:oauth.get_access_token("test_code")assert "Error in GitHub OAuth" in str(exc_info.value)else:@@ -301,7 +301,7 @@ class TestGoogleOAuth(BaseOAuthTest):mock_post.return_value = httpx.Response(200, json=response_data)if should_raise:- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Error in Google OAuth: \\{\\}") as exc_info:oauth.get_access_token("test_code")assert "Error in Google OAuth" in str(exc_info.value)else:diff --git a/api/tests/unit_tests/libs/test_password.py b/api/tests/unit_tests/libs/test_password.pyindex b0ead5605e0..5cfaf73b4ee 100644--- a/api/tests/unit_tests/libs/test_password.py+++ b/api/tests/unit_tests/libs/test_password.py@@ -22,25 +22,40 @@ class TestValidPassword:def test_should_reject_invalid_passwords(self):"""Test rejecting invalid password formats"""# Too short- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=("Password must contain letters and numbers, and the length must be at least 8 characters\\."),+ ) as exc_info:valid_password("abc123")assert "Password must contain letters and numbers" in str(exc_info.value)# No numbers- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("Password must contain letters and numbers, and the length must be at least 8 characters\\."),+ ):valid_password("abcdefgh")# No letters- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("Password must contain letters and numbers, and the length must be at least 8 characters\\."),+ ):valid_password("12345678")# Empty- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("Password must contain letters and numbers, and the length must be at least 8 characters\\."),+ ):valid_password("")def test_should_reject_password_shorter_than_minimum_length(self):"""A 7-character password with letters and numbers is rejected for length."""- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=("Password must contain letters and numbers, and the length must be at least 8 characters\\."),+ ) as exc_info:valid_password("abc1234")assert "at least 8" in str(exc_info.value)diff --git a/api/tests/unit_tests/libs/test_sendgrid_client.py b/api/tests/unit_tests/libs/test_sendgrid_client.pyindex a65a9b18827..05bcd7b01e1 100644--- a/api/tests/unit_tests/libs/test_sendgrid_client.py+++ b/api/tests/unit_tests/libs/test_sendgrid_client.py@@ -28,7 +28,7 @@ def test_sendgrid_success(mock_client_cls: MagicMock):@patch("libs.sendgrid.sendgrid.SendGridAPIClient")def test_sendgrid_missing_to_raises(mock_client_cls: MagicMock):sg = SendGridClient(sendgrid_api_key="key", _from="[email protected]")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="SendGridClient: Cannot send email: recipient address is missing\\."):sg.send(_mail(to=""))diff --git a/api/tests/unit_tests/libs/test_uuid_utils.py b/api/tests/unit_tests/libs/test_uuid_utils.pyindex 9e040efb629..688d4663638 100644--- a/api/tests/unit_tests/libs/test_uuid_utils.py+++ b/api/tests/unit_tests/libs/test_uuid_utils.py@@ -203,7 +203,7 @@ def test_uuidv7_timestamp_error_handling_wrong_version():"""Test error handling for non-UUIDv7 inputs."""uuid_v4 = uuid.uuid4()- with pytest.raises(ValueError) as exc_ctx:+ with pytest.raises(ValueError, match="Expected UUIDv7 \\(version 7\\), got version 4") as exc_ctx:uuidv7_timestamp(uuid_v4)assert "Expected UUIDv7 (version 7)" in str(exc_ctx.value)assert f"got version {uuid_v4.version}" in str(exc_ctx.value)diff --git a/api/tests/unit_tests/libs/test_yarl.py b/api/tests/unit_tests/libs/test_yarl.pyindex ff1a3e80d0f..7bb98fb35cc 100644--- a/api/tests/unit_tests/libs/test_yarl.py+++ b/api/tests/unit_tests/libs/test_yarl.py@@ -24,6 +24,6 @@ def test_yarl_urls():expected_5 = "/api"assert str(URL("/") / "api") == expected_5- with pytest.raises(ValueError) as e1:+ with pytest.raises(ValueError, match="Appending path '/api' starting from slash is forbidden") as e1:str(URL("https://dify.ai") / "/api")assert str(e1.value) == "Appending path '/api' starting from slash is forbidden"diff --git a/api/tests/unit_tests/models/test_agent_config_entities.py b/api/tests/unit_tests/models/test_agent_config_entities.pyindex f3a83d410f4..dbd6f84c30e 100644--- a/api/tests/unit_tests/models/test_agent_config_entities.py+++ b/api/tests/unit_tests/models/test_agent_config_entities.py@@ -274,5 +274,12 @@ def test_enabled_output_routes_require_at_least_two_routes(count: int) -> None:@pytest.mark.parametrize("ids", [[""], ["source"], ["fail-branch"], ["target"], ["same", "same"]])def test_output_routes_reject_invalid_handle_identities(ids: list[str]) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for WorkflowNodeJobConfig\\\noutput_routes|1 "+ "validation error for WorkflowNodeJobConfig\\\noutput_routes\\.routes\\"+ ".0\\.id)"+ ),+ ):WorkflowNodeJobConfig.model_validate({"output_routes": {"routes": [{"id": id, "name": ""} for id in ids]}})diff --git a/api/tests/unit_tests/models/test_end_user_type.py b/api/tests/unit_tests/models/test_end_user_type.pyindex 7179d802386..7cbd69de4a3 100644--- a/api/tests/unit_tests/models/test_end_user_type.py+++ b/api/tests/unit_tests/models/test_end_user_type.py@@ -28,14 +28,14 @@ def test_end_user_type_is_plain_persisted_value_enum() -> None:def test_end_user_type_rejects_legacy_service_api_value() -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'service_api' is not a valid EndUserType"):EndUserType("service_api")assert EndUserType("service-api") is EndUserType.SERVICE_APIdef test_end_user_type_still_rejects_unknown_values() -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'not\\-a\\-real\\-end\\-user\\-type' is not a valid EndUserType"):EndUserType("not-a-real-end-user-type")diff --git a/api/tests/unit_tests/models/test_enums_creator_user_role.py b/api/tests/unit_tests/models/test_enums_creator_user_role.pyindex de69686bc66..bdbac3202d7 100644--- a/api/tests/unit_tests/models/test_enums_creator_user_role.py+++ b/api/tests/unit_tests/models/test_enums_creator_user_role.py@@ -15,5 +15,5 @@ def test_creator_user_role_missing_maps_hyphen_to_enum() -> None:def test_creator_user_role_missing_raises_for_unknown() -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="'unknown' is not a valid CreatorUserRole"):CreatorUserRole("unknown")diff --git a/api/tests/unit_tests/repositories/knowledge/test_indexing_segments.py b/api/tests/unit_tests/repositories/knowledge/test_indexing_segments.pyindex d4b68d33346..4ed1bda2840 100644--- a/api/tests/unit_tests/repositories/knowledge/test_indexing_segments.py+++ b/api/tests/unit_tests/repositories/knowledge/test_indexing_segments.py@@ -85,7 +85,7 @@ def test_token_count_mismatch_rolls_back_segments_and_state(sqlite_session_factory: sessionmaker[Session], indexing_rows: IndexingRows) -> None:segments, job, chunks = indexing_rows- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="zip\\(\\) argument 2 is shorter than argument 1"):segments.save_for_indexing(job, chunks, [13])with sqlite_session_factory() as session:assert session.scalars(select(DocumentSegment)).all() == []diff --git a/api/tests/unit_tests/services/agent/test_agent_composer_entities.py b/api/tests/unit_tests/services/agent/test_agent_composer_entities.pyindex 66309de5b59..3b9bf5db1ee 100644--- a/api/tests/unit_tests/services/agent/test_agent_composer_entities.py+++ b/api/tests/unit_tests/services/agent/test_agent_composer_entities.py@@ -32,7 +32,13 @@ def test_default_agent_soul_enables_file_upload_feature() -> None:def test_workflow_variant_rejects_agent_app_only_fields() -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ComposerSavePayload\\\n Value error, Workflow "+ "Variant must not include app variables"+ ),+ ):ComposerSavePayload.model_validate({"variant": ComposerVariant.WORKFLOW,@@ -45,7 +51,13 @@ def test_workflow_variant_rejects_agent_app_only_fields() -> None:def test_agent_app_variant_rejects_workflow_node_job() -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "1 validation error for ComposerSavePayload\\\n Value error, Agent "+ "App Variant must not include workflow node job config"+ ),+ ):ComposerSavePayload.model_validate({"variant": ComposerVariant.AGENT_APP,diff --git a/api/tests/unit_tests/services/agent/test_agent_services.py b/api/tests/unit_tests/services/agent/test_agent_services.pyindex 55647c056b4..0131ad97d57 100644--- a/api/tests/unit_tests/services/agent/test_agent_services.py+++ b/api/tests/unit_tests/services/agent/test_agent_services.py@@ -587,7 +587,7 @@ def test_save_workflow_composer_rejects_agent_app_variant(sqlite_session: Sessio})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Workflow composer endpoint only accepts workflow variant"):AgentComposerService.save_workflow_composer(session=session,tenant_id="tenant-1",@@ -3537,7 +3537,7 @@ def test_composer_version_helpers_and_lookup_errors(monkeypatch: pytest.MonkeyPa)workflow = AgentComposerService._get_draft_workflow(session=session, tenant_id="tenant-1", app_id="app-1")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Draft workflow not found"):AgentComposerService._get_draft_workflow(session=session, tenant_id="tenant-1", app_id="missing")assert (AgentComposerService._require_agent(session=session, tenant_id="tenant-1", agent_id="agent-1").id == "agent-1"@@ -3607,9 +3607,9 @@ def test_composer_current_version_and_error_paths(monkeypatch: pytest.MonkeyPatccreated_version = session.get(AgentConfigSnapshot, result.current_snapshot_id)assert created_version is not Noneassert created_version.home_snapshot_id == "home-1"- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Workflow agent binding not found"):AgentComposerService._require_binding(None)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="agent_soul is required"):AgentComposerService._save_as_new_agent(session=session,tenant_id="tenant-1",diff --git a/api/tests/unit_tests/services/enterprise/test_enterprise_service.py b/api/tests/unit_tests/services/enterprise/test_enterprise_service.pyindex 0d9c5a075c4..5d2a4c8fd94 100644--- a/api/tests/unit_tests/services/enterprise/test_enterprise_service.py+++ b/api/tests/unit_tests/services/enterprise/test_enterprise_service.py@@ -271,7 +271,7 @@ class TestJoinDefaultWorkspace:EnterpriseService.join_default_workspace(account_id=account_id)def test_join_default_workspace_invalid_account_id_raises(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="account_id must be a valid UUID: not\\-a\\-uuid"):EnterpriseService.join_default_workspace(account_id="not-a-uuid")def test_join_default_workspace_missing_required_fields_raises(self) -> None:diff --git a/api/tests/unit_tests/services/knowledge/test_dataset_application_service.py b/api/tests/unit_tests/services/knowledge/test_dataset_application_service.pyindex 391c12abde7..9041397de01 100644--- a/api/tests/unit_tests/services/knowledge/test_dataset_application_service.py+++ b/api/tests/unit_tests/services/knowledge/test_dataset_application_service.py@@ -156,5 +156,7 @@ def test_tidb_retrieval_setting(fulltext: bool) -> None:@pytest.mark.parametrize("store", [None, "unsupported"])def test_invalid_vector_store(store: str | None) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match=("(?:Unsupported vector db type unsupported\\.|Vector store type is not configured\\.)")+ ):retrieval_methods(store)diff --git a/api/tests/unit_tests/services/knowledge/test_document_application_service.py b/api/tests/unit_tests/services/knowledge/test_document_application_service.pyindex 952d7024896..7a15bb9d7ac 100644--- a/api/tests/unit_tests/services/knowledge/test_document_application_service.py+++ b/api/tests/unit_tests/services/knowledge/test_document_application_service.py@@ -166,7 +166,7 @@ def test_invalid_metadata_never_writes(doc_type: str | None,metadata: dict[str, object] | None,) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="(?:Both doc_type and doc_metadata must be provided\\.|Invalid doc_type\\.)"):service.update_metadata(CONTEXT, dataset_id="dataset-1", document_id="document-1", doc_type=doc_type, doc_metadata=metadata)diff --git a/api/tests/unit_tests/services/knowledge/test_external_application_service.py b/api/tests/unit_tests/services/knowledge/test_external_application_service.pyindex 5d98b8581b6..9edcb376894 100644--- a/api/tests/unit_tests/services/knowledge/test_external_application_service.py+++ b/api/tests/unit_tests/services/knowledge/test_external_application_service.py@@ -45,7 +45,7 @@ def test_template_validation_prevents_io(extra: dict[str, str] = ({"template_id": "template"} if method is ExternalKnowledgeApplicationService.update_template else {})- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="(?:api list is empty|api_key is required|endpoint is required)"):method(service, CONTEXT, name="API", settings=settings, **extra)assert operations.mock_calls == []@@ -63,7 +63,7 @@ def test_retrieval_authorization_precedes_validation_and_network(def test_invalid_query_prevents_retrieval(service: ExternalKnowledgeApplicationService, operations: MagicMock, query: str) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="(?:Query cannot exceed 250 characters|Query or attachment_ids is required)"):service.hit_testing(CONTEXT, dataset_id="dataset", query=query, retrieval_model=None, metadata_filters=None)operations.retrieve.assert_not_called()diff --git a/api/tests/unit_tests/services/plugin/test_dependencies_analysis.py b/api/tests/unit_tests/services/plugin/test_dependencies_analysis.pyindex 670c4a97341..933b8871d87 100644--- a/api/tests/unit_tests/services/plugin/test_dependencies_analysis.py+++ b/api/tests/unit_tests/services/plugin/test_dependencies_analysis.py@@ -26,7 +26,7 @@ class TestAnalyzeToolDependency:assert result == "langgenius/websearch"def test_invalid_format_raises(self) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="Invalid plugin id bad/format"):DependenciesAnalysisService.analyze_tool_dependency("bad/format")def test_plugin_id_reference_is_preserved(self) -> None:diff --git a/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_factory.py b/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_factory.pyindex d8178490e91..8d90d48fe74 100644--- a/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_factory.py+++ b/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_factory.py@@ -24,7 +24,7 @@ def test_get_pipeline_template_factory(mode: str, expected_cls: type) -> None:def test_get_pipeline_template_factory_invalid_mode() -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="invalid fetch recommended apps mode: invalid"):PipelineTemplateRetrievalFactory.get_pipeline_template_factory("invalid")diff --git a/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_remote_retrieval.py b/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_remote_retrieval.pyindex 27eff6e2aeb..d6ea59b71bf 100644--- a/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_remote_retrieval.py+++ b/api/tests/unit_tests/services/rag_pipeline/pipeline_template/test_remote_retrieval.py@@ -70,7 +70,7 @@ def test_fetch_pipeline_templates_from_dify_official(mocker: MockerFixture, monksuccess_result = RemotePipelineTemplateRetrieval.fetch_pipeline_templates_from_dify_official("en-US")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="fetch pipeline templates failed, status code: 500"):RemotePipelineTemplateRetrieval.fetch_pipeline_templates_from_dify_official("en-US")assert success_result == {"pipeline_templates": [{"id": "remote-1"}]}@@ -94,7 +94,9 @@ def test_fetch_pipeline_template_detail_from_dify_official()success_result = RemotePipelineTemplateRetrieval.fetch_pipeline_template_detail_from_dify_official("remote-1")- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match="fetch pipeline template detail failed, status_code: 404, response: Not Found"+ ):RemotePipelineTemplateRetrieval.fetch_pipeline_template_detail_from_dify_official("missing")assert success_result == {"id": "remote-1", "name": "Remote Template"}diff --git a/api/tests/unit_tests/services/retention/workflow_run/test_clear_free_plan_expired_workflow_run_logs.py b/api/tests/unit_tests/services/retention/workflow_run/test_clear_free_plan_expired_workflow_run_logs.pyindex 507e0faaac4..5a25ee8c452 100644--- a/api/tests/unit_tests/services/retention/workflow_run/test_clear_free_plan_expired_workflow_run_logs.py+++ b/api/tests/unit_tests/services/retention/workflow_run/test_clear_free_plan_expired_workflow_run_logs.py@@ -75,7 +75,7 @@ class TestWorkflowRunCleanupInit:def test_equal_start_end_raises(self, mock_repo):dt = datetime.datetime(2024, 1, 1)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="end_before must be greater than start_from\\."):WorkflowRunCleanup(days=30,batch_size=10,@@ -89,7 +89,7 @@ class TestWorkflowRunCleanupInit:WorkflowRunCleanup(days=30, batch_size=0, workflow_run_repo=mock_repo)def test_negative_batch_size_raises(self, mock_repo):- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="batch_size must be greater than 0\\."):WorkflowRunCleanup(days=30, batch_size=-1, workflow_run_repo=mock_repo)def test_valid_window_init(self, mock_repo, config_overrides):diff --git a/api/tests/unit_tests/services/test_app_dsl_service.py b/api/tests/unit_tests/services/test_app_dsl_service.pyindex 03e91bf174e..df4b5e11c85 100644--- a/api/tests/unit_tests/services/test_app_dsl_service.py+++ b/api/tests/unit_tests/services/test_app_dsl_service.py@@ -433,7 +433,14 @@ def test_pending_import_owner_access(],)def test_pending_import_owner_is_required(payload: str) -> None:- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=(+ "(?:1 validation error for PendingData\\\naccount_id|1 validation "+ "error for PendingData\\\ntenant_id|2 validation errors for "+ "PendingData\\\ntenant_id)"+ ),+ ) as exc_info:PendingData.model_validate_json(payload)assert "secret-token-123" not in str(exc_info.value)diff --git a/api/tests/unit_tests/services/test_billing_service.py b/api/tests/unit_tests/services/test_billing_service.pyindex 46ad4e8ef0f..aca41db2307 100644--- a/api/tests/unit_tests/services/test_billing_service.py+++ b/api/tests/unit_tests/services/test_billing_service.py@@ -155,7 +155,7 @@ class TestBillingServiceSendRequest:mock_httpx_request.return_value = mock_response# Act & Assert- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Invalid arguments\\.") as exc_info:BillingService._send_request("PUT", "/test", json={"key": "value"})assert "Invalid arguments." in str(exc_info.value)@@ -215,7 +215,13 @@ class TestBillingServiceSendRequest:# Act & Assertwith caplog.at_level(logging.ERROR, logger="services.billing_service"):- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=(+ "Unable to process delete request https://billing\\-api\\.example\\.com"+ "/test\\. Please try again later or contact support\\."+ ),+ ) as exc_info:BillingService._send_request("DELETE", "/test", json={"key": "value"})assert "Unable to process delete request" in str(exc_info.value)assert "DELETE response" in caplog.text@@ -259,7 +265,13 @@ class TestBillingServiceSendRequest:# Act & Assertwith caplog.at_level(logging.ERROR, logger="services.billing_service"):- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(+ ValueError,+ match=(+ "Unable to process delete request https://billing\\-api\\.example\\.com"+ "/test\\. Please try again later or contact support\\."+ ),+ ) as exc_info:BillingService._send_request("DELETE", "/test", json={"key": "value"})assert "Unable to process delete request" in str(exc_info.value)assert "DELETE response" in caplog.textdiff --git a/api/tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.py b/api/tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.pyindex e143fd6bcad..ffdff6df787 100644--- a/api/tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.py+++ b/api/tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.py@@ -466,11 +466,11 @@ def test_between_sets_window_bounds(monkeypatch: pytest.MonkeyPatch) -> None:def test_between_requires_both_boundaries(monkeypatch: pytest.MonkeyPatch) -> None:- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="start_from and end_before must be both set or both omitted\\."):create_cleanup(monkeypatch, repo=FakeRepo([]), days=30, batch_size=10, start_from=datetime.datetime.now(), end_before=None)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="start_from and end_before must be both set or both omitted\\."):create_cleanup(monkeypatch, repo=FakeRepo([]), days=30, batch_size=10, start_from=None, end_before=datetime.datetime.now())@@ -479,7 +479,7 @@ def test_between_requires_both_boundaries(monkeypatch: pytest.MonkeyPatch) -> Nodef test_between_requires_end_after_start(monkeypatch: pytest.MonkeyPatch) -> None:start_from = datetime.datetime(2024, 6, 1, 0, 0, 0)end_before = datetime.datetime(2024, 5, 1, 0, 0, 0)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="end_before must be greater than start_from\\."):create_cleanup(monkeypatch, repo=FakeRepo([]), days=30, batch_size=10, start_from=start_from, end_before=end_before)diff --git a/api/tests/unit_tests/services/test_export_app_messages.py b/api/tests/unit_tests/services/test_export_app_messages.pyindex 5f2d3f21c06..d409d3dd25f 100644--- a/api/tests/unit_tests/services/test_export_app_messages.py+++ b/api/tests/unit_tests/services/test_export_app_messages.py@@ -23,7 +23,17 @@ def test_validate_export_filename_accepts_relative_path():],)def test_validate_export_filename_rejects_invalid_values(filename: str):- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:\\-\\-filename is too long; max length is 1024\\.|\\-\\-filename "+ "must be a relative path; absolute paths are not allowed\\.|"+ "\\-\\-filename must not contain '\\.' or '\\.\\.' path segments\\.|"+ "\\-\\-filename must not contain control characters or NUL\\.|"+ "\\-\\-filename must not include \\.jsonl\\.gz/\\.jsonl/\\.gz suffix; "+ "pass base filename only\\.)"+ ),+ ):AppMessageExportService.validate_export_filename(filename)diff --git a/api/tests/unit_tests/services/test_external_dataset_service.py b/api/tests/unit_tests/services/test_external_dataset_service.pyindex 30fdfeb50b5..2d540963c9a 100644--- a/api/tests/unit_tests/services/test_external_dataset_service.py+++ b/api/tests/unit_tests/services/test_external_dataset_service.py@@ -776,7 +776,7 @@ class TestExternalDatasetServiceCheckEndpoint:mock_proxy.post.return_value = mock_response# Act- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="Forbidden: Authorization failed with the provided api_key") as exc_info:ExternalDatasetService.check_endpoint_and_api_key(settings)# Assert -- the message names the failure but does not include the key.diff --git a/api/tests/unit_tests/services/test_installed_app_generation_adapters.py b/api/tests/unit_tests/services/test_installed_app_generation_adapters.pyindex 715fcfe5e1f..9c36a3c6b09 100644--- a/api/tests/unit_tests/services/test_installed_app_generation_adapters.py+++ b/api/tests/unit_tests/services/test_installed_app_generation_adapters.py@@ -312,7 +312,7 @@ def test_streaming_preparation_errors_raise_eagerly_and_rollback_runtime_writes(raise failure_patch_generation(monkeypatch, harness, generate, streaming=True, more_like_this=more_like_this)- with pytest.raises(ValueError) as raised:+ with pytest.raises(ValueError, match="query must be a string") as raised:_invoke_generation(harness, streaming=True, more_like_this=more_like_this)assert raised.value is failurediff --git a/api/tests/unit_tests/services/test_metadata_service_session_boundary.py b/api/tests/unit_tests/services/test_metadata_service_session_boundary.pyindex 2f3a6951576..cf72155954b 100644--- a/api/tests/unit_tests/services/test_metadata_service_session_boundary.py+++ b/api/tests/unit_tests/services/test_metadata_service_session_boundary.py@@ -69,7 +69,12 @@ def test_create_commits_through_owned_session(@pytest.mark.parametrize("name", ["x" * 256, "document_name", "uploader", "upload_date", "last_update_date", "source"])def test_invalid_name_is_rejected(metadata_service: MetadataService, name: str) -> None:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "(?:Metadata name already exists in Built\\-in fields\\.|Metadata name cannot exceed 255 characters\\.)"+ ),+ ):metadata_service.create_metadata(REF, MetadataArgs(type="string", name=name), actor_id="actor")assert metadata_service.get_dataset_metadatas(REF)["doc_metadata"] == []diff --git a/api/tests/unit_tests/services/test_schedule_service.py b/api/tests/unit_tests/services/test_schedule_service.pyindex 40f1801c561..18f68560579 100644--- a/api/tests/unit_tests/services/test_schedule_service.py+++ b/api/tests/unit_tests/services/test_schedule_service.py@@ -63,7 +63,14 @@ class TestScheduleService(unittest.TestCase):cron_expr = "invalid cron"timezone = "UTC"- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=(+ "Cron expression must have exactly 5 fields or be a predefined "+ "expression \\(@daily, @weekly, etc\\.\\)\\. Got 2 fields: 'invalid "+ "cron'"+ ),+ ):calculate_next_run_at(cron_expr, timezone)def test_calculate_next_run_at_invalid_timezone(self):diff --git a/api/tests/unit_tests/services/test_skill_management_service.py b/api/tests/unit_tests/services/test_skill_management_service.pyindex fd692806d27..866f42e9a56 100644--- a/api/tests/unit_tests/services/test_skill_management_service.py+++ b/api/tests/unit_tests/services/test_skill_management_service.py@@ -184,21 +184,29 @@ def _skill_md(name: str = "finance-sop", description: str = "Finance SOP", body:def test_validate_skill_name_rejects_underscores_and_double_hyphens() -> None:assert validate_skill_name("finance-sop") == "finance-sop"for bad in ["finance_sop", "finance--sop", "-finance", "finance-", "Finance", "x" * 65]:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match="config skill name .* must match|skill name must",+ ):validate_skill_name(bad)def test_validate_skill_description_rejects_blank_and_long_values() -> None:assert validate_skill_description(" Finance SOP ") == "Finance SOP"for bad in ["", " ", "x" * 1025]:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError,+ match=("(?:skill description must be at most 1024 characters|skill description must not be blank)"),+ ):validate_skill_description(bad)def test_normalize_skill_file_path_rejects_escape_paths() -> None:assert normalize_skill_file_path("references//guide.md") == "references/guide.md"for bad in ["", "../x", "/etc/passwd", "a/\x00b"]:- with pytest.raises(ValueError):+ with pytest.raises(+ ValueError, match="(?:skill file path contains control characters|skill file path is invalid)"+ ):normalize_skill_file_path(bad)diff --git a/api/tests/unit_tests/services/test_upload_file_delivery_service.py b/api/tests/unit_tests/services/test_upload_file_delivery_service.pyindex 37381416123..f8fde4a0bc8 100644--- a/api/tests/unit_tests/services/test_upload_file_delivery_service.py+++ b/api/tests/unit_tests/services/test_upload_file_delivery_service.py@@ -205,7 +205,7 @@ def test_storage_error_is_not_converted(mocker.patch.object(storage, "load_stream", side_effect=storage_error)with patch("services.upload_file_delivery_service.file_helpers.verify_file_signature", return_value=True):- with pytest.raises(OSError) as error_info:+ with pytest.raises(OSError, match="storage unavailable") as error_info:service.get_signed_file_preview(file_id="text-id", timestamp="1", nonce="nonce", sign="valid")assert error_info.value is storage_errordiff --git a/api/tests/unit_tests/services/test_variable_truncator.py b/api/tests/unit_tests/services/test_variable_truncator.pyindex f2ba1784a28..8af859dc357 100644--- a/api/tests/unit_tests/services/test_variable_truncator.py+++ b/api/tests/unit_tests/services/test_variable_truncator.py@@ -492,13 +492,13 @@ class TestEdgeCases:def test_zero_and_negative_limits(self):"""Test truncator behavior with zero or very small limits."""# Zero string limit- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="string_length_limit should be greater than 3\\."):truncator = VariableTruncator(string_length_limit=3)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="array_element_limit should be greater than 0\\."):truncator = VariableTruncator(array_element_limit=0)- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="max_size_bytes should be greater than 0\\."):truncator = VariableTruncator(max_size_bytes=0)def test_unicode_and_special_characters(self):diff --git a/api/tests/unit_tests/tools/test_api_tool.py b/api/tests/unit_tests/tools/test_api_tool.pyindex cc639db27ea..948482269ae 100644--- a/api/tests/unit_tests/tools/test_api_tool.py+++ b/api/tests/unit_tests/tools/test_api_tool.py@@ -226,7 +226,7 @@ class TestApiToolInvoke:result_generator = self.api_tool._invoke(session=database_session, user_id="test_user", tool_parameters={})# Invoke the tool and expect an error- with pytest.raises(Exception) as exc_info:+ with pytest.raises(Exception, match="Request failed with status code 404 and Not Found") as exc_info:list(result_generator) # Consume the generator to trigger the error# Verify the error messagediff --git a/api/tests/unit_tests/utils/encryption/test_system_encryption.py b/api/tests/unit_tests/utils/encryption/test_system_encryption.pyindex f9e2c9d8143..e76edc377fc 100644--- a/api/tests/unit_tests/utils/encryption/test_system_encryption.py+++ b/api/tests/unit_tests/utils/encryption/test_system_encryption.py@@ -113,10 +113,12 @@ class TestSystemEncrypter:"""Test encryption with invalid input types"""encrypter = SystemEncrypter("test_secret")- with pytest.raises(Exception): # noqa: B017+ with pytest.raises(Exception, match="Encryption failed: 'NoneType' object is not iterable"):encrypter.encrypt_params(None)- with pytest.raises(Exception): # noqa: B017+ with pytest.raises(+ Exception, match=("Encryption failed: dictionary update sequence element \\#0 has length 1; 2 is required")+ ):encrypter.encrypt_params("not_a_dict")def test_decrypt_params_basic(self):@@ -195,7 +197,7 @@ class TestSystemEncrypter:"""Test decryption with empty string"""encrypter = SystemEncrypter("test_secret")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="encrypted_data cannot be empty") as exc_info:encrypter.decrypt_params("")assert "encrypted_data cannot be empty" in str(exc_info.value)@@ -204,12 +206,12 @@ class TestSystemEncrypter:"""Test decryption with non-string input"""encrypter = SystemEncrypter("test_secret")- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="encrypted_data must be a string") as exc_info:encrypter.decrypt_params(123)assert "encrypted_data must be a string" in str(exc_info.value)- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="encrypted_data must be a string") as exc_info:encrypter.decrypt_params(None)assert "encrypted_data must be a string" in str(exc_info.value)@@ -455,14 +457,14 @@ class TestConvenienceFunctions:def test_convenience_functions_with_errors(self):"""Test convenience functions with error conditions"""# Test encryption with invalid input- with pytest.raises(Exception): # noqa: B017+ with pytest.raises(Exception, match="Encryption failed: 'NoneType' object is not iterable"):encrypt_system_params(None)# Test decryption with invalid input- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="encrypted_data cannot be empty"):decrypt_system_params("")- with pytest.raises(ValueError):+ with pytest.raises(ValueError, match="encrypted_data must be a string"):decrypt_system_params(None)@@ -490,12 +492,12 @@ class TestErrorHandling:encrypter = SystemEncrypter("test_secret")# Test empty string error- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="encrypted_data cannot be empty") as exc_info:encrypter.decrypt_params("")assert "encrypted_data cannot be empty" in str(exc_info.value)# Test non-string error- with pytest.raises(ValueError) as exc_info:+ with pytest.raises(ValueError, match="encrypted_data must be a string") as exc_info:encrypter.decrypt_params(123)assert "encrypted_data must be a string" in str(exc_info.value)