Skip to content

Commit eb5d8f1

Browse files
Merge pull request #753 from microsoft/macae-v4-unittestcases-kd
test: Macae v4 unittestcases kd
2 parents 7e5aae8 + b0b9f5f commit eb5d8f1

42 files changed

Lines changed: 19854 additions & 35 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[run]
2+
source = .
3+
omit =
4+
src/mcp_server/*
5+
src/backend/tests/*
6+
src/tests/mcp_server/*
7+
src/tests/agents/*
8+
src/**/__init__.py
9+
tests/e2e-test/*
10+
*/venv/*
11+
*/env/*
12+
*/.pytest_cache/*
13+
*/node_modules/*
14+
15+
[paths]
16+
source =
17+
src/backend
18+
*/site-packages
19+
20+
[report]
21+
exclude_lines =
22+
pragma: no cover
23+
def __repr__
24+
raise AssertionError
25+
raise NotImplementedError

.github/workflows/test.yml

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ on:
44
push:
55
branches:
66
- main
7-
- dev
8-
- demo
9-
- hotfix
7+
- demo-v4
8+
- dev-v4
109
paths:
1110
- 'src/backend/**/*.py'
1211
- 'src/tests/**/*.py'
@@ -24,9 +23,8 @@ on:
2423
- synchronize
2524
branches:
2625
- main
27-
- dev
28-
- demo
29-
- hotfix
26+
- demo-v4
27+
- dev-v4
3028
paths:
3129
- 'src/backend/**/*.py'
3230
- 'src/tests/**/*.py'
@@ -66,26 +64,23 @@ jobs:
6664
echo "skip_tests=false" >> $GITHUB_ENV
6765
fi
6866
69-
- name: Run tests with coverage
67+
- name: Run backend tests with coverage
7068
if: env.skip_tests == 'false'
7169
run: |
72-
pytest --cov=. --cov-report=term-missing --cov-report=xml \
73-
--ignore=tests/e2e-test/tests \
74-
--ignore=src/backend/tests/test_app.py \
75-
--ignore=src/tests/agents/test_foundry_integration.py \
76-
--ignore=src/tests/mcp_server/test_factory.py \
77-
--ignore=src/tests/mcp_server/test_hr_service.py \
78-
--ignore=src/backend/tests/test_config.py \
79-
--ignore=src/tests/agents/test_human_approval_manager.py \
80-
--ignore=src/backend/tests/test_team_specific_methods.py \
81-
--ignore=src/backend/tests/models/test_messages.py \
82-
--ignore=src/backend/tests/test_otlp_tracing.py \
83-
--ignore=src/backend/tests/auth/test_auth_utils.py
84-
85-
# - name: Run tests with coverage
86-
# if: env.skip_tests == 'false'
87-
# run: |
88-
# pytest --cov=. --cov-report=term-missing --cov-report=xml --ignore=tests/e2e-test/tests
70+
python -m pytest src/tests/backend/test_app.py --cov=backend.app --cov-report= --cov-config=.coveragerc -q > /dev/null 2>&1
71+
python -m pytest src/tests/backend --cov=backend --cov-append --cov-report=xml --cov-report= --cov-config=.coveragerc --ignore=src/tests/backend/test_app.py 2>&1 | tee /tmp/pytest_output.txt
72+
python -m coverage report --rcfile=.coveragerc
73+
tail -1 /tmp/pytest_output.txt
74+
75+
# Check coverage threshold
76+
if [ -f coverage.xml ]; then
77+
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('coverage.xml'); root = tree.getroot(); print(float(root.attrib['line-rate']) * 100)")
78+
echo "Coverage: $COVERAGE%"
79+
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
80+
echo "Coverage is below 80%, failing the job."
81+
exit 1
82+
fi
83+
fi
8984
9085
- name: Skip coverage report if no tests
9186
if: env.skip_tests == 'true'

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
[pytest]
22
addopts = -p pytest_asyncio
3+
pythonpath = src
4+
testpaths = src/tests
5+
python_files = test_*.py *_test.py
6+
python_functions = test_*
7+
python_classes = Test*

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# src package

src/backend/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# backend package

src/backend/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66

77
from azure.monitor.opentelemetry import configure_azure_monitor
8-
from common.config.app_config import config
9-
from common.models.messages_af import UserLanguage
8+
from backend.common.config.app_config import config
9+
from backend.common.models.messages_af import UserLanguage
1010

1111
# FastAPI imports
1212
from fastapi import FastAPI, Request
1313
from fastapi.middleware.cors import CORSMiddleware
1414

1515
# Local imports
16-
from middleware.health_check import HealthCheckMiddleware
17-
from v4.api.router import app_v4
16+
from backend.middleware.health_check import HealthCheckMiddleware
17+
from backend.v4.api.router import app_v4
1818

1919
# Azure monitoring
2020

2121

22-
from v4.config.agent_registry import agent_registry
22+
from backend.v4.config.agent_registry import agent_registry
2323

2424

2525
@asynccontextmanager

src/backend/v4/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# from agent_framework_azure_ai import AzureOpenAIChatClient
1818
from agent_framework import ChatOptions
1919

20-
from v4.models.messages import MPlan, WebsocketMessageType
20+
from backend.v4.models.messages import MPlan, WebsocketMessageType
2121

2222
logger = logging.getLogger(__name__)
2323

src/backend/v4/models/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import BaseModel
99

1010
from common.models.messages_af import AgentMessageType
11-
from v4.models.models import MPlan, PlanStatus
11+
from backend.v4.models.models import MPlan, PlanStatus
1212

1313

1414
# ---------------------------------------------------------------------------

src/backend/v4/orchestration/helper/plan_to_mplan_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
from typing import Iterable, List, Optional
44

5-
from v4.models.models import MPlan, MStep
5+
from backend.v4.models.models import MPlan, MStep
66

77
logger = logging.getLogger(__name__)
88

src/tests/backend/auth/conftest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Test configuration for auth module tests.
3+
"""
4+
5+
import pytest
6+
import sys
7+
import os
8+
from unittest.mock import MagicMock, patch
9+
import base64
10+
import json
11+
12+
# Add the backend directory to the Python path for imports
13+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'backend'))
14+
15+
@pytest.fixture
16+
def mock_sample_headers():
17+
"""Mock headers with EasyAuth authentication data."""
18+
return {
19+
"x-ms-client-principal-id": "12345678-1234-1234-1234-123456789012",
20+
"x-ms-client-principal-name": "testuser@example.com",
21+
"x-ms-client-principal-idp": "aad",
22+
"x-ms-token-aad-id-token": "sample.jwt.token",
23+
"x-ms-client-principal": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsInRpZCI6IjEyMzQ1Njc4LTEyMzQtMTIzNC0xMjM0LTEyMzQ1Njc4OTAxMiJ9"
24+
}
25+
26+
@pytest.fixture
27+
def mock_empty_headers():
28+
"""Mock headers without authentication data."""
29+
return {
30+
"content-type": "application/json",
31+
"user-agent": "test-agent"
32+
}
33+
34+
@pytest.fixture
35+
def mock_valid_base64_principal():
36+
"""Mock valid base64 encoded principal with tenant ID."""
37+
mock_data = {
38+
"typ": "JWT",
39+
"alg": "RS256",
40+
"tid": "87654321-4321-4321-4321-210987654321",
41+
"oid": "12345678-1234-1234-1234-123456789012",
42+
"preferred_username": "testuser@example.com",
43+
"name": "Test User"
44+
}
45+
46+
json_str = json.dumps(mock_data)
47+
return base64.b64encode(json_str.encode('utf-8')).decode('utf-8')
48+
49+
@pytest.fixture
50+
def mock_invalid_base64_principal():
51+
"""Mock invalid base64 encoded principal."""
52+
return "invalid_base64_string!"
53+
54+
@pytest.fixture
55+
def sample_user_mock():
56+
"""Mock sample_user data for testing."""
57+
return {
58+
"x-ms-client-principal-id": "00000000-0000-0000-0000-000000000000",
59+
"x-ms-client-principal-name": "testusername@contoso.com",
60+
"x-ms-client-principal-idp": "aad",
61+
"x-ms-token-aad-id-token": "your_aad_id_token",
62+
"x-ms-client-principal": "your_base_64_encoded_token"
63+
}

0 commit comments

Comments
 (0)