Skip to content

Commit d5b899e

Browse files
Merge remote-tracking branch 'origin/dev-v4' into psl-logging-improvements
2 parents 9bd60fe + 2c19410 commit d5b899e

23 files changed

Lines changed: 1490 additions & 879 deletions

.github/workflows/test.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,29 @@ jobs:
6666
6767
- name: Run tests with coverage
6868
if: env.skip_tests == 'false'
69+
env:
70+
PYTHONPATH: src:src/backend
6971
run: |
70-
if python -m pytest src/tests/backend/test_app.py --cov=backend --cov-config=.coveragerc -q > /dev/null 2>&1 && \
71-
python -m pytest src/tests/backend --cov=backend --cov-append --cov-report=term --cov-report=xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py; then
72-
echo "Tests completed, checking coverage."
73-
if [ -f coverage.xml ]; then
74-
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib.get('line-rate', 0)) * 100)")
75-
echo "Overall coverage: $COVERAGE%"
76-
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
77-
echo "Coverage is below 80%, failing the job."
78-
exit 1
79-
fi
72+
# Run test_app.py first (isolation required)
73+
python -m pytest src/tests/backend/test_app.py --cov=src/backend --cov-config=.coveragerc -q
74+
75+
# Run remaining backend tests with coverage append
76+
python -m pytest src/tests/backend --cov=src/backend --cov-append --cov-report=term --cov-report=xml --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py
77+
78+
- name: Check coverage threshold
79+
if: env.skip_tests == 'false'
80+
run: |
81+
if [ -f coverage.xml ]; then
82+
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib.get('line-rate', 0)) * 100)")
83+
echo "Overall coverage: $COVERAGE%"
84+
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
85+
echo "::error::Coverage is below 80% threshold. Current: $COVERAGE%"
86+
exit 1
8087
fi
88+
echo "✅ Coverage threshold met: $COVERAGE% >= 80%"
8189
else
82-
echo "No tests found, skipping coverage check."
90+
echo "::error::coverage.xml not found"
91+
exit 1
8392
fi
8493
8594
- name: Skip coverage report if no tests

conftest.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77

88
import pytest
99

10-
# Add the agents path
11-
agents_path = Path(__file__).parent.parent.parent / "backend" / "v4" / "magentic_agents"
12-
sys.path.insert(0, str(agents_path))
10+
# Get the root directory of the project
11+
root_dir = Path(__file__).parent
12+
13+
# Add src directory to path for 'backend', 'common', 'v4' etc. imports
14+
src_path = root_dir / "src"
15+
if str(src_path) not in sys.path:
16+
sys.path.insert(0, str(src_path))
17+
18+
# Add src/backend to path for relative imports within backend
19+
backend_path = root_dir / "src" / "backend"
20+
if str(backend_path) not in sys.path:
21+
sys.path.insert(0, str(backend_path))
1322

1423
@pytest.fixture
1524
def agent_env_vars():

src/tests/backend/auth/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tests/backend/common/config/__init__.py

Whitespace-only changes.

src/tests/backend/common/database/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/backend/common/database/test_database_base.py

Lines changed: 635 additions & 0 deletions
Large diffs are not rendered by default.

src/tests/backend/common/utils/test_utils_af.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ class TestCreateRAIAgent:
218218
def setup_method(self):
219219
"""Setup for each test method."""
220220
self.mock_team = Mock(spec=TeamConfiguration)
221+
# Setup model_copy to return a new mock that can be modified
222+
self.mock_rai_team = Mock(spec=TeamConfiguration)
223+
self.mock_team.model_copy = Mock(return_value=self.mock_rai_team)
221224
self.mock_memory_store = Mock(spec=DatabaseBase)
222225

223226
@pytest.mark.asyncio
@@ -238,6 +241,9 @@ async def test_create_rai_agent_success(self, mock_registry, mock_foundry_class,
238241
# Execute
239242
result = await create_RAI_agent(self.mock_team, self.mock_memory_store)
240243

244+
# Verify team.model_copy() was called to create a copy
245+
self.mock_team.model_copy.assert_called_once()
246+
241247
# Verify agent creation
242248
mock_foundry_class.assert_called_once()
243249
call_args = mock_foundry_class.call_args
@@ -251,13 +257,14 @@ async def test_create_rai_agent_success(self, mock_registry, mock_foundry_class,
251257
assert call_args[1]['project_endpoint'] == "https://test.project.azure.com/"
252258
assert call_args[1]['mcp_config'] is None
253259
assert call_args[1]['search_config'] is None
254-
assert call_args[1]['team_config'] is self.mock_team
260+
# The team_config passed should be the copy (rai_team), not the original
261+
assert call_args[1]['team_config'] is self.mock_rai_team
255262
assert call_args[1]['memory_store'] is self.mock_memory_store
256263

257-
# Verify team configuration updates
258-
assert self.mock_team.team_id == "rai_team"
259-
assert self.mock_team.name == "RAI Team"
260-
assert self.mock_team.description == "Team responsible for Responsible AI checks"
264+
# Verify the copied team configuration was updated (not the original)
265+
assert self.mock_rai_team.team_id == "rai_team"
266+
assert self.mock_rai_team.name == "RAI Team"
267+
assert self.mock_rai_team.description == "Team responsible for Responsible AI checks"
261268

262269
# Verify agent initialization
263270
mock_agent.open.assert_called_once()

0 commit comments

Comments
 (0)