Skip to content

Commit 684b82f

Browse files
Stabilize Gemini auth recovery e2e
1 parent 7a41370 commit 684b82f

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

tests/test_e2e.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
from __future__ import annotations
1212

13+
import json
1314
import os
1415
import shutil
1516
import subprocess
17+
from urllib import error as urllib_error
18+
from urllib import request as urllib_request
1619

1720
import pytest
1821

@@ -57,6 +60,39 @@ def _run_agent(
5760
)
5861

5962

63+
def _run_gemini_gateway_smoke(workspace: str, model: str, token: str) -> str:
64+
"""Call the Gemini gateway directly with a text-only prompt.
65+
66+
This keeps auth recovery coverage focused on the recovered Databricks token
67+
instead of Gemini CLI's separate tool-calling request shape.
68+
"""
69+
url = f"{build_tool_base_url('gemini', workspace)}/v1beta/models/{model}:generateContent"
70+
payload = {
71+
"contents": [
72+
{"role": "user", "parts": [{"text": "say hi in 5 words or less"}]},
73+
],
74+
}
75+
req = urllib_request.Request(
76+
url,
77+
data=json.dumps(payload).encode("utf-8"),
78+
headers={
79+
"Authorization": f"Bearer {token}",
80+
"Content-Type": "application/json",
81+
"Accept": "application/json",
82+
},
83+
method="POST",
84+
)
85+
try:
86+
with urllib_request.urlopen(req, timeout=30) as response:
87+
body = response.read().decode("utf-8")
88+
except urllib_error.HTTPError as exc:
89+
body = exc.read().decode("utf-8", errors="replace") if exc.fp else ""
90+
raise AssertionError(f"Gemini gateway smoke failed: HTTP {exc.code}: {body[:500]}") from exc
91+
92+
data = json.loads(body)
93+
return data.get("candidates", [{}])[0].get("content", {}).get("parts", [{}])[0].get("text", "")
94+
95+
6096
# ---------------------------------------------------------------------------
6197
# Databricks auth / token
6298
# ---------------------------------------------------------------------------
@@ -878,11 +914,4 @@ def test_recovers_when_initial_token_empty(
878914
"get_databricks_token may not be retrying after auth login."
879915
)
880916

881-
env = gemini.build_runtime_env(e2e_workspace, model, recovered_token)
882-
cmd = gemini.validate_cmd("gemini")
883-
result = _run_agent(cmd, env=env, timeout=90)
884-
combined = (result.stdout + result.stderr).strip()
885-
assert result.returncode == 0 and combined, (
886-
f"Gemini failed after auth recovery: rc={result.returncode} "
887-
f"stdout={result.stdout[:300]!r} stderr={result.stderr[:300]!r}"
888-
)
917+
assert _run_gemini_gateway_smoke(e2e_workspace, model, recovered_token).strip()

0 commit comments

Comments
 (0)