HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
gateway: a connection saved with a list of model ids is saved, and any other shape is a 400 (#560)
github-actions[bot]4d18f215c388
diff --git a/gateway/app.py b/gateway/app.pyindex edd8b702..c4b79851 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -6234,8 +6234,19 @@ async def admin_integrations_put(body: IntegrationsBody, request: Request) -> di# Persisting the derived list instead is what made this list go stale — and worse, a# model later retired from the table would live on forever in whatever was written here.table = _vendor_models(provider)- rows = [(str(m.get("canonical") or "").strip(), str(m.get("provider_id") or "").strip())- for m in (i.get("models") or [])]+ # A row is {canonical, provider_id}; a bare id is that id with a blank wire id, which is the+ # same model on the wire (below). Anything else is refused by name: it used to fail the whole+ # save with a 500 (`'str' object has no attribute 'get'` for a list of ids).+ rows = []+ given = i.get("models")+ if given is not None and not isinstance(given, list):+ raise HTTPException(400, f"integration '{name}': models is a list")+ for m in (given or []):+ if isinstance(m, str):+ m = {"canonical": m}+ if not isinstance(m, dict):+ raise HTTPException(400, f"integration '{name}': each model is an id or {{canonical, provider_id}}")+ rows.append((str(m.get("canonical") or "").strip(), str(m.get("provider_id") or "").strip()))if provider == "custom":# No vendor table: the rows are the endpoint's model list, kept whole (see# _integration_models); a blank wire id is the canonical, written out so the storeddiff --git a/gateway/tests/test_integration_model_rows.py b/gateway/tests/test_integration_model_rows.pynew file mode 100644index 00000000..f1b15e35--- /dev/null+++ b/gateway/tests/test_integration_model_rows.py@@ -0,0 +1,65 @@+"""A connection's model rows on save (PUT /v1/admin/integrations).++A row is {canonical, provider_id}, and a blank wire id is the canonical. A list of bare ids is the same+rows with blank wire ids; it used to fail the whole save with a 500 ('str' object has no attribute+'get'). Any other shape is refused by name, with a 400, never a crash.+"""+import asyncio+import json+import sys+from pathlib import Path++import pytest+from fastapi import HTTPException++sys.path.insert(0, str(Path(__file__).resolve().parents[1]))+import app as gw # noqa: E402+++def _save(monkeypatch, integrations):+ written = {}++ async def allow(request):+ return None++ async def doc():+ return []++ async def vget(tenant, key):+ return None++ async def vput(tenant, key, value):+ written[key] = value+ return True+ monkeypatch.setattr(gw, "_require_integrations_admin", allow)+ monkeypatch.setattr(gw, "_integrations_doc", doc)+ monkeypatch.setattr(gw, "_vault_get", vget)+ monkeypatch.setattr(gw, "_vault_put", vput)+ asyncio.run(gw.admin_integrations_put(gw.IntegrationsBody(integrations=list(integrations)), None))+ return {i["name"]: i for i in json.loads(written[gw._INTEGRATIONS_KEY])}+++CUSTOM = {"name": "Mine", "provider": "custom",+ "config": {"base_url": "http://127.0.0.1:9/v1", "api_key": "k-for-a-test", "api_format": "openai"}}+++def test_bare_ids_are_rows_whose_wire_id_is_their_own(monkeypatch):+ saved = _save(monkeypatch, [{**CUSTOM, "models": ["m-one", {"canonical": "m-two", "provider_id": "wire-two"}]}])+ assert saved["Mine"]["models"] == [{"canonical": "m-one", "provider_id": "m-one"},+ {"canonical": "m-two", "provider_id": "wire-two"}]++[email protected]("bad", [7, ["m"], None])+def test_any_other_shape_is_refused_by_name(monkeypatch, bad):+ with pytest.raises(HTTPException) as e:+ _save(monkeypatch, [{**CUSTOM, "models": ["ok", bad]}])+ assert e.value.status_code == 400+ assert "Mine" in str(e.value.detail)++[email protected]("models", ["m-one", {"m-one": "w"}, 7])+def test_models_that_are_not_a_list_are_refused_and_nothing_is_written(monkeypatch, models):+ # a string used to be read letter by letter, each letter a model+ with pytest.raises(HTTPException) as e:+ _save(monkeypatch, [{**CUSTOM, "models": models}])+ assert e.value.status_code == 400 and "Mine" in str(e.value.detail)