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:
Mathias Gesbert 2026-06-04 18:26:35 +02:00 committed by GitHub
parent ad0d5c9520
commit 3f8487f761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
197 changed files with 10819 additions and 2830 deletions

View file

@ -2,6 +2,8 @@ from __future__ import annotations
from pathlib import Path
import pytest
from vibe.core.autocompletion.path_prompt import (
build_path_prompt_payload,
build_title_segments,
@ -22,6 +24,47 @@ def test_deduplicates_same_file_mentioned_twice(tmp_path: Path) -> None:
assert len(payload.all_resources) == 2
class TestTildeExpansion:
def test_tilde_path_expands_and_attaches(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("HOME", str(tmp_path))
shot = tmp_path / "shot.png"
shot.write_bytes(b"\x89PNG")
payload = build_path_prompt_payload("look at @~/shot.png", base_dir=tmp_path)
assert len(payload.resources) == 1
resource = payload.resources[0]
assert resource.path == shot.resolve()
assert resource.alias == "~/shot.png"
assert resource.kind == "image"
def test_bare_tilde_attaches_home_as_folder(
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("HOME", str(tmp_path))
payload = build_path_prompt_payload("go to @~", base_dir=tmp_path)
assert len(payload.resources) == 1
assert payload.resources[0].path == tmp_path.resolve()
assert payload.resources[0].kind == "folder"
def test_unknown_user_tilde_does_not_crash(self, tmp_path: Path) -> None:
payload = build_path_prompt_payload(
"see @~nonexistentuser1234/x.png", base_dir=tmp_path
)
assert payload.resources == []
def test_tilde_mid_token_without_anchor_stays_text(self, tmp_path: Path) -> None:
payload = build_path_prompt_payload("foo~bar baz", base_dir=tmp_path)
assert payload.resources == []
assert payload.prompt_text == "foo~bar baz"
class TestBuildTitleSegments:
def test_empty_message(self) -> None:
assert build_title_segments("") == []

View file

@ -0,0 +1,70 @@
from __future__ import annotations
from pathlib import Path
from vibe.core.autocompletion.path_prompt import build_path_prompt_payload
from vibe.core.autocompletion.path_prompt_adapter import (
extract_image_resources,
render_path_prompt,
)
def test_image_extension_is_classified_as_image_kind(tmp_path: Path) -> None:
(tmp_path / "logo.png").write_bytes(b"\x89PNG")
payload = build_path_prompt_payload("look at @logo.png", base_dir=tmp_path)
assert len(payload.resources) == 1
assert payload.resources[0].kind == "image"
assert payload.resources[0].alias == "logo.png"
def test_text_file_remains_kind_file(tmp_path: Path) -> None:
(tmp_path / "notes.md").write_text("hello")
payload = build_path_prompt_payload("read @notes.md", base_dir=tmp_path)
assert payload.resources[0].kind == "file"
def test_image_mentions_omit_resource_link_when_skip_images(tmp_path: Path) -> None:
(tmp_path / "logo.png").write_bytes(b"\x89PNG")
rendered = render_path_prompt(
"look at @logo.png", base_dir=tmp_path, skip_images=True
)
assert "logo.png" in rendered # kept in the prompt text as the @ mention
assert "file://" not in rendered # no resource_link block emitted
def test_image_mentions_emit_resource_link_by_default(tmp_path: Path) -> None:
(tmp_path / "logo.png").write_bytes(b"\x89PNG")
rendered = render_path_prompt("look at @logo.png", base_dir=tmp_path)
assert "logo.png" in rendered
assert (tmp_path / "logo.png").as_uri() in rendered
def test_extract_image_resources_filters_only_images(tmp_path: Path) -> None:
(tmp_path / "logo.png").write_bytes(b"\x89PNG")
(tmp_path / "notes.md").write_text("hi")
(tmp_path / "diagram.webp").write_bytes(b"RIFF")
payload = build_path_prompt_payload(
"see @logo.png @notes.md @diagram.webp", base_dir=tmp_path
)
images = extract_image_resources(payload)
aliases = sorted(r.alias for r in images)
assert aliases == ["diagram.webp", "logo.png"]
def test_case_insensitive_image_extension(tmp_path: Path) -> None:
(tmp_path / "screenshot.PNG").write_bytes(b"\x89PNG")
payload = build_path_prompt_payload("see @screenshot.PNG", base_dir=tmp_path)
assert payload.resources[0].kind == "image"