File size: 1,761 Bytes
35e80ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Fixtures: settings that never touch the network or the real cache."""

from __future__ import annotations

import logging

import pytest

from ai_coach.config import Settings
from ai_coach.input_builder import build_coach_input
from ai_coach.schemas import CoachInput

from .helpers import example_names, load_example


@pytest.fixture(autouse=True)
def isolate_coach_logging():
    """Entry-point tests must not leave their file handlers or propagation policy behind."""
    logger = logging.getLogger("ai_coach")
    handlers = list(logger.handlers)
    level, propagate, disabled = logger.level, logger.propagate, logger.disabled
    try:
        yield
    finally:
        for handler in list(logger.handlers):
            if handler not in handlers:
                logger.removeHandler(handler)
                handler.close()
        for handler in handlers:
            if handler not in logger.handlers:
                logger.addHandler(handler)
        logger.setLevel(level)
        logger.propagate, logger.disabled = propagate, disabled


@pytest.fixture
def settings(tmp_path) -> Settings:
    """LLM disabled by default; tests that need it pass a key explicitly."""
    return Settings(_env_file=None, google_api_key=None, cache_path=tmp_path / "cache.sqlite3", daily_budget_usd=1.0)


@pytest.fixture
def keyed_settings(tmp_path) -> Settings:
    return Settings(
        _env_file=None,
        google_api_key="test-key-123",
        cache_path=tmp_path / "cache.sqlite3",
        model="gemini-3.1-flash-lite",
        escalation_model="gemini-3.8-flash",
        daily_budget_usd=1.0,
    )


@pytest.fixture
def real_inputs() -> dict[str, CoachInput]:
    return {name: build_coach_input(load_example(name)) for name in example_names()}