akif/arclet-boards
Arclet Boards — private Kanban workspaces with AppID, DataK3, shared web and MCP actions.
A remix template · 1 remixes · Remix akif/arclet-boards
tests/test_models.py
import httpx
import pytest
from app.domain.model import Unavailable
from app.infrastructure import dodil
def response(body,status=200):
return httpx.Response(status,json=body,request=httpx.Request('POST','https://api.dodil.io/v1/test'))
def test_dodil_chat_envelope_is_unwrapped_and_json_draft_validated(monkeypatch):
monkeypatch.setattr(dodil.credentials,'token',lambda:'test-token')
captured = []
def post(url,**kwargs):
captured.append((url,kwargs['json']))
return response({'status':'success','data':{'choices':[{'message':{
'content':'{"items":["Draft","Review","Publish"]}'}}]}})
monkeypatch.setattr(dodil.httpx,'post',post)
assert dodil.ModelsAssistant().checklist('Launch','Customer release') == ['Draft','Review','Publish']
url,payload = captured[0]
assert url == 'https://api.dodil.io/v1/chat/completions'
assert payload['max_tokens'] == 2048 and payload['response_format'] == {'type':'json_object'}
assert 'Customer release' in payload['messages'][1]['content']
def test_truncated_model_json_is_an_error_and_never_saved_as_a_fake_draft(monkeypatch):
monkeypatch.setattr(dodil.credentials,'token',lambda:'test-token')
monkeypatch.setattr(dodil.httpx,'post',lambda *args,**kwargs:response({
'choices':[{'finish_reason':'length','message':{'content':'{"items":["Unfinished'}}]}))
with pytest.raises(Unavailable):
dodil.ModelsAssistant().checklist('Launch','Context')
def test_embedding_request_uses_live_verified_enum_and_validated_dimensions(monkeypatch):
monkeypatch.setattr(dodil.credentials,'token',lambda:'test-token')
captured = []
def post(url,**kwargs):
captured.append((url,kwargs['json']))
return response({'status':'success','data':{'data':[
{'index':0,'embedding':[1.0]+[0.0]*511}]}})
monkeypatch.setattr(dodil.httpx,'post',post)
result = dodil.ModelsAssistant().embed(['Release notes'])
assert len(result) == 1
assert captured[0][0] == 'https://api.dodil.io/v1/embeddings'
assert captured[0][1]['task_type'] == 'EMBED_TASK_TYPE_SEMANTIC_SIMILARITY'
assert captured[0][1]['dimensions'] == 512
def test_wrong_embedding_index_is_refused_instead_of_attaching_to_wrong_card(monkeypatch):
monkeypatch.setattr(dodil.credentials,'token',lambda:'test-token')
monkeypatch.setattr(dodil.httpx,'post',lambda *args,**kwargs:response({
'data':[{'index':5,'embedding':[1.0]+[0.0]*511}]}))
with pytest.raises(Unavailable):
dodil.ModelsAssistant().embed(['Release notes'])