Spaces:
Running
Running
fix: pass username through ts_authenticate for ai grading calls
Browse filesAllows run_ai_grading to authenticate as the correct user rather than
always falling back to TEST_USER.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- tests/e2e_quality.py +5 -4
tests/e2e_quality.py
CHANGED
|
@@ -539,15 +539,16 @@ def _find_ts_key_for_url(ts_base_url: str) -> str:
|
|
| 539 |
return os.getenv("TS_ENV_1_KEY_VAR", "")
|
| 540 |
|
| 541 |
|
| 542 |
-
def ts_authenticate(ts_base_url: str) -> requests.Session:
|
| 543 |
secret_key = _find_ts_key_for_url(ts_base_url)
|
| 544 |
if not secret_key:
|
| 545 |
raise RuntimeError(f"No trusted auth key found for {ts_base_url}")
|
|
|
|
| 546 |
session = requests.Session()
|
| 547 |
session.headers["Accept"] = "application/json"
|
| 548 |
resp = session.post(
|
| 549 |
f"{ts_base_url}/api/rest/2.0/auth/token/full",
|
| 550 |
-
json={"username":
|
| 551 |
timeout=30,
|
| 552 |
)
|
| 553 |
resp.raise_for_status()
|
|
@@ -859,7 +860,7 @@ Return ONLY valid JSON:
|
|
| 859 |
|
| 860 |
|
| 861 |
def run_ai_grading(run_context: dict, company: str, vertical: str, line: str, function: str,
|
| 862 |
-
schema_override: str = None) -> dict:
|
| 863 |
result = {
|
| 864 |
"data_score": None, "data_points": 0.0,
|
| 865 |
"data_reasoning": "Not graded", "data_strengths": [], "data_weaknesses": [],
|
|
@@ -877,7 +878,7 @@ def run_ai_grading(run_context: dict, company: str, vertical: str, line: str, fu
|
|
| 877 |
return result
|
| 878 |
|
| 879 |
try:
|
| 880 |
-
session = ts_authenticate(ts_base)
|
| 881 |
except Exception as e:
|
| 882 |
result["grading_errors"].append(f"ThoughtSpot auth failed: {e}")
|
| 883 |
return result
|
|
|
|
| 539 |
return os.getenv("TS_ENV_1_KEY_VAR", "")
|
| 540 |
|
| 541 |
|
| 542 |
+
def ts_authenticate(ts_base_url: str, username: str = None) -> requests.Session:
|
| 543 |
secret_key = _find_ts_key_for_url(ts_base_url)
|
| 544 |
if not secret_key:
|
| 545 |
raise RuntimeError(f"No trusted auth key found for {ts_base_url}")
|
| 546 |
+
auth_user = username or TEST_USER
|
| 547 |
session = requests.Session()
|
| 548 |
session.headers["Accept"] = "application/json"
|
| 549 |
resp = session.post(
|
| 550 |
f"{ts_base_url}/api/rest/2.0/auth/token/full",
|
| 551 |
+
json={"username": auth_user, "secret_key": secret_key, "validity_time_in_sec": 3600},
|
| 552 |
timeout=30,
|
| 553 |
)
|
| 554 |
resp.raise_for_status()
|
|
|
|
| 860 |
|
| 861 |
|
| 862 |
def run_ai_grading(run_context: dict, company: str, vertical: str, line: str, function: str,
|
| 863 |
+
schema_override: str = None, username: str = None) -> dict:
|
| 864 |
result = {
|
| 865 |
"data_score": None, "data_points": 0.0,
|
| 866 |
"data_reasoning": "Not graded", "data_strengths": [], "data_weaknesses": [],
|
|
|
|
| 878 |
return result
|
| 879 |
|
| 880 |
try:
|
| 881 |
+
session = ts_authenticate(ts_base, username=username)
|
| 882 |
except Exception as e:
|
| 883 |
result["grading_errors"].append(f"ThoughtSpot auth failed: {e}")
|
| 884 |
return result
|