fix: commit semantic repair changes
This commit is contained in:
@@ -14,11 +14,14 @@ from src.plugins.llm_analysis.models import LLMProviderConfig, LLMProviderType
|
||||
|
||||
# [DEF:_test_encryption_key_fixture:Global]
|
||||
# @PURPOSE: Ensure encryption-dependent provider tests run with a valid Fernet key.
|
||||
# @RELATION: DEPENDS_ON ->[pytest:Module]
|
||||
os.environ.setdefault("ENCRYPTION_KEY", Fernet.generate_key().decode())
|
||||
# [/DEF:_test_encryption_key_fixture:Global]
|
||||
|
||||
# @TEST_CONTRACT: EncryptionManagerModel -> Invariants
|
||||
# @TEST_INVARIANT: symmetric_encryption
|
||||
# [DEF:test_encryption_cycle:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_encryption_cycle():
|
||||
"""Verify encrypted data can be decrypted back to original string."""
|
||||
manager = EncryptionManager()
|
||||
@@ -28,6 +31,10 @@ def test_encryption_cycle():
|
||||
assert manager.decrypt(encrypted) == original
|
||||
|
||||
# @TEST_EDGE: empty_string_encryption
|
||||
# [/DEF:test_encryption_cycle:Function]
|
||||
|
||||
# [DEF:test_empty_string_encryption:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_empty_string_encryption():
|
||||
manager = EncryptionManager()
|
||||
original = ""
|
||||
@@ -35,12 +42,18 @@ def test_empty_string_encryption():
|
||||
assert manager.decrypt(encrypted) == ""
|
||||
|
||||
# @TEST_EDGE: decrypt_invalid_data
|
||||
# [/DEF:test_empty_string_encryption:Function]
|
||||
|
||||
# [DEF:test_decrypt_invalid_data:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_decrypt_invalid_data():
|
||||
manager = EncryptionManager()
|
||||
with pytest.raises(Exception):
|
||||
manager.decrypt("not-encrypted-string")
|
||||
|
||||
# @TEST_FIXTURE: mock_db_session
|
||||
# [/DEF:test_decrypt_invalid_data:Function]
|
||||
|
||||
@pytest.fixture
|
||||
def mock_db():
|
||||
return MagicMock(spec=Session)
|
||||
@@ -49,11 +62,17 @@ def mock_db():
|
||||
def service(mock_db):
|
||||
return LLMProviderService(db=mock_db)
|
||||
|
||||
# [DEF:test_get_all_providers:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_get_all_providers(service, mock_db):
|
||||
service.get_all_providers()
|
||||
mock_db.query.assert_called()
|
||||
mock_db.query().all.assert_called()
|
||||
|
||||
# [/DEF:test_get_all_providers:Function]
|
||||
|
||||
# [DEF:test_create_provider:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_create_provider(service, mock_db):
|
||||
config = LLMProviderConfig(
|
||||
provider_type=LLMProviderType.OPENAI,
|
||||
@@ -73,6 +92,10 @@ def test_create_provider(service, mock_db):
|
||||
# Decrypt to verify it matches
|
||||
assert EncryptionManager().decrypt(provider.api_key) == "sk-test"
|
||||
|
||||
# [/DEF:test_create_provider:Function]
|
||||
|
||||
# [DEF:test_get_decrypted_api_key:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_get_decrypted_api_key(service, mock_db):
|
||||
# Setup mock provider
|
||||
encrypted_key = EncryptionManager().encrypt("secret-value")
|
||||
@@ -82,10 +105,18 @@ def test_get_decrypted_api_key(service, mock_db):
|
||||
key = service.get_decrypted_api_key("p1")
|
||||
assert key == "secret-value"
|
||||
|
||||
# [/DEF:test_get_decrypted_api_key:Function]
|
||||
|
||||
# [DEF:test_get_decrypted_api_key_not_found:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_get_decrypted_api_key_not_found(service, mock_db):
|
||||
mock_db.query().filter().first.return_value = None
|
||||
assert service.get_decrypted_api_key("missing") is None
|
||||
|
||||
# [/DEF:test_get_decrypted_api_key_not_found:Function]
|
||||
|
||||
# [DEF:test_update_provider_ignores_masked_placeholder_api_key:Function]
|
||||
# @RELATION: BINDS_TO -> __tests__/test_llm_provider
|
||||
def test_update_provider_ignores_masked_placeholder_api_key(service, mock_db):
|
||||
existing_encrypted = EncryptionManager().encrypt("secret-value")
|
||||
mock_provider = LLMProvider(
|
||||
@@ -114,3 +145,4 @@ def test_update_provider_ignores_masked_placeholder_api_key(service, mock_db):
|
||||
assert updated.api_key == existing_encrypted
|
||||
assert EncryptionManager().decrypt(updated.api_key) == "secret-value"
|
||||
assert updated.is_active is False
|
||||
# [/DEF:test_update_provider_ignores_masked_placeholder_api_key:Function]
|
||||
|
||||
Reference in New Issue
Block a user