b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
from run_agent import AIAgent
|
|
|
|
|
|
def _make_copilot_agent():
|
|
with patch("run_agent.OpenAI") as mock_openai:
|
|
mock_openai.return_value = MagicMock()
|
|
agent = AIAgent(
|
|
api_key="gh-token",
|
|
base_url="https://api.githubcopilot.com",
|
|
provider="copilot",
|
|
model="gpt-5.4",
|
|
quiet_mode=True,
|
|
skip_context_files=True,
|
|
skip_memory=True,
|
|
)
|
|
return agent
|
|
|
|
|
|
def test_request_client_adds_copilot_vision_header_for_native_image_payload():
|
|
agent = _make_copilot_agent()
|
|
built_kwargs = []
|
|
|
|
def fake_create(kwargs, *, reason, shared):
|
|
built_kwargs.append(dict(kwargs))
|
|
return MagicMock()
|
|
|
|
api_kwargs = {
|
|
"model": "gpt-5.4",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content": [
|
|
{"type": "text", "text": "What is in this image?"},
|
|
{"type": "image_url", "image_url": {"url": "data:image/png;base64,abc"}},
|
|
],
|
|
}
|
|
],
|
|
}
|
|
|
|
agent.client = object()
|
|
with patch.object(agent, "_is_openai_client_closed", return_value=False), patch.object(
|
|
agent, "_create_openai_client", side_effect=fake_create
|
|
):
|
|
agent._create_request_openai_client(reason="test", api_kwargs=api_kwargs)
|
|
|
|
headers = built_kwargs[-1]["default_headers"]
|
|
assert headers["Copilot-Vision-Request"] == "true"
|
|
|
|
|
|
def test_request_client_leaves_copilot_text_requests_without_vision_header():
|
|
agent = _make_copilot_agent()
|
|
built_kwargs = []
|
|
|
|
def fake_create(kwargs, *, reason, shared):
|
|
built_kwargs.append(dict(kwargs))
|
|
return MagicMock()
|
|
|
|
api_kwargs = {"model": "gpt-5.4", "messages": [{"role": "user", "content": "hello"}]}
|
|
|
|
agent.client = object()
|
|
with patch.object(agent, "_is_openai_client_closed", return_value=False), patch.object(
|
|
agent, "_create_openai_client", side_effect=fake_create
|
|
):
|
|
agent._create_request_openai_client(reason="test", api_kwargs=api_kwargs)
|
|
|
|
headers = built_kwargs[-1]["default_headers"]
|
|
assert "Copilot-Vision-Request" not in headers
|
|
|
|
|
|
def test_request_client_does_not_add_vision_header_after_non_vision_fallback():
|
|
agent = _make_copilot_agent()
|
|
built_kwargs = []
|
|
|
|
def fake_create(kwargs, *, reason, shared):
|
|
built_kwargs.append(dict(kwargs))
|
|
return MagicMock()
|
|
|
|
# This is the shape after _prepare_messages_for_non_vision_model has
|
|
# replaced image parts with text, so Copilot should not get the vision route.
|
|
api_kwargs = {
|
|
"model": "gpt-5.4",
|
|
"messages": [
|
|
{"role": "user", "content": "[user image: a dog]\n\nWhat is in this image?"}
|
|
],
|
|
}
|
|
|
|
agent.client = object()
|
|
with patch.object(agent, "_is_openai_client_closed", return_value=False), patch.object(
|
|
agent, "_create_openai_client", side_effect=fake_create
|
|
):
|
|
agent._create_request_openai_client(reason="test", api_kwargs=api_kwargs)
|
|
|
|
headers = built_kwargs[-1]["default_headers"]
|
|
assert "Copilot-Vision-Request" not in headers
|