north-scape/relayboard
Relayboard: accessible team boards with audited actions, dependency maps, and shared web/MCP use cases.
A remix template · 0 remixes · Remix north-scape/relayboard
tests/test_models.py
"""Models payload contract only: no real network calls or tokens."""
import pytest
import httpx
from boards.infrastructure import dodil
class Response:
def __init__(self,body): self.body=body
def raise_for_status(self): pass
def json(self): return self.body
def test_chat_unwraps_dodil_gateway_response(monkeypatch):
calls=[]
monkeypatch.setattr(dodil,'token',lambda:'FAKE')
def post(url,**kw):
calls.append((url,kw));return Response({'status':'ok','data':{'choices':[{'message':{'content':'Plan\nVerify'}}]}})
monkeypatch.setattr(dodil.httpx,'post',post)
assert dodil.ModelsAssistant().checklist('A task')==['Plan','Verify']
assert calls[0][0]=='https://api.dodil.io/v1/chat/completions'
assert calls[0][1]['json']['model']=='kimi-k2.6'
assert calls[0][1]['json']['max_tokens']==2048
assert calls[0][1]['json']['messages'][0]['role']=='system'
@pytest.mark.parametrize('body',[
{'choices':[{'message':{'content':''},'finish_reason':'length'}]},
{'choices':[{'message':{'content':'partial'},'finish_reason':'length'}]},
{'choices':[{'message':{'content':None}}]},
{'choices':[{'message':{'content':' '}}]},
{'choices':[]},
{},
])
def test_chat_rejects_empty_truncated_or_invalid_answers(monkeypatch,body):
monkeypatch.setattr(dodil,'token',lambda:'FAKE')
monkeypatch.setattr(dodil.httpx,'post',lambda *args,**kw:Response(body))
with pytest.raises(httpx.HTTPError):
dodil.chat('Synthetic task')
def test_embeddings_unwrap_and_restore_input_order(monkeypatch):
monkeypatch.setattr(dodil,'token',lambda:'FAKE')
calls=[]
def post(url,**kw):
calls.append((url,kw));return Response({'status':'ok','data':{'data':[{'index':1,'embedding':[0,1]},{'index':0,'embedding':[1,0]}]}})
monkeypatch.setattr(dodil.httpx,'post',post)
assert dodil.ModelsAssistant().embeddings(['first','second'])==[[1,0],[0,1]]
assert calls[0][0]=='https://api.dodil.io/v1/embeddings'
assert calls[0][1]['json']=={'model':'jina-embeddings-v4','input':['first','second']}