File size: 1,715 Bytes
eb2384f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi.testclient import TestClient
from serve import create_app

class FakeJudge:
    model_name = 'test-preview'
    def system_one(self, state, questions):
        if state == 'invalid':
            raise ValueError('Input exceeds configured context; nothing was truncated.')
        return {'model': self.model_name, 'answers': {key: {'type': 'noul', 'noul': 0.75} for key in questions}}

def test_api_request_and_health():
    with TestClient(create_app(loader=FakeJudge)) as client:
        assert client.get('/health').json()['ready'] is True
        response = client.post('/v1/judgments', json={'state': 'Evidence.', 'questions': {'q': {'type': 'noul', 'instructions': 'Supported?'}}})
        assert response.status_code == 200
        assert response.json()['answers']['q']['noul'] == 0.75
        assert response.json()['timing']['inference_ms'] >= 0

def test_api_rejects_bad_requests_without_inference():
    with TestClient(create_app(loader=FakeJudge)) as client:
        assert client.post('/v1/judgments', json={'state': 'Evidence.', 'questions': {}}).status_code == 422
        assert client.post('/v1/judgments', json={'state': 'invalid', 'questions': {'q': {}}}).status_code == 422

def test_examples_follow_native_contract():
    import json
    from pathlib import Path
    from core import normalize_question
    request = json.loads((Path(__file__).resolve().parents[1]/'examples/request.json').read_text())
    assert {q['type'] for q in request['questions'].values()} == {'noul','choice','score'}
    for question in request['questions'].values():
        kind,instructions,candidates,keys = normalize_question(question)
        assert instructions and len(candidates) == len(keys)