|
| 1 | +"""Tests for the chat-client agenthub_config default behavior. |
| 2 | +
|
| 3 | +Direct construction of UiPathChat / UiPathChatOpenAI / UiPathAzureChatOpenAI / |
| 4 | +UiPathChatBedrock / UiPathChatBedrockConverse / UiPathChatAnthropicBedrock / |
| 5 | +UiPathChatGoogleGenerativeAI / UiPathChatVertex must default |
| 6 | +client_settings.agenthub_config to None, so ad-hoc local SDK use isn't |
| 7 | +treated as deployed-runtime traffic by AOps governance. |
| 8 | +
|
| 9 | +The upstream classes (used by chat_model_factory for deployed runtimes) |
| 10 | +must keep the upstream library default of "agentsruntime", proving the |
| 11 | +local override does not leak globally onto the upstream class. |
| 12 | +""" |
| 13 | + |
| 14 | +import pytest |
| 15 | + |
| 16 | +from uipath_langchain.chat import ( |
| 17 | + UiPathAzureChatOpenAI, |
| 18 | + UiPathChat, |
| 19 | + UiPathChatAnthropicBedrock, |
| 20 | + UiPathChatBedrock, |
| 21 | + UiPathChatBedrockConverse, |
| 22 | + UiPathChatGoogleGenerativeAI, |
| 23 | + UiPathChatOpenAI, |
| 24 | + UiPathChatVertex, |
| 25 | +) |
| 26 | + |
| 27 | +_FAKE_JWT = ( |
| 28 | + "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9." |
| 29 | + "eyJzdWIiOiAidGVzdCIsICJpc3MiOiAidGVzdCJ9." |
| 30 | + "signature" |
| 31 | +) |
| 32 | + |
| 33 | + |
| 34 | +@pytest.fixture(autouse=True) |
| 35 | +def _platform_env(monkeypatch): |
| 36 | + monkeypatch.setenv("UIPATH_ACCESS_TOKEN", _FAKE_JWT) |
| 37 | + monkeypatch.setenv("UIPATH_URL", "https://example.com/org/tenant/orchestrator_/") |
| 38 | + monkeypatch.setenv("UIPATH_TENANT_ID", "tenant") |
| 39 | + monkeypatch.setenv("UIPATH_ORGANIZATION_ID", "org") |
| 40 | + monkeypatch.delenv("UIPATH_AGENTHUB_CONFIG", raising=False) |
| 41 | + monkeypatch.delenv("UIPATH_MODEL_NAME", raising=False) |
| 42 | + |
| 43 | + |
| 44 | +_DIRECT_CTOR_CASES = [ |
| 45 | + UiPathChat, |
| 46 | + UiPathAzureChatOpenAI, |
| 47 | + UiPathChatOpenAI, |
| 48 | + UiPathChatBedrock, |
| 49 | + UiPathChatBedrockConverse, |
| 50 | + UiPathChatAnthropicBedrock, |
| 51 | + UiPathChatGoogleGenerativeAI, |
| 52 | + UiPathChatVertex, |
| 53 | +] |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.parametrize("cls", _DIRECT_CTOR_CASES) |
| 57 | +class TestDirectConstructorAgentHubConfig: |
| 58 | + def test_default_is_none(self, cls): |
| 59 | + llm = cls() |
| 60 | + assert llm.client_settings.agenthub_config is None |
| 61 | + |
| 62 | + def test_env_var_is_honored(self, cls, monkeypatch): |
| 63 | + monkeypatch.setenv("UIPATH_AGENTHUB_CONFIG", "agentsplayground") |
| 64 | + llm = cls() |
| 65 | + assert llm.client_settings.agenthub_config == "agentsplayground" |
| 66 | + |
| 67 | + |
| 68 | +_UPSTREAM_CASES = [ |
| 69 | + "uipath_langchain_client.clients.normalized.chat_models:UiPathChat", |
| 70 | + "uipath_langchain_client.clients.openai.chat_models:UiPathChatOpenAI", |
| 71 | + "uipath_langchain_client.clients.openai.chat_models:UiPathAzureChatOpenAI", |
| 72 | + "uipath_langchain_client.clients.bedrock.chat_models:UiPathChatBedrock", |
| 73 | + "uipath_langchain_client.clients.bedrock.chat_models:UiPathChatBedrockConverse", |
| 74 | + "uipath_langchain_client.clients.bedrock.chat_models:UiPathChatAnthropicBedrock", |
| 75 | + "uipath_langchain_client.clients.google.chat_models:UiPathChatGoogleGenerativeAI", |
| 76 | +] |
| 77 | + |
| 78 | + |
| 79 | +@pytest.mark.parametrize("upstream_path", _UPSTREAM_CASES) |
| 80 | +class TestUpstreamAgentHubConfigUntouched: |
| 81 | + """Deployed runtimes go through chat_model_factory, which instantiates the |
| 82 | + upstream classes directly. Those must keep the upstream library default of |
| 83 | + 'agentsruntime'.""" |
| 84 | + |
| 85 | + def _resolve(self, upstream_path: str): |
| 86 | + import importlib |
| 87 | + |
| 88 | + module_name, attr = upstream_path.split(":") |
| 89 | + return getattr(importlib.import_module(module_name), attr) |
| 90 | + |
| 91 | + def test_upstream_keeps_agentsruntime_default(self, upstream_path): |
| 92 | + # make sure model rebinds are not breaking the agenthub_config |
| 93 | + import uipath_langchain.chat # noqa: F401 |
| 94 | + |
| 95 | + upstream_cls = self._resolve(upstream_path) |
| 96 | + llm = upstream_cls(model="gpt-4.1-mini-2025-04-14") |
| 97 | + assert llm.client_settings.agenthub_config == "agentsruntime" |
0 commit comments