75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from lai_automation.config import Settings
|
|
|
|
|
|
def base_environment(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv(
|
|
"SOURCE_REPOSITORY",
|
|
"https://gitea.example.test/owner/lai.git",
|
|
)
|
|
monkeypatch.setenv("GITEA_URL", "https://gitea.example.test")
|
|
monkeypatch.setenv("GITEA_OWNER", "owner")
|
|
monkeypatch.setenv("GITEA_REPOSITORY", "lai")
|
|
monkeypatch.setenv("GITEA_TOKEN", "secret")
|
|
monkeypatch.setenv("MISTRAL_API_KEY", "model-secret")
|
|
monkeypatch.setenv("TEST_DB_NAME", "lai_agent_test")
|
|
monkeypatch.setenv("TEST_CUSTOMER_DB", "customer_agent_test")
|
|
monkeypatch.setenv("TEST_CONFIG_DB", "config_agent_test")
|
|
|
|
|
|
def test_settings_load_issue_workflow_defaults(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
base_environment(monkeypatch)
|
|
|
|
settings = Settings.from_env()
|
|
|
|
assert settings.queued_label == "ai:queued"
|
|
assert settings.running_label == "ai:running"
|
|
assert settings.agent_model == "mistral/devstral-latest"
|
|
assert settings.test_commands == ("npm run build", "php artisan test")
|
|
assert settings.test_environment["DB_DATABASE"] == "lai_agent_test"
|
|
assert settings.test_environment["ERP_DATABASE"] == "customer_agent_test"
|
|
assert settings.test_environment["COCKPIT_CONFIG_DATABASE"] == "config_agent_test"
|
|
assert settings.test_environment["AGENT_TEST_DB_ENABLED"] == "true"
|
|
assert settings.test_environment["AI_MISTRAL_API_KEY"] == "test-only-placeholder"
|
|
assert "GITEA_TOKEN" not in settings.test_environment
|
|
assert "MISTRAL_API_KEY" not in settings.test_environment
|
|
|
|
|
|
def test_settings_reject_non_https_source(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
base_environment(monkeypatch)
|
|
monkeypatch.setenv(
|
|
"SOURCE_REPOSITORY",
|
|
"http://gitea.example.test/owner/lai.git",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="HTTPS"):
|
|
Settings.from_env()
|
|
|
|
|
|
def test_settings_reject_different_repository_host(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
base_environment(monkeypatch)
|
|
monkeypatch.setenv(
|
|
"SOURCE_REPOSITORY",
|
|
"https://attacker.example/owner/lai.git",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="configured Gitea"):
|
|
Settings.from_env()
|
|
|
|
|
|
def test_settings_require_isolated_test_database(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
base_environment(monkeypatch)
|
|
monkeypatch.setenv("TEST_DB_NAME", "production")
|
|
|
|
with pytest.raises(ValueError, match="isolated test database"):
|
|
Settings.from_env()
|