Skip to content

Commit 4c46ae3

Browse files
Testcases
1 parent a1b6077 commit 4c46ae3

File tree

10 files changed

+253
-178
lines changed

10 files changed

+253
-178
lines changed

src/backend/agents/tech_support.py

Lines changed: 107 additions & 108 deletions
Large diffs are not rendered by default.

src/backend/app.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,23 @@ async def input_task_endpoint(input_task: InputTask, request: Request):
157157
track_event(
158158
"InputTaskProcessed",
159159
{
160-
"status": f"Plan created:\n {plan.summary}"
161-
if plan.id
162-
else "Error occurred: Plan ID is empty",
160+
"status": (
161+
f"Plan created:\n {plan.summary}"
162+
if plan.id
163+
else "Error occurred: Plan ID is empty"
164+
),
163165
"session_id": input_task.session_id,
164166
"plan_id": plan.id,
165167
"description": input_task.description,
166168
},
167169
)
168170

169171
return {
170-
"status": f"Plan created:\n {plan.summary}"
171-
if plan.id
172-
else "Error occurred: Plan ID is empty",
172+
"status": (
173+
f"Plan created:\n {plan.summary}"
174+
if plan.id
175+
else "Error occurred: Plan ID is empty"
176+
),
173177
"session_id": input_task.session_id,
174178
"plan_id": plan.id,
175179
"description": input_task.description,

src/backend/otlp_tracing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from opentelemetry import trace
2-
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import \
3-
OTLPSpanExporter
2+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
43
from opentelemetry.sdk.resources import Resource
54
from opentelemetry.sdk.trace import TracerProvider
65
from opentelemetry.sdk.trace.export import BatchSpanProcessor
@@ -13,4 +12,4 @@ def configure_oltp_tracing(endpoint: str = None) -> trace.TracerProvider:
1312
tracer_provider.add_span_processor(processor)
1413
trace.set_tracer_provider(tracer_provider)
1514

16-
return tracer_provider
15+
return tracer_provider

src/backend/tests/agents/test_agentutils.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import json # Fix for missing import
55
from unittest.mock import AsyncMock, MagicMock, patch
66
from pydantic import ValidationError
7-
sys.modules['azure.monitor.events.extension'] = MagicMock()
7+
8+
sys.modules["azure.monitor.events.extension"] = MagicMock()
89

910
# Set environment variables to mock Config dependencies before any import
1011
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
@@ -15,14 +16,15 @@
1516
os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01"
1617
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint"
1718

18-
from autogen_core.components.models import AssistantMessage, AzureOpenAIChatCompletionClient
19+
from autogen_core.components.models import (
20+
AssistantMessage,
21+
AzureOpenAIChatCompletionClient,
22+
)
1923
from src.backend.models.messages import Step
2024
from src.backend.context.cosmos_memory import CosmosBufferedChatCompletionContext
2125
from src.backend.agents.agentutils import extract_and_update_transition_states
2226

2327

24-
25-
2628
@pytest.mark.asyncio
2729
async def test_extract_and_update_transition_states_invalid_response():
2830
"""Test handling of invalid JSON response from model client."""
@@ -41,8 +43,11 @@ async def test_extract_and_update_transition_states_invalid_response():
4143
cosmos_mock = MagicMock()
4244

4345
model_client.create.return_value = MagicMock(content="invalid_json")
44-
45-
with patch("src.backend.context.cosmos_memory.CosmosBufferedChatCompletionContext", cosmos_mock):
46+
47+
with patch(
48+
"src.backend.context.cosmos_memory.CosmosBufferedChatCompletionContext",
49+
cosmos_mock,
50+
):
4651
with pytest.raises(json.JSONDecodeError):
4752
await extract_and_update_transition_states(
4853
step=step,
@@ -54,6 +59,7 @@ async def test_extract_and_update_transition_states_invalid_response():
5459

5560
cosmos_mock.update_step.assert_not_called()
5661

62+
5763
@pytest.mark.asyncio
5864
async def test_extract_and_update_transition_states_validation_error():
5965
"""Test handling of a response missing required fields."""
@@ -71,12 +77,15 @@ async def test_extract_and_update_transition_states_validation_error():
7177
model_client = AsyncMock()
7278
cosmos_mock = MagicMock()
7379

74-
invalid_response = {"identifiedTargetState": "state1"} # Missing 'identifiedTargetTransition'
75-
model_client.create.return_value = MagicMock(
76-
content=json.dumps(invalid_response)
77-
)
78-
79-
with patch("src.backend.context.cosmos_memory.CosmosBufferedChatCompletionContext", cosmos_mock):
80+
invalid_response = {
81+
"identifiedTargetState": "state1"
82+
} # Missing 'identifiedTargetTransition'
83+
model_client.create.return_value = MagicMock(content=json.dumps(invalid_response))
84+
85+
with patch(
86+
"src.backend.context.cosmos_memory.CosmosBufferedChatCompletionContext",
87+
cosmos_mock,
88+
):
8089
with pytest.raises(ValidationError):
8190
await extract_and_update_transition_states(
8291
step=step,
@@ -88,6 +97,7 @@ async def test_extract_and_update_transition_states_validation_error():
8897

8998
cosmos_mock.update_step.assert_not_called()
9099

100+
91101
def test_step_initialization():
92102
"""Test Step initialization with valid data."""
93103
step = Step(
@@ -110,6 +120,7 @@ def test_step_initialization():
110120
assert step.status == "planned"
111121
assert step.human_approval_status == "requested"
112122

123+
113124
def test_step_missing_required_fields():
114125
"""Test Step initialization with missing required fields."""
115126
with pytest.raises(ValidationError):

src/backend/tests/agents/test_generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import json # Fix for missing import
55
from unittest.mock import AsyncMock, MagicMock, patch
66
from pydantic import ValidationError
7-
sys.modules['azure.monitor.events.extension'] = MagicMock()
7+
8+
sys.modules["azure.monitor.events.extension"] = MagicMock()
89

910
# Set environment variables to mock Config dependencies before any import
1011
os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint"
@@ -26,7 +27,6 @@
2627
from src.backend.agents.generic import get_generic_tools, GenericAgent, dummy_function
2728

2829

29-
3030
class TestGenericAgent(unittest.TestCase):
3131
def setUp(self):
3232
self.mock_model_client = MagicMock(spec=AzureOpenAIChatCompletionClient)
@@ -36,7 +36,7 @@ def setUp(self):
3636
self.mock_tools = get_generic_tools()
3737
self.mock_agent_id = MagicMock(spec=AgentId)
3838

39-
39+
4040
class TestDummyFunction(unittest.IsolatedAsyncioTestCase):
4141
async def test_dummy_function(self):
4242
result = await dummy_function()

0 commit comments

Comments
 (0)