Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
test: keep integration config overrides typed (#40850)
Asuka Minatoc7f4422333ac
diff --git a/api/tests/unit_tests/extensions/storage/test_supabase_storage.py b/api/tests/unit_tests/extensions/storage/test_supabase_storage.pyindex 1f4146a9caf..dade3adc9c9 100644--- a/api/tests/unit_tests/extensions/storage/test_supabase_storage.py+++ b/api/tests/unit_tests/extensions/storage/test_supabase_storage.py@@ -10,105 +10,81 @@ from extensions.storage.supabase_storage import SupabaseStorageclass TestSupabaseStorage:"""Test suite for SupabaseStorage class."""+ @pytest.fixture(autouse=True)+ def _supabase_config(self, config_overrides) -> None:+ config_overrides(+ SUPABASE_URL="https://test.supabase.co",+ SUPABASE_API_KEY="test-api-key",+ SUPABASE_BUCKET_NAME="test-bucket",+ )+def test_init_success_with_all_config(self):"""Test successful initialization when all required config is provided."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"-- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- # Mock bucket_exists to return True so create_bucket is not called- with patch.object(SupabaseStorage, "bucket_exists", return_value=True):- storage = SupabaseStorage()+ # Mock bucket_exists to return True so create_bucket is not called+ with patch.object(SupabaseStorage, "bucket_exists", return_value=True):+ storage = SupabaseStorage()- assert storage.bucket_name == "test-bucket"- mock_client_class.assert_called_once_with(- supabase_url="https://test.supabase.co", supabase_key="test-api-key"- )+ assert storage.bucket_name == "test-bucket"+ mock_client_class.assert_called_once_with(+ supabase_url="https://test.supabase.co", supabase_key="test-api-key"+ )- def test_init_raises_error_when_url_missing(self):+ def test_init_raises_error_when_url_missing(self, config_overrides):"""Test initialization raises ValueError when SUPABASE_URL is None."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = None- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"+ config_overrides(SUPABASE_URL=None)+ with pytest.raises(ValueError, match="SUPABASE_URL is not set"):+ SupabaseStorage()- with pytest.raises(ValueError, match="SUPABASE_URL is not set"):- SupabaseStorage()-- def test_init_raises_error_when_api_key_missing(self):+ def test_init_raises_error_when_api_key_missing(self, config_overrides):"""Test initialization raises ValueError when SUPABASE_API_KEY is None."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = None- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"+ config_overrides(SUPABASE_API_KEY=None)+ with pytest.raises(ValueError, match="SUPABASE_API_KEY is not set"):+ SupabaseStorage()- with pytest.raises(ValueError, match="SUPABASE_API_KEY is not set"):- SupabaseStorage()-- def test_init_raises_error_when_bucket_name_missing(self):+ def test_init_raises_error_when_bucket_name_missing(self, config_overrides):"""Test initialization raises ValueError when SUPABASE_BUCKET_NAME is None."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = None-- with pytest.raises(ValueError, match="SUPABASE_BUCKET_NAME is not set"):- SupabaseStorage()+ config_overrides(SUPABASE_BUCKET_NAME=None)+ with pytest.raises(ValueError, match="SUPABASE_BUCKET_NAME is not set"):+ SupabaseStorage()def test_create_bucket_when_not_exists(self):"""Test create_bucket creates bucket when it doesn't exist."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client-- with patch.object(SupabaseStorage, "bucket_exists", return_value=False):- storage = SupabaseStorage()+ with patch.object(SupabaseStorage, "bucket_exists", return_value=False):+ SupabaseStorage()- mock_client.storage.create_bucket.assert_called_once_with(id="test-bucket", name="test-bucket")+ mock_client.storage.create_bucket.assert_called_once_with(id="test-bucket", name="test-bucket")def test_create_bucket_when_exists(self):"""Test create_bucket does not create bucket when it already exists."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client-- with patch.object(SupabaseStorage, "bucket_exists", return_value=True):- storage = SupabaseStorage()+ with patch.object(SupabaseStorage, "bucket_exists", return_value=True):+ SupabaseStorage()- mock_client.storage.create_bucket.assert_not_called()+ mock_client.storage.create_bucket.assert_not_called()@pytest.fixturedef storage_with_mock_client(self):"""Fixture providing SupabaseStorage with mocked client."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"-- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- with patch.object(SupabaseStorage, "bucket_exists", return_value=True):- storage = SupabaseStorage()- # Create fresh mock for each test- mock_client.reset_mock()- yield storage, mock_client+ with patch.object(SupabaseStorage, "bucket_exists", return_value=True):+ storage = SupabaseStorage()+ # Create fresh mock for each test+ mock_client.reset_mock()+ yield storage, mock_clientdef test_save(self, storage_with_mock_client):"""Test save calls client.storage.from_(bucket).upload(path, data)."""@@ -210,63 +186,48 @@ class TestSupabaseStorage:def test_bucket_exists_returns_true_when_bucket_found(self):"""Test bucket_exists returns True when bucket is found in list."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"-- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client-- mock_bucket = Mock()- mock_bucket.name = "test-bucket"- mock_client.storage.list_buckets.return_value = [mock_bucket]- storage = SupabaseStorage()- result = storage.bucket_exists()+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- assert result is True- assert mock_client.storage.list_buckets.call_count >= 1+ mock_bucket = Mock()+ mock_bucket.name = "test-bucket"+ mock_client.storage.list_buckets.return_value = [mock_bucket]+ storage = SupabaseStorage()+ result = storage.bucket_exists()++ assert result is True+ assert mock_client.storage.list_buckets.call_count >= 1def test_bucket_exists_returns_false_when_bucket_not_found(self):"""Test bucket_exists returns False when bucket is not found in list."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"-- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- # Mock different bucket- mock_bucket = Mock()- mock_bucket.name = "different-bucket"- mock_client.storage.list_buckets.return_value = [mock_bucket]- mock_client.storage.create_bucket = Mock()+ # Mock different bucket+ mock_bucket = Mock()+ mock_bucket.name = "different-bucket"+ mock_client.storage.list_buckets.return_value = [mock_bucket]+ mock_client.storage.create_bucket = Mock()- storage = SupabaseStorage()- result = storage.bucket_exists()+ storage = SupabaseStorage()+ result = storage.bucket_exists()- assert result is False- assert mock_client.storage.list_buckets.call_count >= 1+ assert result is False+ assert mock_client.storage.list_buckets.call_count >= 1def test_bucket_exists_returns_false_when_no_buckets(self):"""Test bucket_exists returns False when no buckets exist."""- with patch("extensions.storage.supabase_storage.dify_config") as mock_config:- mock_config.SUPABASE_URL = "https://test.supabase.co"- mock_config.SUPABASE_API_KEY = "test-api-key"- mock_config.SUPABASE_BUCKET_NAME = "test-bucket"+ with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:+ mock_client = Mock()+ mock_client_class.return_value = mock_client- with patch("extensions.storage.supabase_storage.Client", autospec=True) as mock_client_class:- mock_client = Mock()- mock_client_class.return_value = mock_client+ mock_client.storage.list_buckets.return_value = []+ mock_client.storage.create_bucket = Mock()- mock_client.storage.list_buckets.return_value = []- mock_client.storage.create_bucket = Mock()-- storage = SupabaseStorage()- result = storage.bucket_exists()+ storage = SupabaseStorage()+ result = storage.bucket_exists()- assert result is False- assert mock_client.storage.list_buckets.call_count >= 1+ assert result is False+ assert mock_client.storage.list_buckets.call_count >= 1diff --git a/api/tests/unit_tests/extensions/test_redis.py b/api/tests/unit_tests/extensions/test_redis.pyindex 923e737d676..05e14b9a83d 100644--- a/api/tests/unit_tests/extensions/test_redis.py+++ b/api/tests/unit_tests/extensions/test_redis.py@@ -1,5 +1,6 @@-from unittest.mock import MagicMock, patch+from unittest.mock import MagicMock+import pytestfrom redis import RedisErrorfrom redis.retry import Retry@@ -14,16 +15,30 @@ from extensions.ext_redis import ()-class TestGetConnectionHealthParams:- @patch("extensions.ext_redis.dify_config")- def test_includes_all_health_params(self, mock_config):- mock_config.REDIS_RETRY_RETRIES = 3- mock_config.REDIS_RETRY_BACKOFF_BASE = 1.0- mock_config.REDIS_RETRY_BACKOFF_CAP = 10.0- mock_config.REDIS_SOCKET_TIMEOUT = 5.0- mock_config.REDIS_SOCKET_CONNECT_TIMEOUT = 5.0- mock_config.REDIS_HEALTH_CHECK_INTERVAL = 30[email protected](autouse=True)+def _redis_config(config_overrides) -> None:+ config_overrides(+ REDIS_USERNAME=None,+ REDIS_PASSWORD=None,+ REDIS_DB=0,+ REDIS_SERIALIZATION_PROTOCOL=3,+ REDIS_ENABLE_CLIENT_SIDE_CACHE=False,+ REDIS_RETRY_RETRIES=3,+ REDIS_RETRY_BACKOFF_BASE=1.0,+ REDIS_RETRY_BACKOFF_CAP=10.0,+ REDIS_SOCKET_TIMEOUT=5.0,+ REDIS_SOCKET_CONNECT_TIMEOUT=5.0,+ REDIS_HEALTH_CHECK_INTERVAL=30,+ REDIS_KEEPALIVE=True,+ REDIS_KEEPALIVE_IDLE=60,+ REDIS_KEEPALIVE_INTERVAL=10,+ REDIS_KEEPALIVE_COUNT=3,+ REDIS_KEY_PREFIX="",+ )++class TestGetConnectionHealthParams:+ def test_includes_all_health_params(self):params = _get_connection_health_params()assert "retry" in params@@ -38,15 +53,7 @@ class TestGetConnectionHealthParams:class TestGetClusterConnectionHealthParams:- @patch("extensions.ext_redis.dify_config")- def test_excludes_health_check_interval(self, mock_config):- mock_config.REDIS_RETRY_RETRIES = 3- mock_config.REDIS_RETRY_BACKOFF_BASE = 1.0- mock_config.REDIS_RETRY_BACKOFF_CAP = 10.0- mock_config.REDIS_SOCKET_TIMEOUT = 5.0- mock_config.REDIS_SOCKET_CONNECT_TIMEOUT = 5.0- mock_config.REDIS_HEALTH_CHECK_INTERVAL = 30-+ def test_excludes_health_check_interval(self):params = _get_cluster_connection_health_params()assert "retry" in params@@ -56,24 +63,7 @@ class TestGetClusterConnectionHealthParams:class TestGetBaseRedisParams:- @patch("extensions.ext_redis.dify_config")- def test_includes_retry_and_health_params(self, mock_config):- mock_config.REDIS_USERNAME = None- mock_config.REDIS_PASSWORD = None- mock_config.REDIS_DB = 0- mock_config.REDIS_SERIALIZATION_PROTOCOL = 3- mock_config.REDIS_ENABLE_CLIENT_SIDE_CACHE = False- mock_config.REDIS_RETRY_RETRIES = 3- mock_config.REDIS_RETRY_BACKOFF_BASE = 1.0- mock_config.REDIS_RETRY_BACKOFF_CAP = 10.0- mock_config.REDIS_SOCKET_TIMEOUT = 5.0- mock_config.REDIS_SOCKET_CONNECT_TIMEOUT = 5.0- mock_config.REDIS_HEALTH_CHECK_INTERVAL = 30- mock_config.REDIS_KEEPALIVE = True- mock_config.REDIS_KEEPALIVE_IDLE = 60- mock_config.REDIS_KEEPALIVE_INTERVAL = 10- mock_config.REDIS_KEEPALIVE_COUNT = 3-+ def test_includes_retry_and_health_params(self):params = _get_base_redis_params()assert "retry" in params@@ -149,86 +139,74 @@ class TestRedisKeyPrefixHelpers:class TestRedisClientWrapperKeyPrefix:- def test_wrapper_get_prefixes_string_keys(self):+ def test_wrapper_get_prefixes_string_keys(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = "enterprise-a"-- wrapper.get("oauth_state:abc")+ config_overrides(REDIS_KEY_PREFIX="enterprise-a")+ wrapper.get("oauth_state:abc")mock_client.get.assert_called_once_with("enterprise-a:oauth_state:abc")- def test_wrapper_delete_prefixes_multiple_keys(self):+ def test_wrapper_delete_prefixes_multiple_keys(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = "enterprise-a"-- wrapper.delete("key:a", "key:b")+ config_overrides(REDIS_KEY_PREFIX="enterprise-a")+ wrapper.delete("key:a", "key:b")mock_client.delete.assert_called_once_with("enterprise-a:key:a", "enterprise-a:key:b")- def test_wrapper_lock_prefixes_lock_name(self):+ def test_wrapper_lock_prefixes_lock_name(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = "enterprise-a"-- wrapper.lock("resource-lock", timeout=10)+ config_overrides(REDIS_KEY_PREFIX="enterprise-a")+ wrapper.lock("resource-lock", timeout=10)mock_client.lock.assert_called_once()args, kwargs = mock_client.lock.call_argsassert args == ("enterprise-a:resource-lock",)assert kwargs["timeout"] == 10- def test_wrapper_hash_operations_prefix_key_name(self):+ def test_wrapper_hash_operations_prefix_key_name(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = "enterprise-a"-- wrapper.hset("hash:key", "field", "value")- wrapper.hgetall("hash:key")- wrapper.hkeys("hash:key")- wrapper.hexists("hash:key", "field")+ config_overrides(REDIS_KEY_PREFIX="enterprise-a")+ wrapper.hset("hash:key", "field", "value")+ wrapper.hgetall("hash:key")+ wrapper.hkeys("hash:key")+ wrapper.hexists("hash:key", "field")mock_client.hset.assert_called_once_with("enterprise-a:hash:key", "field", "value")mock_client.hgetall.assert_called_once_with("enterprise-a:hash:key")mock_client.hkeys.assert_called_once_with("enterprise-a:hash:key")mock_client.hexists.assert_called_once_with("enterprise-a:hash:key", "field")- def test_wrapper_zadd_prefixes_sorted_set_name(self):+ def test_wrapper_zadd_prefixes_sorted_set_name(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = "enterprise-a"-- wrapper.zadd("zset:key", {"member": 1})+ config_overrides(REDIS_KEY_PREFIX="enterprise-a")+ wrapper.zadd("zset:key", {"member": 1})mock_client.zadd.assert_called_once()args, kwargs = mock_client.zadd.call_argsassert args == ("enterprise-a:zset:key", {"member": 1})assert kwargs["nx"] is False- def test_wrapper_preserves_keys_when_prefix_is_empty(self):+ def test_wrapper_preserves_keys_when_prefix_is_empty(self, config_overrides):mock_client = MagicMock()wrapper = RedisClientWrapper()wrapper.initialize(mock_client)- with patch("extensions.ext_redis.dify_config") as mock_config:- mock_config.REDIS_KEY_PREFIX = " "-- wrapper.get("plain:key")+ config_overrides(REDIS_KEY_PREFIX=" ")+ wrapper.get("plain:key")mock_client.get.assert_called_once_with("plain:key")diff --git a/api/tests/unit_tests/services/plugin/test_plugin_service_installation.py b/api/tests/unit_tests/services/plugin/test_plugin_service_installation.pyindex a98a249457e..c002b4f2983 100644--- a/api/tests/unit_tests/services/plugin/test_plugin_service_installation.py+++ b/api/tests/unit_tests/services/plugin/test_plugin_service_installation.py@@ -55,6 +55,15 @@ def plugin_db() -> Iterator[Session]:yield session[email protected](autouse=True)+def _plugin_config(config_overrides) -> None:+ config_overrides(+ CONSOLE_API_URL="https://console.example.com",+ MARKETPLACE_ENABLED=True,+ DEPLOYMENT_EDITION=DeploymentEdition.COMMUNITY,+ )++class TestFetchLatestPluginVersion:@patch("core.plugin.plugin_service.marketplace")@patch("core.plugin.plugin_service.redis_client")@@ -200,10 +209,7 @@ class TestCheckPluginInstallationScope:class TestGetPluginIconUrl:- @patch("core.plugin.plugin_service.dify_config")- def test_constructs_url_with_params(self, mock_config):- mock_config.CONSOLE_API_URL = "https://console.example.com"-+ def test_constructs_url_with_params(self):url = PluginService.get_plugin_icon_url("tenant-1", "icon.svg")assert "tenant_id=tenant-1" in url@@ -245,26 +251,20 @@ class TestIsPluginVerified:class TestUpgradePluginWithMarketplace:- @patch("core.plugin.plugin_service.dify_config")- def test_raises_when_marketplace_disabled(self, mock_config):- mock_config.MARKETPLACE_ENABLED = False+ def test_raises_when_marketplace_disabled(self, config_overrides):+ config_overrides(MARKETPLACE_ENABLED=False)with pytest.raises(ValueError, match="marketplace is not enabled"):PluginService.upgrade_plugin_with_marketplace("t1", "old-uid", "new-uid")- @patch("core.plugin.plugin_service.dify_config")- def test_raises_when_same_identifier(self, mock_config):- mock_config.MARKETPLACE_ENABLED = True-+ def test_raises_when_same_identifier(self):with pytest.raises(ValueError, match="same plugin"):PluginService.upgrade_plugin_with_marketplace("t1", "same-uid", "same-uid")@patch("core.plugin.plugin_service.marketplace")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_skips_download_when_already_installed(self, mock_config, mock_installer_cls, mock_fs, mock_marketplace):- mock_config.MARKETPLACE_ENABLED = True+ def test_skips_download_when_already_installed(self, mock_installer_cls, mock_fs, mock_marketplace):mock_fs.get_plugin_installation_permission.return_value = _make_permission()installer = mock_installer_cls.return_valueinstaller.fetch_plugin_manifest.return_value = MagicMock()@@ -278,9 +278,7 @@ class TestUpgradePluginWithMarketplace:@patch("core.plugin.plugin_service.download_plugin_pkg")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_downloads_when_not_installed(self, mock_config, mock_installer_cls, mock_fs, mock_download):- mock_config.MARKETPLACE_ENABLED = True+ def test_downloads_when_not_installed(self, mock_installer_cls, mock_fs, mock_download):mock_fs.get_plugin_installation_permission.return_value = _make_permission()installer = mock_installer_cls.return_valueinstaller.fetch_plugin_manifest.side_effect = RuntimeError("not found")@@ -303,11 +301,9 @@ class TestUpgradePluginWithMarketplace:@patch("core.plugin.plugin_service.marketplace")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")def test_rejects_cached_pkg_outside_scope(- self, mock_config, mock_installer_cls, mock_fs, mock_marketplace, mock_download, scope+ self, mock_installer_cls, mock_fs, mock_marketplace, mock_download, scope):- mock_config.MARKETPLACE_ENABLED = Truemock_fs.get_plugin_installation_permission.return_value = _make_permission(scope=scope)installer = mock_installer_cls.return_valueinstaller.fetch_plugin_manifest.return_value = MagicMock()@@ -326,9 +322,7 @@ class TestUpgradePluginWithMarketplace:@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_rejects_before_touching_daemon_when_scope_is_none(self, mock_config, mock_installer_cls, mock_fs):- mock_config.MARKETPLACE_ENABLED = True+ def test_rejects_before_touching_daemon_when_scope_is_none(self, mock_installer_cls, mock_fs):mock_fs.get_plugin_installation_permission.return_value = _make_permission(scope=PluginInstallationScope.NONE)installer = mock_installer_cls.return_value@@ -341,11 +335,7 @@ class TestUpgradePluginWithMarketplace:@patch("core.plugin.plugin_service.marketplace")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_allows_cached_official_pkg_under_official_only(- self, mock_config, mock_installer_cls, mock_fs, mock_marketplace- ):- mock_config.MARKETPLACE_ENABLED = True+ def test_allows_cached_official_pkg_under_official_only(self, mock_installer_cls, mock_fs, mock_marketplace):mock_fs.get_plugin_installation_permission.return_value = _make_permission(scope=PluginInstallationScope.OFFICIAL_ONLY)@@ -391,9 +381,8 @@ class TestUploadPkg:class TestInstallFromMarketplacePkg:- @patch("core.plugin.plugin_service.dify_config")- def test_raises_when_marketplace_disabled(self, mock_config):- mock_config.MARKETPLACE_ENABLED = False+ def test_raises_when_marketplace_disabled(self, config_overrides):+ config_overrides(MARKETPLACE_ENABLED=False)with pytest.raises(ValueError, match="marketplace is not enabled"):PluginService.install_from_marketplace_pkg("t1", ["uid-1"])@@ -401,9 +390,7 @@ class TestInstallFromMarketplacePkg:@patch("core.plugin.plugin_service.download_plugin_pkg")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_downloads_when_not_cached(self, mock_config, mock_installer_cls, mock_fs, mock_download):- mock_config.MARKETPLACE_ENABLED = True+ def test_downloads_when_not_cached(self, mock_installer_cls, mock_fs, mock_download):mock_fs.get_plugin_installation_permission.return_value = _make_permission()installer = mock_installer_cls.return_valueinstaller.fetch_plugin_manifest.side_effect = RuntimeError("not found")@@ -423,9 +410,7 @@ class TestInstallFromMarketplacePkg:@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_uses_cached_when_already_downloaded(self, mock_config, mock_installer_cls: MagicMock, mock_fs: MagicMock):- mock_config.MARKETPLACE_ENABLED = True+ def test_uses_cached_when_already_downloaded(self, mock_installer_cls: MagicMock, mock_fs: MagicMock):mock_fs.get_plugin_installation_permission.return_value = _make_permission()installer = mock_installer_cls.return_valueinstaller.fetch_plugin_manifest.return_value = MagicMock()@@ -443,9 +428,7 @@ class TestInstallFromMarketplacePkg:@patch("core.plugin.plugin_service.download_plugin_pkg")@patch("core.plugin.plugin_service.FeatureService")@patch("core.plugin.plugin_service.PluginInstaller")- @patch("core.plugin.plugin_service.dify_config")- def test_rejects_cached_pkg_outside_scope(self, mock_config, mock_installer_cls, mock_fs, mock_download):- mock_config.MARKETPLACE_ENABLED = True+ def test_rejects_cached_pkg_outside_scope(self, mock_installer_cls, mock_fs, mock_download):mock_fs.get_plugin_installation_permission.return_value = _make_permission(scope=PluginInstallationScope.OFFICIAL_ONLY)@@ -516,9 +499,7 @@ class TestUninstall:installer.list_plugins.return_value = [plugin]installer.uninstall.return_value = True- with patch("core.plugin.plugin_service.dify_config") as mock_config:- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- result = PluginService.uninstall(tenant_id, "install-1")+ result = PluginService.uninstall(tenant_id, "install-1")assert result is Trueinstaller.uninstall.assert_called_once()@@ -579,9 +560,7 @@ class TestUninstall:installer.list_plugins.return_value = [plugin]installer.uninstall.return_value = True- with patch("core.plugin.plugin_service.dify_config") as mock_config:- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- result = PluginService.uninstall(tenant_id, "install-1", preserve_credentials=True)+ result = PluginService.uninstall(tenant_id, "install-1", preserve_credentials=True)assert result is Trueplugin_db.expire_all()@@ -609,9 +588,7 @@ class TestUninstall:installer.list_plugins.return_value = [plugin]installer.uninstall.return_value = False- with patch("core.plugin.plugin_service.dify_config") as mock_config:- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- result = PluginService.uninstall(tenant_id, "install-1")+ result = PluginService.uninstall(tenant_id, "install-1")assert result is Falseplugin_db.expire_all()diff --git a/api/tests/unit_tests/services/recommend_app/test_remote_retrieval.py b/api/tests/unit_tests/services/recommend_app/test_remote_retrieval.pyindex fd50db9f384..165381c1f68 100644--- a/api/tests/unit_tests/services/recommend_app/test_remote_retrieval.py+++ b/api/tests/unit_tests/services/recommend_app/test_remote_retrieval.py@@ -117,10 +117,16 @@ class TestRemoteRecommendAppRetrieval:class TestFetchFromDifyOfficial:- @patch("services.recommend_app.remote.remote_retrieval.dify_config")+ @pytest.fixture(autouse=True)+ def _remote_config(self, config_overrides):+ config_overrides(+ HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN="https://example.com",+ HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL=300,+ CONSOLE_WEB_URL="",+ )+@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_detail_returns_json_on_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_detail_returns_json_on_200(self, mock_get):mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"id": "app-1", "name": "Test"}mock_get.return_value = mock_response@@ -130,20 +136,16 @@ class TestFetchFromDifyOfficial:assert result == {"id": "app-1", "name": "Test"}mock_get.assert_called_once()- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_detail_returns_none_on_non_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_detail_returns_none_on_non_200(self, mock_get):mock_get.return_value = MagicMock(status_code=404)result = RemoteRecommendAppRetrieval.fetch_recommended_app_detail_from_dify_official("app-1")assert result is None- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_preserves_remote_categories_order_on_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_apps_preserves_remote_categories_order_on_200(self, mock_get):mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": [],@@ -155,19 +157,15 @@ class TestFetchFromDifyOfficial:assert result["categories"] == ["writing", "agent", "chat"]- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_raises_on_non_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_apps_raises_on_non_200(self, mock_get):mock_get.return_value = MagicMock(status_code=500)with pytest.raises(ValueError, match="fetch recommended apps failed"):RemoteRecommendAppRetrieval.fetch_recommended_apps_from_dify_official("en-US")- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_without_categories_key(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_apps_without_categories_key(self, mock_get):mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -177,11 +175,9 @@ class TestFetchFromDifyOfficial:assert "categories" not in resultassert mock_get.call_args.kwargs["headers"] == {}- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_forwards_request_origin_header(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.CONSOLE_WEB_URL = "https://saas.dify.dev"+ def test_apps_forwards_request_origin_header(self, mock_get, config_overrides):+ config_overrides(CONSOLE_WEB_URL="https://saas.dify.dev")mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -192,11 +188,9 @@ class TestFetchFromDifyOfficial:assert mock_get.call_args.kwargs["headers"] == {"Origin": "https://cloud.example.com"}- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_falls_back_to_console_web_url_origin(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.CONSOLE_WEB_URL = "https://saas.dify.dev/console"+ def test_apps_falls_back_to_console_web_url_origin(self, mock_get, config_overrides):+ config_overrides(CONSOLE_WEB_URL="https://saas.dify.dev/console")mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -207,11 +201,9 @@ class TestFetchFromDifyOfficial:assert mock_get.call_args.kwargs["headers"] == {"Origin": "https://saas.dify.dev/console"}- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_falls_back_to_console_web_url_without_request_context(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.CONSOLE_WEB_URL = "http://localhost:3000/console"+ def test_apps_falls_back_to_console_web_url_without_request_context(self, mock_get, config_overrides):+ config_overrides(CONSOLE_WEB_URL="http://localhost:3000/console")mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -220,11 +212,9 @@ class TestFetchFromDifyOfficial:assert mock_get.call_args.kwargs["headers"] == {"Origin": "http://localhost:3000/console"}- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_uses_console_web_url_without_scheme(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.CONSOLE_WEB_URL = "saas.dify.dev"+ def test_apps_uses_console_web_url_without_scheme(self, mock_get, config_overrides):+ config_overrides(CONSOLE_WEB_URL="saas.dify.dev")mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -235,10 +225,8 @@ class TestFetchFromDifyOfficial:assert mock_get.call_args.kwargs["headers"] == {"Origin": "saas.dify.dev"}- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_learn_dify_apps_returns_json_on_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_learn_dify_apps_returns_json_on_200(self, mock_get):mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": [{"id": "learn-dify-app"}]}mock_get.return_value = mock_response@@ -248,20 +236,16 @@ class TestFetchFromDifyOfficial:assert result == {"recommended_apps": [{"id": "learn-dify-app"}]}assert mock_get.call_args.args[0] == "https://example.com/apps/learn-dify?language=en-US"- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_learn_dify_apps_raises_on_non_200(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"+ def test_learn_dify_apps_raises_on_non_200(self, mock_get):mock_get.return_value = MagicMock(status_code=500)with pytest.raises(ValueError, match="fetch learn dify apps failed"):RemoteRecommendAppRetrieval.fetch_learn_dify_apps_from_dify_official("en-US")- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_uses_cache_for_repeated_requests(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL = 600+ def test_apps_uses_cache_for_repeated_requests(self, mock_get, config_overrides):+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL=600)mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": [{"id": "app-1"}]}mock_get.return_value = mock_response@@ -272,11 +256,9 @@ class TestFetchFromDifyOfficial:assert first == second == {"recommended_apps": [{"id": "app-1"}]}mock_get.assert_called_once()- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_does_not_cache_failed_responses(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL = 600+ def test_apps_does_not_cache_failed_responses(self, mock_get, config_overrides):+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL=600)mock_get.return_value = MagicMock(status_code=500)with pytest.raises(ValueError, match="fetch recommended apps failed"):@@ -286,11 +268,9 @@ class TestFetchFromDifyOfficial:assert mock_get.call_count == 2- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_skips_cache_when_ttl_disabled(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL = 0+ def test_apps_skips_cache_when_ttl_disabled(self, mock_get, config_overrides):+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL=0)mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_response@@ -300,11 +280,9 @@ class TestFetchFromDifyOfficial:assert mock_get.call_count == 2- @patch("services.recommend_app.remote.remote_retrieval.dify_config")@patch("services.recommend_app.remote.remote_retrieval.httpx.get")- def test_apps_cache_isolated_by_origin_header(self, mock_get, mock_config):- mock_config.HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN = "https://example.com"- mock_config.HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL = 600+ def test_apps_cache_isolated_by_origin_header(self, mock_get, config_overrides):+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_CACHE_TTL=600)mock_response = MagicMock(status_code=200)mock_response.json.return_value = {"recommended_apps": []}mock_get.return_value = mock_responsediff --git a/api/tests/unit_tests/services/test_recommended_app_service.py b/api/tests/unit_tests/services/test_recommended_app_service.pyindex 98f4ca467ca..c4a039e1bc8 100644--- a/api/tests/unit_tests/services/test_recommended_app_service.py+++ b/api/tests/unit_tests/services/test_recommended_app_service.py@@ -3,6 +3,7 @@from __future__ import annotationsimport uuid+from collections.abc import Callablefrom typing import TypedDict, Unpack, castfrom unittest.mock import MagicMock, patch@@ -22,6 +23,15 @@ pytestmark = pytest.mark.parametrize()[email protected](autouse=True)+def _recommended_app_config(config_overrides: Callable[..., None]) -> None:+ config_overrides(+ HOSTED_FETCH_APP_TEMPLATES_MODE="remote",+ DEPLOYMENT_EDITION=DeploymentEdition.COMMUNITY,+ ENABLE_TRIAL_APP=True,+ )++class RecommendedAppPayload(TypedDict, total=False):id: strapp_id: str@@ -58,14 +68,13 @@ class AppDetailKwargs(TypedDict, total=False):],)def test_trial_app_policy_is_cloud_only(- monkeypatch: pytest.MonkeyPatch,+ config_overrides: Callable[..., None],sqlite_session: Session,edition: DeploymentEdition,feature_enabled: bool,expected: bool,) -> None:- monkeypatch.setattr(service_module.dify_config, "DEPLOYMENT_EDITION", edition)- monkeypatch.setattr(service_module.dify_config, "ENABLE_TRIAL_APP", feature_enabled)+ config_overrides(DEPLOYMENT_EDITION=edition, ENABLE_TRIAL_APP=feature_enabled)assert RecommendedAppService.is_trial_app_enabled() is expected@@ -168,11 +177,7 @@ def _persist_app(session: Session, *, name: str) -> App:class TestRecommendedAppServiceGetApps:@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")- def test_success_with_apps(- self, mock_config: MagicMock, mock_factory_class: MagicMock, sqlite_session: Session- ) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "remote"+ def test_success_with_apps(self, mock_factory_class: MagicMock, sqlite_session: Session) -> None:expected = _apps_response()mock_instance = MagicMock()@@ -189,11 +194,7 @@ class TestRecommendedAppServiceGetApps:mock_instance.get_recommended_apps_and_categories.assert_called_once_with("en-US", session=sqlite_session)@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")- def test_fallback_to_builtin_when_empty(- self, mock_config: MagicMock, mock_factory_class: MagicMock, sqlite_session: Session- ) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "remote"+ def test_fallback_to_builtin_when_empty(self, mock_factory_class: MagicMock, sqlite_session: Session) -> None:empty_response = AppsResponse(recommended_apps=[], categories=[])builtin_response = _apps_response(recommended_apps=[{"app_id": "builtin-1", "name": "Builtin App", "category": "default"}]@@ -214,11 +215,13 @@ class TestRecommendedAppServiceGetApps:mock_builtin_instance.fetch_recommended_apps_from_builtin.assert_called_once_with("en-US")@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_fallback_when_none_recommended_apps(- self, mock_config: MagicMock, mock_factory_class: MagicMock, sqlite_session: Session+ self,+ mock_factory_class: MagicMock,+ sqlite_session: Session,+ config_overrides: Callable[..., None],) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "db"+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_MODE="db")none_response = AppsResponse(recommended_apps=None, categories=["test"])builtin_response = _apps_response()@@ -236,11 +239,13 @@ class TestRecommendedAppServiceGetApps:mock_builtin_instance.fetch_recommended_apps_from_builtin.assert_called_once()@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_different_languages(- self, mock_config: MagicMock, mock_factory_class: MagicMock, sqlite_session: Session+ self,+ mock_factory_class: MagicMock,+ sqlite_session: Session,+ config_overrides: Callable[..., None],) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "builtin"+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_MODE="builtin")for language in ["en-US", "zh-CN", "ja-JP", "fr-FR"]:lang_response = _apps_response(@@ -256,12 +261,14 @@ class TestRecommendedAppServiceGetApps:mock_instance.get_recommended_apps_and_categories.assert_called_with(language, session=sqlite_session)@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_uses_correct_factory_mode(- self, mock_config: MagicMock, mock_factory_class: MagicMock, sqlite_session: Session+ self,+ mock_factory_class: MagicMock,+ sqlite_session: Session,+ config_overrides: Callable[..., None],) -> None:for mode in ["remote", "builtin", "db"]:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = mode+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_MODE=mode)response = _apps_response()mock_instance = MagicMock()mock_instance.get_recommended_apps_and_categories.return_value = response@@ -310,16 +317,11 @@ class TestRecommendedAppServiceGetApp:class TestRecommendedAppServiceGetDetail:@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_returns_retrieval_detail_when_trial_disabled(self,- mock_config: MagicMock,mock_factory_class: MagicMock,sqlite_session: Session,) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "remote"- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- mock_config.ENABLE_TRIAL_APP = Truecases: list[tuple[str, RecommendedAppPayload]] = [("complex-app",@@ -350,17 +352,14 @@ class TestRecommendedAppServiceGetDetail:mock_instance.get_recommend_app_detail.assert_called_once_with(app_id, session=sqlite_session)@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_different_modes(self,- mock_config: MagicMock,mock_factory_class: MagicMock,sqlite_session: Session,+ config_overrides: Callable[..., None],) -> None:- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- mock_config.ENABLE_TRIAL_APP = Truefor mode in ["remote", "builtin", "db"]:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = mode+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_MODE=mode)detail = _app_detail(app_id="test-app", name=f"App from {mode}")mock_instance = MagicMock()mock_instance.get_recommend_app_detail.return_value = detail@@ -378,16 +377,11 @@ class TestRecommendedAppServiceGetDetail:class TestRecommendedAppServiceGetLearnDifyApps:@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_uses_configured_retrieval_source(self,- mock_config: MagicMock,mock_factory_class: MagicMock,sqlite_session: Session,) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "remote"- mock_config.DEPLOYMENT_EDITION = DeploymentEdition.COMMUNITY- mock_config.ENABLE_TRIAL_APP = Trueexpected_app = RecommendedAppPayload(app_id="app-1", category="Workflow")mock_instance = MagicMock()mock_instance.get_learn_dify_apps.return_value = {@@ -402,11 +396,13 @@ class TestRecommendedAppServiceGetLearnDifyApps:mock_factory_class.get_recommend_app_factory.assert_called_once_with("remote")mock_instance.get_learn_dify_apps.assert_called_once_with("en-US", session=sqlite_session)- @patch("services.recommended_app_service.dify_config")def test_sets_can_trial_when_trial_feature_enabled(- self, mock_config: MagicMock, monkeypatch: pytest.MonkeyPatch, sqlite_session: Session+ self,+ monkeypatch: pytest.MonkeyPatch,+ sqlite_session: Session,+ config_overrides: Callable[..., None],) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "db"+ config_overrides(HOSTED_FETCH_APP_TEMPLATES_MODE="db")app = RecommendedAppPayload(app_id="app-1", category="Workflow")mock_retrieval_instance = MagicMock()mock_retrieval_instance.get_learn_dify_apps.return_value = {@@ -514,14 +510,11 @@ class TestRecommendedAppServiceTrialFeatures:assert detail_result["can_trial"] is has_trial_app@patch("services.recommended_app_service.RecommendAppRetrievalFactory", autospec=True)- @patch("services.recommended_app_service.dify_config")def test_get_detail_returns_none_before_reading_trial_flag(self,- mock_config: MagicMock,mock_factory_class: MagicMock,sqlite_session: Session,) -> None:- mock_config.HOSTED_FETCH_APP_TEMPLATES_MODE = "remote"mock_instance = MagicMock()mock_instance.get_recommend_app_detail.return_value = Nonemock_factory_class.get_recommend_app_factory.return_value = MagicMock(return_value=mock_instance)