from __future__ import annotations import json from pathlib import Path import pytest from fastapi.testclient import TestClient from backend.main import app from backend.services import ai_service, history_service, note_service, reminder_service, task_service @pytest.fixture(autouse=True) def isolated_storage(tmp_path: Path): stores = [ (history_service.STORE, tmp_path / "chats.json", {"sessions": [], "saved_messages": []}), (task_service.STORE, tmp_path / "tasks.json", []), (reminder_service.STORE, tmp_path / "reminders.json", []), (note_service.STORE, tmp_path / "notes.json", []), ] for store, path, default in stores: store.path = path store.default = json.loads(json.dumps(default)) store.path.parent.mkdir(parents=True, exist_ok=True) store.write(json.loads(json.dumps(default))) ai_service.LLM_API_KEY = None ai_service.LLM_API_URL = None ai_service.LLM_MODEL = ai_service._default_model() yield @pytest.fixture def client(): with TestClient(app) as test_client: yield test_client