mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
Coworker manifests list models as `openai:gpt-5.6-sol`, while the machine's model list names OpenAI models bare (`gpt-5.6-sol`). The composer compared the two as plain strings, so on a machine with only an OpenAI key every such coworker showed "No model" and could not be used. The server made the same comparison, so a session or team worker could record the model under either name, which split one model into two in Usage. One rule now decides model identity: a prefix naming the default provider is dropped, every other prefix is kept. It lives in `coworker/providers/router.py` (`canonical_model`) and `surfaces/gui/src/modelNames.ts` (`canonicalModel`). - Composer: `coworkerModels` picks the picker list, the unrunnable entries and the model a fresh draft binds to, using that rule. - Event-started session settings: same rule for the coworker's model list. - Server: `resolve_persona_model` and `resolve_worker_model` compare and return the canonical id, so new sessions and team workers record one name per model. Existing records keep the name they were saved with.
129 lines
6.1 KiB
Python
129 lines
6.1 KiB
Python
"""Models per coworker (connectors-across-machines spec §4).
|
|
|
|
A manifest's ordered `models:` list binds its sessions: the first entry the machine can
|
|
run is the default there, a requested model outside the list resolves back onto it, an
|
|
empty list means "any" (today's behaviour). `recommended_models` reads as an alias for
|
|
one release.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from coworker.personas.manifest import ManifestError, parse_manifest
|
|
from coworker.server import create_app
|
|
from tests.test_persona_connections import _mgr
|
|
|
|
MANIFEST = """---
|
|
id: picky
|
|
name: Picky
|
|
icon: ops
|
|
tagline: Runs on a short list
|
|
tools: [files]
|
|
models: [anthropic:claude-opus-4-8, openai:gpt-5.5]
|
|
---
|
|
Body.
|
|
"""
|
|
|
|
|
|
def test_models_key_parses_in_order_and_dedupes():
|
|
m = parse_manifest(MANIFEST.replace("openai:gpt-5.5]", "openai:gpt-5.5, anthropic:claude-opus-4-8]"))
|
|
assert m.models == ["anthropic:claude-opus-4-8", "openai:gpt-5.5"]
|
|
assert m.recommended_models == m.models # alias, one release
|
|
|
|
|
|
def test_recommended_models_is_read_as_an_alias():
|
|
m = parse_manifest(MANIFEST.replace("models:", "recommended_models:"))
|
|
assert m.models == ["anthropic:claude-opus-4-8", "openai:gpt-5.5"]
|
|
|
|
|
|
def test_both_keys_must_agree():
|
|
text = MANIFEST.replace("---\nBody.", "recommended_models: [openai:gpt-5.5]\n---\nBody.")
|
|
with pytest.raises(ManifestError):
|
|
parse_manifest(text)
|
|
|
|
|
|
|
|
def test_resolve_prefers_the_first_runnable_entry(tmp_path, monkeypatch):
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
# The builtin ops coworker lists [anthropic:claude-opus-4-8, openai:gpt-5.5].
|
|
assert mgr.persona_models("ops")[:2] == ["anthropic:claude-opus-4-8", "openai:gpt-5.5"]
|
|
# Nothing configured: the list still binds — first entry, honest "No model" state.
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: False)
|
|
assert mgr.resolve_persona_model("ops") == "anthropic:claude-opus-4-8"
|
|
assert mgr.persona_models_available("ops") == []
|
|
# Only OpenAI configured: the first RUNNABLE entry wins over the list head, named the
|
|
# way the machine's model list names it (no default-provider prefix).
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
assert mgr.resolve_persona_model("ops") == "gpt-5.5"
|
|
assert mgr.persona_models_available("ops") == ["openai:gpt-5.5"]
|
|
# A requested model ON the list is honoured even when unrunnable (user's pick).
|
|
assert mgr.resolve_persona_model("ops", "anthropic:claude-opus-4-8") == "anthropic:claude-opus-4-8"
|
|
# A requested model OFF the list resolves back onto it.
|
|
assert mgr.resolve_persona_model("ops", "ollama:llama3") == "gpt-5.5"
|
|
|
|
|
|
def test_no_list_means_any_model(tmp_path, monkeypatch):
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
assert mgr.persona_models("cowork") == []
|
|
assert mgr.resolve_persona_model("cowork", "ollama:qwen3") == "ollama:qwen3"
|
|
assert mgr.resolve_persona_model("cowork") == mgr.model
|
|
|
|
|
|
def test_personas_index_annotates_availability(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("OPENWORKER_UNSHIPPED", "1") # ops is ships:false
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
client = TestClient(create_app(mgr))
|
|
rows = {p["id"]: p for p in client.get("/v1/personas").json()["personas"]}
|
|
assert rows["ops"]["models"][:2] == ["anthropic:claude-opus-4-8", "openai:gpt-5.5"]
|
|
assert rows["ops"]["models_available"] == ["openai:gpt-5.5"]
|
|
assert rows["cowork"]["models"] == [] and rows["cowork"]["models_available"] == []
|
|
detail = client.get("/v1/personas/ops").json()
|
|
assert detail["models"] == rows["ops"]["models"]
|
|
assert detail["models_available"] == ["openai:gpt-5.5"]
|
|
assert detail["recommended_models"] == detail["models"] # old name, one release
|
|
|
|
|
|
def test_new_session_binds_to_the_list(tmp_path, monkeypatch):
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
engine = mgr.get_engine("s-ops", agent="ops")
|
|
assert engine is not None and engine.model == "gpt-5.5"
|
|
plain = mgr.get_engine("s-plain", agent="cowork")
|
|
assert plain is not None and plain.model == mgr.model
|
|
|
|
|
|
def test_socket_set_model_off_the_list_resolves_onto_it(tmp_path, monkeypatch):
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
client = TestClient(create_app(mgr))
|
|
with client.websocket_connect("/ws/session/s-ws?agent=ops") as ws:
|
|
ready = ws.receive_json()
|
|
assert ready["type"] == "ready" and ready["data"]["model"] == "gpt-5.5"
|
|
ws.send_json({"type": "set_model", "model": "ollama:llama3"})
|
|
# The rebind is a no-op (resolved back onto the same model): no notice frame.
|
|
assert mgr.get_engine("s-ws").model == "gpt-5.5"
|
|
|
|
|
|
def test_bare_and_prefixed_spellings_are_one_model(tmp_path, monkeypatch):
|
|
"""The machine's list says `gpt-5.5`; the manifest says `openai:gpt-5.5`. Same model:
|
|
a requested bare id is ON the list, and the session records the bare id."""
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
assert mgr.resolve_persona_model("ops", "gpt-5.5") == "gpt-5.5"
|
|
assert mgr.resolve_persona_model("ops", "openai:gpt-5.5") == "gpt-5.5"
|
|
# Other prefixes are kept as written.
|
|
assert mgr.resolve_persona_model("ops", "anthropic:claude-opus-4-8") == "anthropic:claude-opus-4-8"
|
|
assert mgr.resolve_persona_model("cowork", "openai:gpt-test-1") == "gpt-test-1"
|
|
assert mgr.resolve_persona_model("cowork", "ollama:qwen-test:32b") == "ollama:qwen-test:32b"
|
|
|
|
|
|
def test_anthropic_only_list_stays_unrunnable_without_an_anthropic_key(tmp_path, monkeypatch):
|
|
mgr = _mgr(tmp_path, monkeypatch)
|
|
monkeypatch.setattr(mgr, "_provider_configured", lambda name: name == "openai")
|
|
monkeypatch.setattr(mgr, "persona_models", lambda pid: ["anthropic:model-a", "anthropic:model-b"])
|
|
assert mgr.persona_models_available("ops") == []
|
|
assert mgr.resolve_persona_model("ops") == "anthropic:model-a"
|