Spaces:
Sleeping
Sleeping
yc1838 commited on
Commit ·
8c0d3aa
1
Parent(s): 756ec1b
test: cover gemini cooldown lane behavior
Browse files- tests/test_models.py +56 -0
tests/test_models.py
CHANGED
|
@@ -195,3 +195,59 @@ def test_success_resets_lane_failure_counter(monkeypatch):
|
|
| 195 |
failing._generate([])
|
| 196 |
|
| 197 |
assert raised.value.cooldown_seconds == 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
failing._generate([])
|
| 196 |
|
| 197 |
assert raised.value.cooldown_seconds == 60
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def test_same_gemini_lane_shares_cooldown(monkeypatch):
|
| 201 |
+
_reset_rate_limit_state_for_tests()
|
| 202 |
+
exc = _make_genai_client_error(429)
|
| 203 |
+
now = [1000.0]
|
| 204 |
+
sleeps = []
|
| 205 |
+
monkeypatch.setattr("lilith_agent.models.time.monotonic", lambda: now[0])
|
| 206 |
+
monkeypatch.setattr("lilith_agent.models.time.sleep", sleeps.append)
|
| 207 |
+
first = _RetryWrapper.model_construct(
|
| 208 |
+
inner=_FailingGenerateModel(exc), provider="google", model_name="gemini-3.1-pro"
|
| 209 |
+
)
|
| 210 |
+
second = _RetryWrapper.model_construct(
|
| 211 |
+
inner=_SuccessfulGenerateModel(), provider="google", model_name="gemini-3.1-pro"
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
with pytest.raises(RateLimitCooldownError):
|
| 215 |
+
first._generate([])
|
| 216 |
+
now[0] = 1005.0
|
| 217 |
+
second._generate([])
|
| 218 |
+
|
| 219 |
+
assert sleeps == [55.0]
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def test_other_gemini_lane_does_not_sleep_for_pro_cooldown(monkeypatch):
|
| 223 |
+
_reset_rate_limit_state_for_tests()
|
| 224 |
+
exc = _make_genai_client_error(429)
|
| 225 |
+
now = [1000.0]
|
| 226 |
+
sleeps = []
|
| 227 |
+
monkeypatch.setattr("lilith_agent.models.time.monotonic", lambda: now[0])
|
| 228 |
+
monkeypatch.setattr("lilith_agent.models.time.sleep", sleeps.append)
|
| 229 |
+
pro = _RetryWrapper.model_construct(
|
| 230 |
+
inner=_FailingGenerateModel(exc), provider="google", model_name="gemini-3.1-pro"
|
| 231 |
+
)
|
| 232 |
+
flash = _RetryWrapper.model_construct(
|
| 233 |
+
inner=_SuccessfulGenerateModel(), provider="google", model_name="gemini-3-flash-preview"
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
with pytest.raises(RateLimitCooldownError):
|
| 237 |
+
pro._generate([])
|
| 238 |
+
now[0] = 1005.0
|
| 239 |
+
flash._generate([])
|
| 240 |
+
|
| 241 |
+
assert sleeps == []
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_unknown_google_model_does_not_get_gemini_cooldown(monkeypatch):
|
| 245 |
+
_reset_rate_limit_state_for_tests()
|
| 246 |
+
exc = _make_genai_client_error(429)
|
| 247 |
+
monkeypatch.setattr("lilith_agent.models.time.sleep", lambda _: None)
|
| 248 |
+
wrapper = _RetryWrapper.model_construct(
|
| 249 |
+
inner=_FailingGenerateModel(exc), provider="google", model_name="gemini-unknown"
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
with pytest.raises(type(exc)):
|
| 253 |
+
wrapper._generate([])
|