-
Notifications
You must be signed in to change notification settings - Fork 56
Fix ChannelServiceAdapter.create_conversation implementation #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rodrigobr-msft
merged 12 commits into
main
from
users/robrandao/create-conversation-bug
Nov 14, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aef2f82
Beginning for channel adapter unit tests
rodrigobr-msft 4dd5224
Adjusting create_connector_client to not necessitate context
rodrigobr-msft bcfb70e
Sketch of RestChannelServiceClientFactory test
rodrigobr-msft 3082380
Adding create_connector_client tests for non agentic scenarios
rodrigobr-msft 96ebfea
Another commit
rodrigobr-msft a8c9ebe
TestChannelServiceAdapter outline
rodrigobr-msft 0d7a746
First pass at create_conversation unit test
rodrigobr-msft 0340b5a
adding more assertions to test
rodrigobr-msft a536596
Formatting
rodrigobr-msft 6527ec7
Adding create_connector_client calls that use agentic identity
rodrigobr-msft 2587a60
Small change to error message
rodrigobr-msft 4fa1770
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import pytest | ||
|
|
||
| from microsoft_agents.activity import ( | ||
| ConversationResourceResponse, | ||
| ConversationParameters, | ||
| ) | ||
| from microsoft_agents.hosting.core import ( | ||
| ChannelServiceAdapter, | ||
| TurnContext, | ||
| ConnectorClientBase, | ||
| UserTokenClientBase, | ||
| ChannelServiceClientFactoryBase, | ||
| RestChannelServiceClientFactory, | ||
| TeamsConnectorClient, | ||
| UserTokenClient, | ||
| Connections, | ||
| ) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from microsoft_agents.hosting.core.connector.conversations_base import ConversationsBase | ||
|
|
||
|
|
||
| class MyChannelServiceAdapter(ChannelServiceAdapter): | ||
| pass | ||
|
|
||
|
|
||
| class TestChannelServiceAdapter: | ||
|
|
||
| @pytest.fixture | ||
| def connector_client(self, mocker): | ||
| connector_client = mocker.Mock(spec=TeamsConnectorClient) | ||
| mocker.patch.object( | ||
| TeamsConnectorClient, "__new__", return_value=connector_client | ||
| ) | ||
| return connector_client | ||
|
|
||
| @pytest.fixture | ||
| def user_token_client(self, mocker): | ||
| user_token_client = mocker.Mock(spec=UserTokenClient) | ||
| mocker.patch.object(UserTokenClient, "__new__", return_value=user_token_client) | ||
| return user_token_client | ||
|
|
||
| @pytest.fixture | ||
| def connection_manager(self, mocker, user_token_client): | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| connection_manager = mocker.Mock(spec=Connections) | ||
| connection_manager.get_token_provider = mocker.Mock( | ||
| return_value=user_token_client | ||
| ) | ||
| return connection_manager | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @pytest.fixture | ||
| def factory(self, connection_manager): | ||
| client_factory = RestChannelServiceClientFactory(connection_manager) | ||
| return client_factory | ||
|
|
||
| @pytest.fixture | ||
| def adapter(self, factory): | ||
| return MyChannelServiceAdapter(factory) | ||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_create_conversation_basic( | ||
| self, mocker, user_token_client, connector_client, adapter | ||
| ): | ||
|
|
||
| user_token_client.get_access_token = mocker.AsyncMock( | ||
| return_value="user_token_value" | ||
| ) | ||
| adapter.run_pipeline = mocker.AsyncMock() | ||
|
|
||
| connector_client.conversations = mocker.Mock(spec=ConversationsBase) | ||
| connector_client.conversations.create_conversation.return_value = ( | ||
| ConversationResourceResponse( | ||
| activity_id="activity123", | ||
| service_url="https://service.url", | ||
| id="conversation123", | ||
| ) | ||
| ) | ||
rodrigobr-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async def callback(context: TurnContext): | ||
| return None | ||
|
|
||
| await adapter.create_conversation( | ||
| "agent_app_id", | ||
| "channel_id", | ||
| "service_url", | ||
| "audience", | ||
| ConversationParameters(), | ||
| callback, | ||
| ) | ||
|
|
||
| adapter.run_pipeline.assert_awaited_once() | ||
|
|
||
| context_arg, callback_arg = adapter.run_pipeline.call_args[0] | ||
| assert callback_arg == callback | ||
| assert context_arg.activity.conversation.id == "conversation123" | ||
| assert context_arg.activity.channel_id == "channel_id" | ||
| assert context_arg.activity.service_url == "service_url" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.