Skip to content

Commit 291da1d

Browse files
author
Jesus Terrazas
committed
copilot comments
1 parent 49c27fd commit 291da1d

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

‎libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,23 @@ def resolve_agent_identity(context: Any, auth_token: Optional[str]) -> str:
8787

8888
@staticmethod
8989
def get_user_agent_header(orchestrator: str = "") -> str:
90+
"""
91+
Generates a User-Agent header string for SDK requests.
92+
93+
Args:
94+
orchestrator: Optional orchestrator name to include in the User-Agent header.
95+
Defaults to empty string if not provided.
96+
97+
Returns:
98+
str: A formatted User-Agent header string containing SDK version, OS type,
99+
Python version, and optional orchestrator information.
100+
"""
90101
if Utility._cached_version is None:
91102
try:
92103
Utility._cached_version = version("microsoft-agents-a365-runtime")
93-
print("Successfully retrieved version")
94104
except Exception:
95105
Utility._cached_version = "unknown"
96106

97-
print(f"Utility._cached_version: {Utility._cached_version}")
98-
99107
orchestrator_part = f"; {orchestrator}" if orchestrator else ""
100108
os_type = platform.system()
101109
python_version = platform.python_version()

‎tests/runtime/test_utility.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
import jwt
1010
import pytest
11+
import platform
12+
import re
1113
from microsoft_agents_a365.runtime.utility import Utility
1214

13-
import platform
1415

1516
# Fixtures (Mocks and Helpers)
1617
@pytest.fixture
@@ -130,16 +131,24 @@ def test_get_user_agent_header_default():
130131
"""Test get_user_agent_header returns expected format with default orchestrator."""
131132
# Patch version to a known value
132133
Utility._cached_version = "1.2.3"
133-
result = Utility.get_user_agent_header()
134134
os_type = platform.system()
135135
py_version = platform.python_version()
136-
assert result.startswith(f"Agent365SDK/1.2.3 ({os_type}; Python/{py_version}")
137-
assert ";" not in result.split("Python/")[1] # No orchestrator
136+
137+
result = Utility.get_user_agent_header()
138+
139+
# Regex for Agent365SDK/version (OS; Python/version)
140+
pattern = rf"^Agent365SDK/.+ \({os_type}; Python/{py_version}\)$"
141+
assert re.match(pattern, result)
138142

139143
def test_get_user_agent_header_with_orchestrator():
140144
"""Test get_user_agent_header includes orchestrator when provided."""
141145
Utility._cached_version = "2.0.0"
142146
orchestrator = "TestOrchestrator"
147+
os_type = platform.system()
148+
py_version = platform.python_version()
149+
143150
result = Utility.get_user_agent_header(orchestrator)
144-
assert f"; {orchestrator}" in result
145-
assert result.startswith("Agent365SDK/2.0.0 (")
151+
152+
# Regex for Agent365SDK/version (OS; Python/version; TestOrchestrator)
153+
pattern = rf"^Agent365SDK/.+ \({os_type}; Python/{py_version}; {orchestrator}\)$"
154+
assert re.match(pattern, result)

0 commit comments

Comments
 (0)