diff --git a/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py b/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py index dafba7adf..376142c05 100644 --- a/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py +++ b/packages/jupyter-ai/jupyter_ai/tests/test_config_manager.py @@ -3,6 +3,7 @@ import os import pytest +from unittest.mock import mock_open, patch from jupyter_ai.config_manager import ( AuthError, ConfigManager, @@ -83,6 +84,11 @@ def reset(config_path, schema_path): pass +@pytest.fixture +def config_with_bad_provider_ids(): + return json.dumps({"model_provider_id:": "foo", "embeddings_provider_id": "bar"}) + + def configure_to_cohere(cm: ConfigManager): """Configures the ConfigManager to use Cohere language and embedding models with the API key set. Returns a 3-tuple of the keyword arguments used.""" @@ -290,3 +296,11 @@ def test_forbid_deleting_key_in_use(cm: ConfigManager): with pytest.raises(KeyInUseError): cm.delete_api_key("COHERE_API_KEY") + + +def test_handle_bad_provider_ids(config_with_bad_provider_ids, common_cm_kwargs): + with patch("builtins.open", mock_open(read_data=config_with_bad_provider_ids)): + cm = ConfigManager(**common_cm_kwargs) + config_desc = cm.get_config() + assert config_desc.model_provider_id is None + assert config_desc.embeddings_provider_id is None