v2.17.0 (#822)
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Hdandria <henri.dandria@mistral.ai> Co-authored-by: Ivana Dunisijevic <ivana.dunisijevic@mistral.ai> Co-authored-by: Jean Burellier <sheplu@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Mert Unsal <mert.unsal@mistral.ai> Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com> Co-authored-by: Paul VEZIA <166131032+le-codeur-rapide@users.noreply.github.com> Co-authored-by: Pierre Rossinès <pierre.rossines@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: renovate-mistral[bot] <253709520+renovate-mistral[bot]@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
564a14365e
commit
6bedf271ce
223 changed files with 10533 additions and 6947 deletions
|
|
@ -1,11 +1,17 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from vibe.core.session.image_snapshot import ImageSnapshotError, snapshot_image
|
||||
from vibe.core.session.image_snapshot import (
|
||||
ImageSnapshotError,
|
||||
snapshot_image,
|
||||
snapshot_image_bytes,
|
||||
)
|
||||
from vibe.core.types import MAX_IMAGE_BYTES, FileImageSource, InlineImageSource
|
||||
|
||||
PNG_BYTES = b"\x89PNG\r\n\x1a\n" + b"\x00" * 16
|
||||
|
||||
|
|
@ -19,10 +25,11 @@ def test_snapshot_image_copies_to_attachments_dir(tmp_path: Path) -> None:
|
|||
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 isinstance(att.source, FileImageSource)
|
||||
assert att.source.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
|
||||
assert att.source.path.read_bytes() == PNG_BYTES
|
||||
|
||||
|
||||
def test_snapshot_image_is_idempotent_on_same_bytes(tmp_path: Path) -> None:
|
||||
|
|
@ -35,7 +42,9 @@ def test_snapshot_image_is_idempotent_on_same_bytes(tmp_path: Path) -> None:
|
|||
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 isinstance(att_a.source, FileImageSource)
|
||||
assert isinstance(att_b.source, FileImageSource)
|
||||
assert att_a.source.path == att_b.source.path
|
||||
assert sum(1 for _ in (session_dir / "attachments").iterdir()) == 1
|
||||
|
||||
|
||||
|
|
@ -45,7 +54,8 @@ def test_snapshot_image_returns_source_when_session_dir_is_none(tmp_path: Path)
|
|||
|
||||
att = snapshot_image(src, alias="screenshot.png", session_dir=None)
|
||||
|
||||
assert att.path == src.resolve()
|
||||
assert isinstance(att.source, FileImageSource)
|
||||
assert att.source.path == src.resolve()
|
||||
assert att.alias == "screenshot.png"
|
||||
|
||||
|
||||
|
|
@ -69,3 +79,54 @@ def test_snapshot_image_normalizes_jpg_to_jpeg_mime(tmp_path: Path) -> None:
|
|||
att = snapshot_image(src, alias="photo.jpg", session_dir=None)
|
||||
|
||||
assert att.mime_type == "image/jpeg"
|
||||
|
||||
|
||||
def test_snapshot_image_bytes_inlines_when_session_dir_is_none() -> None:
|
||||
att = snapshot_image_bytes(
|
||||
PNG_BYTES, alias="pasted.png", mime_type="image/png", session_dir=None
|
||||
)
|
||||
|
||||
assert isinstance(att.source, InlineImageSource)
|
||||
assert att.source.data == base64.b64encode(PNG_BYTES).decode("ascii")
|
||||
assert att.alias == "pasted.png"
|
||||
assert att.mime_type == "image/png"
|
||||
|
||||
|
||||
def test_snapshot_image_bytes_writes_file_when_session_dir_is_set(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
session_dir = tmp_path / "session"
|
||||
|
||||
att = snapshot_image_bytes(
|
||||
PNG_BYTES, alias="pasted.png", mime_type="image/png", session_dir=session_dir
|
||||
)
|
||||
|
||||
digest = hashlib.sha1(PNG_BYTES, usedforsecurity=False).hexdigest()
|
||||
assert isinstance(att.source, FileImageSource)
|
||||
assert att.source.path == (session_dir / "attachments" / f"{digest}.png").resolve()
|
||||
assert att.source.path.read_bytes() == PNG_BYTES
|
||||
|
||||
|
||||
def test_snapshot_image_bytes_rejects_unsupported_mime() -> None:
|
||||
with pytest.raises(ImageSnapshotError):
|
||||
snapshot_image_bytes(
|
||||
PNG_BYTES, alias="x", mime_type="image/tiff", session_dir=None
|
||||
)
|
||||
|
||||
|
||||
def test_snapshot_image_rejects_oversized_file(tmp_path: Path) -> None:
|
||||
src = tmp_path / "big.png"
|
||||
src.write_bytes(b"\x89PNG\r\n\x1a\n" + b"\x00" * MAX_IMAGE_BYTES)
|
||||
|
||||
with pytest.raises(ImageSnapshotError):
|
||||
snapshot_image(src, alias="big.png", session_dir=None)
|
||||
|
||||
|
||||
def test_snapshot_image_bytes_rejects_oversized_data() -> None:
|
||||
with pytest.raises(ImageSnapshotError):
|
||||
snapshot_image_bytes(
|
||||
b"x" * (MAX_IMAGE_BYTES + 1),
|
||||
alias="big.png",
|
||||
mime_type="image/png",
|
||||
session_dir=None,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue