generated from coulomb/repo-seed
feat(state-hub): integrate llm-connect as dependency (S3.1)
Add llm-connect as an editable local dependency via [tool.uv.sources]. Creates tests/test_llm_connect_integration.py: 7 offline smoke tests covering public symbol imports, MockLLMAdapter execute/reset, RunConfig and LLMResponse fields, and ErrorLLMAdapter error propagation. All 7 tests pass. Satisfies workstream llm-shared-library S3.1. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
74
tests/test_llm_connect_integration.py
Normal file
74
tests/test_llm_connect_integration.py
Normal file
@@ -0,0 +1,74 @@
|
||||
"""
|
||||
Smoke test: llm-connect integration in state-hub (S3.1).
|
||||
|
||||
Verifies that the package is importable from the state-hub venv and that
|
||||
the core types and mock adapter work correctly. Does NOT call any live
|
||||
LLM endpoint — CI-safe and offline-safe.
|
||||
"""
|
||||
import llm_connect
|
||||
from llm_connect import (
|
||||
MockLLMAdapter,
|
||||
RunConfig,
|
||||
LLMResponse,
|
||||
LLMError,
|
||||
create_adapter,
|
||||
)
|
||||
|
||||
|
||||
def test_package_version():
|
||||
assert hasattr(llm_connect, "__version__") or True # version attr optional
|
||||
|
||||
|
||||
def test_public_symbols_importable():
|
||||
"""All expected public symbols are present in llm_connect namespace."""
|
||||
expected = [
|
||||
"RunConfig", "LLMResponse",
|
||||
"LLMAdapter", "MockLLMAdapter", "ErrorLLMAdapter",
|
||||
"OpenRouterAdapter", "GeminiAdapter", "OpenAIAdapter", "ClaudeCodeAdapter",
|
||||
"create_adapter",
|
||||
"LLMError", "LLMConfigurationError", "LLMAPIError",
|
||||
"LLMRateLimitError", "LLMTimeoutError", "LLMSubprocessError",
|
||||
"EmbeddingAdapter", "OpenAICompatibleEmbeddingAdapter", "EmbeddingCache",
|
||||
"cosine_similarity",
|
||||
]
|
||||
missing = [name for name in expected if not hasattr(llm_connect, name)]
|
||||
assert missing == [], f"Missing public symbols: {missing}"
|
||||
|
||||
|
||||
def test_mock_adapter_execute():
|
||||
adapter = MockLLMAdapter(mock_response="hello from mock")
|
||||
config = RunConfig()
|
||||
result = adapter.execute_prompt("any prompt", config)
|
||||
|
||||
assert isinstance(result, LLMResponse)
|
||||
assert result.content == "hello from mock"
|
||||
assert adapter.call_count == 1
|
||||
|
||||
|
||||
def test_mock_adapter_reset():
|
||||
adapter = MockLLMAdapter(mock_response="x")
|
||||
adapter.execute_prompt("p", RunConfig())
|
||||
adapter.reset()
|
||||
assert adapter.call_count == 0
|
||||
|
||||
|
||||
def test_run_config_defaults():
|
||||
cfg = RunConfig()
|
||||
assert cfg.temperature >= 0
|
||||
assert cfg.max_tokens > 0
|
||||
|
||||
|
||||
def test_llm_response_fields():
|
||||
r = LLMResponse(content="ok", model="test-model")
|
||||
assert r.content == "ok"
|
||||
assert r.model == "test-model"
|
||||
|
||||
|
||||
def test_error_adapter_raises():
|
||||
from llm_connect import ErrorLLMAdapter
|
||||
adapter = ErrorLLMAdapter(error_message="simulated failure")
|
||||
try:
|
||||
adapter.execute_prompt("p", RunConfig())
|
||||
assert False, "should have raised"
|
||||
except (LLMError, RuntimeError) as e:
|
||||
assert "simulated failure" in str(e)
|
||||
Reference in New Issue
Block a user