64 lines
3.5 KiB
Python
64 lines
3.5 KiB
Python
"""The shipped IDE must use the same public OmniRoute catalog as every member."""
|
|
import io
|
|
import json
|
|
import unittest
|
|
from unittest.mock import patch
|
|
import ide_catalog as c
|
|
|
|
|
|
def row(mid, name, source="omniroute", capabilities=("chat",)):
|
|
return {"id": mid, "turkservis": {"display_name": name, "source": source,
|
|
"capabilities": list(capabilities)}}
|
|
|
|
|
|
class MemberCatalog(unittest.TestCase):
|
|
def test_metadata_classifies_only_public_models(self):
|
|
public = [row("plain", "Plain"), row("team", "Team")]
|
|
metadata = [{"id": "plain", "kind": "model"}, {"id": "team", "kind": "combo"},
|
|
{"id": "internal", "kind": "combo"}]
|
|
replies = [io.BytesIO(json.dumps({"data": public}).encode()),
|
|
io.BytesIO(json.dumps({"models": metadata}).encode())]
|
|
with patch.object(c, "ayar_oku", return_value={"enabled": True, "kapsam": "ide"}), \
|
|
patch.object(c, "anahtar_oku", return_value="test-key"), \
|
|
patch.object(c, "ide_yapilandirma", return_value=("https://example.test/v1", "", [])), \
|
|
patch.object(c.urllib.request, "urlopen", side_effect=replies):
|
|
status, _, _, selected = c.yukle()
|
|
self.assertEqual(status, "tamam")
|
|
self.assertEqual({m["id"]: m["kind"] for m in selected}, {"plain": "model", "team": "combo"})
|
|
|
|
def test_empty_catalog_is_a_refresh_failure(self):
|
|
with patch.object(c, "ayar_oku", return_value={"enabled": True, "kapsam": "ide"}), \
|
|
patch.object(c, "anahtar_oku", return_value="test-key"), \
|
|
patch.object(c, "ide_yapilandirma", return_value=("https://example.test/v1", "", [])), \
|
|
patch.object(c.urllib.request, "urlopen", return_value=io.BytesIO(b'{"data": []}')):
|
|
with self.assertRaises(ValueError):
|
|
c.yukle()
|
|
|
|
def test_public_omniroute_models_do_not_need_private_local_configuration(self):
|
|
rows = [row("9router-nano-x", "9R · nano/x"), row("agnes-flat", "Agnes Flat"),
|
|
row("Ajan-Arac", "Ajan-Arac"), row("image", "image", capabilities=("image",))]
|
|
self.assertEqual({m["id"] for m in c.sec(rows, [])},
|
|
{"9router-nano-x", "agnes-flat", "Ajan-Arac"})
|
|
|
|
def test_direct_route_is_never_added_beside_omniroute(self):
|
|
rows = [row("9router-nano-x-direct", "9R · nano/x", "9router"),
|
|
row("9router-nano-x", "9R · nano/x")]
|
|
self.assertEqual([m["id"] for m in c.sec(rows, ["nano/x"], "hepsi")], ["9router-nano-x"])
|
|
|
|
def test_model_order_uses_combo_metadata_and_preserves_every_model(self):
|
|
models = [{"slug": "gpt-z", "display_name": "GPT Z", "priority": 1},
|
|
{"slug": "ide/bekci-kurnaz", "display_name": "kurnaz", "priority": 2},
|
|
{"slug": "ide/Z-Team", "display_name": "Z-Team", "priority": 5},
|
|
{"slug": "ide/9router-cc-opus", "display_name": "9R · cc/opus", "priority": 3},
|
|
{"slug": "ide/A-Team", "display_name": "A-Team", "priority": 4}]
|
|
extras = [{"slug": m["slug"], "kind": "combo" if m["slug"].endswith("Team") else "model"}
|
|
for m in models if m["slug"].startswith("ide/")]
|
|
c.sirala_codex(models, extras)
|
|
self.assertEqual([m["slug"] for m in models],
|
|
["ide/A-Team", "ide/Z-Team", "ide/bekci-kurnaz", "ide/9router-cc-opus", "gpt-z"])
|
|
self.assertEqual([m["priority"] for m in models], list(range(5)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|