Strict plugin-only: no model / account / harness table left in core.
- plugins/providers: an unbound or never-seeded store reads the seed dir's
provider-*/harness-* manifests (PLUGINS_SEED_DIR, else the plugins
checkout, else backend/fixtures/typed_plugins) — once seeded, only what is
installed. Harness↔vendor helpers (vendors_of_harness, login_harness,
hosted_harnesses, accounts_for_harness, provider_config/secret).
- models/catalog + presets: list_models / is_local / context_window /
opencode_model / agy_model / pi_provider / key_of / vendor_of / guest pool
delegate to the registry; DEFAULT_MODEL, FAMILIES… computed (PEP 562).
openrouter.py reads the provider-openrouter plugin's catalogueUrl and its
api_key hub secret (OPENROUTER_API_KEY fallback).
- accounts: provider-owned; vendor-native helpers (accounts_for_vendor,
vendor_of_account, resolve_alias, wire_id) + compat for_harness /
valid_for / harness_of joined through harness.supports[]. Clean provider
accounts: keyless evox2 (alias opencode-lab, still sent to the sidecar as
opencode-lab), openrouter's own account — pi no longer bills `personal`.
- profiles: profile-level ★ per vendor (profile.accounts), per-machine
overrides on workers[i].accounts; idempotent migration of the harness-keyed
runner ★ on load (file version 3); default_login takes a vendor or a
harness; PUT|PATCH /api/profiles/{id} edits accounts. The API keeps
harness keys beside vendor keys in each runner's accounts/logins.
- runs/cron/scheduled: harness tuples → the registry (caps lean/fork,
runsOn lab, hosted harnesses); a new run routes model → vendor → the
profile's ★ for it.
- cli: --harness accepts any active harness (checked against
/api/providers); MCP drops its static enum.
- tests: golden-tables.json pins the old tables' answers; new
test_provider_accounts.py (migration, clean accounts, routing by vendor).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
5.8 KiB
Python
126 lines
5.8 KiB
Python
"""Settings → Models (models/presets.py): one key per model across its
|
|
harnesses, presets resolving to the old defaults, the guest pool, and a
|
|
guest's pick running on its preset's harness (users/runs.py model_route)."""
|
|
|
|
import pathlib
|
|
import tempfile
|
|
import time
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
from models import catalog, presets
|
|
from models import routes
|
|
from users import runs as guest_runs
|
|
from users.caller import Caller
|
|
|
|
CATALOGUE = [
|
|
{"id": "claude-opus-5-5", "family": "opus", "alias": "opus", "harness": "claude"},
|
|
{"id": "claude-sonnet-5-5", "family": "sonnet", "alias": "sonnet", "harness": "claude"},
|
|
{"id": "ggml-org/qwen3.8-27b", "family": "qwen", "harness": "pi", "provider": "evox2"},
|
|
{"id": "qwen/qwen3.8-27b", "family": "qwen", "harness": "pi", "provider": "openrouter"},
|
|
{"id": "gpt-6-sol", "family": "gpt", "harness": "opencode", "provider": "openai",
|
|
"efforts": ["low", "high"]},
|
|
{"id": "gpt-6-sol-fast", "family": "gpt", "harness": "opencode", "provider": "openai",
|
|
"fast": True},
|
|
{"id": "evox2/ggml-org/qwen3.8-27b", "family": "qwen", "harness": "opencode",
|
|
"provider": "evox2"},
|
|
{"id": "gemini-4-neon", "family": "gemini", "harness": "agy", "provider": "google"},
|
|
]
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolated(monkeypatch):
|
|
presets.set_store(presets.PresetStore(str(pathlib.Path(tempfile.mkdtemp()) / "p.json")))
|
|
monkeypatch.setattr(catalog, "list_models", lambda force=False: list(CATALOGUE))
|
|
yield
|
|
presets.set_store(None)
|
|
|
|
|
|
def guest(models=("opus", "sonnet")):
|
|
return Caller(id="akira", role="guest", name="Akira", models=tuple(models))
|
|
|
|
|
|
def test_an_inkling_twin_folds_onto_its_pi_id():
|
|
# its own server (llm-inkling) names the twin `evox2-inkling/…`
|
|
twin = {"id": "evox2-inkling/inkling-2-mini", "family": "inkling", "harness": "opencode",
|
|
"provider": "evox2"}
|
|
assert presets.key_of(twin) == "inkling-2-mini"
|
|
assert presets.vendor_of(twin) == "evox2"
|
|
|
|
|
|
def test_keys_fold_twins_and_tiers():
|
|
keys = [presets.key_of(m) for m in CATALOGUE]
|
|
assert keys == ["opus", "sonnet", "ggml-org/qwen3.8-27b", "qwen/qwen3.8-27b",
|
|
"gpt-6-sol", "gpt-6-sol", "ggml-org/qwen3.8-27b", "gemini-4-neon"]
|
|
assert presets.harnesses_by_key(CATALOGUE)["ggml-org/qwen3.8-27b"] == ["pi", "opencode"]
|
|
assert [presets.vendor_of(m) for m in CATALOGUE] == [
|
|
"anthropic", "anthropic", "evox2", "openrouter", "openai", "openai", "evox2", "google"]
|
|
|
|
|
|
def test_defaults_keep_todays_routing():
|
|
p = presets.presets(CATALOGUE)
|
|
assert {k: v["harness"] for k, v in p.items()} == {
|
|
"opus": "claude", "sonnet": "claude", "ggml-org/qwen3.8-27b": "pi",
|
|
"qwen/qwen3.8-27b": "pi", "gpt-6-sol": "opencode", "gemini-4-neon": "agy"}
|
|
assert {k for k, v in p.items() if v["guests"]} == {"opus", "sonnet"}
|
|
|
|
|
|
def test_a_preset_picks_the_harness_and_the_tier():
|
|
presets.store().patch("ggml-org/qwen3.8-27b", {"harness": "opencode"})
|
|
presets.store().patch("gpt-6-sol", {"fast": "fast"})
|
|
p = presets.presets(CATALOGUE)
|
|
assert presets.entry_for(CATALOGUE, "ggml-org/qwen3.8-27b", p["ggml-org/qwen3.8-27b"])["id"] \
|
|
== "evox2/ggml-org/qwen3.8-27b"
|
|
assert presets.entry_for(CATALOGUE, "gpt-6-sol", p["gpt-6-sol"])["id"] == "gpt-6-sol-fast"
|
|
# cleared → back to the default
|
|
presets.store().patch("gpt-6-sol", {"fast": None})
|
|
assert presets.presets(CATALOGUE)["gpt-6-sol"]["fast"] == ""
|
|
|
|
|
|
def test_bad_patches_are_refused():
|
|
for bad in ({"harness": "emacs"}, {"fast": "warp"}, {"guests": "yes"}, {"colour": 1}):
|
|
with pytest.raises(presets.PresetError):
|
|
presets.store().patch("opus", bad)
|
|
|
|
|
|
def test_a_guest_sees_only_pool_models_of_their_list_on_the_preset_harness():
|
|
presets.store().patch("ggml-org/qwen3.8-27b", {"guests": True})
|
|
presets.store().patch("gemini-4-neon", {"guests": True})
|
|
p = presets.presets(CATALOGUE)
|
|
out = routes.for_caller(CATALOGUE, False, None, p, ["opus", "ggml-org/qwen3.8-27b"])
|
|
ids = [m["id"] for m in out]
|
|
# every Claude entry (their own login may run any); Qwen on pi only; no
|
|
# Gemini (not in their own list), no GPT (not in the pool).
|
|
assert ids == ["claude-opus-5-5", "claude-sonnet-5-5", "ggml-org/qwen3.8-27b"]
|
|
owner = routes.for_caller(CATALOGUE, True, None, p, [])
|
|
assert len(owner) == len(CATALOGUE)
|
|
|
|
|
|
def test_the_pool_gates_a_guests_own_list():
|
|
g = guest(("opus", "ggml-org/qwen3.8-27b"))
|
|
with pytest.raises(HTTPException) as cm:
|
|
guest_runs.check_model(g, "ggml-org/qwen3.8-27b")
|
|
assert cm.value.detail["kind"] == "guest_model"
|
|
presets.store().patch("ggml-org/qwen3.8-27b", {"guests": True})
|
|
assert guest_runs.check_model(g, "ggml-org/qwen3.8-27b") == "ggml-org/qwen3.8-27b"
|
|
assert guest_runs.check_model(g, "claude-opus-4-8") == "claude-opus-4-8" # a family id
|
|
assert guest_runs.check_model(g, None) == "opus"
|
|
presets.store().patch("opus", {"guests": False})
|
|
with pytest.raises(HTTPException):
|
|
guest_runs.check_model(g, None) # no Claude model left to default to
|
|
|
|
|
|
def test_a_guests_pick_runs_on_its_preset_harness():
|
|
g = guest(("sonnet", "ggml-org/qwen3.8-27b", "gemini-4-neon"))
|
|
presets.store().patch("ggml-org/qwen3.8-27b", {"guests": True})
|
|
presets.store().patch("gemini-4-neon", {"guests": True})
|
|
assert guest_runs.model_route(g, None) == ("claude", None)
|
|
assert guest_runs.model_route(g, "sonnet") == ("claude", "sonnet")
|
|
assert guest_runs.model_route(g, "ggml-org/qwen3.8-27b") == ("pi", "ggml-org/qwen3.8-27b")
|
|
# the opencode twin's id resolves to the same model, on its preset harness
|
|
assert guest_runs.model_route(g, "evox2/ggml-org/qwen3.8-27b") == ("pi", "ggml-org/qwen3.8-27b")
|
|
assert guest_runs.model_route(g, "gemini-4-neon") == ("agy", "gemini-4-neon")
|
|
with pytest.raises(HTTPException):
|
|
guest_runs.model_route(g, "gpt-6-sol")
|