mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Co-authored-by: Sergey Borisov <sergey.borisov@dataimpact.io>
This commit is contained in:
@@ -861,6 +861,7 @@ class TestGitHubCopilotAgentSessionManagement:
|
||||
streaming=unittest.mock.ANY,
|
||||
tools=unittest.mock.ANY,
|
||||
mcp_servers=unittest.mock.ANY,
|
||||
provider=unittest.mock.ANY,
|
||||
)
|
||||
|
||||
async def test_session_config_includes_model(
|
||||
@@ -1084,6 +1085,198 @@ class TestGitHubCopilotAgentMCPServers:
|
||||
assert config["mcp_servers"] is None
|
||||
|
||||
|
||||
class TestGitHubCopilotAgentProvider:
|
||||
"""Test cases for provider configuration (BYOK / Managed Identity)."""
|
||||
|
||||
async def test_provider_passed_to_create_session(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider config is passed through to create_session."""
|
||||
from copilot.session import ProviderConfig
|
||||
|
||||
provider: ProviderConfig = {
|
||||
"type": "azure",
|
||||
"base_url": "https://my-resource.openai.azure.com",
|
||||
"bearer_token": "test-token",
|
||||
}
|
||||
|
||||
agent: GitHubCopilotAgent[GitHubCopilotOptions] = GitHubCopilotAgent(
|
||||
client=mock_client,
|
||||
default_options={"provider": provider},
|
||||
)
|
||||
await agent.start()
|
||||
|
||||
await agent._get_or_create_session(AgentSession()) # type: ignore
|
||||
|
||||
call_args = mock_client.create_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"]["type"] == "azure"
|
||||
assert config["provider"]["base_url"] == "https://my-resource.openai.azure.com"
|
||||
assert config["provider"]["bearer_token"] == "test-token"
|
||||
|
||||
async def test_provider_passed_to_resume_session(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider config is passed through to resume_session."""
|
||||
from copilot.session import ProviderConfig
|
||||
|
||||
provider: ProviderConfig = {
|
||||
"type": "azure",
|
||||
"base_url": "https://my-resource.openai.azure.com",
|
||||
"bearer_token": "test-token",
|
||||
}
|
||||
|
||||
agent: GitHubCopilotAgent[GitHubCopilotOptions] = GitHubCopilotAgent(
|
||||
client=mock_client,
|
||||
default_options={"provider": provider},
|
||||
)
|
||||
await agent.start()
|
||||
|
||||
session = AgentSession()
|
||||
session.service_session_id = "existing-session-id"
|
||||
|
||||
await agent._get_or_create_session(session) # type: ignore
|
||||
|
||||
mock_client.resume_session.assert_called_once()
|
||||
call_args = mock_client.resume_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"]["type"] == "azure"
|
||||
|
||||
async def test_session_config_excludes_provider_when_not_set(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider is None in session config when not set."""
|
||||
agent = GitHubCopilotAgent(client=mock_client)
|
||||
await agent.start()
|
||||
|
||||
await agent._get_or_create_session(AgentSession()) # type: ignore
|
||||
|
||||
call_args = mock_client.create_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"] is None
|
||||
|
||||
async def test_resume_session_excludes_provider_when_not_set(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider is None in resume session config when not set."""
|
||||
agent = GitHubCopilotAgent(client=mock_client)
|
||||
await agent.start()
|
||||
|
||||
session = AgentSession()
|
||||
session.service_session_id = "existing-session-id"
|
||||
|
||||
await agent._get_or_create_session(session) # type: ignore
|
||||
|
||||
call_args = mock_client.resume_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"] is None
|
||||
|
||||
async def test_runtime_provider_takes_precedence(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that runtime provider options override default_options provider."""
|
||||
from copilot.session import ProviderConfig
|
||||
|
||||
default_provider: ProviderConfig = {
|
||||
"type": "azure",
|
||||
"base_url": "https://default.openai.azure.com",
|
||||
"bearer_token": "default-token",
|
||||
}
|
||||
runtime_provider: ProviderConfig = {
|
||||
"type": "openai",
|
||||
"base_url": "https://runtime.openai.com",
|
||||
"api_key": "runtime-key",
|
||||
}
|
||||
|
||||
agent: GitHubCopilotAgent[GitHubCopilotOptions] = GitHubCopilotAgent(
|
||||
client=mock_client,
|
||||
default_options={"provider": default_provider},
|
||||
)
|
||||
await agent.start()
|
||||
|
||||
await agent._get_or_create_session( # type: ignore
|
||||
AgentSession(),
|
||||
runtime_options={"provider": runtime_provider},
|
||||
)
|
||||
|
||||
call_args = mock_client.create_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"]["type"] == "openai"
|
||||
assert config["provider"]["base_url"] == "https://runtime.openai.com"
|
||||
|
||||
async def test_provider_not_leaked_into_default_options(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider is popped from opts and not left in _default_options."""
|
||||
from copilot.session import ProviderConfig
|
||||
|
||||
provider: ProviderConfig = {
|
||||
"type": "azure",
|
||||
"base_url": "https://my-resource.openai.azure.com",
|
||||
"bearer_token": "test-token",
|
||||
}
|
||||
|
||||
agent: GitHubCopilotAgent[GitHubCopilotOptions] = GitHubCopilotAgent(
|
||||
client=mock_client,
|
||||
default_options={"provider": provider, "model": "gpt-5"},
|
||||
)
|
||||
|
||||
assert "provider" not in agent._default_options
|
||||
assert agent._provider is not None
|
||||
assert agent._provider["type"] == "azure"
|
||||
|
||||
async def test_provider_coexists_with_other_options(
|
||||
self,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test that provider works alongside model, tools, and mcp_servers."""
|
||||
from copilot.session import MCPServerConfig, ProviderConfig
|
||||
|
||||
provider: ProviderConfig = {
|
||||
"type": "azure",
|
||||
"base_url": "https://my-resource.openai.azure.com",
|
||||
"bearer_token": "test-token",
|
||||
}
|
||||
mcp_servers: dict[str, MCPServerConfig] = {
|
||||
"test-server": {
|
||||
"type": "stdio",
|
||||
"command": "echo",
|
||||
"args": ["hello"],
|
||||
"tools": ["*"],
|
||||
},
|
||||
}
|
||||
|
||||
def my_tool(arg: str) -> str:
|
||||
"""A test tool."""
|
||||
return arg
|
||||
|
||||
agent: GitHubCopilotAgent[GitHubCopilotOptions] = GitHubCopilotAgent(
|
||||
client=mock_client,
|
||||
tools=[my_tool],
|
||||
default_options={
|
||||
"model": "gpt-5",
|
||||
"provider": provider,
|
||||
"mcp_servers": mcp_servers,
|
||||
},
|
||||
)
|
||||
await agent.start()
|
||||
|
||||
await agent._get_or_create_session(AgentSession()) # type: ignore
|
||||
|
||||
call_args = mock_client.create_session.call_args
|
||||
config = call_args.kwargs
|
||||
assert config["provider"]["type"] == "azure"
|
||||
assert config["model"] == "gpt-5"
|
||||
assert config["mcp_servers"] is not None
|
||||
assert config["tools"] is not None
|
||||
|
||||
|
||||
class TestGitHubCopilotAgentToolConversion:
|
||||
"""Test cases for tool conversion."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user