-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathtest_model.py
More file actions
59 lines (41 loc) · 1.97 KB
/
Copy pathtest_model.py
File metadata and controls
59 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""The agent runs on Anthropic Claude — Fable 5 by default, LLM_MODEL overridable.
gpt-* model names route to ChatOpenAI as a production fallback."""
import os
import pytest
os.environ.setdefault("ANTHROPIC_API_KEY", "test-key")
os.environ.setdefault("OPENAI_API_KEY", "test-key")
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
from src.model import build_model
def test_default_model_is_fable():
model = build_model()
assert isinstance(model, ChatAnthropic)
assert model.model == "claude-fable-5"
def test_llm_model_env_override(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("LLM_MODEL", "claude-opus-4-6")
model = build_model()
assert model.model == "claude-opus-4-6"
def test_gpt_model_names_route_to_openai_fallback(monkeypatch: pytest.MonkeyPatch):
# Production fallback: flipping LLM_MODEL to a gpt-* name in the Render
# dashboard must work without a code change.
monkeypatch.setenv("LLM_MODEL", "gpt-5.4-2026-03-05")
model = build_model()
assert isinstance(model, ChatOpenAI)
assert model.model_name == "gpt-5.4-2026-03-05"
def test_claude_model_names_route_to_anthropic(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setenv("LLM_MODEL", "claude-opus-4-6")
assert isinstance(build_model(), ChatAnthropic)
def test_max_tokens_fits_full_widget_generation():
# langchain-anthropic's default (4096) truncates generateSandboxedUi args
# mid-stream: css+html arrive but jsFunctions/jsExpressions are cut off, so
# htmlComplete never fires and the widget never leaves the preview sandbox.
model = build_model()
assert model.max_tokens >= 32000
def test_main_uses_build_model():
import ast
from pathlib import Path
main_src = Path(__file__).parent.parent / "main.py"
tree = ast.parse(main_src.read_text())
names = {n.id for n in ast.walk(tree) if isinstance(n, ast.Name)}
assert "build_model" in names
assert "ChatOpenAI" not in main_src.read_text()