@@ -147,10 +147,6 @@ def _swap_copilot_sdk_layout(*, session_has_handler: bool, types_has_handler: bo
147147# Helpers
148148# ---------------------------------------------------------------------------
149149
150- def _copilot_cli_available ():
151- return shutil .which ("copilot" ) is not None
152-
153-
154150def _copilot_sdk_installed ():
155151 try :
156152 from importlib .metadata import version
@@ -1599,14 +1595,9 @@ def test_run_with_old_sdk_layout_types(self):
15991595
16001596
16011597# ---------------------------------------------------------------------------
1602- # Integration tests — require real Docker + copilot-cli + auth
1598+ # Integration tests — require real Docker + copilot-SDK + auth
16031599# ---------------------------------------------------------------------------
16041600
1605- _skip_no_copilot_cli = pytest .mark .skipif (
1606- not _copilot_cli_available (),
1607- reason = "GitHub Copilot CLI not installed (copilot not in PATH)" ,
1608- )
1609-
16101601_skip_no_copilot_sdk = pytest .mark .skipif (
16111602 not _copilot_sdk_installed (),
16121603 reason = "github-copilot-sdk not installed (pip install microbots[ghcp])" ,
@@ -1618,11 +1609,10 @@ def test_run_with_old_sdk_layout_types(self):
16181609)
16191610
16201611
1621- @_skip_no_copilot_cli
16221612@_skip_no_copilot_sdk
1623- @_skip_no_copilot_auth
16241613@pytest .mark .integration
16251614@pytest .mark .slow
1615+ @pytest .mark .ghcp
16261616class TestCopilotBotIntegration :
16271617 """End-to-end integration tests with real Copilot SDK."""
16281618
@@ -1631,7 +1621,7 @@ def test_simple_task(self, test_repo, issue_1):
16311621 _restore_real_copilot_modules ()
16321622 from microbots .bot .CopilotBot import CopilotBot
16331623
1634- issue_text = issue_1 [0 ]
1624+ issue_text = issue_1 [0 ] + " \n Fix the error in the original file."
16351625 verify_function = issue_1 [1 ]
16361626
16371627 bot = CopilotBot (
@@ -1658,22 +1648,38 @@ def test_simple_task(self, test_repo, issue_1):
16581648def _byok_openai_available ():
16591649 """Check if OpenAI BYOK credentials are configured via env vars."""
16601650 return bool (
1661- os .environ .get ("OPEN_AI_KEY " )
1662- and os .environ .get ("OPEN_AI_END_POINT " )
1651+ os .environ .get ("AZURE_OPENAI_API_KEY " )
1652+ and os .environ .get ("AZURE_OPENAI_ENDPOINT " )
16631653 )
16641654
16651655
16661656_skip_no_byok_openai = pytest .mark .skipif (
16671657 not _byok_openai_available (),
1668- reason = "OpenAI BYOK not configured (set OPEN_AI_KEY and OPEN_AI_END_POINT)" ,
1658+ reason = "OpenAI BYOK not configured (set env variables AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT)" ,
1659+ )
1660+
1661+ def _azure_ad_auth_available ():
1662+ """Check if Azure AD auth is available via DefaultAzureCredential."""
1663+ try :
1664+ from azure .identity import DefaultAzureCredential
1665+ credential = DefaultAzureCredential ()
1666+ # Attempt to get a token to verify credentials are working
1667+ credential .get_token ("https://cognitiveservices.azure.com/.default" )
1668+ return True
1669+ except Exception :
1670+ return False
1671+
1672+ _skip_no_azure_ad_auth = pytest .mark .skipif (
1673+ not _azure_ad_auth_available (),
1674+ reason = "Azure AD auth not available (set up DefaultAzureCredential)" ,
16691675)
16701676
16711677
1672- @_skip_no_copilot_cli
16731678@_skip_no_copilot_sdk
16741679@_skip_no_byok_openai
16751680@pytest .mark .integration
16761681@pytest .mark .slow
1682+ @pytest .mark .ghcp
16771683class TestCopilotBotBYOKOpenAIIntegration :
16781684 """End-to-end integration tests for CopilotBot with OpenAI BYOK."""
16791685
@@ -1682,22 +1688,68 @@ def test_byok_openai_simple_task(self, test_repo, issue_1):
16821688 _restore_real_copilot_modules ()
16831689 from microbots .bot .CopilotBot import CopilotBot
16841690
1691+ issue_text = issue_1 [0 ] + "\n Fix the error in the original file."
1692+ verify_function = issue_1 [1 ]
1693+
1694+ api_key = os .environ ["AZURE_OPENAI_API_KEY" ]
1695+ base_url = os .environ ["OPENAI_ENDPOINT" ]
1696+ model = os .getenv (
1697+ "AZURE_OPENAI_DEPLOYMENT_NAME" , "mini-swe-agent-gpt5"
1698+ )
1699+
1700+ bot = CopilotBot (
1701+ model = model ,
1702+ folder_to_mount = str (test_repo ),
1703+ permission = "READ_WRITE" ,
1704+ api_key = api_key ,
1705+ base_url = base_url ,
1706+ provider_type = "openai" ,
1707+ )
1708+
1709+ try :
1710+ assert bot ._provider_config is not None
1711+ assert bot ._provider_config ["type" ] == "openai"
1712+ assert bot .github_token is None
1713+
1714+ result = bot .run (
1715+ issue_text ,
1716+ timeout_in_seconds = 300 ,
1717+ )
1718+ assert result .status is True , f"CopilotBot BYOK run failed: { result .error } "
1719+ verify_function (test_repo )
1720+ finally :
1721+ bot .stop ()
1722+
1723+ @_skip_no_azure_ad_auth
1724+ def test_byok_openai_simple_task_with_token_provider (self , test_repo , issue_1 ):
1725+ """CopilotBot can fix a simple syntax error using OpenAI BYOK credentials."""
1726+ _restore_real_copilot_modules ()
1727+ from microbots .bot .CopilotBot import CopilotBot
1728+
16851729 issue_text = issue_1 [0 ]
16861730 verify_function = issue_1 [1 ]
16871731
1688- api_key = os .environ ["OPEN_AI_KEY " ]
1689- base_url = os .environ ["OPEN_AI_END_POINT " ]
1732+ api_key = os .environ ["AZURE_OPENAI_API_KEY " ]
1733+ base_url = os .environ ["AZURE_OPENAI_ENDPOINT " ]
16901734 model = os .getenv (
16911735 "AZURE_OPENAI_DEPLOYMENT_NAME" , "mini-swe-agent-gpt5"
16921736 )
16931737
1738+ from azure .identity import DefaultAzureCredential
1739+ credential = DefaultAzureCredential ()
1740+ def get_token ():
1741+ return credential .get_token (
1742+ "https://cognitiveservices.azure.com/.default"
1743+ ).token
1744+
16941745 bot = CopilotBot (
16951746 model = model ,
16961747 folder_to_mount = str (test_repo ),
16971748 permission = "READ_WRITE" ,
16981749 api_key = api_key ,
16991750 base_url = base_url ,
17001751 provider_type = "openai" ,
1752+ token_provider = get_token ,
17011753 )
17021754
17031755 try :
@@ -1713,3 +1765,4 @@ def test_byok_openai_simple_task(self, test_repo, issue_1):
17131765 verify_function (test_repo )
17141766 finally :
17151767 bot .stop ()
1768+
0 commit comments