generated from coulomb/repo-seed
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from llm_connect.claude_code import ClaudeCodeAdapter
|
|
from llm_connect.config import LLMConfig
|
|
from llm_connect.models import RunConfig
|
|
|
|
|
|
def test_execute_prompt_passes_json_schema_to_claude_cli(monkeypatch):
|
|
calls: dict[str, object] = {}
|
|
|
|
def fake_run(cmd, input, capture_output, text, timeout): # noqa: ANN001
|
|
calls["cmd"] = cmd
|
|
calls["input"] = input
|
|
calls["capture_output"] = capture_output
|
|
calls["text"] = text
|
|
calls["timeout"] = timeout
|
|
return SimpleNamespace(
|
|
returncode=0,
|
|
stdout='{"summary":"ok","recommendations":[]}',
|
|
stderr="",
|
|
)
|
|
|
|
monkeypatch.setattr("llm_connect.claude_code.subprocess.run", fake_run)
|
|
adapter = ClaudeCodeAdapter(cli_path="/custom/claude")
|
|
|
|
response = adapter.execute_prompt(
|
|
"Produce a report.",
|
|
RunConfig(
|
|
timeout_seconds=42,
|
|
model_params={"json_schema": {"type": "object"}},
|
|
),
|
|
)
|
|
|
|
assert calls == {
|
|
"cmd": [
|
|
"/custom/claude",
|
|
"--print",
|
|
"--json-schema",
|
|
'{"type":"object"}',
|
|
],
|
|
"input": "Produce a report.",
|
|
"capture_output": True,
|
|
"text": True,
|
|
"timeout": 42,
|
|
}
|
|
assert response.content == '{"summary":"ok","recommendations":[]}'
|
|
|
|
|
|
def test_claude_code_adapter_prefers_env_cli_path(monkeypatch):
|
|
monkeypatch.setenv("LLM_CONNECT_CLAUDE_CLI_PATH", "/home/me/bin/claude")
|
|
|
|
adapter = ClaudeCodeAdapter(
|
|
config=LLMConfig(provider="claude-code", claude_cli_path="claude")
|
|
)
|
|
|
|
assert adapter._cli_path == "/home/me/bin/claude"
|