v2.4.2 (#482)
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-authored-by: Clement Sirieix <clem.sirieix@gmail.com> Co-authored-by: laurens <laurens@mistral.ai>
This commit is contained in:
parent
e9428bce23
commit
9421fbc08e
21 changed files with 370 additions and 40 deletions
|
|
@ -28,7 +28,7 @@ class TestACPInitialize:
|
|||
session_capabilities=SessionCapabilities(list=SessionListCapabilities()),
|
||||
)
|
||||
assert response.agent_info == Implementation(
|
||||
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.4.1"
|
||||
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.4.2"
|
||||
)
|
||||
|
||||
assert response.auth_methods == []
|
||||
|
|
@ -52,7 +52,7 @@ class TestACPInitialize:
|
|||
session_capabilities=SessionCapabilities(list=SessionListCapabilities()),
|
||||
)
|
||||
assert response.agent_info == Implementation(
|
||||
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.4.1"
|
||||
name="@mistralai/mistral-vibe", title="Mistral Vibe", version="2.4.2"
|
||||
)
|
||||
|
||||
assert response.auth_methods is not None
|
||||
|
|
|
|||
|
|
@ -114,10 +114,6 @@ class TestAcpSearchReplaceExecution:
|
|||
assert isinstance(result, SearchReplaceResult)
|
||||
assert result.file == str(test_file)
|
||||
assert result.blocks_applied == 1
|
||||
assert (
|
||||
result.file_content_before
|
||||
== "original line 1\noriginal line 2\noriginal line 3"
|
||||
)
|
||||
assert mock_client._read_text_file_called
|
||||
assert mock_client._write_text_file_called
|
||||
assert mock_client._session_update_called
|
||||
|
|
@ -318,7 +314,6 @@ class TestAcpSearchReplaceSessionUpdates:
|
|||
lines_changed=1,
|
||||
content=search_replace_content,
|
||||
warnings=[],
|
||||
file_content_before="old text",
|
||||
)
|
||||
|
||||
event = ToolResultEvent(
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ class TestAcpWriteFileExecution:
|
|||
assert result.content == "Hello, world!"
|
||||
assert result.bytes_written == len(b"Hello, world!")
|
||||
assert result.file_existed is False
|
||||
assert result.file_content_before is None
|
||||
assert mock_client._write_text_file_called
|
||||
assert mock_client._session_update_called
|
||||
|
||||
|
|
@ -114,7 +113,6 @@ class TestAcpWriteFileExecution:
|
|||
assert result.content == "New content"
|
||||
assert result.bytes_written == len(b"New content")
|
||||
assert result.file_existed is True
|
||||
assert result.file_content_before == ""
|
||||
assert mock_client._write_text_file_called
|
||||
assert mock_client._session_update_called
|
||||
|
||||
|
|
|
|||
152
tests/cli/test_ui_skill_dispatch.py
Normal file
152
tests/cli/test_ui_skill_dispatch.py
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.conftest import build_test_vibe_app, build_test_vibe_config
|
||||
from tests.skills.conftest import create_skill
|
||||
from vibe.cli.textual_ui.app import VibeApp
|
||||
from vibe.cli.textual_ui.widgets.chat_input.container import ChatInputContainer
|
||||
from vibe.cli.textual_ui.widgets.messages import ErrorMessage, UserMessage
|
||||
|
||||
SKILL_BODY = "## Instructions\n\nDo the thing."
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def vibe_app_with_skills(tmp_path: Path) -> VibeApp:
|
||||
skills_dir = tmp_path / "skills"
|
||||
skills_dir.mkdir()
|
||||
create_skill(skills_dir, "my-skill", body=SKILL_BODY)
|
||||
return build_test_vibe_app(config=build_test_vibe_config(skill_paths=[skills_dir]))
|
||||
|
||||
|
||||
async def _wait_for_user_message_containing(
|
||||
vibe_app: VibeApp, pilot, text: str, timeout: float = 1.0
|
||||
) -> UserMessage:
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
for message in vibe_app.query(UserMessage):
|
||||
if text in message._content:
|
||||
return message
|
||||
await pilot.pause(0.05)
|
||||
raise TimeoutError(
|
||||
f"UserMessage containing {text!r} did not appear within {timeout}s"
|
||||
)
|
||||
|
||||
|
||||
async def _wait_for_error_message_containing(
|
||||
vibe_app: VibeApp, pilot, text: str, timeout: float = 1.0
|
||||
) -> ErrorMessage:
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
for error in vibe_app.query(ErrorMessage):
|
||||
if text in error._error:
|
||||
return error
|
||||
await pilot.pause(0.05)
|
||||
raise TimeoutError(
|
||||
f"ErrorMessage containing {text!r} did not appear within {timeout}s"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_skill_without_args_sends_skill_content(
|
||||
vibe_app_with_skills: VibeApp,
|
||||
) -> None:
|
||||
async with vibe_app_with_skills.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app_with_skills.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/my-skill"))
|
||||
await pilot.pause(0.1)
|
||||
|
||||
message = await _wait_for_user_message_containing(
|
||||
vibe_app_with_skills, pilot, "Do the thing."
|
||||
)
|
||||
assert "Do the thing." in message._content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_skill_with_args_prepends_invocation_line(
|
||||
vibe_app_with_skills: VibeApp,
|
||||
) -> None:
|
||||
async with vibe_app_with_skills.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app_with_skills.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/my-skill foo bar"))
|
||||
await pilot.pause(0.1)
|
||||
|
||||
message = await _wait_for_user_message_containing(
|
||||
vibe_app_with_skills, pilot, "Do the thing."
|
||||
)
|
||||
assert "/my-skill foo bar" in message._content
|
||||
assert "Do the thing." in message._content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unknown_skill_falls_through_to_agent(
|
||||
vibe_app_with_skills: VibeApp,
|
||||
) -> None:
|
||||
async with vibe_app_with_skills.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app_with_skills.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/nonexistent-skill"))
|
||||
await pilot.pause(0.2)
|
||||
|
||||
skill_errors = [
|
||||
e
|
||||
for e in vibe_app_with_skills.query(ErrorMessage)
|
||||
if "skill" in str(getattr(e, "_error", "")).lower()
|
||||
]
|
||||
assert not skill_errors
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bare_slash_falls_through(vibe_app_with_skills: VibeApp) -> None:
|
||||
async with vibe_app_with_skills.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app_with_skills.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/"))
|
||||
await pilot.pause(0.2)
|
||||
|
||||
assert not any(
|
||||
"Do the thing." in m._content
|
||||
for m in vibe_app_with_skills.query(UserMessage)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_skill_without_args_does_not_prepend_invocation_line(
|
||||
vibe_app_with_skills: VibeApp,
|
||||
) -> None:
|
||||
async with vibe_app_with_skills.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app_with_skills.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/my-skill"))
|
||||
await pilot.pause(0.1)
|
||||
|
||||
message = await _wait_for_user_message_containing(
|
||||
vibe_app_with_skills, pilot, "Do the thing."
|
||||
)
|
||||
assert "/my-skill" not in message._content
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_skill_with_missing_file_shows_error(tmp_path: Path) -> None:
|
||||
skills_dir = tmp_path / "skills"
|
||||
skills_dir.mkdir()
|
||||
skill_dir = create_skill(skills_dir, "my-skill", body=SKILL_BODY)
|
||||
vibe_app = build_test_vibe_app(
|
||||
config=build_test_vibe_config(skill_paths=[skills_dir])
|
||||
)
|
||||
(skill_dir / "SKILL.md").unlink()
|
||||
|
||||
async with vibe_app.run_test() as pilot:
|
||||
await pilot.pause(0.1)
|
||||
chat_input = vibe_app.query_one(ChatInputContainer)
|
||||
chat_input.post_message(ChatInputContainer.Submitted("/my-skill"))
|
||||
|
||||
error = await _wait_for_error_message_containing(
|
||||
vibe_app, pilot, "Failed to read skill file"
|
||||
)
|
||||
assert "Failed to read skill file" in error._error
|
||||
|
|
@ -4,6 +4,8 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from tests.conftest import build_test_vibe_config
|
||||
from vibe.core.config import ModelConfig
|
||||
from vibe.core.config.harness_files import (
|
||||
HarnessFilesManager,
|
||||
init_harness_files_manager,
|
||||
|
|
@ -80,3 +82,40 @@ class TestResolveConfigFile:
|
|||
def test_user_only_returns_global_config(self) -> None:
|
||||
mgr = HarnessFilesManager(sources=("user",))
|
||||
assert mgr.config_file == VIBE_HOME.path / "config.toml"
|
||||
|
||||
|
||||
class TestAutoCompactThresholdFallback:
|
||||
def test_model_without_explicit_threshold_inherits_global(self) -> None:
|
||||
model = ModelConfig(name="m", provider="p", alias="m")
|
||||
cfg = build_test_vibe_config(
|
||||
auto_compact_threshold=42_000, models=[model], active_model="m"
|
||||
)
|
||||
assert cfg.get_active_model().auto_compact_threshold == 42_000
|
||||
|
||||
def test_model_with_explicit_threshold_keeps_own_value(self) -> None:
|
||||
model = ModelConfig(
|
||||
name="m", provider="p", alias="m", auto_compact_threshold=99_000
|
||||
)
|
||||
cfg = build_test_vibe_config(
|
||||
auto_compact_threshold=42_000, models=[model], active_model="m"
|
||||
)
|
||||
assert cfg.get_active_model().auto_compact_threshold == 99_000
|
||||
|
||||
def test_default_global_threshold_used_when_nothing_set(self) -> None:
|
||||
model = ModelConfig(name="m", provider="p", alias="m")
|
||||
cfg = build_test_vibe_config(models=[model], active_model="m")
|
||||
assert cfg.get_active_model().auto_compact_threshold == 200_000
|
||||
|
||||
def test_changed_global_threshold_propagates_on_reload(self) -> None:
|
||||
model = ModelConfig(name="m", provider="p", alias="m")
|
||||
|
||||
cfg1 = build_test_vibe_config(
|
||||
auto_compact_threshold=50_000, models=[model], active_model="m"
|
||||
)
|
||||
assert cfg1.get_active_model().auto_compact_threshold == 50_000
|
||||
|
||||
# Simulate config reload with a different global threshold
|
||||
cfg2 = build_test_vibe_config(
|
||||
auto_compact_threshold=75_000, models=[model], active_model="m"
|
||||
)
|
||||
assert cfg2.get_active_model().auto_compact_threshold == 75_000
|
||||
|
|
|
|||
|
|
@ -272,3 +272,103 @@ class TestTelemetryClient:
|
|||
assert properties["entrypoint"] == "cli"
|
||||
assert properties["terminal_emulator"] == "vscode"
|
||||
assert "version" in properties
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_id_added_when_getter_provided(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
TelemetryClient, "send_telemetry_event", _original_send_telemetry_event
|
||||
)
|
||||
config = build_test_vibe_config(enable_telemetry=True)
|
||||
env_key = config.get_provider_for_model(
|
||||
config.get_active_model()
|
||||
).api_key_env_var
|
||||
monkeypatch.setenv(env_key, "sk-test")
|
||||
session_id = "test-session-uuid"
|
||||
client = TelemetryClient(
|
||||
config_getter=lambda: config, session_id_getter=lambda: session_id
|
||||
)
|
||||
mock_post = AsyncMock(return_value=MagicMock(status_code=204))
|
||||
client._client = MagicMock()
|
||||
client._client.post = mock_post
|
||||
client._client.aclose = AsyncMock()
|
||||
|
||||
client.send_telemetry_event("vibe.test_event", {"key": "value"})
|
||||
await client.aclose()
|
||||
|
||||
mock_post.assert_called_once_with(
|
||||
DATALAKE_EVENTS_URL,
|
||||
json={
|
||||
"event": "vibe.test_event",
|
||||
"properties": {"session_id": session_id, "key": "value"},
|
||||
},
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer sk-test",
|
||||
"User-Agent": get_user_agent(Backend.MISTRAL),
|
||||
},
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_id_absent_when_no_getter(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
TelemetryClient, "send_telemetry_event", _original_send_telemetry_event
|
||||
)
|
||||
config = build_test_vibe_config(enable_telemetry=True)
|
||||
env_key = config.get_provider_for_model(
|
||||
config.get_active_model()
|
||||
).api_key_env_var
|
||||
monkeypatch.setenv(env_key, "sk-test")
|
||||
client = TelemetryClient(config_getter=lambda: config)
|
||||
mock_post = AsyncMock(return_value=MagicMock(status_code=204))
|
||||
client._client = MagicMock()
|
||||
client._client.post = mock_post
|
||||
client._client.aclose = AsyncMock()
|
||||
|
||||
client.send_telemetry_event("vibe.test_event", {"key": "value"})
|
||||
await client.aclose()
|
||||
|
||||
mock_post.assert_called_once_with(
|
||||
DATALAKE_EVENTS_URL,
|
||||
json={"event": "vibe.test_event", "properties": {"key": "value"}},
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer sk-test",
|
||||
"User-Agent": get_user_agent(Backend.MISTRAL),
|
||||
},
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_id_getter_reflects_latest_value(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
TelemetryClient, "send_telemetry_event", _original_send_telemetry_event
|
||||
)
|
||||
config = build_test_vibe_config(enable_telemetry=True)
|
||||
env_key = config.get_provider_for_model(
|
||||
config.get_active_model()
|
||||
).api_key_env_var
|
||||
monkeypatch.setenv(env_key, "sk-test")
|
||||
current_id = "first-session-id"
|
||||
client = TelemetryClient(
|
||||
config_getter=lambda: config, session_id_getter=lambda: current_id
|
||||
)
|
||||
mock_post = AsyncMock(return_value=MagicMock(status_code=204))
|
||||
client._client = MagicMock()
|
||||
client._client.post = mock_post
|
||||
client._client.aclose = AsyncMock()
|
||||
|
||||
client.send_telemetry_event("vibe.test_event", {})
|
||||
current_id = "second-session-id"
|
||||
client.send_telemetry_event("vibe.test_event", {})
|
||||
await client.aclose()
|
||||
|
||||
calls = mock_post.call_args_list
|
||||
assert calls[0].kwargs["json"]["properties"]["session_id"] == "first-session-id"
|
||||
assert (
|
||||
calls[1].kwargs["json"]["properties"]["session_id"] == "second-session-id"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue