Repository navigation
Expand file tree
/
Copy pathtest_capability.py
More file actions
277 lines (232 loc) · 9.12 KB
/
Copy pathtest_capability.py
File metadata and controls
277 lines (232 loc) · 9.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
"""Tests for airlock/capability.py — shared served-by provider classifier."""
from __future__ import annotations
import pytest
from airlock.capability import (
airlock_provider_for,
capability_record,
endpoints_for,
normalize_provider_token,
)
def _entry(model: str, **params) -> dict:
lp = {"model": model}
lp.update(params)
return {"litellm_params": lp}
class TestNormalizeProviderToken:
def test_aistudio_to_gemini(self):
assert normalize_provider_token("aistudio") == "gemini"
def test_vertex_to_vertex_ai(self):
assert normalize_provider_token("vertex") == "vertex_ai"
def test_vertex_ai_beta_to_vertex_ai(self):
assert normalize_provider_token("vertex_ai_beta") == "vertex_ai"
@pytest.mark.parametrize(
"token",
[
"gemini",
"vertex_ai",
"openai",
"anthropic",
"mistral",
"perplexity",
"tavily",
],
)
def test_native_tokens_pass_through(self, token):
assert normalize_provider_token(token) == token
def test_unknown_identity(self):
assert normalize_provider_token("weird") == "weird"
class TestAirlockProviderFor:
def test_anthropic(self):
assert airlock_provider_for(_entry("anthropic/claude-opus-4-8")) == "anthropic"
def test_openai(self):
assert airlock_provider_for(_entry("openai/gpt-5.5")) == "openai"
def test_gemini_aistudio_entry(self):
# alias `aistudio/gemini-3.5-flash` -> litellm model gemini/...
assert airlock_provider_for(_entry("gemini/gemini-3.5-flash")) == "gemini"
def test_vertex(self):
assert airlock_provider_for(_entry("vertex_ai/gemini-3.5-flash")) == "vertex_ai"
def test_vertex_ai_beta_normalized(self):
assert (
airlock_provider_for(_entry("vertex_ai_beta/gemini-3.5-flash"))
== "vertex_ai"
)
def test_mistral(self):
assert airlock_provider_for(_entry("mistral/mistral-large-latest")) == "mistral"
def test_perplexity(self):
assert airlock_provider_for(_entry("perplexity/sonar")) == "perplexity"
def test_tavily(self):
assert airlock_provider_for(_entry("tavily/web-search")) == "tavily"
def test_vllm_is_openai(self):
assert (
airlock_provider_for(
_entry("openai/qwen3.6-27b", api_base="http://host:8000/v1")
)
== "openai"
)
def test_enhanced_resolves_to_target_gemini(self):
entry = {
"litellm_params": {
"model": "enhanced/gemini-coding",
"enhanced_profile": {
"target_model": "gemini/gemini-3.1-pro-preview-customtools",
},
}
}
assert airlock_provider_for(entry) == "gemini"
def test_enhanced_never_returns_enhanced(self):
entry = {
"litellm_params": {
"model": "enhanced/gemini-coding",
"enhanced_profile": {
"target_model": "gemini/gemini-3.1-pro-preview-customtools",
},
}
}
assert airlock_provider_for(entry) != "enhanced"
def test_missing_model_returns_none(self):
assert airlock_provider_for({"litellm_params": {}}) is None
assert airlock_provider_for({}) is None
class TestEndpointsFor:
def test_plain_entry_chat_only(self):
assert endpoints_for(_entry("gemini/gemini-3.5-flash")) == ["chat"]
def test_anthropic_chat_only(self):
assert endpoints_for(_entry("anthropic/claude-opus-4-8")) == ["chat"]
def test_airlock_batch_marker_aistudio(self):
entry = {
"model_name": "aistudio/gemini-3.5-flash",
"litellm_params": {"model": "gemini/gemini-3.5-flash"},
"airlock_batch": {"backend": "aistudio", "provider_model": "x"},
}
assert endpoints_for(entry) == ["chat", "batch"]
def test_airlock_batch_marker_mistral(self):
entry = {
"litellm_params": {"model": "mistral/mistral-large-latest"},
"airlock_batch": {"backend": "mistral"},
}
assert endpoints_for(entry) == ["chat", "batch"]
def test_airlock_batch_marker_vllm(self):
entry = {
"litellm_params": {"model": "openai/qwen3.6-27b"},
"airlock_batch": {"backend": "vllm"},
}
assert endpoints_for(entry) == ["chat", "batch"]
def test_vertex_global_is_chat_only(self):
entry = _entry("vertex_ai/gemini-3.5-flash", vertex_location="global")
assert endpoints_for(entry) == ["chat"]
def test_vertex_global_uppercase_is_chat_only(self):
entry = _entry("vertex_ai/gemini-3.5-flash", vertex_location="GLOBAL")
assert endpoints_for(entry) == ["chat"]
def test_vertex_regional_gets_batch(self):
entry = _entry("vertex_ai/gemini-3.5-flash", vertex_location="us-central1")
assert endpoints_for(entry) == ["chat", "batch"]
def test_vertex_no_location_chat_only(self):
assert endpoints_for(_entry("vertex_ai/gemini-3.5-flash")) == ["chat"]
def test_falsy_airlock_batch_chat_only(self):
entry = {
"litellm_params": {"model": "gemini/gemini-3.5-flash"},
"airlock_batch": None,
}
assert endpoints_for(entry) == ["chat"]
def test_empty_model_chat_only(self):
assert endpoints_for({"litellm_params": {}}) == ["chat"]
assert endpoints_for({}) == ["chat"]
class TestCapabilityRecord:
def test_anthropic_bare(self):
entry = {
"model_name": "claude-opus",
"litellm_params": {"model": "anthropic/claude-opus-4-8"},
}
rec = capability_record(entry)
assert rec == {
"airlock_provider": "anthropic",
"endpoints": ["chat"],
"underlying": "anthropic/claude-opus-4-8",
"region": None,
"deprecated": False,
}
def test_aistudio_batch_marker(self):
entry = {
"model_name": "aistudio/gemini-3.5-flash",
"litellm_params": {"model": "gemini/gemini-3.5-flash"},
"airlock_batch": {"backend": "aistudio"},
}
rec = capability_record(entry)
assert rec["airlock_provider"] == airlock_provider_for(entry)
assert rec["airlock_provider"] == "gemini"
assert rec["underlying"] == "gemini/gemini-3.5-flash"
assert rec["endpoints"] == endpoints_for(entry)
assert rec["endpoints"] == ["chat", "batch"]
assert rec["region"] is None
assert rec["deprecated"] is False
def test_embedding_marker_is_embedding_only(self):
entry = {
"model_name": "text-embedding-3-small",
"litellm_params": {"model": "openai/text-embedding-3-small"},
"airlock_embeddings": True,
}
rec = capability_record(entry)
assert rec["airlock_provider"] == "openai"
assert rec["endpoints"] == ["embeddings"]
def test_vertex_global_region_and_chat_only(self):
entry = {
"model_name": "gemini-3.5-flash-vertex",
"litellm_params": {
"model": "vertex_ai/gemini-3.5-flash",
"vertex_location": "global",
},
}
rec = capability_record(entry)
assert rec["airlock_provider"] == "vertex_ai"
assert rec["region"] == "global"
assert rec["endpoints"] == ["chat"]
assert rec["deprecated"] is True
@pytest.mark.parametrize(
"model_name",
[
"gemini-3.5-flash-aistudio",
"gemini-3.1-pro-aistudio",
"gemini-3.5-flash-vertex",
"gemini-3.1-pro-vertex",
"mistral-large-batch",
"mistral-small-batch",
"qwen36-27b-vllm-batch",
],
)
def test_suffix_twins_deprecated(self, model_name):
entry = {
"model_name": model_name,
"litellm_params": {"model": "gemini/gemini-3.5-flash"},
}
assert capability_record(entry)["deprecated"] is True
@pytest.mark.parametrize(
"model_name",
[
"gemini-3.5-flash",
"aistudio/gemini-3.5-flash",
"mistral/mistral-large",
"vertex/gemini-3.1-pro",
],
)
def test_bare_and_provider_aliases_not_deprecated(self, model_name):
entry = {
"model_name": model_name,
"litellm_params": {"model": "gemini/gemini-3.5-flash"},
}
assert capability_record(entry)["deprecated"] is False
def test_empty_litellm_params_safe(self):
rec = capability_record({"model_name": "weird"})
assert rec["airlock_provider"] is None
assert rec["endpoints"] == ["chat"]
assert rec["underlying"] is None
assert rec["region"] is None
assert rec["deprecated"] is False
def test_record_has_exact_keys(self):
rec = capability_record(
{"model_name": "x", "litellm_params": {"model": "openai/gpt-5.5"}}
)
assert set(rec) == {
"airlock_provider",
"endpoints",
"underlying",
"region",
"deprecated",
}