mirror of
https://github.com/turnstonelabs/turnstone.git
synced 2026-08-12 23:12:23 -06:00
fix(console): available-models rows always carry effort_ladder
The except path for a malformed capabilities column appended the row without the key, so clients had to null-check a field the happy path guarantees. Initialize each entry with an empty ladder and let the try block overwrite it — the response schema is stable per row.
This commit is contained in:
@@ -372,6 +372,30 @@ def test_effort_ladder_parses_string_capabilities(storage: SQLiteBackend) -> Non
|
||||
assert ladder["max"] == "on"
|
||||
|
||||
|
||||
def test_effort_ladder_key_survives_malformed_capabilities(
|
||||
storage: SQLiteBackend,
|
||||
) -> None:
|
||||
"""A capabilities column that fails to parse must not drop the key —
|
||||
every row carries ``effort_ladder`` (empty on failure) so clients can
|
||||
index it unconditionally instead of null-checking per row."""
|
||||
storage.create_model_definition(
|
||||
definition_id="m1",
|
||||
alias="broken",
|
||||
model="model-x",
|
||||
provider="openai-compatible",
|
||||
base_url="http://localhost:8000/v1",
|
||||
api_key="dummy",
|
||||
context_window=131072,
|
||||
capabilities="{not valid json",
|
||||
enabled=True,
|
||||
created_by="admin",
|
||||
)
|
||||
body = _get_models(_make_client(storage))
|
||||
entry = body["models"][0]
|
||||
assert set(entry) == {"alias", "model", "provider", "effort_ladder"}
|
||||
assert entry["effort_ladder"] == []
|
||||
|
||||
|
||||
def test_effort_ladder_honors_responses_api_surface(storage: SQLiteBackend) -> None:
|
||||
"""server_compat.api_surface (namespaced inside the capabilities JSON)
|
||||
switches the projection to the flat-param path — no template toggle."""
|
||||
|
||||
@@ -1916,10 +1916,14 @@ async def list_available_models(request: Request) -> JSONResponse:
|
||||
|
||||
models = []
|
||||
for r in rows:
|
||||
# ``effort_ladder`` starts as the empty list so the row schema is
|
||||
# stable even when the try block below bails on a malformed
|
||||
# capabilities column — clients can index the key unconditionally.
|
||||
entry: dict[str, Any] = {
|
||||
"alias": r["alias"],
|
||||
"model": r["model"],
|
||||
"provider": r["provider"],
|
||||
"effort_ladder": [],
|
||||
}
|
||||
try:
|
||||
# ``capabilities`` is a JSON string (sa.Text column) with
|
||||
|
||||
Reference in New Issue
Block a user