2.0.0
Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai> Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai> Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai> Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai> Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com> Co-Authored-By: David Brochart <david.brochart@gmail.com> Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com> Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com> Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
This commit is contained in:
parent
79f215d91c
commit
d33db9fff8
217 changed files with 16911 additions and 4305 deletions
|
|
@ -1,9 +1,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from acp import AgentSideConnection, NewSessionRequest, PromptRequest
|
||||
from acp import PromptRequest
|
||||
from acp.schema import (
|
||||
EmbeddedResourceContentBlock,
|
||||
ResourceContentBlock,
|
||||
|
|
@ -13,58 +12,28 @@ from acp.schema import (
|
|||
import pytest
|
||||
|
||||
from tests.stubs.fake_backend import FakeBackend
|
||||
from tests.stubs.fake_connection import FakeAgentSideConnection
|
||||
from vibe.acp.acp_agent import VibeAcpAgent
|
||||
from vibe.core.agent import Agent
|
||||
from vibe.core.types import LLMChunk, LLMMessage, LLMUsage, Role
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def backend() -> FakeBackend:
|
||||
backend = FakeBackend(
|
||||
LLMChunk(
|
||||
message=LLMMessage(role=Role.assistant, content="Hi"),
|
||||
usage=LLMUsage(prompt_tokens=1, completion_tokens=1),
|
||||
)
|
||||
)
|
||||
return backend
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def acp_agent(backend: FakeBackend) -> VibeAcpAgent:
|
||||
class PatchedAgent(Agent):
|
||||
def __init__(self, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs, backend=backend)
|
||||
|
||||
patch("vibe.acp.acp_agent.VibeAgent", side_effect=PatchedAgent).start()
|
||||
|
||||
vibe_acp_agent: VibeAcpAgent | None = None
|
||||
|
||||
def _create_agent(connection: AgentSideConnection) -> VibeAcpAgent:
|
||||
nonlocal vibe_acp_agent
|
||||
vibe_acp_agent = VibeAcpAgent(connection)
|
||||
return vibe_acp_agent
|
||||
|
||||
FakeAgentSideConnection(_create_agent)
|
||||
return vibe_acp_agent # pyright: ignore[reportReturnType]
|
||||
from vibe.acp.acp_agent_loop import VibeAcpAgentLoop
|
||||
from vibe.core.types import Role
|
||||
|
||||
|
||||
class TestACPContent:
|
||||
@pytest.mark.asyncio
|
||||
async def test_text_content(
|
||||
self, acp_agent: VibeAcpAgent, backend: FakeBackend
|
||||
self, acp_agent_loop: VibeAcpAgentLoop, backend: FakeBackend
|
||||
) -> None:
|
||||
session_response = await acp_agent.newSession(
|
||||
NewSessionRequest(cwd=str(Path.cwd()), mcpServers=[])
|
||||
session_response = await acp_agent_loop.new_session(
|
||||
cwd=str(Path.cwd()), mcp_servers=[]
|
||||
)
|
||||
prompt_request = PromptRequest(
|
||||
prompt=[TextContentBlock(type="text", text="Say hi")],
|
||||
sessionId=session_response.sessionId,
|
||||
session_id=session_response.session_id,
|
||||
)
|
||||
|
||||
response = await acp_agent.prompt(params=prompt_request)
|
||||
response = await acp_agent_loop.prompt(
|
||||
prompt=prompt_request.prompt, session_id=session_response.session_id
|
||||
)
|
||||
|
||||
assert response.stopReason == "end_turn"
|
||||
assert response.stop_reason == "end_turn"
|
||||
user_message = next(
|
||||
(msg for msg in backend._requests_messages[0] if msg.role == Role.user),
|
||||
None,
|
||||
|
|
@ -74,12 +43,13 @@ class TestACPContent:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resource_content(
|
||||
self, acp_agent: VibeAcpAgent, backend: FakeBackend
|
||||
self, acp_agent_loop: VibeAcpAgentLoop, backend: FakeBackend
|
||||
) -> None:
|
||||
session_response = await acp_agent.newSession(
|
||||
NewSessionRequest(cwd=str(Path.cwd()), mcpServers=[])
|
||||
session_response = await acp_agent_loop.new_session(
|
||||
cwd=str(Path.cwd()), mcp_servers=[]
|
||||
)
|
||||
prompt_request = PromptRequest(
|
||||
|
||||
response = await acp_agent_loop.prompt(
|
||||
prompt=[
|
||||
TextContentBlock(type="text", text="What does this file do?"),
|
||||
EmbeddedResourceContentBlock(
|
||||
|
|
@ -87,16 +57,14 @@ class TestACPContent:
|
|||
resource=TextResourceContents(
|
||||
uri="file:///home/my_file.py",
|
||||
text="def hello():\n print('Hello, world!')",
|
||||
mimeType="text/x-python",
|
||||
mime_type="text/x-python",
|
||||
),
|
||||
),
|
||||
],
|
||||
sessionId=session_response.sessionId,
|
||||
session_id=session_response.session_id,
|
||||
)
|
||||
|
||||
response = await acp_agent.prompt(params=prompt_request)
|
||||
|
||||
assert response.stopReason == "end_turn"
|
||||
assert response.stop_reason == "end_turn"
|
||||
user_message = next(
|
||||
(msg for msg in backend._requests_messages[0] if msg.role == Role.user),
|
||||
None,
|
||||
|
|
@ -111,12 +79,13 @@ class TestACPContent:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resource_link_content(
|
||||
self, acp_agent: VibeAcpAgent, backend: FakeBackend
|
||||
self, acp_agent_loop: VibeAcpAgentLoop, backend: FakeBackend
|
||||
) -> None:
|
||||
session_response = await acp_agent.newSession(
|
||||
NewSessionRequest(cwd=str(Path.cwd()), mcpServers=[])
|
||||
session_response = await acp_agent_loop.new_session(
|
||||
cwd=str(Path.cwd()), mcp_servers=[]
|
||||
)
|
||||
prompt_request = PromptRequest(
|
||||
|
||||
response = await acp_agent_loop.prompt(
|
||||
prompt=[
|
||||
TextContentBlock(type="text", text="Analyze this resource"),
|
||||
ResourceContentBlock(
|
||||
|
|
@ -125,16 +94,14 @@ class TestACPContent:
|
|||
name="document.pdf",
|
||||
title="Important Document",
|
||||
description="A PDF document containing project specifications",
|
||||
mimeType="application/pdf",
|
||||
mime_type="application/pdf",
|
||||
size=1024,
|
||||
),
|
||||
],
|
||||
sessionId=session_response.sessionId,
|
||||
session_id=session_response.session_id,
|
||||
)
|
||||
|
||||
response = await acp_agent.prompt(params=prompt_request)
|
||||
|
||||
assert response.stopReason == "end_turn"
|
||||
assert response.stop_reason == "end_turn"
|
||||
user_message = next(
|
||||
(msg for msg in backend._requests_messages[0] if msg.role == Role.user),
|
||||
None,
|
||||
|
|
@ -146,19 +113,20 @@ class TestACPContent:
|
|||
+ "\nname: document.pdf"
|
||||
+ "\ntitle: Important Document"
|
||||
+ "\ndescription: A PDF document containing project specifications"
|
||||
+ "\nmimeType: application/pdf"
|
||||
+ "\nmime_type: application/pdf"
|
||||
+ "\nsize: 1024"
|
||||
)
|
||||
assert user_message.content == expected_content
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resource_link_minimal(
|
||||
self, acp_agent: VibeAcpAgent, backend: FakeBackend
|
||||
self, acp_agent_loop: VibeAcpAgentLoop, backend: FakeBackend
|
||||
) -> None:
|
||||
session_response = await acp_agent.newSession(
|
||||
NewSessionRequest(cwd=str(Path.cwd()), mcpServers=[])
|
||||
session_response = await acp_agent_loop.new_session(
|
||||
cwd=str(Path.cwd()), mcp_servers=[]
|
||||
)
|
||||
prompt_request = PromptRequest(
|
||||
|
||||
response = await acp_agent_loop.prompt(
|
||||
prompt=[
|
||||
ResourceContentBlock(
|
||||
type="resource_link",
|
||||
|
|
@ -166,12 +134,10 @@ class TestACPContent:
|
|||
name="minimal.txt",
|
||||
)
|
||||
],
|
||||
sessionId=session_response.sessionId,
|
||||
session_id=session_response.session_id,
|
||||
)
|
||||
|
||||
response = await acp_agent.prompt(params=prompt_request)
|
||||
|
||||
assert response.stopReason == "end_turn"
|
||||
assert response.stop_reason == "end_turn"
|
||||
user_message = next(
|
||||
(msg for msg in backend._requests_messages[0] if msg.role == Role.user),
|
||||
None,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue