From 60f4b656ddb9355b41779ab672d8522afe8013f4 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Fri, 7 Feb 2025 23:12:38 +0530 Subject: [PATCH 1/5] appfixes --- src/backend/.env.sample | 12 -- src/backend/app.py | 8 +- src/backend/tests/agents/test_agentutils.py | 194 ++++++++++++++++---- 3 files changed, 165 insertions(+), 49 deletions(-) delete mode 100644 src/backend/.env.sample diff --git a/src/backend/.env.sample b/src/backend/.env.sample deleted file mode 100644 index 64102ab7b..000000000 --- a/src/backend/.env.sample +++ /dev/null @@ -1,12 +0,0 @@ -COSMOSDB_ENDPOINT= -COSMOSDB_DATABASE=autogen -COSMOSDB_CONTAINER=memory - -AZURE_OPENAI_ENDPOINT= -AZURE_OPENAI_MODEL_NAME=gpt-4o -AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o -AZURE_OPENAI_API_VERSION=2024-08-01-preview -APPLICATIONINSIGHTS_INSTRUMENTATION_KEY= - -BACKEND_API_URL='http://localhost:8000' -FRONTEND_SITE_NAME='http://127.0.0.1:3000' \ No newline at end of file diff --git a/src/backend/app.py b/src/backend/app.py index ab65affdc..b4e269d41 100644 --- a/src/backend/app.py +++ b/src/backend/app.py @@ -1,4 +1,10 @@ -# app.py +#!/usr/bin/env python +import os +import sys + +# Add the parent directory (the one that contains the "src" folder) to sys.path. +# This allows absolute imports such as "from src.backend.middleware.health_check" to work. +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) import asyncio import logging import os diff --git a/src/backend/tests/agents/test_agentutils.py b/src/backend/tests/agents/test_agentutils.py index c5131815f..83199d5c4 100644 --- a/src/backend/tests/agents/test_agentutils.py +++ b/src/backend/tests/agents/test_agentutils.py @@ -1,13 +1,15 @@ -# pylint: disable=import-error, wrong-import-position, missing-module-docstring +# src/backend/tests/agents/test_agentutils.py import os import sys -from unittest.mock import MagicMock +import json import pytest -from pydantic import ValidationError +from unittest.mock import MagicMock, patch +from pydantic import BaseModel -# Environment and module setup -sys.modules["azure.monitor.events.extension"] = MagicMock() +# Adjust sys.path so that the project root is found. +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../"))) +# Set required environment variables. os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint" os.environ["COSMOSDB_KEY"] = "mock-key" os.environ["COSMOSDB_DATABASE"] = "mock-database" @@ -16,39 +18,159 @@ os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01" os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint" -from src.backend.agents.agentutils import extract_and_update_transition_states # noqa: F401, C0413 -from src.backend.models.messages import Step # noqa: F401, C0413 +# Patch missing azure module so that event_utils imports without error. +sys.modules["azure.monitor.events.extension"] = MagicMock() + +# --- Import the function and constant under test --- +from src.backend.agents.agentutils import ( + extract_and_update_transition_states, + common_agent_system_message, +) +from src.backend.models.messages import Step +from autogen_core.components.models import AzureOpenAIChatCompletionClient + +# Configure the Step model to allow extra attributes. +Step.model_config["extra"] = "allow" + + +# Dummy Cosmos class that records update calls. +class DummyCosmosRecorder: + def __init__(self): + self.update_called = False + + async def update_step(self, step): + # To allow setting extra attributes, ensure __pydantic_extra__ is initialized. + if step.__pydantic_extra__ is None: + step.__pydantic_extra__ = {} + step.__pydantic_extra__["updated_field"] = True + self.update_called = True + + +# Dummy model client classes to simulate LLM responses. + +class DummyModelClient(AzureOpenAIChatCompletionClient): + def __init__(self, **kwargs): + # Bypass parent's __init__. + pass + + async def create(self, messages, extra_create_args=None): + # Simulate a valid response that matches the expected FSMStateAndTransition schema. + response_dict = { + "identifiedTargetState": "State1", + "identifiedTargetTransition": "Transition1" + } + dummy_resp = MagicMock() + dummy_resp.content = json.dumps(response_dict) + return dummy_resp + +class DummyModelClientError(AzureOpenAIChatCompletionClient): + def __init__(self, **kwargs): + pass + + async def create(self, messages, extra_create_args=None): + raise Exception("LLM error") +class DummyModelClientInvalidJSON(AzureOpenAIChatCompletionClient): + def __init__(self, **kwargs): + pass -def test_step_initialization(): - """Test Step initialization with valid data.""" + async def create(self, messages, extra_create_args=None): + dummy_resp = MagicMock() + dummy_resp.content = "invalid json" + return dummy_resp + +# Fixture: a dummy Step for testing. +@pytest.fixture +def dummy_step(): step = Step( - data_type="step", - plan_id="test_plan", - action="test_action", - agent="HumanAgent", - session_id="test_session", - user_id="test_user", - agent_reply="test_reply", + id="step1", + plan_id="plan1", + action="Test Action", + agent="HumanAgent", # Using string for simplicity. + status="planned", + session_id="sess1", + user_id="user1", + human_approval_status="requested", ) + # Provide a value for agent_reply. + step.agent_reply = "Test reply" + # Ensure __pydantic_extra__ is initialized for extra fields. + step.__pydantic_extra__ = {} + return step + +# Tests for extract_and_update_transition_states + +@pytest.mark.asyncio +async def test_extract_and_update_transition_states_success(dummy_step): + """ + Test that extract_and_update_transition_states correctly parses the LLM response, + updates the step with the expected target state and transition, and calls cosmos.update_step. + """ + model_client = DummyModelClient() + dummy_cosmos = DummyCosmosRecorder() + with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=dummy_cosmos): + updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) + assert updated_step.identified_target_state == "State1" + assert updated_step.identified_target_transition == "Transition1" + assert dummy_cosmos.update_called is True + # Check that our extra field was set. + assert updated_step.__pydantic_extra__.get("updated_field") is True + + +@pytest.mark.asyncio +async def test_extract_and_update_transition_states_model_client_error(dummy_step): + """ + Test that if the model client raises an exception, it propagates. + """ + model_client = DummyModelClientError() + with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): + with pytest.raises(Exception, match="LLM error"): + await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) + + +@pytest.mark.asyncio +async def test_extract_and_update_transition_states_invalid_json(dummy_step): + """ + Test that an invalid JSON response from the model client causes an exception. + """ + model_client = DummyModelClientInvalidJSON() + with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): + with pytest.raises(Exception): + await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) + + +def test_common_agent_system_message_contains_delivery_address(): + """ + Test that the common_agent_system_message constant contains instructions regarding the delivery address. + """ + assert "delivery address" in common_agent_system_message + + +@pytest.mark.asyncio +async def test_extract_and_update_transition_states_no_agent_reply(dummy_step): + """ + Test the behavior when step.agent_reply is empty. + """ + dummy_step.agent_reply = "" + # Ensure extra dict is initialized. + dummy_step.__pydantic_extra__ = {} + model_client = DummyModelClient() + with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): + updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) + # Even with an empty agent_reply, our dummy client returns the same valid JSON. + assert updated_step.identified_target_state == "State1" + assert updated_step.identified_target_transition == "Transition1" + - assert step.data_type == "step" - assert step.plan_id == "test_plan" - assert step.action == "test_action" - assert step.agent == "HumanAgent" - assert step.session_id == "test_session" - assert step.user_id == "test_user" - assert step.agent_reply == "test_reply" - assert step.status == "planned" - assert step.human_approval_status == "requested" - - -def test_step_missing_required_fields(): - """Test Step initialization with missing required fields.""" - with pytest.raises(ValidationError): - Step( - data_type="step", - action="test_action", - agent="test_agent", - session_id="test_session", - ) +def test_dummy_json_parsing(): + """ + Test that the JSON parsing in extract_and_update_transition_states works for valid JSON. + """ + json_str = '{"identifiedTargetState": "TestState", "identifiedTargetTransition": "TestTransition"}' + data = json.loads(json_str) + class DummySchema(BaseModel): + identifiedTargetState: str + identifiedTargetTransition: str + schema = DummySchema(**data) + assert schema.identifiedTargetState == "TestState" + assert schema.identifiedTargetTransition == "TestTransition" From ff6d85e2c511731862002b17b56dfc39abc68230 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Fri, 7 Feb 2025 23:16:37 +0530 Subject: [PATCH 2/5] Delete src/backend/tests/agents/test_agentutils.py --- src/backend/tests/agents/test_agentutils.py | 176 -------------------- 1 file changed, 176 deletions(-) delete mode 100644 src/backend/tests/agents/test_agentutils.py diff --git a/src/backend/tests/agents/test_agentutils.py b/src/backend/tests/agents/test_agentutils.py deleted file mode 100644 index 83199d5c4..000000000 --- a/src/backend/tests/agents/test_agentutils.py +++ /dev/null @@ -1,176 +0,0 @@ -# src/backend/tests/agents/test_agentutils.py -import os -import sys -import json -import pytest -from unittest.mock import MagicMock, patch -from pydantic import BaseModel - -# Adjust sys.path so that the project root is found. -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../"))) - -# Set required environment variables. -os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint" -os.environ["COSMOSDB_KEY"] = "mock-key" -os.environ["COSMOSDB_DATABASE"] = "mock-database" -os.environ["COSMOSDB_CONTAINER"] = "mock-container" -os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] = "mock-deployment-name" -os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01" -os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint" - -# Patch missing azure module so that event_utils imports without error. -sys.modules["azure.monitor.events.extension"] = MagicMock() - -# --- Import the function and constant under test --- -from src.backend.agents.agentutils import ( - extract_and_update_transition_states, - common_agent_system_message, -) -from src.backend.models.messages import Step -from autogen_core.components.models import AzureOpenAIChatCompletionClient - -# Configure the Step model to allow extra attributes. -Step.model_config["extra"] = "allow" - - -# Dummy Cosmos class that records update calls. -class DummyCosmosRecorder: - def __init__(self): - self.update_called = False - - async def update_step(self, step): - # To allow setting extra attributes, ensure __pydantic_extra__ is initialized. - if step.__pydantic_extra__ is None: - step.__pydantic_extra__ = {} - step.__pydantic_extra__["updated_field"] = True - self.update_called = True - - -# Dummy model client classes to simulate LLM responses. - -class DummyModelClient(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - # Bypass parent's __init__. - pass - - async def create(self, messages, extra_create_args=None): - # Simulate a valid response that matches the expected FSMStateAndTransition schema. - response_dict = { - "identifiedTargetState": "State1", - "identifiedTargetTransition": "Transition1" - } - dummy_resp = MagicMock() - dummy_resp.content = json.dumps(response_dict) - return dummy_resp - -class DummyModelClientError(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - pass - - async def create(self, messages, extra_create_args=None): - raise Exception("LLM error") - -class DummyModelClientInvalidJSON(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - pass - - async def create(self, messages, extra_create_args=None): - dummy_resp = MagicMock() - dummy_resp.content = "invalid json" - return dummy_resp - -# Fixture: a dummy Step for testing. -@pytest.fixture -def dummy_step(): - step = Step( - id="step1", - plan_id="plan1", - action="Test Action", - agent="HumanAgent", # Using string for simplicity. - status="planned", - session_id="sess1", - user_id="user1", - human_approval_status="requested", - ) - # Provide a value for agent_reply. - step.agent_reply = "Test reply" - # Ensure __pydantic_extra__ is initialized for extra fields. - step.__pydantic_extra__ = {} - return step - -# Tests for extract_and_update_transition_states - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_success(dummy_step): - """ - Test that extract_and_update_transition_states correctly parses the LLM response, - updates the step with the expected target state and transition, and calls cosmos.update_step. - """ - model_client = DummyModelClient() - dummy_cosmos = DummyCosmosRecorder() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=dummy_cosmos): - updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - assert updated_step.identified_target_state == "State1" - assert updated_step.identified_target_transition == "Transition1" - assert dummy_cosmos.update_called is True - # Check that our extra field was set. - assert updated_step.__pydantic_extra__.get("updated_field") is True - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_model_client_error(dummy_step): - """ - Test that if the model client raises an exception, it propagates. - """ - model_client = DummyModelClientError() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - with pytest.raises(Exception, match="LLM error"): - await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_invalid_json(dummy_step): - """ - Test that an invalid JSON response from the model client causes an exception. - """ - model_client = DummyModelClientInvalidJSON() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - with pytest.raises(Exception): - await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - - -def test_common_agent_system_message_contains_delivery_address(): - """ - Test that the common_agent_system_message constant contains instructions regarding the delivery address. - """ - assert "delivery address" in common_agent_system_message - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_no_agent_reply(dummy_step): - """ - Test the behavior when step.agent_reply is empty. - """ - dummy_step.agent_reply = "" - # Ensure extra dict is initialized. - dummy_step.__pydantic_extra__ = {} - model_client = DummyModelClient() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - # Even with an empty agent_reply, our dummy client returns the same valid JSON. - assert updated_step.identified_target_state == "State1" - assert updated_step.identified_target_transition == "Transition1" - - -def test_dummy_json_parsing(): - """ - Test that the JSON parsing in extract_and_update_transition_states works for valid JSON. - """ - json_str = '{"identifiedTargetState": "TestState", "identifiedTargetTransition": "TestTransition"}' - data = json.loads(json_str) - class DummySchema(BaseModel): - identifiedTargetState: str - identifiedTargetTransition: str - schema = DummySchema(**data) - assert schema.identifiedTargetState == "TestState" - assert schema.identifiedTargetTransition == "TestTransition" From 56b3ed7ac266e7869d66efc284596d5958a7fbb0 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Sun, 9 Feb 2025 14:18:57 +0530 Subject: [PATCH 3/5] appfixes --- src/backend/.env.sample | 12 ++ src/backend/app.py | 2 +- src/backend/tests/agents/test_agentutils.py | 195 ++++---------------- 3 files changed, 50 insertions(+), 159 deletions(-) create mode 100644 src/backend/.env.sample diff --git a/src/backend/.env.sample b/src/backend/.env.sample new file mode 100644 index 000000000..64102ab7b --- /dev/null +++ b/src/backend/.env.sample @@ -0,0 +1,12 @@ +COSMOSDB_ENDPOINT= +COSMOSDB_DATABASE=autogen +COSMOSDB_CONTAINER=memory + +AZURE_OPENAI_ENDPOINT= +AZURE_OPENAI_MODEL_NAME=gpt-4o +AZURE_OPENAI_DEPLOYMENT_NAME=gpt-4o +AZURE_OPENAI_API_VERSION=2024-08-01-preview +APPLICATIONINSIGHTS_INSTRUMENTATION_KEY= + +BACKEND_API_URL='http://localhost:8000' +FRONTEND_SITE_NAME='http://127.0.0.1:3000' \ No newline at end of file diff --git a/src/backend/app.py b/src/backend/app.py index b4e269d41..147e21cfd 100644 --- a/src/backend/app.py +++ b/src/backend/app.py @@ -3,7 +3,7 @@ import sys # Add the parent directory (the one that contains the "src" folder) to sys.path. -# This allows absolute imports such as "from src.backend.middleware.health_check" to work. +# This allows absolute imports such as "from src.backend.middleware.health_check" to work sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) import asyncio import logging diff --git a/src/backend/tests/agents/test_agentutils.py b/src/backend/tests/agents/test_agentutils.py index 83199d5c4..aaa0e57e5 100644 --- a/src/backend/tests/agents/test_agentutils.py +++ b/src/backend/tests/agents/test_agentutils.py @@ -1,15 +1,13 @@ -# src/backend/tests/agents/test_agentutils.py +# pylint: disable=import-error, wrong-import-position, missing-module-docstring import os import sys -import json +from unittest.mock import MagicMock import pytest -from unittest.mock import MagicMock, patch -from pydantic import BaseModel +from pydantic import ValidationError -# Adjust sys.path so that the project root is found. -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../"))) +# Environment and module setup +sys.modules["azure.monitor.events.extension"] = MagicMock() -# Set required environment variables. os.environ["COSMOSDB_ENDPOINT"] = "https://mock-endpoint" os.environ["COSMOSDB_KEY"] = "mock-key" os.environ["COSMOSDB_DATABASE"] = "mock-database" @@ -18,159 +16,40 @@ os.environ["AZURE_OPENAI_API_VERSION"] = "2023-01-01" os.environ["AZURE_OPENAI_ENDPOINT"] = "https://mock-openai-endpoint" -# Patch missing azure module so that event_utils imports without error. -sys.modules["azure.monitor.events.extension"] = MagicMock() - -# --- Import the function and constant under test --- -from src.backend.agents.agentutils import ( - extract_and_update_transition_states, - common_agent_system_message, -) -from src.backend.models.messages import Step -from autogen_core.components.models import AzureOpenAIChatCompletionClient - -# Configure the Step model to allow extra attributes. -Step.model_config["extra"] = "allow" - - -# Dummy Cosmos class that records update calls. -class DummyCosmosRecorder: - def __init__(self): - self.update_called = False - - async def update_step(self, step): - # To allow setting extra attributes, ensure __pydantic_extra__ is initialized. - if step.__pydantic_extra__ is None: - step.__pydantic_extra__ = {} - step.__pydantic_extra__["updated_field"] = True - self.update_called = True - - -# Dummy model client classes to simulate LLM responses. - -class DummyModelClient(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - # Bypass parent's __init__. - pass - - async def create(self, messages, extra_create_args=None): - # Simulate a valid response that matches the expected FSMStateAndTransition schema. - response_dict = { - "identifiedTargetState": "State1", - "identifiedTargetTransition": "Transition1" - } - dummy_resp = MagicMock() - dummy_resp.content = json.dumps(response_dict) - return dummy_resp - -class DummyModelClientError(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - pass - - async def create(self, messages, extra_create_args=None): - raise Exception("LLM error") +from src.backend.agents.agentutils import extract_and_update_transition_states # noqa: F401, C0413 +from src.backend.models.messages import Step # noqa: F401, C0413 -class DummyModelClientInvalidJSON(AzureOpenAIChatCompletionClient): - def __init__(self, **kwargs): - pass - async def create(self, messages, extra_create_args=None): - dummy_resp = MagicMock() - dummy_resp.content = "invalid json" - return dummy_resp - -# Fixture: a dummy Step for testing. -@pytest.fixture -def dummy_step(): +def test_step_initialization(): + """Test Step initialization with valid data.""" step = Step( - id="step1", - plan_id="plan1", - action="Test Action", - agent="HumanAgent", # Using string for simplicity. - status="planned", - session_id="sess1", - user_id="user1", - human_approval_status="requested", + data_type="step", + plan_id="test_plan", + action="test_action", + agent="HumanAgent", + session_id="test_session", + user_id="test_user", + agent_reply="test_reply", ) - # Provide a value for agent_reply. - step.agent_reply = "Test reply" - # Ensure __pydantic_extra__ is initialized for extra fields. - step.__pydantic_extra__ = {} - return step - -# Tests for extract_and_update_transition_states - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_success(dummy_step): - """ - Test that extract_and_update_transition_states correctly parses the LLM response, - updates the step with the expected target state and transition, and calls cosmos.update_step. - """ - model_client = DummyModelClient() - dummy_cosmos = DummyCosmosRecorder() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=dummy_cosmos): - updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - assert updated_step.identified_target_state == "State1" - assert updated_step.identified_target_transition == "Transition1" - assert dummy_cosmos.update_called is True - # Check that our extra field was set. - assert updated_step.__pydantic_extra__.get("updated_field") is True - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_model_client_error(dummy_step): - """ - Test that if the model client raises an exception, it propagates. - """ - model_client = DummyModelClientError() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - with pytest.raises(Exception, match="LLM error"): - await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_invalid_json(dummy_step): - """ - Test that an invalid JSON response from the model client causes an exception. - """ - model_client = DummyModelClientInvalidJSON() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - with pytest.raises(Exception): - await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - - -def test_common_agent_system_message_contains_delivery_address(): - """ - Test that the common_agent_system_message constant contains instructions regarding the delivery address. - """ - assert "delivery address" in common_agent_system_message - - -@pytest.mark.asyncio -async def test_extract_and_update_transition_states_no_agent_reply(dummy_step): - """ - Test the behavior when step.agent_reply is empty. - """ - dummy_step.agent_reply = "" - # Ensure extra dict is initialized. - dummy_step.__pydantic_extra__ = {} - model_client = DummyModelClient() - with patch("src.backend.agents.agentutils.CosmosBufferedChatCompletionContext", return_value=DummyCosmosRecorder()): - updated_step = await extract_and_update_transition_states(dummy_step, "sess1", "user1", "anything", model_client) - # Even with an empty agent_reply, our dummy client returns the same valid JSON. - assert updated_step.identified_target_state == "State1" - assert updated_step.identified_target_transition == "Transition1" - -def test_dummy_json_parsing(): - """ - Test that the JSON parsing in extract_and_update_transition_states works for valid JSON. - """ - json_str = '{"identifiedTargetState": "TestState", "identifiedTargetTransition": "TestTransition"}' - data = json.loads(json_str) - class DummySchema(BaseModel): - identifiedTargetState: str - identifiedTargetTransition: str - schema = DummySchema(**data) - assert schema.identifiedTargetState == "TestState" - assert schema.identifiedTargetTransition == "TestTransition" + assert step.data_type == "step" + assert step.plan_id == "test_plan" + assert step.action == "test_action" + assert step.agent == "HumanAgent" + assert step.session_id == "test_session" + assert step.user_id == "test_user" + assert step.agent_reply == "test_reply" + assert step.status == "planned" + assert step.human_approval_status == "requested" + + +def test_step_missing_required_fields(): + """Test Step initialization with missing required fields.""" + with pytest.raises(ValidationError): + Step( + data_type="step", + action="test_action", + agent="test_agent", + session_id="test_session", + ) + \ No newline at end of file From 1d0964884d9a67d6551205d6cafc33281dfc8cc4 Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Sun, 9 Feb 2025 14:24:18 +0530 Subject: [PATCH 4/5] appfixes --- src/backend/tests/agents/test_agentutils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/tests/agents/test_agentutils.py b/src/backend/tests/agents/test_agentutils.py index aaa0e57e5..c5131815f 100644 --- a/src/backend/tests/agents/test_agentutils.py +++ b/src/backend/tests/agents/test_agentutils.py @@ -52,4 +52,3 @@ def test_step_missing_required_fields(): agent="test_agent", session_id="test_session", ) - \ No newline at end of file From f388dc157f049725bc4ccbe0e21d830458b23a9b Mon Sep 17 00:00:00 2001 From: UtkarshMishra-Microsoft Date: Mon, 10 Feb 2025 10:17:01 +0530 Subject: [PATCH 5/5] appfixes --- src/backend/app.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/app.py b/src/backend/app.py index 147e21cfd..14d5137c7 100644 --- a/src/backend/app.py +++ b/src/backend/app.py @@ -7,7 +7,6 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) import asyncio import logging -import os import uuid from typing import List, Optional from src.backend.middleware.health_check import HealthCheckMiddleware