fix(credentials): align EnvVarStorage exists with load semantics (#5680)

* Return boolean from exists method for credential check

* Add test for empty value handling in EnvVarStorage

Add test to verify exists() and load() consistency for empty values in EnvVarStorage.
This commit is contained in:
Harshit Shukla
2026-04-30 17:10:28 +05:30
committed by GitHub
parent 3d5f2595c9
commit 038c5fd807
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -519,7 +519,7 @@ class EnvVarStorage(CredentialStorage):
def exists(self, credential_id: str) -> bool:
"""Check if credential is available in environment."""
env_var = self._get_env_var_name(credential_id)
return self._read_env_value(env_var) is not None
return bool(self._read_env_value(env_var))
def add_mapping(self, credential_id: str, env_var: str) -> None:
"""
@@ -258,6 +258,14 @@ class TestEnvVarStorage:
with pytest.raises(NotImplementedError):
storage.delete("test")
def test_exists_matches_load_for_empty_value(self):
"""Test exists() and load() stay consistent for empty values."""
storage = EnvVarStorage(env_mapping={"empty": "EMPTY_API_KEY"})
with patch.object(storage, "_read_env_value", return_value=""):
assert storage.load("empty") is None
assert not storage.exists("empty")
class TestEncryptedFileStorage:
"""Tests for EncryptedFileStorage."""