fix(wizard): parse ranked model selection entries

This commit is contained in:
langbot-dev
2026-08-14 17:43:36 +08:00
parent 7c387f75e1
commit 97b176aef2
2 changed files with 20 additions and 4 deletions
+8 -1
View File
@@ -262,7 +262,14 @@ class SpaceService:
data = data.get('models', data.get('items', []))
if not isinstance(data, list):
raise ValueError('Failed to get model selection: invalid response')
return [SpaceModelSelection.model_validate(model) for model in data]
models = []
for selection in data:
if isinstance(selection, dict) and isinstance(selection.get('model'), dict):
models.append(selection['model'])
else:
models.append(selection)
return [SpaceModelSelection.model_validate(model) for model in models]
async def get_recommended_chat_model(self, context: typing.Any) -> dict:
"""Resolve Space's first ranked chat model to a local Workspace model."""
@@ -823,8 +823,8 @@ class TestSpaceServiceGetModels:
class TestSpaceServiceGetModelSelection:
"""Tests for availability-ranked model selection."""
@pytest.mark.parametrize('use_envelope', [False, True])
async def test_preserves_selection_order_and_category_query(self, use_envelope):
@pytest.mark.parametrize('response_shape', ['direct', 'models-envelope', 'availability-wrapper'])
async def test_preserves_selection_order_and_category_query(self, response_shape):
ap = SimpleNamespace(instance_config=SimpleNamespace(data={}))
service = SpaceService(ap)
models = [
@@ -843,7 +843,16 @@ class TestSpaceServiceGetModelSelection:
'status': 'active',
},
]
payload = {'code': 0, 'data': {'models': models} if use_envelope else models}
if response_shape == 'models-envelope':
data = {'models': models}
elif response_shape == 'availability-wrapper':
data = [
{'model': model, 'latency_ms': index + 10, 'http_code': 200}
for index, model in enumerate(models)
]
else:
data = models
payload = {'code': 0, 'data': data}
mock_response = MagicMock(status=200)
with (