mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
67a8147151
* Python: Add Scaffolding for Durable AzureFunctions package to Agent Framework (#1823) * Add scafolding * update readme * add code owners and label * update owners * .NET: Durable extension: initial src and unit tests (#1900) * Python: Add Durable Agent Wrapper code (#1913) * add initial changes * Move code and add single sample * Update logger * Remove unused code * address PR comments * cleanup code and address comments --------- Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> * Azure Functions .NET samples (#1939) * Python: Add Unit tests for Azurefunctions package (#1976) * Add Unit tests for Azurefunctions * remove duplicate import * .NET: [Feature Branch] Migrate state schema updates and support for agents as MCP tools (#1979) * Python: Add more samples for Azure Functions (#1980) * Move all samples * fix comments * remove dead lines * Make samples simpler * .NET: [Feature Branch] Durable Task extension integration tests (#2017) * .NET: [Feature Branch] Update OpenAI config for integration tests (#2063) * Python: Add Integration tests for AzureFunctions (#2020) * Add Integration tests * Remove DTS extension * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add pyi file for type safety * Add samples in readme * Updated all readme instructions * Address comments * Update readmes * Fix requirements * Address comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * .NET: [Feature Branch] Update dotnet-build-and-test.yml to support integration tests (#2070) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix DTS startup issue and improve logging (#2103) * .NET: [Feature Branch] Introduce Azure OpenAI config for .NET pipeline (#2106) Also fixes an issue where we were trying to start docker containers for integration tests on Windows, which doesn't work. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix uv.lock after merge * Python: Add README for Azure Functions samples setup (#2100) * Add README for Azure Functions samples setup Added setup instructions for Azure Functions samples, including environment setup, virtual environment creation, and running samples. * Update python/samples/getting_started/azure_functions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Laveesh Rohra <larohra@microsoft.com> * Fix or remove broken markdown file links (#2115) * .NET: [Feature Branch] Update HTTP API to be consistent across languages (#2118) * Python: Fix AzureFunctions Integration Tests (#2116) * Add Identity Auth to samples * Update python/samples/getting_started/azure_functions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/01_single_agent/function_app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/02_multi_agent/function_app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/samples/getting_started/azure_functions/06_multi_agent_orchestration_conditionals/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Python: Fix Http Schema (#2112) * Rename to threadid * Respond in plain text * Make snake-case * Add http prefix * rename to wait-for-response * Add query param check * address comments * .NET: Remove IsPackable=false in preparation for nuget release (#2142) * Python: Move `azurefunctions` to `azure` for import (#2141) * Move import to Azure * fix mypy * Update python/packages/azurefunctions/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add missing types * Address comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/azurefunctions/pyproject.toml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update python/packages/azurefunctions/agent_framework_azurefunctions/__init__.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix imports * Address PR feedback from westey-m (#2150) - Adds a link from the /dotnet/samples/README.md to /dotnet/samples/AzureFunctions - Make DurableAgentThread deserialization internal for future-proofing - Update JSON serialization logic to address recently discovered issues with source generator serialization * Address comments (#2160) --------- Co-authored-by: Laveesh Rohra <larohra@microsoft.com> Co-authored-by: Chris Gillum <cgillum@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Anirudh Garg <anirudhg@microsoft.com>
122 lines
3.7 KiB
Python
122 lines
3.7 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
"""
|
|
Pytest configuration for Durable Agent Framework tests.
|
|
|
|
This module provides fixtures and configuration for pytest.
|
|
"""
|
|
|
|
import subprocess
|
|
from collections.abc import Iterator, Mapping
|
|
from typing import Any
|
|
|
|
import pytest
|
|
import requests
|
|
|
|
from .testutils import (
|
|
FunctionAppStartupError,
|
|
build_base_url,
|
|
cleanup_function_app,
|
|
find_available_port,
|
|
get_sample_path_from_marker,
|
|
load_and_validate_env,
|
|
start_function_app,
|
|
wait_for_function_app_ready,
|
|
)
|
|
|
|
|
|
def pytest_configure(config: pytest.Config) -> None:
|
|
"""Register custom markers."""
|
|
config.addinivalue_line("markers", "orchestration: marks tests that use orchestrations (require Azurite)")
|
|
config.addinivalue_line(
|
|
"markers",
|
|
"sample(path): specify the sample directory path for the test (e.g., @pytest.mark.sample('01_single_agent'))",
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def function_app_running() -> bool:
|
|
"""
|
|
Check if the function app is running on localhost:7071.
|
|
|
|
This fixture can be used to skip tests if the function app is not available.
|
|
"""
|
|
try:
|
|
response = requests.get("http://localhost:7071/api/health", timeout=2)
|
|
return response.status_code == 200
|
|
except requests.exceptions.RequestException:
|
|
return False
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def skip_if_no_function_app(function_app_running: bool) -> None:
|
|
"""Skip test if function app is not running."""
|
|
if not function_app_running:
|
|
pytest.skip("Function app is not running on http://localhost:7071")
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def function_app_for_test(request: pytest.FixtureRequest) -> Iterator[dict[str, int | str]]:
|
|
"""
|
|
Start the function app for the corresponding sample based on marker.
|
|
|
|
This fixture:
|
|
1. Determines which sample to run from @pytest.mark.sample()
|
|
2. Validates environment variables
|
|
3. Starts the function app using 'func start'
|
|
4. Waits for the app to be ready
|
|
5. Tears down the app after tests complete
|
|
|
|
Usage:
|
|
@pytest.mark.sample("01_single_agent")
|
|
@pytest.mark.usefixtures("function_app_for_test")
|
|
class TestSample01SingleAgent:
|
|
...
|
|
"""
|
|
# Get sample path from marker
|
|
sample_path, error_message = get_sample_path_from_marker(request)
|
|
if error_message:
|
|
pytest.fail(error_message)
|
|
|
|
assert sample_path is not None, "Sample path must be resolved before starting the function app"
|
|
|
|
# Load .env file if it exists and validate required env vars
|
|
load_and_validate_env()
|
|
|
|
max_attempts = 3
|
|
last_error: Exception | None = None
|
|
func_process: subprocess.Popen[Any] | None = None
|
|
base_url = ""
|
|
port = 0
|
|
|
|
for _ in range(max_attempts):
|
|
port = find_available_port()
|
|
base_url = build_base_url(port)
|
|
func_process = start_function_app(sample_path, port)
|
|
|
|
try:
|
|
wait_for_function_app_ready(func_process, port)
|
|
last_error = None
|
|
break
|
|
except FunctionAppStartupError as exc:
|
|
last_error = exc
|
|
cleanup_function_app(func_process)
|
|
func_process = None
|
|
|
|
if func_process is None:
|
|
error_message = f"Function app failed to start after {max_attempts} attempt(s)."
|
|
if last_error is not None:
|
|
error_message += f" Last error: {last_error}"
|
|
pytest.fail(error_message)
|
|
|
|
try:
|
|
yield {"base_url": base_url, "port": port}
|
|
finally:
|
|
if func_process is not None:
|
|
cleanup_function_app(func_process)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def base_url(function_app_for_test: Mapping[str, int | str]) -> str:
|
|
"""Expose the function app's base URL to tests."""
|
|
return str(function_app_for_test["base_url"])
|