Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions dev/integration/tests/activity_handler/dialogs/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@

"""Scenario definition for ActivityHandler-based dialog integration tests."""

from microsoft_agents.hosting.core import ConversationState, UserState, Storage
from microsoft_agents.testing import ActivityHandlerScenario, ScenarioConfig
from microsoft_agents.testing import (
ActivityHandlerEnvironment,
ActivityHandlerScenario,
ScenarioConfig,
)

from .sample.dialog_agent import DialogAgent
from .sample.user_profile_dialog import UserProfileDialog


def _create_handler(
conv_state: ConversationState,
user_state: UserState,
_storage: Storage,
) -> DialogAgent:
def _create_handler(env: ActivityHandlerEnvironment) -> DialogAgent:
"""Factory consumed by ActivityHandlerScenario."""
dialog = UserProfileDialog(user_state)
return DialogAgent(conv_state, user_state, dialog)
dialog = UserProfileDialog(env.user_state)
return DialogAgent(env.conversation_state, env.user_state, dialog)


def create_dialog_scenario(
config: ScenarioConfig | None = None,
) -> ActivityHandlerScenario:
"""Create a ready-to-use ActivityHandlerScenario for the UserProfileDialog."""
return ActivityHandlerScenario(_create_handler, config=config)
return ActivityHandlerScenario.create(
_create_handler,
config=config,
use_jwt_middleware=False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytest

from microsoft_agents.testing import (
ActivityHandlerEnvironment,
ActivityHandlerScenario,
AgentClient,
ClientConfig,
Expand All @@ -48,10 +49,14 @@


def _make_scenario(config: ScenarioConfig | None = None) -> ActivityHandlerScenario:
def _create_handler(conv_state, user_state, storage):
return DialogAgent(conv_state, user_state, BookingDialog())

return ActivityHandlerScenario(_create_handler, config=config)
def _create_handler(env: ActivityHandlerEnvironment):
return DialogAgent(env.conversation_state, env.user_state, BookingDialog())

return ActivityHandlerScenario.create(
_create_handler,
config=config,
use_jwt_middleware=False,
)


_SCENARIO = _make_scenario(
Expand Down
104 changes: 99 additions & 5 deletions dev/integration/tests/auth/test_oauth_continuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
SignInConstants,
SignInResource,
TokenExchangeResource,
TokenExchangeRequest,
TokenOrSignInResourceResponse,
TokenPostResource,
TokenResponse,
)
from microsoft_agents.hosting.core import TurnContext, TurnState
from microsoft_agents.hosting.core import TurnContext, TurnState, UserTokenClientBase
from microsoft_agents.testing import (
ActivityTemplate,
AgentClient,
Expand Down Expand Up @@ -158,7 +159,7 @@ async def exchange_token(
)


class _FakeUserTokenClient:
class _FakeUserTokenClient(UserTokenClientBase):
def __init__(self, state: _AuthFlowTestState):
self._user_token = _FakeUserToken(state)

Expand All @@ -170,6 +171,99 @@ def user_token(self) -> _FakeUserToken:
def agent_sign_in(self):
return None

async def get_user_token(
self,
user_id: str,
connection_name: str,
channel_id: str,
magic_code: str | None = None,
) -> TokenResponse:
return await self._user_token.get_token(
user_id,
connection_name,
channel_id,
code=magic_code,
)

async def get_sign_in_resource(
self,
connection_name: str,
activity: Activity,
final_redirect: str | None = None,
) -> SignInResource:
response = await self.get_token_or_sign_in_resource(
connection_name,
activity,
final_redirect=final_redirect,
)
return response.sign_in_resource

async def sign_out_user(
self,
user_id: str,
connection_name: str,
channel_id: str,
) -> None:
await self._user_token.sign_out(user_id, connection_name, channel_id)

async def get_token_status(
self,
user_id: str,
channel_id: str,
include: str | None = None,
) -> list:
return await self._user_token.get_token_status(
user_id,
channel_id,
include=include,
)

async def get_aad_tokens(
self,
user_id: str,
connection_name: str,
resource_urls: list[str],
channel_id: str,
) -> dict[str, TokenResponse]:
return await self._user_token.get_aad_tokens(
user_id,
connection_name,
channel_id,
{"resourceUrls": resource_urls},
)

async def exchange_token(
self,
user_id: str,
connection_name: str,
channel_id: str,
exchange_request: TokenExchangeRequest,
) -> TokenResponse:
return await self._user_token.exchange_token(
user_id,
connection_name,
channel_id,
exchange_request.model_dump(exclude_none=True),
)

async def get_token_or_sign_in_resource(
self,
connection_name: str,
activity: Activity,
code: str | None = None,
final_redirect: str | None = None,
fwd_url: str | None = None,
) -> TokenOrSignInResourceResponse:
return await self._user_token._get_token_or_sign_in_resource(
user_id=activity.from_property.id,
connection_name=connection_name,
channel_id=activity.channel_id,
state="test-state",
code=code or "",
final_redirect=final_redirect or "",
fwd_url=fwd_url or "",
)

async def close(self) -> None:
return None

Expand Down Expand Up @@ -257,7 +351,7 @@ async def create_user_token_client(
return self._user_token_client


async def init_agent(env: AgentEnvironment):
def init_agent(env: AgentEnvironment):
env.adapter._channel_service_client_factory = _FakeChannelServiceClientFactory(
_auth_flow
)
Expand Down Expand Up @@ -293,8 +387,8 @@ async def message_handler(context: TurnContext, state: TurnState):
}
)

_SCENARIO = AiohttpScenario(
init_agent=init_agent,
_SCENARIO = AiohttpScenario.create(
init_agent,
config=ScenarioConfig(
env_file_path=str(Path(__file__).with_name("auth.env")),
client_config=ClientConfig(activity_template=_TEMPLATE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def test_aiohttp_global_middleware_accepts_real_service_connection_token(
):
token, auth_config = await acquire_real_service_connection_token()
app = web.Application(middlewares=[jwt_authorization_middleware])
app.agent_configuration = auth_config
app["agent_configuration"] = auth_config
app.router.add_get("/", _claims_handler)
client = await aiohttp_client(app)

Expand All @@ -115,7 +115,7 @@ async def test_aiohttp_global_middleware_rejects_real_token_with_invalid_audienc
):
token, auth_config = await acquire_real_service_connection_token()
app = web.Application(middlewares=[jwt_authorization_middleware])
app.agent_configuration = auth_config_with_invalid_audience(auth_config)
app["agent_configuration"] = auth_config_with_invalid_audience(auth_config)
app.router.add_get("/", _claims_handler)
client = await aiohttp_client(app)

Expand Down
2 changes: 1 addition & 1 deletion dev/integration/tests/scenarios/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def load_scenario(
if name not in _SCENARIO_INITS:
raise ValueError(f"Unknown scenario: {name}")

return AiohttpScenario(
return AiohttpScenario.create(
_SCENARIO_INITS[name],
config=config,
use_jwt_middleware=use_jwt_middleware,
Expand Down
2 changes: 1 addition & 1 deletion dev/integration/tests/scenarios/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AgentEnvironment,
)

async def init_agent(env: AgentEnvironment):
def init_agent(env: AgentEnvironment):
"""Initialize the application for the quickstart sample."""

app: AgentApplication[TurnState] = env.agent_application
Expand Down
5 changes: 2 additions & 3 deletions dev/integration/tests/test_streaming_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_streaminfo(activity: Activity) -> Entity:
return entity
raise ValueError("No streaminfo entity found")

async def init_agent(env: AgentEnvironment):
def init_agent(env: AgentEnvironment):

app = env.agent_application

Expand All @@ -49,7 +49,7 @@ async def stream_handler(context: TurnContext, state: TurnState):
context.streaming_response.queue_text_chunk(CHUNKS[-1])
await context.streaming_response.end_stream()

_SCENARIO = AiohttpScenario(init_agent=init_agent, use_jwt_middleware=False)
_SCENARIO = AiohttpScenario.create(init_agent, use_jwt_middleware=False)

@pytest.mark.asyncio
@pytest.mark.agent_test(_SCENARIO)
Expand Down Expand Up @@ -119,4 +119,3 @@ async def test_basic_streaming_response_streaming_channel(agent_client: AgentCli
assert final_streaminfo.stream_sequence == len(stream_activities)
assert final_streaminfo.stream_type == "final"
assert stream_activities[-1].text == FULL_TEXT.replace(" ", "")

69 changes: 69 additions & 0 deletions dev/integration/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading