Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Corentin André <corentin.andre@mistral.ai>
Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com>
Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai>
Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com>
Co-authored-by: Peter Evers <pevers90@gmail.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: MichisGitIsKing <MichisGitIsKing@users.noreply.github.com>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Mathias Gesbert 2026-05-19 11:56:25 +02:00 committed by GitHub
parent 626f905186
commit 228f3c65a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
158 changed files with 7235 additions and 916 deletions

View file

@ -346,7 +346,10 @@ class TestSessionLoaderFindLatestSession:
assert result == valid_session
def test_find_latest_session_skips_unreadable_messages_file(
self, session_config: SessionLoggingConfig, create_test_session
self,
session_config: SessionLoggingConfig,
create_test_session,
monkeypatch: pytest.MonkeyPatch,
) -> None:
session_dir = Path(session_config.save_dir)
@ -355,14 +358,28 @@ class TestSessionLoaderFindLatestSession:
unreadable_session = create_test_session(session_dir, "unreadab-session")
unreadable_messages = unreadable_session / "messages.jsonl"
unreadable_messages.chmod(0)
# chmod doesn't restrict root, so simulate an unreadable file by
# patching Path.read_bytes (used under the hood by read_safe). This
# keeps the test working in CI environments running as root.
original_read_bytes = Path.read_bytes
def fake_read_bytes(self: Path) -> bytes:
if self == unreadable_messages:
raise PermissionError(f"Permission denied: {self}")
return original_read_bytes(self)
monkeypatch.setattr(Path, "read_bytes", fake_read_bytes)
result = SessionLoader.find_latest_session(session_config)
assert result is not None
assert result == valid_session
def test_find_latest_session_skips_unreadable_metadata_file(
self, session_config: SessionLoggingConfig, create_test_session
self,
session_config: SessionLoggingConfig,
create_test_session,
monkeypatch: pytest.MonkeyPatch,
) -> None:
session_dir = Path(session_config.save_dir)
@ -371,7 +388,15 @@ class TestSessionLoaderFindLatestSession:
unreadable_session = create_test_session(session_dir, "unreadab-session")
unreadable_metadata = unreadable_session / "meta.json"
unreadable_metadata.chmod(0)
original_read_bytes = Path.read_bytes
def fake_read_bytes(self: Path) -> bytes:
if self == unreadable_metadata:
raise PermissionError(f"Permission denied: {self}")
return original_read_bytes(self)
monkeypatch.setattr(Path, "read_bytes", fake_read_bytes)
result = SessionLoader.find_latest_session(session_config)
assert result is not None
@ -436,6 +461,41 @@ class TestSessionLoaderFindSessionById:
assert result is not None
assert result == session_2
def test_find_session_by_id_filters_by_working_directory(
self, session_config: SessionLoggingConfig, create_test_session
) -> None:
session_dir = Path(session_config.save_dir)
session_a = create_test_session(
session_dir,
"abcd1234-session",
working_directory=Path("/home/user/project-a"),
)
time.sleep(0.01)
session_b = create_test_session(
session_dir,
"abcd1234-session",
working_directory=Path("/home/user/project-b"),
)
assert (
SessionLoader.find_session_by_id(
"abcd1234",
session_config,
working_directory=Path("/home/user/project-a"),
)
== session_a
)
assert (
SessionLoader.find_session_by_id(
"abcd1234",
session_config,
working_directory=Path("/home/user/project-c"),
)
is None
)
assert SessionLoader.find_session_by_id("abcd1234", session_config) == session_b
def test_find_session_by_id_no_match(
self, session_config: SessionLoggingConfig, create_test_session
) -> None: