Route live research through llm-connect and record pilot findings
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a0cffe-206f-7323-89d3-b20ca4cf4bf9
This commit is contained in:
parent
1f95f6389a
commit
2ec23bb22c
39 changed files with 2259 additions and 22 deletions
|
|
@ -154,3 +154,80 @@ def test_cli_refuses_fixture_output_on_real_source(tmp_path):
|
|||
assert result.returncode != 0
|
||||
assert "only run against synthetic" in result.stderr
|
||||
assert not (root / "reports/research-run.json").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('finish,content,complete', [
|
||||
('stop', '# Supported claim\n\nProvisional.', True),
|
||||
('length', '# Cut short', False),
|
||||
('stop', '', False),
|
||||
])
|
||||
def test_llm_connect_service_contract(tmp_path, finish, content, complete):
|
||||
from llm_connect.models import LLMResponse
|
||||
from llm_connect.server import LLMServer
|
||||
|
||||
calls = []
|
||||
|
||||
class ServiceAdapter:
|
||||
def validate_config(self, config):
|
||||
return True
|
||||
|
||||
def execute_prompt(self, prompt, config):
|
||||
calls.append((prompt, config))
|
||||
return LLMResponse(content=content, model='resolved/model',
|
||||
usage={'total_tokens': 42}, finish_reason=finish,
|
||||
metadata={'provider': 'test', 'response_id': 'r1',
|
||||
'debug': 'DO-NOT-PERSIST'})
|
||||
|
||||
server = LLMServer(ServiceAdapter(), port=0)
|
||||
server.start()
|
||||
root = initialize(tmp_path)
|
||||
try:
|
||||
live = bench.LLMConnectAdapter(f'http://127.0.0.1:{server.port}', 'requested/model')
|
||||
if complete:
|
||||
assert bench.execute(root, live)['status'] == 'completed'
|
||||
assert len(calls) == 4
|
||||
else:
|
||||
with pytest.raises(ValueError, match='empty or incomplete'):
|
||||
bench.execute(root, live)
|
||||
assert len(calls) == 1
|
||||
receipt_text = (root / 'reports/research-run.json').read_text()
|
||||
receipt = json.loads(receipt_text)
|
||||
assert receipt['responses'][0]['model'] == 'resolved/model'
|
||||
assert receipt['responses'][0]['usage']['total_tokens'] == 42
|
||||
assert receipt['responses'][0]['finish_reason'] == finish
|
||||
assert receipt['service_requests_attempted'] == len(calls)
|
||||
assert calls[0][1].model_name == 'requested/model'
|
||||
assert calls[0][1].max_tokens == 4000
|
||||
assert 'DO-NOT-PERSIST' not in receipt_text
|
||||
finally:
|
||||
server.stop()
|
||||
|
||||
|
||||
def test_llm_connect_http_failure_is_safe_and_not_retried(tmp_path):
|
||||
from llm_connect.exceptions import LLMAPIError
|
||||
from llm_connect.server import LLMServer
|
||||
|
||||
calls = []
|
||||
|
||||
class FailingService:
|
||||
def validate_config(self, config):
|
||||
return True
|
||||
|
||||
def execute_prompt(self, prompt, config):
|
||||
calls.append(prompt)
|
||||
raise LLMAPIError('SECRET-SENTINEL', status_code=401,
|
||||
response_body='SECRET-SENTINEL')
|
||||
|
||||
server = LLMServer(FailingService(), port=0)
|
||||
server.start()
|
||||
root = initialize(tmp_path)
|
||||
try:
|
||||
live = bench.LLMConnectAdapter(f'http://127.0.0.1:{server.port}', 'test')
|
||||
with pytest.raises(bench.InfospaceError) as raised:
|
||||
bench.execute(root, live)
|
||||
text = (root / 'reports/research-run.json').read_text()
|
||||
assert len(calls) == 1
|
||||
assert json.loads(text)['http_status'] >= 400
|
||||
assert 'SECRET-SENTINEL' not in text + str(raised.value)
|
||||
finally:
|
||||
server.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue