From c5ddbe1e6589adcde2a7e54d8948e08b55abd3a1 Mon Sep 17 00:00:00 2001 From: Ayaz-Microsoft Date: Thu, 12 Mar 2026 12:07:01 +0530 Subject: [PATCH 1/4] implemented codeQL and copilot sugestions --- .../common/database/test_database_base.py | 692 ++---------------- src/tests/backend/conftest.py | 1 - src/tests/backend/test_app.py | 2 +- src/tests/backend/v4/config/test_settings.py | 30 +- .../helper/test_plan_to_mplan_converter.py | 6 +- .../test_orchestration_manager.py | 9 +- 6 files changed, 79 insertions(+), 661 deletions(-) diff --git a/src/tests/backend/common/database/test_database_base.py b/src/tests/backend/common/database/test_database_base.py index 2198d9859..24b608f3e 100644 --- a/src/tests/backend/common/database/test_database_base.py +++ b/src/tests/backend/common/database/test_database_base.py @@ -748,639 +748,83 @@ async def get_team_agent(self, team_id, agent_name): return None assert not db.initialized +# Note: Coverage-only tests that exercised abstract base methods via super() +# have been removed to avoid high-maintenance scaffolding without behavioral +# assertions. Abstract/base stubs should instead be excluded from coverage +# or tested via focused, behavior-oriented tests in concrete implementations. + + class TestDatabaseBaseAbstractMethodCoverage: - """Test coverage for abstract method pass statements via super() calls.""" - - @pytest.mark.asyncio - async def test_abstract_initialize_via_super(self): - """Test that initialize abstract method can be called via super().""" - - class TestDatabase(DatabaseBase): - async def initialize(self): - await super().initialize() - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - await db.initialize() # Calls super().initialize() which executes pass - - @pytest.mark.asyncio - async def test_abstract_close_via_super(self): - """Test that close abstract method can be called via super().""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): - await super().close() - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - await db.close() # Calls super().close() which executes pass - + """Minimal test to verify abstract base class methods can be called via super().""" + @pytest.mark.asyncio - async def test_abstract_crud_operations_via_super(self): - """Test CRUD abstract methods via super() calls.""" - + async def test_abstract_methods_callable_via_super(self): + """Verify abstract methods are callable through super() without errors.""" + class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): - await super().add_item(item) - async def update_item(self, item): - await super().update_item(item) - async def get_item_by_id(self, item_id, partition_key, model_class): - return await super().get_item_by_id(item_id, partition_key, model_class) - async def query_items(self, query, parameters, model_class): - return await super().query_items(query, parameters, model_class) - async def delete_item(self, item_id, partition_key): - await super().delete_item(item_id, partition_key) - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - + async def initialize(self): await super().initialize() + async def close(self): await super().close() + async def add_item(self, item): await super().add_item(item) + async def update_item(self, item): await super().update_item(item) + async def get_item_by_id(self, item_id, partition_key, model_class): return await super().get_item_by_id(item_id, partition_key, model_class) + async def query_items(self, query, parameters, model_class): return await super().query_items(query, parameters, model_class) + async def delete_item(self, item_id, partition_key): await super().delete_item(item_id, partition_key) + async def add_plan(self, plan): await super().add_plan(plan) + async def update_plan(self, plan): await super().update_plan(plan) + async def get_plan_by_plan_id(self, plan_id): return await super().get_plan_by_plan_id(plan_id) + async def get_plan(self, plan_id): return await super().get_plan(plan_id) + async def get_all_plans(self): return await super().get_all_plans() + async def get_all_plans_by_team_id(self, team_id): return await super().get_all_plans_by_team_id(team_id) + async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return await super().get_all_plans_by_team_id_status(user_id, team_id, status) + async def add_step(self, step): await super().add_step(step) + async def update_step(self, step): await super().update_step(step) + async def get_steps_by_plan(self, plan_id): return await super().get_steps_by_plan(plan_id) + async def get_step(self, step_id, session_id): return await super().get_step(step_id, session_id) + async def add_team(self, team): await super().add_team(team) + async def update_team(self, team): await super().update_team(team) + async def get_team(self, team_id): return await super().get_team(team_id) + async def get_team_by_id(self, team_id): return await super().get_team_by_id(team_id) + async def get_all_teams(self): return await super().get_all_teams() + async def delete_team(self, team_id): return await super().delete_team(team_id) + async def get_data_by_type(self, data_type): return await super().get_data_by_type(data_type) + async def get_all_items(self): return await super().get_all_items() + async def get_steps_for_plan(self, plan_id): return await super().get_steps_for_plan(plan_id) + async def get_current_team(self, user_id): return await super().get_current_team(user_id) + async def delete_current_team(self, user_id): return await super().delete_current_team(user_id) + async def set_current_team(self, current_team): await super().set_current_team(current_team) + async def update_current_team(self, current_team): await super().update_current_team(current_team) + async def delete_plan_by_plan_id(self, plan_id): return await super().delete_plan_by_plan_id(plan_id) + async def add_mplan(self, mplan): await super().add_mplan(mplan) + async def update_mplan(self, mplan): await super().update_mplan(mplan) + async def get_mplan(self, plan_id): return await super().get_mplan(plan_id) + async def add_agent_message(self, message): await super().add_agent_message(message) + async def update_agent_message(self, message): await super().update_agent_message(message) + async def get_agent_messages(self, plan_id): return await super().get_agent_messages(plan_id) + async def add_team_agent(self, team_agent): await super().add_team_agent(team_agent) + async def delete_team_agent(self, team_id, agent_name): await super().delete_team_agent(team_id, agent_name) + async def get_team_agent(self, team_id, agent_name): return await super().get_team_agent(team_id, agent_name) + db = TestDatabase() mock_item = Mock() + await db.initialize() + await db.close() await db.add_item(mock_item) await db.update_item(mock_item) - result = await db.get_item_by_id("id", "pk", BaseDataModel) - assert result is None - results = await db.query_items("query", [], BaseDataModel) - assert results is None await db.delete_item("id", "pk") - - @pytest.mark.asyncio - async def test_abstract_plan_operations_via_super(self): - """Test plan abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): - await super().add_plan(plan) - async def update_plan(self, plan): - await super().update_plan(plan) - async def get_plan_by_plan_id(self, plan_id): - return await super().get_plan_by_plan_id(plan_id) - async def get_plan(self, plan_id): - return await super().get_plan(plan_id) - async def get_all_plans(self): - return await super().get_all_plans() - async def get_all_plans_by_team_id(self, team_id): - return await super().get_all_plans_by_team_id(team_id) - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): - return await super().get_all_plans_by_team_id_status(user_id, team_id, status) - async def delete_plan_by_plan_id(self, plan_id): - return await super().delete_plan_by_plan_id(plan_id) - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_plan = Mock() - await db.add_plan(mock_plan) - await db.update_plan(mock_plan) - assert await db.get_plan_by_plan_id("id") is None - assert await db.get_plan("id") is None - assert await db.get_all_plans() is None - assert await db.get_all_plans_by_team_id("team_id") is None - assert await db.get_all_plans_by_team_id_status("user", "team", "status") is None - assert await db.delete_plan_by_plan_id("id") is None - - @pytest.mark.asyncio - async def test_abstract_step_operations_via_super(self): - """Test step abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): - await super().add_step(step) - async def update_step(self, step): - await super().update_step(step) - async def get_steps_by_plan(self, plan_id): - return await super().get_steps_by_plan(plan_id) - async def get_step(self, step_id, session_id): - return await super().get_step(step_id, session_id) - async def get_steps_for_plan(self, plan_id): - return await super().get_steps_for_plan(plan_id) - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_step = Mock() - await db.add_step(mock_step) - await db.update_step(mock_step) - assert await db.get_steps_by_plan("plan_id") is None - assert await db.get_step("step_id", "session_id") is None - assert await db.get_steps_for_plan("plan_id") is None - - @pytest.mark.asyncio - async def test_abstract_team_operations_via_super(self): - """Test team abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): - await super().add_team(team) - async def update_team(self, team): - await super().update_team(team) - async def get_team(self, team_id): - return await super().get_team(team_id) - async def get_team_by_id(self, team_id): - return await super().get_team_by_id(team_id) - async def get_all_teams(self): - return await super().get_all_teams() - async def delete_team(self, team_id): - return await super().delete_team(team_id) - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_team = Mock() - await db.add_team(mock_team) - await db.update_team(mock_team) - assert await db.get_team("team_id") is None - assert await db.get_team_by_id("team_id") is None - assert await db.get_all_teams() is None - assert await db.delete_team("team_id") is None - - @pytest.mark.asyncio - async def test_abstract_data_management_via_super(self): - """Test data management abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): - return await super().get_data_by_type(data_type) - async def get_all_items(self): - return await super().get_all_items() - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - assert await db.get_data_by_type("type") is None - assert await db.get_all_items() is None - - @pytest.mark.asyncio - async def test_abstract_current_team_operations_via_super(self): - """Test current team abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): - return await super().get_current_team(user_id) - async def delete_current_team(self, user_id): - return await super().delete_current_team(user_id) - async def set_current_team(self, current_team): - await super().set_current_team(current_team) - async def update_current_team(self, current_team): - await super().update_current_team(current_team) - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_team = Mock() - assert await db.get_current_team("user_id") is None - assert await db.delete_current_team("user_id") is None - await db.set_current_team(mock_team) - await db.update_current_team(mock_team) - - @pytest.mark.asyncio - async def test_abstract_mplan_operations_via_super(self): - """Test mplan abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): - await super().add_mplan(mplan) - async def update_mplan(self, mplan): - await super().update_mplan(mplan) - async def get_mplan(self, plan_id): - return await super().get_mplan(plan_id) - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_mplan = Mock() - await db.add_mplan(mock_mplan) - await db.update_mplan(mock_mplan) - assert await db.get_mplan("plan_id") is None - - @pytest.mark.asyncio - async def test_abstract_agent_message_operations_via_super(self): - """Test agent message abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): - await super().add_agent_message(message) - async def update_agent_message(self, message): - await super().update_agent_message(message) - async def get_agent_messages(self, plan_id): - return await super().get_agent_messages(plan_id) - async def add_team_agent(self, team_agent): pass - async def delete_team_agent(self, team_id, agent_name): pass - async def get_team_agent(self, team_id, agent_name): return None - - db = TestDatabase() - mock_message = Mock() - await db.add_agent_message(mock_message) - await db.update_agent_message(mock_message) - assert await db.get_agent_messages("plan_id") is None - - @pytest.mark.asyncio - async def test_abstract_team_agent_operations_via_super(self): - """Test team agent abstract methods via super() calls.""" - - class TestDatabase(DatabaseBase): - async def initialize(self): pass - async def close(self): pass - async def add_item(self, item): pass - async def update_item(self, item): pass - async def get_item_by_id(self, item_id, partition_key, model_class): return None - async def query_items(self, query, parameters, model_class): return [] - async def delete_item(self, item_id, partition_key): pass - async def add_plan(self, plan): pass - async def update_plan(self, plan): pass - async def get_plan_by_plan_id(self, plan_id): return None - async def get_plan(self, plan_id): return None - async def get_all_plans(self): return [] - async def get_all_plans_by_team_id(self, team_id): return [] - async def get_all_plans_by_team_id_status(self, user_id, team_id, status): return [] - async def add_step(self, step): pass - async def update_step(self, step): pass - async def get_steps_by_plan(self, plan_id): return [] - async def get_step(self, step_id, session_id): return None - async def add_team(self, team): pass - async def update_team(self, team): pass - async def get_team(self, team_id): return None - async def get_team_by_id(self, team_id): return None - async def get_all_teams(self): return [] - async def delete_team(self, team_id): return False - async def get_data_by_type(self, data_type): return [] - async def get_all_items(self): return [] - async def get_steps_for_plan(self, plan_id): return [] - async def get_current_team(self, user_id): return None - async def delete_current_team(self, user_id): return None - async def set_current_team(self, current_team): pass - async def update_current_team(self, current_team): pass - async def delete_plan_by_plan_id(self, plan_id): return False - async def add_mplan(self, mplan): pass - async def update_mplan(self, mplan): pass - async def get_mplan(self, plan_id): return None - async def add_agent_message(self, message): pass - async def update_agent_message(self, message): pass - async def get_agent_messages(self, plan_id): return None - async def add_team_agent(self, team_agent): - await super().add_team_agent(team_agent) - async def delete_team_agent(self, team_id, agent_name): - await super().delete_team_agent(team_id, agent_name) - async def get_team_agent(self, team_id, agent_name): - return await super().get_team_agent(team_id, agent_name) - - db = TestDatabase() - mock_agent = Mock() - await db.add_team_agent(mock_agent) + await db.add_plan(mock_item) + await db.update_plan(mock_item) + await db.add_step(mock_item) + await db.update_step(mock_item) + await db.add_team(mock_item) + await db.update_team(mock_item) + await db.set_current_team(mock_item) + await db.update_current_team(mock_item) + await db.add_mplan(mock_item) + await db.update_mplan(mock_item) + await db.add_agent_message(mock_item) + await db.update_agent_message(mock_item) + await db.add_team_agent(mock_item) await db.delete_team_agent("team_id", "agent_name") - assert await db.get_team_agent("team_id", "agent_name") is None if __name__ == "__main__": diff --git a/src/tests/backend/conftest.py b/src/tests/backend/conftest.py index 1275c82a4..d5001295f 100644 --- a/src/tests/backend/conftest.py +++ b/src/tests/backend/conftest.py @@ -6,7 +6,6 @@ import os import sys -from pathlib import Path from types import ModuleType from unittest.mock import Mock, MagicMock diff --git a/src/tests/backend/test_app.py b/src/tests/backend/test_app.py index 779e131be..5ba254cba 100644 --- a/src/tests/backend/test_app.py +++ b/src/tests/backend/test_app.py @@ -36,7 +36,7 @@ os.environ.setdefault("AZURE_OPENAI_RAI_DEPLOYMENT_NAME", "test-rai-deployment") # Check if v4 has been mocked by another test file (prevents import errors) -_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], Mock) +_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], (Mock, MagicMock)) if _v4_is_mocked: # Skip this module - v4 has been mocked by another test file pytest.skip( diff --git a/src/tests/backend/v4/config/test_settings.py b/src/tests/backend/v4/config/test_settings.py index e1cd2d87c..e086162e4 100644 --- a/src/tests/backend/v4/config/test_settings.py +++ b/src/tests/backend/v4/config/test_settings.py @@ -503,28 +503,6 @@ async def test_close_connection_with_exception(self): # Connection should still be removed self.assertNotIn(process_id, config.connections) - async def test_send_status_update_async_success(self): - """Test sending status update successfully.""" - config = ConnectionConfig() - user_id = "user-123" - process_id = "process-456" - message = "Test message" - connection = AsyncMock() - - config.add_connection(process_id, connection, user_id) - - await config.send_status_update_async(message, user_id) - - connection.send_text.assert_called_once() - sent_data = json.loads(connection.send_text.call_args[0][0]) - # Verify payload structure - type field exists (may be mocked or real enum value) - self.assertIn('type', sent_data) - # If not mocked, verify actual value - type_val = str(sent_data['type']) - if 'MagicMock' not in type_val: - self.assertEqual(sent_data['type'], 'system_message') - self.assertEqual(sent_data['data'], message) - async def test_send_status_update_async_no_user_id(self): """Test sending status update with no user ID.""" @@ -811,7 +789,7 @@ async def approve_task(): result = await config.wait_for_approval(plan_id, timeout=1.0) self.assertTrue(result) - await approve_task_handle + _ = await approve_task_handle async def test_wait_for_approval_rejected(self): """Test waiting for approval when plan is rejected.""" @@ -828,7 +806,7 @@ async def reject_task(): result = await config.wait_for_approval(plan_id, timeout=1.0) self.assertFalse(result) - await reject_task_handle + _ = await reject_task_handle async def test_wait_for_clarification_key_error(self): """Test waiting for clarification with non-existent request_id raises KeyError.""" @@ -854,7 +832,7 @@ async def answer_task(): result = await config.wait_for_clarification(request_id, timeout=1.0) self.assertEqual(result, "User answer") - await answer_task_handle + _ = await answer_task_handle async def test_wait_for_approval_creates_new_event(self): """Test that waiting for approval creates event if not exists.""" @@ -872,7 +850,7 @@ async def approve_task(): result = await config.wait_for_approval(plan_id, timeout=1.0) self.assertTrue(result) - await approve_task_handle + _ = await approve_task_handle if __name__ == '__main__': diff --git a/src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py b/src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py index 2ac11215e..8673eae03 100644 --- a/src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py +++ b/src/tests/backend/v4/orchestration/helper/test_plan_to_mplan_converter.py @@ -11,13 +11,13 @@ import unittest import sys -from unittest.mock import Mock +from unittest.mock import Mock, MagicMock import pytest # Check if v4 has been mocked by another test file (prevents import errors) -_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], Mock) -_v4_models_is_mocked = 'v4.models' in sys.modules and isinstance(sys.modules['v4.models'], Mock) +_v4_is_mocked = 'v4' in sys.modules and isinstance(sys.modules['v4'], (Mock, MagicMock)) +_v4_models_is_mocked = 'v4.models' in sys.modules and isinstance(sys.modules['v4.models'], (Mock, MagicMock)) if _v4_is_mocked or _v4_models_is_mocked: pytest.skip( "Skipping test_plan_to_mplan_converter.py: v4 module has been mocked by another test file. " diff --git a/src/tests/backend/v4/orchestration/test_orchestration_manager.py b/src/tests/backend/v4/orchestration/test_orchestration_manager.py index 27659a4ed..9667e71c4 100644 --- a/src/tests/backend/v4/orchestration/test_orchestration_manager.py +++ b/src/tests/backend/v4/orchestration/test_orchestration_manager.py @@ -927,9 +927,8 @@ def test_extract_response_text_agent_executor_response_with_agent_response(self) agent_resp = Mock() agent_resp.text = "Agent executor response" - executor_resp = Mock() + executor_resp = Mock(spec=['agent_response']) executor_resp.agent_response = agent_resp - del executor_resp.text # Remove text attr so it falls through result = self.manager._extract_response_text(executor_resp) self.assertEqual(result, "Agent executor response") @@ -941,10 +940,9 @@ def test_extract_response_text_agent_executor_response_fallback_to_conversation( last_msg = MockChatMessage("Last conversation message") - executor_resp = Mock() + executor_resp = Mock(spec=['agent_response', 'full_conversation']) executor_resp.agent_response = agent_resp executor_resp.full_conversation = [MockChatMessage("First"), last_msg] - del executor_resp.text # Remove text attr result = self.manager._extract_response_text(executor_resp) self.assertEqual(result, "Last conversation message") @@ -954,10 +952,9 @@ def test_extract_response_text_agent_executor_response_empty_conversation(self): agent_resp = Mock() agent_resp.text = None - executor_resp = Mock() + executor_resp = Mock(spec=['agent_response', 'full_conversation']) executor_resp.agent_response = agent_resp executor_resp.full_conversation = [] - del executor_resp.text # Remove text attr result = self.manager._extract_response_text(executor_resp) self.assertEqual(result, "") From da96959cb6d50c92d46c99f13d2f58900c1c113d Mon Sep 17 00:00:00 2001 From: Ayaz-Microsoft Date: Thu, 12 Mar 2026 12:47:22 +0530 Subject: [PATCH 2/4] test: add async test for successful status update in ConnectionConfig --- src/tests/backend/v4/config/test_settings.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/tests/backend/v4/config/test_settings.py b/src/tests/backend/v4/config/test_settings.py index e086162e4..d25edc7bb 100644 --- a/src/tests/backend/v4/config/test_settings.py +++ b/src/tests/backend/v4/config/test_settings.py @@ -502,6 +502,24 @@ async def test_close_connection_with_exception(self): mock_logger.error.assert_called() # Connection should still be removed self.assertNotIn(process_id, config.connections) + + async def test_send_status_update_async_success(self): + """Test sending a plain string status update successfully.""" + + config = ConnectionConfig() + user_id = "user-123" + process_id = "process-456" + message = "Test message" + connection = AsyncMock() + + config.add_connection(process_id, connection, user_id) + + await config.send_status_update_async(message, user_id) + + connection.send_text.assert_called_once() + sent_data = json.loads(connection.send_text.call_args[0][0]) + self.assertIn('type', sent_data) + self.assertEqual(sent_data['data'], message) async def test_send_status_update_async_no_user_id(self): """Test sending status update with no user ID.""" From b07c5b3f669cae95f4b41af7097944d5cc0bdf2f Mon Sep 17 00:00:00 2001 From: Ayaz-Microsoft Date: Thu, 12 Mar 2026 18:10:58 +0530 Subject: [PATCH 3/4] test: update event tracking test to verify callable mock integration --- .../v4/common/services/test_plan_service.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/tests/backend/v4/common/services/test_plan_service.py b/src/tests/backend/v4/common/services/test_plan_service.py index 455200af7..43b739ddc 100644 --- a/src/tests/backend/v4/common/services/test_plan_service.py +++ b/src/tests/backend/v4/common/services/test_plan_service.py @@ -530,17 +530,11 @@ async def test_static_method_properties(self): assert result is False def test_event_tracking_calls(self): - """Test that event tracking is called appropriately.""" - # This test verifies the event tracking integration - with patch.object(mock_event_utils, 'track_event_if_configured') as mock_track: - mock_approval = MockPlanApprovalResponse( - plan_id="test-plan", - m_plan_id="test-m-plan", - approved=True - ) - - # The actual event tracking calls are tested indirectly through the service methods - assert mock_track is not None + """Test that event tracking is callable via the mocked event_utils module.""" + # Verify the mock event_utils has the track function accessible + assert callable(mock_event_utils.track_event_if_configured) + # Verify the plan_service module imported it (may be a mock attribute) + assert hasattr(plan_service_module, 'track_event_if_configured') def test_logging_integration(self): """Test that logging is properly configured.""" From f36a005f208a5f783eaad83ee2c643ca27565270 Mon Sep 17 00:00:00 2001 From: Ayaz-Microsoft Date: Thu, 12 Mar 2026 18:19:04 +0530 Subject: [PATCH 4/4] test: remove redundant assertion for plan_service module in event tracking test --- src/tests/backend/v4/common/services/test_plan_service.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/backend/v4/common/services/test_plan_service.py b/src/tests/backend/v4/common/services/test_plan_service.py index 43b739ddc..9d805508a 100644 --- a/src/tests/backend/v4/common/services/test_plan_service.py +++ b/src/tests/backend/v4/common/services/test_plan_service.py @@ -533,8 +533,6 @@ def test_event_tracking_calls(self): """Test that event tracking is callable via the mocked event_utils module.""" # Verify the mock event_utils has the track function accessible assert callable(mock_event_utils.track_event_if_configured) - # Verify the plan_service module imported it (may be a mock attribute) - assert hasattr(plan_service_module, 'track_event_if_configured') def test_logging_integration(self): """Test that logging is properly configured."""