v2.18.0 (#843)
Co-authored-by: Clément Drouin <clement.drouin@mistral.ai> Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai> Co-authored-by: Cyprien <courtot.c@gmail.com> Co-authored-by: Guillaume LE GOFF <guillaume.lgf@gmail.com> Co-authored-by: Jean Burellier <sheplu@users.noreply.github.com> Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com> Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai> Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@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: Quentin <quentin.torroba@mistral.ai> Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com> Co-authored-by: josephine-delas <57808586+josephine-delas@users.noreply.github.com> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
725d3a56ce
commit
e607ccbb00
242 changed files with 7372 additions and 1974 deletions
|
|
@ -1,11 +1,23 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
from weakref import WeakKeyDictionary
|
||||
|
||||
import pytest
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Link
|
||||
|
||||
from vibe.cli.textual_ui.widgets.messages import UserMessage
|
||||
from vibe.cli.textual_ui.widgets.no_markup_static import NoMarkupStatic
|
||||
from vibe.cli.textual_ui.windowing.history import build_history_widgets
|
||||
from vibe.core.types import FileImageSource, ImageAttachment, LLMMessage, Role
|
||||
from vibe.core.types import (
|
||||
FileImageSource,
|
||||
ImageAttachment,
|
||||
InlineImageSource,
|
||||
LLMMessage,
|
||||
Role,
|
||||
)
|
||||
|
||||
|
||||
def _att(path: Path, alias: str) -> ImageAttachment:
|
||||
|
|
@ -15,35 +27,92 @@ def _att(path: Path, alias: str) -> ImageAttachment:
|
|||
)
|
||||
|
||||
|
||||
def test_attachments_footer_singular(tmp_path: Path) -> None:
|
||||
att = _att(tmp_path / "shot.png", "shot.png")
|
||||
class _UserMessageApp(App[None]):
|
||||
CSS = """
|
||||
.user-message-wrapper,
|
||||
.user-message-container,
|
||||
.user-message-attachments,
|
||||
.user-message-attachment-line {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
rendered = UserMessage._format_attachments_footer([att])
|
||||
.user-message-attachment-label,
|
||||
.user-message-attachment-link {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
"""
|
||||
|
||||
assert "attached image:" in rendered
|
||||
assert '[link="file://' in rendered
|
||||
assert "]shot.png[/link]" in rendered
|
||||
def __init__(self, message: UserMessage) -> None:
|
||||
super().__init__()
|
||||
self._message = message
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield self._message
|
||||
|
||||
|
||||
def test_attachments_footer_plural(tmp_path: Path) -> None:
|
||||
@pytest.mark.asyncio
|
||||
async def test_attachments_render_one_clickable_link_per_image(tmp_path: Path) -> None:
|
||||
a = _att(tmp_path / "a.png", "a.png")
|
||||
b = _att(tmp_path / "b.png", "b.png")
|
||||
app = _UserMessageApp(UserMessage("look", images=[a, b]))
|
||||
opened: list[str] = []
|
||||
|
||||
rendered = UserMessage._format_attachments_footer([a, b])
|
||||
a_uri = (tmp_path / "a.png").as_uri()
|
||||
b_uri = (tmp_path / "b.png").as_uri()
|
||||
|
||||
assert "attached images:" in rendered
|
||||
assert rendered.count('[link="file://') == 2
|
||||
assert "a.png" in rendered
|
||||
assert "b.png" in rendered
|
||||
async with app.run_test() as pilot:
|
||||
links = list(app.query(Link))
|
||||
assert [link.text for link in links] == ["a.png", "b.png"]
|
||||
assert [link.url for link in links] == [a_uri, b_uri]
|
||||
|
||||
with patch.object(
|
||||
app, "open_url", side_effect=lambda url, **_kwargs: opened.append(url)
|
||||
):
|
||||
await pilot.click(links[0])
|
||||
|
||||
assert opened == [a_uri]
|
||||
|
||||
|
||||
def test_attachments_footer_escapes_alias_brackets(tmp_path: Path) -> None:
|
||||
@pytest.mark.asyncio
|
||||
async def test_inline_attachment_renders_label_without_link() -> None:
|
||||
att = ImageAttachment(
|
||||
source=InlineImageSource(data="aW1n"), alias="pasted.png", mime_type="image/png"
|
||||
)
|
||||
app = _UserMessageApp(UserMessage("look", images=[att]))
|
||||
|
||||
async with app.run_test():
|
||||
assert list(app.query(Link)) == []
|
||||
label = app.query_one(".user-message-attachment-link")
|
||||
|
||||
assert isinstance(label, NoMarkupStatic)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_attachment_link_renders_alias_brackets_literally(tmp_path: Path) -> None:
|
||||
att = _att(tmp_path / "shot.png", "weird [bracket].png")
|
||||
app = _UserMessageApp(UserMessage("look", images=[att]))
|
||||
|
||||
rendered = UserMessage._format_attachments_footer([att])
|
||||
async with app.run_test():
|
||||
link = app.query_one(Link)
|
||||
|
||||
# Rich's escape() turns "[" into "\[".
|
||||
assert "\\[bracket]" in rendered
|
||||
assert link.text == "weird [bracket].png"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_attachment_link_shortens_home_absolute_alias() -> None:
|
||||
path = Path.home() / "Pictures" / "shot.png"
|
||||
att = ImageAttachment(
|
||||
source=FileImageSource(path=path), alias=str(path), mime_type="image/png"
|
||||
)
|
||||
app = _UserMessageApp(UserMessage("look", images=[att]))
|
||||
|
||||
async with app.run_test():
|
||||
link = app.query_one(Link)
|
||||
|
||||
assert link.text == "~/Pictures/shot.png"
|
||||
assert link.url == path.as_uri()
|
||||
|
||||
|
||||
def test_resumed_user_message_with_images_renders_footer(tmp_path: Path) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue