53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from reuse_surface.llm_bridge import (
|
||
|
|
extract_json_object,
|
||
|
|
llm_connect_url,
|
||
|
|
request_registry_draft,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_extract_json_object_from_fenced_block():
|
||
|
|
data = extract_json_object('```json\n{"capabilities": []}\n```')
|
||
|
|
assert data == {"capabilities": []}
|
||
|
|
|
||
|
|
|
||
|
|
def test_llm_connect_url_missing_raises():
|
||
|
|
with pytest.raises(ValueError, match="LLM_CONNECT_URL"):
|
||
|
|
llm_connect_url(None)
|
||
|
|
|
||
|
|
|
||
|
|
def test_request_registry_draft_mock_http():
|
||
|
|
payload = {
|
||
|
|
"content": json.dumps(
|
||
|
|
{
|
||
|
|
"capabilities": [
|
||
|
|
{
|
||
|
|
"id": "capability.demo.sample",
|
||
|
|
"name": "Sample",
|
||
|
|
"summary": "Demo capability",
|
||
|
|
}
|
||
|
|
]
|
||
|
|
}
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
class FakeResponse:
|
||
|
|
def __enter__(self):
|
||
|
|
return self
|
||
|
|
|
||
|
|
def __exit__(self, *args):
|
||
|
|
return False
|
||
|
|
|
||
|
|
def read(self):
|
||
|
|
return json.dumps(payload).encode("utf-8")
|
||
|
|
|
||
|
|
with patch.dict("os.environ", {"LLM_CONNECT_URL": "http://llm.test"}):
|
||
|
|
with patch("urllib.request.urlopen", return_value=FakeResponse()):
|
||
|
|
draft = request_registry_draft("test prompt")
|
||
|
|
assert draft["capabilities"][0]["id"] == "capability.demo.sample"
|