Skip to content

Commit 92e8ba9

Browse files
Asaif AliAsaif Ali
authored andcommitted
CI Fixes
1 parent b1f98be commit 92e8ba9

2 files changed

Lines changed: 39 additions & 13 deletions

File tree

agent_service/app/infrastructure/agents_backend/model_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Environment Variables
2121
# --------------------------------------------------
2222
MODEL_TYPE = os.getenv("MODEL_TYPE", "OpenAI")
23-
OPENAI_MODEL_ID = os.getenv("LLM_MODEL") or os.getenv("OPENAI_MODEL_ID", "gateway-managed")
23+
OPENAI_MODEL_ID = os.getenv("OPENAI_MODEL_ID", "gateway-managed")
2424
LLM_GATEWAY_URL = os.getenv("LLM_GATEWAY_URL", "https://portfolio-llm-gateway.onrender.com/v1").strip()
2525
LLM_GATEWAY_TIMEOUT = float(os.getenv("LLM_GATEWAY_TIMEOUT", "180"))
2626
# Demo/portfolio gateways commonly rate-limit bursts. Avoid immediate SDK retries
Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
1-
import os
2-
import sys
31
from pathlib import Path
2+
import ast
43

54
ROOT = Path(__file__).resolve().parents[1]
65
MODEL_PROVIDER = ROOT / "agent_service/app/infrastructure/agents_backend/model_provider.py"
76

87

9-
def test_model_config_does_not_use_legacy_llm_model(monkeypatch):
10-
monkeypatch.delenv("LLM_MODEL", raising=False)
11-
monkeypatch.setenv("OPENAI_MODEL_ID", "gemini-2.5-flash")
12-
monkeypatch.setenv("LLM_DIRECT_PROVIDER", "google")
8+
def test_model_config_does_not_use_legacy_llm_model():
9+
source = MODEL_PROVIDER.read_text(encoding="utf-8")
10+
tree = ast.parse(source)
11+
12+
assignments = {}
13+
for node in tree.body:
14+
if isinstance(node, ast.Assign):
15+
for target in node.targets:
16+
if isinstance(target, ast.Name):
17+
assignments[target.id] = node.value
18+
19+
# OPENAI_MODEL_ID must be independently configurable and must not
20+
# inherit from the removed legacy LLM_MODEL variable.
21+
openai_node = assignments.get("OPENAI_MODEL_ID")
22+
assert openai_node is not None
23+
24+
rendered = ast.unparse(openai_node)
25+
assert "LLM_MODEL" not in rendered
26+
assert "OPENAI_MODEL_ID" in rendered
27+
assert "gateway-managed" in rendered
28+
1329

14-
# This setting is retained only as a compatibility/read-only value.
15-
# Runtime routing remains Gateway-only and never uses a direct provider.
30+
def test_gateway_aware_model_requires_request_scoped_gateway_token():
1631
source = MODEL_PROVIDER.read_text(encoding="utf-8")
17-
assert 'OPENAI_MODEL_ID = os.getenv("OPENAI_MODEL_ID", "gateway-managed")' in source
18-
assert 'DIRECT_PROVIDER = os.getenv("LLM_DIRECT_PROVIDER", "")' in source
19-
assert 'return super().get_client()' not in source
20-
assert 'return super().get_async_client()' not in source
32+
assert "get_llm_gateway_token()" in source
33+
assert "LLM gateway session token is required" in source
34+
assert 'api_key=token' in source
35+
assert 'base_url=gateway_url' in source
36+
37+
38+
def test_no_direct_google_fallback_is_used_by_gateway_aware_model():
39+
source = MODEL_PROVIDER.read_text(encoding="utf-8")
40+
start = source.index("class GatewayAwareOpenAIChat")
41+
end = source.index("# --------------------------------------------------\n# Model Factory", start)
42+
gateway_section = source[start:end]
43+
44+
assert "GOOGLE_API_KEY" not in gateway_section
45+
assert "Gemini(" not in gateway_section
46+
assert "OpenRouter" not in gateway_section

0 commit comments

Comments
 (0)