aa5d5eeaf5
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 16s
CI / quality (pull_request) Successful in 18s
CI / security (pull_request) Successful in 36s
CI / typecheck (pull_request) Successful in 38s
CI / unit_tests (pull_request) Successful in 2m42s
CI / integration_tests (pull_request) Successful in 3m13s
CI / docker (pull_request) Successful in 39s
CI / coverage (pull_request) Successful in 6m15s
CI / benchmark-regression (pull_request) Successful in 34m51s
Implement TDD bug-capture tests for bug #570 where `agents session create` fails because `_get_session_service()` calls `container.db()` which does not exist on the DI Container class (AttributeError). Same root cause as bug #554. Behave BDD scenarios tagged @tdd_bug @tdd_bug_570 @tdd_expected_fail exercise the real DI path (no mocks). Includes Robot Framework integration smoke tests with self-inverting helper and ASV benchmark baseline. ISSUES CLOSED: #631
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Shared setup/teardown for TDD session DI Robot helpers.
|
|
|
|
Extracted from ``helper_tdd_session_create_di.py`` and
|
|
``helper_tdd_session_list_di.py`` to eliminate duplication (review finding F8).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
# Ensure local source tree is importable
|
|
_SRC = str(Path(__file__).resolve().parents[1] / "src")
|
|
if _SRC not in sys.path:
|
|
sys.path.insert(0, _SRC)
|
|
|
|
from typer.testing import CliRunner # noqa: E402
|
|
|
|
from cleveragents.application.container import reset_container # noqa: E402
|
|
from cleveragents.cli.commands import session as session_mod # noqa: E402
|
|
from cleveragents.config.settings import Settings # noqa: E402
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def setup_real_di() -> str:
|
|
"""Prepare the environment for real DI resolution.
|
|
|
|
Returns the path to a temporary database file (caller must clean up).
|
|
"""
|
|
session_mod._service = None
|
|
# Reset any stale container from a prior test.
|
|
reset_container()
|
|
fd, db_path = tempfile.mkstemp(suffix=".db")
|
|
os.close(fd)
|
|
os.environ["CLEVERAGENTS_DATABASE_URL"] = f"sqlite:///{db_path}"
|
|
return db_path
|
|
|
|
|
|
def teardown(db_path: str) -> None:
|
|
"""Clean up after a test."""
|
|
session_mod._service = None
|
|
os.environ.pop("CLEVERAGENTS_DATABASE_URL", None)
|
|
reset_container()
|
|
# Reset the Settings singleton so stale database URLs do not leak.
|
|
Settings._instance = None
|
|
Path(db_path).unlink(missing_ok=True)
|