v2.14.0 (#743)
Co-authored-by: Alexis Tacnet <alexis@mistral.ai> Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Lucas Marandat <31749711+lucasmrdt@users.noreply.github.com> Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai> Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai> Co-authored-by: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Val <102326092+vdeva@users.noreply.github.com> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: p.vezia <166131032+le-codeur-rapide@users.noreply.github.com> Co-authored-by: Hiba Chaabnia <Hiba-Chaabnia@users.noreply.github.com> Co-authored-by: Nikhil Bhima <nikhilbhima@users.noreply.github.com> Co-authored-by: Nkipohcs <Nkipohcs@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
ad0d5c9520
commit
3f8487f761
197 changed files with 10819 additions and 2830 deletions
71
tests/core/session/test_image_snapshot.py
Normal file
71
tests/core/session/test_image_snapshot.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from vibe.core.session.image_snapshot import ImageSnapshotError, snapshot_image
|
||||
|
||||
PNG_BYTES = b"\x89PNG\r\n\x1a\n" + b"\x00" * 16
|
||||
|
||||
|
||||
def test_snapshot_image_copies_to_attachments_dir(tmp_path: Path) -> None:
|
||||
src = tmp_path / "screenshot.png"
|
||||
src.write_bytes(PNG_BYTES)
|
||||
session_dir = tmp_path / "session"
|
||||
session_dir.mkdir()
|
||||
|
||||
att = snapshot_image(src, alias="screenshot.png", session_dir=session_dir)
|
||||
|
||||
digest = hashlib.sha1(PNG_BYTES, usedforsecurity=False).hexdigest()
|
||||
assert att.path == (session_dir / "attachments" / f"{digest}.png").resolve()
|
||||
assert att.alias == "screenshot.png"
|
||||
assert att.mime_type == "image/png"
|
||||
assert att.path.read_bytes() == PNG_BYTES
|
||||
|
||||
|
||||
def test_snapshot_image_is_idempotent_on_same_bytes(tmp_path: Path) -> None:
|
||||
src_a = tmp_path / "a.png"
|
||||
src_b = tmp_path / "b.png"
|
||||
src_a.write_bytes(PNG_BYTES)
|
||||
src_b.write_bytes(PNG_BYTES)
|
||||
session_dir = tmp_path / "session"
|
||||
|
||||
att_a = snapshot_image(src_a, alias="a.png", session_dir=session_dir)
|
||||
att_b = snapshot_image(src_b, alias="b.png", session_dir=session_dir)
|
||||
|
||||
assert att_a.path == att_b.path
|
||||
assert sum(1 for _ in (session_dir / "attachments").iterdir()) == 1
|
||||
|
||||
|
||||
def test_snapshot_image_returns_source_when_session_dir_is_none(tmp_path: Path) -> None:
|
||||
src = tmp_path / "screenshot.png"
|
||||
src.write_bytes(PNG_BYTES)
|
||||
|
||||
att = snapshot_image(src, alias="screenshot.png", session_dir=None)
|
||||
|
||||
assert att.path == src.resolve()
|
||||
assert att.alias == "screenshot.png"
|
||||
|
||||
|
||||
def test_snapshot_image_rejects_non_image_extension(tmp_path: Path) -> None:
|
||||
src = tmp_path / "readme.txt"
|
||||
src.write_bytes(b"hi")
|
||||
|
||||
with pytest.raises(ImageSnapshotError):
|
||||
snapshot_image(src, alias="readme.txt", session_dir=None)
|
||||
|
||||
|
||||
def test_snapshot_image_rejects_missing_file(tmp_path: Path) -> None:
|
||||
with pytest.raises(ImageSnapshotError):
|
||||
snapshot_image(tmp_path / "missing.png", alias="missing.png", session_dir=None)
|
||||
|
||||
|
||||
def test_snapshot_image_normalizes_jpg_to_jpeg_mime(tmp_path: Path) -> None:
|
||||
src = tmp_path / "photo.jpg"
|
||||
src.write_bytes(b"\xff\xd8\xff\xe0" + b"\x00" * 8)
|
||||
|
||||
att = snapshot_image(src, alias="photo.jpg", session_dir=None)
|
||||
|
||||
assert att.mime_type == "image/jpeg"
|
||||
|
|
@ -80,6 +80,36 @@ def test_record_ignores_empty_session_id(
|
|||
assert last_session_pointer.load(session_logging) is None
|
||||
|
||||
|
||||
def test_clear_matching_removes_matching_pointers_only(
|
||||
session_logging: SessionLoggingConfig,
|
||||
) -> None:
|
||||
pointer_dir = Path(session_logging.save_dir) / last_session_pointer.POINTER_DIR_NAME
|
||||
pointer_dir.mkdir()
|
||||
(pointer_dir / "ttys001").write_text("deleted-session\n", encoding="utf-8")
|
||||
(pointer_dir / "ttys002").write_text("other-session\n", encoding="utf-8")
|
||||
(pointer_dir / "ttys003").write_text("deleted-session\n", encoding="utf-8")
|
||||
(pointer_dir / "nested").mkdir()
|
||||
|
||||
last_session_pointer.clear_matching(session_logging, "deleted-session")
|
||||
|
||||
assert not (pointer_dir / "ttys001").exists()
|
||||
assert (pointer_dir / "ttys002").read_text(encoding="utf-8") == "other-session\n"
|
||||
assert not (pointer_dir / "ttys003").exists()
|
||||
assert (pointer_dir / "nested").is_dir()
|
||||
|
||||
|
||||
def test_clear_matching_skips_when_logging_disabled(tmp_path: Path) -> None:
|
||||
disabled = SessionLoggingConfig(save_dir=str(tmp_path), enabled=False)
|
||||
pointer_dir = tmp_path / last_session_pointer.POINTER_DIR_NAME
|
||||
pointer_dir.mkdir()
|
||||
pointer_path = pointer_dir / "ttys001"
|
||||
pointer_path.write_text("deleted-session\n", encoding="utf-8")
|
||||
|
||||
last_session_pointer.clear_matching(disabled, "deleted-session")
|
||||
|
||||
assert pointer_path.exists()
|
||||
|
||||
|
||||
def test_current_tty_key_returns_none_when_ttyname_is_unavailable(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue