Files
cleveragents-core/benchmarks/_session_bench_common.py
brent.edwards 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
test(session): add TDD failing tests for session create DI error
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
2026-03-11 02:42:13 +00:00

46 lines
1.3 KiB
Python

"""Shared helpers for TDD session DI ASV benchmarks.
Extracted from ``tdd_session_create_di_bench.py`` and
``tdd_session_list_di_bench.py`` to eliminate duplication (review finding F9).
"""
from __future__ import annotations
import sys
from datetime import datetime
from pathlib import Path
# Ensure the local *source* tree is importable even when ASV has an
# older build of the package installed. This is a permanent mutation of
# ``sys.path`` — acceptable because ASV runs each benchmark suite in its
# own isolated process.
_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 ulid import ULID # noqa: E402
from cleveragents.domain.models.core.session import ( # noqa: E402
Session,
SessionTokenUsage,
)
runner = CliRunner()
def mock_session(
session_id: str | None = None,
actor_name: str | None = None,
) -> Session:
"""Create a ``Session`` instance with sensible defaults for benchmarks."""
return Session(
session_id=session_id or str(ULID()),
actor_name=actor_name,
namespace="local",
messages=[],
token_usage=SessionTokenUsage(),
created_at=datetime.now(),
updated_at=datetime.now(),
)