- dodanie dostawcy z setkami modeli (OpenRouter) nie konczy sie 422 (limit 100 -> 1000) - opcjonalna lista LM Studio (302/HTML/401) nie wywraca discover/refresh - nieoczekiwany ksztalt JSON od cudzego serwera = 422 provider_unreachable, nie 500 - wklejony adres chmurowy (api.anthropic.com) pytany po swojemu - ten sam model u dwoch dostawcow pokazany raz, pod tym, ktory odpowie - testy: jeden limit czasu na cala wymiane, przekierowanie bez drugiego zadania; piec mutacji, kazda zlapana Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016uwxqJbh3fPYdfdLG3MU6f
95 lines
4.0 KiB
Python
95 lines
4.0 KiB
Python
"""Home's model picker: how a model id is shown and which family's mark it wears.
|
|
|
|
`prettyModel` and `modelFamily` are lifted out of `frontend/app.js` and run under Node, so the
|
|
behaviour is asserted, not the source text. DB-free; skipped only where no `node` binary exists.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import pathlib
|
|
import shutil
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
NODE = shutil.which("node")
|
|
SRC = (ROOT / "frontend" / "app.js").read_text(encoding="utf-8")
|
|
|
|
|
|
def _fn(head: str) -> str:
|
|
i = SRC.index(head)
|
|
return SRC[i:SRC.index("\n}\n", i) + 3]
|
|
|
|
|
|
def _run(fn: str, args: list[str]) -> list[str]:
|
|
script = _fn(f"function {fn}(") + f"\nconsole.log(JSON.stringify({json.dumps(args)}.map({fn})));"
|
|
r = subprocess.run([NODE, "-e", script], capture_output=True, text=True, timeout=60)
|
|
assert r.returncode == 0, r.stderr
|
|
return json.loads(r.stdout)
|
|
|
|
|
|
@pytest.mark.skipif(NODE is None, reason="needs node on PATH")
|
|
def test_pretty_model_reads_like_a_name() -> None:
|
|
assert _run("prettyModel", ["claude-opus-5-5", "qwen/qwen3.5-9b", "claude-sonnet-4-5-20250929"]) == [
|
|
"Claude Opus 5.5", "Qwen3.5 9B", "Claude Sonnet 4.5 20250929"]
|
|
|
|
|
|
@pytest.mark.skipif(NODE is None, reason="needs node on PATH")
|
|
def test_model_family_by_id() -> None:
|
|
cases = {
|
|
"claude-opus-5-5": "anthropic", "anthropic/claude-haiku-5-5": "anthropic",
|
|
"gpt-5": "openai", "o3-mini": "openai", "openai/o4": "openai",
|
|
"gemini-2.5-pro": "google", "google/gemma-3-27b": "google",
|
|
"qwen/qwen3.5-9b": "qwen", "speakleash/bielik-11b-v2.6": "bielik",
|
|
"meta-llama/llama-3.3-70b": "meta", "mistral-large": "mistral", "mixtral-8x7b": "mistral",
|
|
"deepseek-r1": "D", "phi-4": "P",
|
|
}
|
|
assert _run("modelFamily", list(cases)) == list(cases.values())
|
|
|
|
|
|
def test_picker_groups_by_provider_and_escapes() -> None:
|
|
body = _fn("function modelOptions(")
|
|
assert "<optgroup label=\"${esc(g.provider)}\" data-no-i18n>" in body
|
|
assert "${esc(prettyModel(m.id))}" in body and 'title="${esc(m.id)}"' in body
|
|
assert "modelLabel" not in SRC
|
|
|
|
|
|
def test_pick_is_remembered_and_the_icon_follows_it() -> None:
|
|
change = _fn("function homeModelChange(")
|
|
assert "saveModelPick(sel.value)" in change
|
|
assert "$('homeModelIcon').innerHTML = familyIcon(sel.value)" in change
|
|
assert "savedModelPick()" in SRC and "localStorage.setItem(modelPickKey()" in SRC
|
|
assert '<span id="homeModelIcon">${familyIcon(picked)}</span>' in SRC
|
|
assert "markSvg(fam, letter)" in _fn("function familyIcon(")
|
|
assert "${esc(letter)}" in _fn("function markSvg(")
|
|
|
|
|
|
def test_every_vendored_logotype_is_credited() -> None:
|
|
import re
|
|
|
|
brand = SRC[SRC.index("const BRAND = {"):]
|
|
brand = brand[:brand.index("\n};")]
|
|
keys = re.findall(r"^ (\w+): '", brand, re.M)
|
|
assert keys, "BRAND map is empty"
|
|
credits = (ROOT / "CREDITS.md").read_text(encoding="utf-8")
|
|
assert "Simple Icons" in credits and "CC0" in credits
|
|
for key in keys:
|
|
assert f"`{key}`" in credits, key
|
|
|
|
|
|
@pytest.mark.skipif(NODE is None, reason="needs node on PATH")
|
|
def test_a_model_two_providers_offer_is_listed_once_under_the_one_that_answers() -> None:
|
|
# The server routes an id to the FIRST provider offering it; a second option for the same id
|
|
# would show one provider and send the question to another.
|
|
start = SRC.index("const esc = ")
|
|
esc = SRC[start:SRC.index("}[c]));", start) + len("}[c]));")]
|
|
script = "\n".join([esc, _fn("function prettyModel("), _fn("function modelOptions(")]) + (
|
|
"\nconsole.log(modelOptions([{id:'qwen3',provider:'Lokalny'},{id:'qwen3',provider:'OpenRouter'},"
|
|
"{id:'gpt-5',provider:'OpenRouter'}], 'qwen3', 'Tylko szukaj'));")
|
|
r = subprocess.run([NODE, "-e", script], capture_output=True, text=True, timeout=60)
|
|
assert r.returncode == 0, r.stderr
|
|
html = r.stdout
|
|
assert html.count('value="qwen3"') == 1 and html.count(" selected") == 1
|
|
assert html.index('value="qwen3"') < html.index('label="OpenRouter"')
|