diff --git a/src/goose/cli/config.py b/src/goose/cli/config.py index ef60aa3d6..ce576e4c0 100644 --- a/src/goose/cli/config.py +++ b/src/goose/cli/config.py @@ -1,6 +1,5 @@ from functools import cache from io import StringIO -from pathlib import Path from typing import Callable, Dict, Mapping, Tuple from rich import print @@ -9,7 +8,7 @@ from rich.text import Text from ruamel.yaml import YAML -from ..config import SESSIONS_PATH, SESSION_FILE_SUFFIX, PROFILES_CONFIG_PATH +from ..config import PROFILES_CONFIG_PATH from goose.profile import Profile from goose.utils import load_plugins from goose.utils.diff import pretty_diff @@ -19,12 +18,6 @@ def default_profiles() -> Mapping[str, Callable]: return load_plugins(group="goose.profile") - -def session_path(name: str) -> Path: - SESSIONS_PATH.mkdir(parents=True, exist_ok=True) - return SESSIONS_PATH.joinpath(f"{name}{SESSION_FILE_SUFFIX}") - - def write_config(profiles: Dict[str, Profile]) -> None: """Overwrite the config with the passed profiles""" PROFILES_CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True) diff --git a/src/goose/cli/main.py b/src/goose/cli/main.py index b79bbfab5..085fd2d86 100644 --- a/src/goose/cli/main.py +++ b/src/goose/cli/main.py @@ -7,7 +7,7 @@ from rich import print from ruamel.yaml import YAML -from goose.cli.config import SESSIONS_PATH +from ..config import SESSIONS_PATH from goose.cli.session import Session from goose.utils import load_plugins from goose.utils.session_file import list_sorted_session_files diff --git a/src/goose/cli/session.py b/src/goose/cli/session.py index 713bd1f8c..f4208db57 100644 --- a/src/goose/cli/session.py +++ b/src/goose/cli/session.py @@ -16,8 +16,8 @@ default_profiles, ensure_config, read_config, - session_path, ) +from ..utils.session_file import session_path from goose.cli.prompt.goose_prompt_session import GoosePromptSession from goose.notifier import Notifier from goose.profile import Profile diff --git a/src/goose/utils/session_file.py b/src/goose/utils/session_file.py index 1f33ea7de..2927717e5 100644 --- a/src/goose/utils/session_file.py +++ b/src/goose/utils/session_file.py @@ -4,7 +4,7 @@ from exchange import Message -from goose.cli.config import SESSION_FILE_SUFFIX +from ..config import SESSIONS_PATH, SESSION_FILE_SUFFIX def write_to_file(file_path: Path, messages: List[Message]) -> None: with open(file_path, "w") as f: @@ -36,3 +36,7 @@ def session_file_exists(session_files_directory: Path) -> bool: if not session_files_directory.exists(): return False return any(list_session_files(session_files_directory)) + +def session_path(name: str) -> Path: + SESSIONS_PATH.mkdir(parents=True, exist_ok=True) + return SESSIONS_PATH.joinpath(f"{name}{SESSION_FILE_SUFFIX}") diff --git a/tests/cli/test_config.py b/tests/cli/test_config.py index b857f8b99..d9e8e9da3 100644 --- a/tests/cli/test_config.py +++ b/tests/cli/test_config.py @@ -1,7 +1,7 @@ from unittest.mock import patch import pytest -from goose.cli.config import ensure_config, read_config, session_path, write_config +from goose.cli.config import ensure_config, read_config, write_config from goose.profile import default_profile @@ -76,6 +76,3 @@ def test_ensure_config_keep_original_default_profile( assert read_config() == {"default": existing_profile} - -def test_session_path(mock_sessions_path): - assert session_path("session1") == mock_sessions_path / "session1.jsonl" diff --git a/tests/cli/test_session.py b/tests/cli/test_session.py index 79a7c4a2b..a14840ccd 100644 --- a/tests/cli/test_session.py +++ b/tests/cli/test_session.py @@ -16,14 +16,18 @@ def mock_specified_session_name(): with patch.object(PromptSession, "prompt", return_value=SPECIFIED_SESSION_NAME) as specified_session_name: yield specified_session_name +@pytest.fixture +def mock_sessions_path(tmp_path): + with patch("goose.config.SESSIONS_PATH", tmp_path) as mock_path: + yield mock_path @pytest.fixture -def create_session_with_mock_configs(mock_sessions_path, exchange_factory, profile_factory): +def create_session_with_mock_configs(exchange_factory, profile_factory, tmp_path): with patch("goose.cli.session.build_exchange", return_value=exchange_factory()), patch( "goose.cli.session.load_profile", return_value=profile_factory() ), patch("goose.cli.session.SessionNotifier") as mock_session_notifier, patch( "goose.cli.session.load_provider", return_value="provider" - ): + ), patch("goose.utils.session_file.SESSIONS_PATH", tmp_path): mock_session_notifier.return_value = MagicMock() def create_session(session_attributes: dict = {}): diff --git a/tests/conftest.py b/tests/conftest.py index 975066579..7ec6942aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -40,12 +40,6 @@ def _create_exchange(attributes={}): return _create_exchange -@pytest.fixture -def mock_sessions_path(tmp_path): - with patch("goose.cli.config.SESSIONS_PATH", tmp_path) as mock_path: - yield mock_path - - @pytest.fixture def create_session_file(): def _create_session_file(messages, session_file_path, mtime=time()): diff --git a/tests/utils/test_session_file.py b/tests/utils/test_session_file.py index d922bd81d..935eea2c5 100644 --- a/tests/utils/test_session_file.py +++ b/tests/utils/test_session_file.py @@ -1,8 +1,9 @@ from pathlib import Path +from unittest.mock import patch import pytest from exchange import Message -from goose.utils.session_file import list_sorted_session_files, read_from_file, session_file_exists, write_to_file +from goose.utils.session_file import list_sorted_session_files, read_from_file, session_file_exists, session_path, write_to_file @pytest.fixture @@ -75,3 +76,7 @@ def create_session_file(file_path, file_name) -> Path: file = file_path / f"{file_name}.jsonl" file.touch() return file + +def test_session_path(tmp_path): + with patch("goose.utils.session_file.SESSIONS_PATH", tmp_path) as mock_session_path: + assert session_path("session1") == mock_session_path / "session1.jsonl"