05c3efd09c
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 3m19s
CI / typecheck (pull_request) Successful in 3m55s
CI / quality (pull_request) Successful in 4m16s
CI / unit_tests (pull_request) Failing after 4m22s
CI / security (pull_request) Successful in 4m42s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Successful in 6m54s
CI / coverage (pull_request) Successful in 11m41s
CI / status-check (pull_request) Failing after 1s
CI / e2e_tests (pull_request) Successful in 8m21s
CI / benchmark-regression (pull_request) Successful in 55m3s
Ensure that when database_url is a relative path (like sqlite:///cleveragents.db), it resolves relative to CLEVERAGENTS_HOME instead of the current working directory. This fixes E2E test isolation where data from previous runs persisted across runs at CWD, causing UNIQUE constraint failures. Changes: - Added _resolve_database_urls model validator in Settings to rewrite relative SQLite paths to absolute paths under CLEVERAGENTS_HOME - Updated get_database_url() in container.py to use CLEVERAGENTS_HOME as base directory and create parent directories when CLEVERAGENTS_HOME is explicitly set - Updated _check_database() in system.py to walk up directory tree for writable ancestor check, handling cases where intermediate directories have not yet been created - Removed @tdd_expected_fail from TDD test (now passes genuinely) ISSUES CLOSED: #1024
154 lines
5.2 KiB
Python
154 lines
5.2 KiB
Python
"""Step definitions for coverage boost tests."""
|
|
|
|
import os
|
|
|
|
from behave import then, when
|
|
|
|
from cleveragents.config.settings import Settings
|
|
from cleveragents.platform import ensure_cli_importable
|
|
|
|
|
|
@when("I create a Settings instance")
|
|
def step_create_settings(context):
|
|
"""Create a Settings instance."""
|
|
# Clear any existing singleton
|
|
if hasattr(Settings, "_instance"):
|
|
Settings._instance = None
|
|
# Remove database URL env vars so we test the actual pydantic defaults,
|
|
# not the per-scenario temp paths injected by environment.py.
|
|
for key in ("CLEVERAGENTS_DATABASE_URL", "CLEVERAGENTS_TEST_DATABASE_URL"):
|
|
os.environ.pop(key, None)
|
|
context.settings = Settings()
|
|
|
|
|
|
@then("it should have default values")
|
|
def step_check_default_values(context):
|
|
"""Check Settings has default values."""
|
|
assert context.settings.server_host == "0.0.0.0"
|
|
assert context.settings.server_port == 8080
|
|
# After the _resolve_database_urls validator, relative SQLite paths are
|
|
# resolved to absolute paths under CLEVERAGENTS_HOME (or CWD).
|
|
assert context.settings.database_url.startswith("sqlite:///")
|
|
assert context.settings.database_url.endswith("cleveragents.db")
|
|
assert context.settings.debug_log_level == "INFO"
|
|
assert context.settings.storage_base_path.name == "data"
|
|
|
|
|
|
@when("I check if Settings is in production mode")
|
|
def step_check_production_mode(context):
|
|
"""Check production mode."""
|
|
settings = Settings()
|
|
context.is_production = settings.is_production
|
|
|
|
|
|
@then("it should return the correct production status")
|
|
def step_verify_production_status(context):
|
|
"""Verify production status."""
|
|
# Default should be production (debug_enabled=False, server_reload=False)
|
|
assert context.is_production
|
|
|
|
|
|
@when("I get the database URL from Settings")
|
|
def step_get_database_url(context):
|
|
"""Get database URL."""
|
|
# Clear singleton and database URL env vars so we test the actual
|
|
# pydantic defaults, not per-scenario temp paths from environment.py.
|
|
if hasattr(Settings, "_instance"):
|
|
Settings._instance = None
|
|
for key in ("CLEVERAGENTS_DATABASE_URL", "CLEVERAGENTS_TEST_DATABASE_URL"):
|
|
os.environ.pop(key, None)
|
|
settings = Settings()
|
|
context.db_url = settings.get_database_url()
|
|
context.test_db_url = settings.get_database_url(test=True)
|
|
|
|
|
|
@then("it should return the configured database URL")
|
|
def step_check_database_url(context):
|
|
"""Check database URL."""
|
|
# After the _resolve_database_urls validator, relative SQLite paths are
|
|
# resolved to absolute paths under CLEVERAGENTS_HOME (or CWD).
|
|
assert context.db_url.startswith("sqlite:///")
|
|
assert context.db_url.endswith("cleveragents.db")
|
|
assert context.test_db_url.startswith("sqlite:///")
|
|
assert context.test_db_url.endswith("cleveragents_test.db")
|
|
|
|
|
|
@when("I check if any provider is configured in Settings")
|
|
def step_check_provider_configured(context):
|
|
"""Check if provider is configured."""
|
|
import shutil
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Clear any existing settings
|
|
from cleveragents.config import settings as settings_module
|
|
from cleveragents.config.settings import Settings
|
|
|
|
settings_module._settings = None
|
|
|
|
# Store current env vars
|
|
stored_vars = {}
|
|
for key in [
|
|
"OPENAI_API_KEY",
|
|
"ANTHROPIC_API_KEY",
|
|
"GOOGLE_API_KEY",
|
|
"AZURE_API_KEY",
|
|
"OPENROUTER_API_KEY",
|
|
"GEMINI_API_KEY",
|
|
"HF_TOKEN",
|
|
]:
|
|
stored_vars[key] = os.environ.get(key)
|
|
os.environ.pop(key, None)
|
|
|
|
# Move .env file temporarily if it exists
|
|
env_file = Path(".env")
|
|
temp_env = None
|
|
if env_file.exists():
|
|
temp_env = Path(tempfile.mktemp(suffix=".env"))
|
|
shutil.move(str(env_file), str(temp_env))
|
|
|
|
try:
|
|
# Test with no providers
|
|
settings1 = Settings()
|
|
context.no_provider = settings1.has_provider_configured()
|
|
|
|
# Test with a provider
|
|
os.environ["OPENAI_API_KEY"] = "test-key"
|
|
# Force new settings instance
|
|
settings_module._settings = None
|
|
settings2 = Settings()
|
|
context.with_provider = settings2.has_provider_configured()
|
|
finally:
|
|
# Restore .env file
|
|
if temp_env and temp_env.exists():
|
|
shutil.move(str(temp_env), str(env_file))
|
|
|
|
# Clean up and restore env vars
|
|
os.environ.pop("OPENAI_API_KEY", None)
|
|
for key, val in stored_vars.items():
|
|
if val:
|
|
os.environ[key] = val
|
|
settings_module._settings = None
|
|
|
|
|
|
@then("it should return the provider status")
|
|
def step_verify_provider_status(context):
|
|
"""Verify provider status."""
|
|
assert not context.no_provider
|
|
assert context.with_provider
|
|
|
|
|
|
@when("I import and use the platform module")
|
|
def step_use_platform_module(context):
|
|
"""Use platform module."""
|
|
context.cli_module = ensure_cli_importable()
|
|
|
|
|
|
@then("ensure_cli_importable should work")
|
|
def step_check_cli_importable(context):
|
|
"""Check ensure_cli_importable worked."""
|
|
assert context.cli_module is not None
|
|
assert context.cli_module.__name__ == "cleveragents.cli"
|
|
assert hasattr(context.cli_module, "main")
|
|
assert hasattr(context.cli_module, "app")
|