Files
reuse-surface/tests/test_llm_bridge.py
tegwick 70a5003f6e
Some checks failed
ci / validate-registry (push) Has been cancelled
Implement REUSE-WP-0013 registry establish, update, and stats
Add stats, establish (scaffold, publish-check, discover), and update CLI
commands with optional llm-connect bridge, validate --root for sibling repos,
pytest coverage, and documentation for sibling registry onboarding.
2026-06-16 01:21:01 +02:00

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"