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:
Clément Drouin 2026-06-19 11:01:24 +02:00 committed by GitHub
parent 564a14365e
commit 6bedf271ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
223 changed files with 10533 additions and 6947 deletions

View file

@ -0,0 +1,131 @@
from __future__ import annotations
import math
from types import SimpleNamespace
from pydantic import ValidationError
import pytest
from vibe.core.types import LLMMessage, Role, UserDisplayContentMetadata
def _metadata() -> UserDisplayContentMetadata:
return UserDisplayContentMetadata(
version="1.0.0",
host="mistral-vscode",
content=[
{"type": "text", "text": "Look at "},
{
"type": "workspace_mention",
"kind": "file",
"uri": "file:///repo/src/app.ts",
"name": "app.ts",
},
],
)
def test_accepts_valid_metadata_and_preserves_host_owned_content() -> None:
metadata = UserDisplayContentMetadata.model_validate({
"version": "1.0.0",
"host": "mistral-vscode",
"content": [
{"type": "text", "text": "Look at "},
{
"type": "workspace_mention",
"kind": "file",
"uri": "file:///repo/src/app.ts",
"name": "app.ts",
"automatic": False,
"nested": {"line": 12, "tags": ["source", None]},
},
],
})
assert metadata.version == "1.0.0"
assert metadata.host == "mistral-vscode"
assert metadata.content == [
{"type": "text", "text": "Look at "},
{
"type": "workspace_mention",
"kind": "file",
"uri": "file:///repo/src/app.ts",
"name": "app.ts",
"automatic": False,
"nested": {"line": 12, "tags": ["source", None]},
},
]
def test_strips_metadata_strings_without_stripping_host_owned_content() -> None:
metadata = UserDisplayContentMetadata.model_validate({
"version": " 1.0.0 ",
"host": " mistral-vscode ",
"content": [{"type": "text", "text": " keep spaces "}],
})
assert metadata.version == "1.0.0"
assert metadata.host == "mistral-vscode"
assert metadata.content == [{"type": "text", "text": " keep spaces "}]
@pytest.mark.parametrize(
"payload",
[
{"version": " ", "host": "mistral-vscode", "content": []},
{"version": 2, "host": "mistral-vscode", "content": []},
{"version": "1.0.0", "host": " ", "content": []},
{"version": "1.0.0", "host": "mistral-vscode", "content": ["plain text"]},
{"version": "1.0.0", "host": "mistral-vscode", "content": {"type": "text"}},
{
"version": "1.0.0",
"host": "mistral-vscode",
"content": [{"type": "text"}],
"unexpected": True,
},
{
"version": "1.0.0",
"host": "mistral-vscode",
"content": [{"type": "text", "value": object()}],
},
{
"version": "1.0.0",
"host": "mistral-vscode",
"content": [{"type": "text", "value": math.nan}],
},
],
)
def test_rejects_invalid_metadata(payload: object) -> None:
with pytest.raises(ValidationError):
UserDisplayContentMetadata.model_validate(payload)
def test_llm_message_round_trips_user_display_content() -> None:
metadata = _metadata()
message = LLMMessage(
role=Role.user, content="Look at app.ts", user_display_content=metadata
)
dumped = message.model_dump(exclude_none=True, mode="json")
loaded = LLMMessage.model_validate(dumped)
assert dumped["user_display_content"] == metadata.model_dump(mode="json")
assert loaded.user_display_content == metadata
def test_llm_message_keeps_old_sessions_without_user_display_content_valid() -> None:
message = LLMMessage.model_validate({"role": "user", "content": "hello"})
assert message.user_display_content is None
def test_llm_message_object_adapter_preserves_user_display_content() -> None:
metadata = _metadata()
message = LLMMessage.model_validate(
SimpleNamespace(
role=Role.user, content="Look at app.ts", user_display_content=metadata
)
)
assert message.user_display_content == metadata