Skip to content

Commit d94e0cd

Browse files
authored
Fix integration tests to skip when credentials not available (#102)
* Fix integration tests to skip when credentials not available - Use OCI_COMPARTMENT_ID instead of OCI_COMP for consistency - Add pytest.skip() when OCI_COMPARTMENT_ID not set - Make auth_type and auth_profile configurable via env vars - Update documentation with correct environment variable names - Tests now skip gracefully instead of failing with 401 errors * Fix remaining tests to skip when credentials not available - Fix test_response_format_via_model_kwargs to check OCI_COMPARTMENT_ID - Fix test_multi_step_tool_orchestration to check OCI_COMPARTMENT_ID - All 18 integration tests now skip gracefully instead of failing * Standardize environment variables and auth defaults across all integration tests - Change OCI_COMP to OCI_COMPARTMENT_ID in test_openai_models.py - Remove OCI_COMP fallback in test_react_integration.py - Use environment variables for auth_type/auth_profile instead of hardcoded values - Standardize defaults to SECURITY_TOKEN and DEFAULT across all tests - Update docstrings to reflect correct environment variable names
1 parent d6f7da1 commit d94e0cd

File tree

6 files changed

+87
-37
lines changed

6 files changed

+87
-37
lines changed

libs/oci/tests/integration_tests/agents/test_react_integration.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def calculate(expression: str) -> str:
7070

7171
def skip_if_no_oci_credentials() -> bool:
7272
"""Check if OCI credentials are available."""
73-
compartment_id = os.environ.get("OCI_COMPARTMENT_ID") or os.environ.get("OCI_COMP")
73+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
7474
return compartment_id is None
7575

7676

@@ -85,23 +85,39 @@ class TestOCIReactAgentIntegration:
8585
@pytest.fixture
8686
def compartment_id(self) -> str:
8787
"""Get compartment ID from environment."""
88-
return os.environ.get("OCI_COMPARTMENT_ID") or os.environ.get("OCI_COMP", "")
88+
return os.environ.get("OCI_COMPARTMENT_ID", "")
8989

9090
@pytest.fixture
9191
def service_endpoint(self) -> str:
9292
"""Get service endpoint from environment."""
9393
region = os.environ.get("OCI_REGION", "us-chicago-1")
9494
return f"https://inference.generativeai.{region}.oci.oraclecloud.com"
9595

96-
def test_simple_tool_call(self, compartment_id: str, service_endpoint: str) -> None:
96+
@pytest.fixture
97+
def auth_type(self) -> str:
98+
"""Get auth type from environment."""
99+
return os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN")
100+
101+
@pytest.fixture
102+
def auth_profile(self) -> str:
103+
"""Get auth profile from environment."""
104+
return os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT")
105+
106+
def test_simple_tool_call(
107+
self,
108+
compartment_id: str,
109+
service_endpoint: str,
110+
auth_type: str,
111+
auth_profile: str,
112+
) -> None:
97113
"""Test agent can make a simple tool call."""
98114
agent = create_oci_agent(
99115
model_id="meta.llama-4-scout-17b-16e-instruct",
100116
tools=[get_weather],
101117
compartment_id=compartment_id,
102118
service_endpoint=service_endpoint,
103-
auth_type="API_KEY",
104-
auth_profile="API_KEY_AUTH",
119+
auth_type=auth_type,
120+
auth_profile=auth_profile,
105121
system_prompt=(
106122
"You are a helpful weather assistant. "
107123
"Use the get_weather tool to answer weather questions."
@@ -128,15 +144,21 @@ def test_simple_tool_call(self, compartment_id: str, service_endpoint: str) -> N
128144
final_message = result["messages"][-1]
129145
assert final_message.content, "Final message should have content"
130146

131-
def test_multi_tool_agent(self, compartment_id: str, service_endpoint: str) -> None:
147+
def test_multi_tool_agent(
148+
self,
149+
compartment_id: str,
150+
service_endpoint: str,
151+
auth_type: str,
152+
auth_profile: str,
153+
) -> None:
132154
"""Test agent with multiple tools."""
133155
agent = create_oci_agent(
134156
model_id="meta.llama-4-scout-17b-16e-instruct",
135157
tools=[get_weather, calculate],
136158
compartment_id=compartment_id,
137159
service_endpoint=service_endpoint,
138-
auth_type="API_KEY",
139-
auth_profile="API_KEY_AUTH",
160+
auth_type=auth_type,
161+
auth_profile=auth_profile,
140162
system_prompt=(
141163
"You can check weather and do math. "
142164
"Use the calculate tool for math questions."
@@ -156,16 +178,20 @@ def test_multi_tool_agent(self, compartment_id: str, service_endpoint: str) -> N
156178
)
157179

158180
def test_agent_without_tool_call(
159-
self, compartment_id: str, service_endpoint: str
181+
self,
182+
compartment_id: str,
183+
service_endpoint: str,
184+
auth_type: str,
185+
auth_profile: str,
160186
) -> None:
161187
"""Test agent responds without tool call when not needed."""
162188
agent = create_oci_agent(
163189
model_id="meta.llama-4-scout-17b-16e-instruct",
164190
tools=[get_weather],
165191
compartment_id=compartment_id,
166192
service_endpoint=service_endpoint,
167-
auth_type="API_KEY",
168-
auth_profile="API_KEY_AUTH",
193+
auth_type=auth_type,
194+
auth_profile=auth_profile,
169195
system_prompt="You are a helpful assistant. Only use tools when necessary.",
170196
temperature=0.3,
171197
max_tokens=512,
@@ -181,7 +207,11 @@ def test_agent_without_tool_call(
181207
assert final_message.content, "Should have a response"
182208

183209
def test_agent_with_memory_checkpointer(
184-
self, compartment_id: str, service_endpoint: str
210+
self,
211+
compartment_id: str,
212+
service_endpoint: str,
213+
auth_type: str,
214+
auth_profile: str,
185215
) -> None:
186216
"""Test agent with memory checkpointer for conversation persistence."""
187217
from langgraph.checkpoint.memory import MemorySaver
@@ -192,8 +222,8 @@ def test_agent_with_memory_checkpointer(
192222
tools=[get_weather],
193223
compartment_id=compartment_id,
194224
service_endpoint=service_endpoint,
195-
auth_type="API_KEY",
196-
auth_profile="API_KEY_AUTH",
225+
auth_type=auth_type,
226+
auth_profile=auth_profile,
197227
system_prompt="You are a helpful weather assistant.",
198228
checkpointer=checkpointer,
199229
temperature=0.3,

libs/oci/tests/integration_tests/chat_models/test_openai_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
2. **Environment Variables**: Export the following:
1818
```bash
1919
export OCI_REGION="us-chicago-1" # or your region
20-
export OCI_COMP="ocid1.compartment.oc1..your-compartment-id"
20+
export OCI_COMPARTMENT_ID="ocid1.compartment.oc1..your-compartment-id"
2121
```
2222
2323
3. **OCI Config**: Ensure `~/.oci/config` exists with DEFAULT profile
@@ -48,9 +48,9 @@
4848
@pytest.fixture
4949
def openai_config():
5050
"""Get OpenAI model configuration."""
51-
compartment_id = os.environ.get("OCI_COMP")
51+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
5252
if not compartment_id:
53-
pytest.skip("OCI_COMP environment variable not set")
53+
pytest.skip("OCI_COMPARTMENT_ID not set")
5454

5555
region = os.environ.get("OCI_REGION", "us-chicago-1")
5656
return {

libs/oci/tests/integration_tests/chat_models/test_response_format.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
1616
2. **Environment Variables**: Export the following:
1717
```bash
18-
export OCI_REGION="us-chicago-1" # or your region
19-
export OCI_COMP="ocid1.compartment.oc1..your-compartment-id"
18+
export OCI_COMPARTMENT_ID="ocid1.compartment.oc1..your-compartment-id"
19+
export OCI_REGION="us-chicago-1" # Optional, defaults to us-chicago-1
20+
export OCI_AUTH_TYPE="SECURITY_TOKEN" # Optional, defaults to SECURITY_TOKEN
21+
export OCI_CONFIG_PROFILE="DEFAULT" # Optional, defaults to DEFAULT
2022
```
2123
2224
3. **OCI Config**: Ensure `~/.oci/config` exists with DEFAULT profile
@@ -55,6 +57,10 @@
5557

5658
def create_chat_model(model_id: str, response_format=None, **kwargs):
5759
"""Create a ChatOCIGenAI instance for testing."""
60+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
61+
if not compartment_id:
62+
pytest.skip("OCI_COMPARTMENT_ID not set")
63+
5864
region = os.getenv("OCI_REGION", "us-chicago-1")
5965
endpoint = f"https://inference.generativeai.{region}.oci.oraclecloud.com"
6066

@@ -65,10 +71,10 @@ def create_chat_model(model_id: str, response_format=None, **kwargs):
6571
return ChatOCIGenAI(
6672
model_id=model_id,
6773
service_endpoint=endpoint,
68-
compartment_id=os.getenv("OCI_COMP"),
74+
compartment_id=compartment_id,
6975
model_kwargs=model_kwargs,
70-
auth_type="SECURITY_TOKEN",
71-
auth_profile="DEFAULT",
76+
auth_type=os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
77+
auth_profile=os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
7278
auth_file_location=os.path.expanduser("~/.oci/config"),
7379
**kwargs,
7480
)
@@ -259,21 +265,25 @@ def test_response_format_via_model_kwargs():
259265
260266
This tests an alternative way to set response_format at initialization time.
261267
"""
268+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
269+
if not compartment_id:
270+
pytest.skip("OCI_COMPARTMENT_ID not set")
271+
262272
model_id = "meta.llama-3.3-70b-instruct"
263273
region = os.getenv("OCI_REGION", "us-chicago-1")
264274
endpoint = f"https://inference.generativeai.{region}.oci.oraclecloud.com"
265275

266276
llm = ChatOCIGenAI(
267277
model_id=model_id,
268278
service_endpoint=endpoint,
269-
compartment_id=os.getenv("OCI_COMP"),
279+
compartment_id=compartment_id,
270280
model_kwargs={
271281
"temperature": 0.1,
272282
"max_tokens": 512,
273283
"response_format": {"type": "JSON_OBJECT"},
274284
},
275-
auth_type="SECURITY_TOKEN",
276-
auth_profile="DEFAULT",
285+
auth_type=os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
286+
auth_profile=os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
277287
auth_file_location=os.path.expanduser("~/.oci/config"),
278288
)
279289

libs/oci/tests/integration_tests/chat_models/test_tool_calling.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
1616
2. **Environment Variables**: Export the following:
1717
```bash
18-
export OCI_REGION="us-chicago-1" # or your region
19-
export OCI_COMP="ocid1.compartment.oc1..your-compartment-id"
18+
export OCI_COMPARTMENT_ID="ocid1.compartment.oc1..your-compartment-id"
19+
export OCI_REGION="us-chicago-1" # Optional, defaults to us-chicago-1
20+
export OCI_AUTH_TYPE="SECURITY_TOKEN" # Optional, defaults to SECURITY_TOKEN
21+
export OCI_CONFIG_PROFILE="DEFAULT" # Optional, defaults to DEFAULT
2022
```
2123
2224
3. **OCI Config**: Ensure `~/.oci/config` exists with DEFAULT profile
@@ -83,15 +85,19 @@ def weather_tool():
8385

8486
def create_agent(model_id: str, weather_tool: StructuredTool):
8587
"""Create a LangGraph agent with tool calling."""
88+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
89+
if not compartment_id:
90+
pytest.skip("OCI_COMPARTMENT_ID not set")
91+
8692
region = os.getenv("OCI_REGION", "us-chicago-1")
8793
endpoint = f"https://inference.generativeai.{region}.oci.oraclecloud.com"
8894
chat_model = ChatOCIGenAI(
8995
model_id=model_id,
9096
service_endpoint=endpoint,
91-
compartment_id=os.getenv("OCI_COMP"),
97+
compartment_id=compartment_id,
9298
model_kwargs={"temperature": 0.3, "max_tokens": 512, "top_p": 0.9},
93-
auth_type="SECURITY_TOKEN",
94-
auth_profile="DEFAULT",
99+
auth_type=os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
100+
auth_profile=os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
95101
auth_file_location=os.path.expanduser("~/.oci/config"),
96102
disable_streaming="tool_calling",
97103
)
@@ -351,15 +357,19 @@ def take_action(resource: str, action: str) -> str:
351357
]
352358

353359
# Create agent with higher recursion limit to allow multi-step
360+
compartment_id = os.environ.get("OCI_COMPARTMENT_ID")
361+
if not compartment_id:
362+
pytest.skip("OCI_COMPARTMENT_ID not set")
363+
354364
region = os.getenv("OCI_REGION", "us-chicago-1")
355365
endpoint = f"https://inference.generativeai.{region}.oci.oraclecloud.com"
356366
chat_model = ChatOCIGenAI(
357367
model_id=model_id,
358368
service_endpoint=endpoint,
359-
compartment_id=os.getenv("OCI_COMP"),
369+
compartment_id=compartment_id,
360370
model_kwargs={"temperature": 0.2, "max_tokens": 2048, "top_p": 0.9},
361-
auth_type="SECURITY_TOKEN",
362-
auth_profile="DEFAULT",
371+
auth_type=os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
372+
auth_profile=os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
363373
auth_file_location=os.path.expanduser("~/.oci/config"),
364374
disable_streaming="tool_calling",
365375
max_sequential_tool_calls=8, # Allow up to 8 sequential tool calls

libs/oci/tests/integration_tests/chat_models/test_vision.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def get_config():
7373
"https://inference.generativeai.us-chicago-1.oci.oraclecloud.com",
7474
),
7575
"compartment_id": compartment_id,
76-
"auth_profile": os.environ.get("OCI_CONFIG_PROFILE", "API_KEY_AUTH"),
77-
"auth_type": os.environ.get("OCI_AUTH_TYPE", "API_KEY"),
76+
"auth_profile": os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
77+
"auth_type": os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
7878
}
7979

8080

libs/oci/tests/integration_tests/test_vision_real_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def get_config():
4040
"OCI_GENAI_ENDPOINT",
4141
"https://inference.generativeai.us-phoenix-1.oci.oraclecloud.com",
4242
),
43-
"auth_profile": os.environ.get("OCI_CONFIG_PROFILE", "API_KEY_AUTH"),
44-
"auth_type": os.environ.get("OCI_AUTH_TYPE", "API_KEY"),
43+
"auth_profile": os.environ.get("OCI_CONFIG_PROFILE", "DEFAULT"),
44+
"auth_type": os.environ.get("OCI_AUTH_TYPE", "SECURITY_TOKEN"),
4545
}
4646

4747

0 commit comments

Comments
 (0)