|
1 | | -import os |
2 | | -import sys |
3 | 1 | from pathlib import Path |
| 2 | +import ast |
4 | 3 |
|
5 | 4 | ROOT = Path(__file__).resolve().parents[1] |
6 | 5 | MODEL_PROVIDER = ROOT / "agent_service/app/infrastructure/agents_backend/model_provider.py" |
7 | 6 |
|
8 | 7 |
|
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 | + |
13 | 29 |
|
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(): |
16 | 31 | 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