repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources15d ago| #1 | """Unit tests for the host LLM backend registry.""" |
| #2 | |
| #3 | from __future__ import annotations |
| #4 | |
| #5 | import pytest |
| #6 | |
| #7 | from mnemosyne.core import llm_backends |
| #8 | from mnemosyne.core.llm_backends import ( |
| #9 | CallableLLMBackend, |
| #10 | call_host_llm, |
| #11 | get_host_llm_backend, |
| #12 | set_host_llm_backend, |
| #13 | ) |
| #14 | |
| #15 | |
| #16 | def test_set_get_backend_round_trip(): |
| #17 | assert get_host_llm_backend() is None |
| #18 | |
| #19 | backend = CallableLLMBackend("test", lambda *a, **k: "ok") |
| #20 | set_host_llm_backend(backend) |
| #21 | try: |
| #22 | assert get_host_llm_backend() is backend |
| #23 | finally: |
| #24 | set_host_llm_backend(None) |
| #25 | |
| #26 | assert get_host_llm_backend() is None |
| #27 | |
| #28 | |
| #29 | def test_call_host_llm_returns_none_without_backend(): |
| #30 | assert get_host_llm_backend() is None |
| #31 | assert call_host_llm("anything", max_tokens=64) is None |
| #32 | |
| #33 | |
| #34 | def test_call_host_llm_passes_args_through(): |
| #35 | captured = {} |
| #36 | |
| #37 | def fake(prompt, *, max_tokens, temperature, timeout, provider=None, model=None): |
| #38 | captured["prompt"] = prompt |
| #39 | captured["max_tokens"] = max_tokens |
| #40 | captured["temperature"] = temperature |
| #41 | captured["timeout"] = timeout |
| #42 | captured["provider"] = provider |
| #43 | captured["model"] = model |
| #44 | return "out" |
| #45 | |
| #46 | set_host_llm_backend(CallableLLMBackend("test", fake)) |
| #47 | try: |
| #48 | result = call_host_llm( |
| #49 | "hello", |
| #50 | max_tokens=128, |
| #51 | temperature=0.1, |
| #52 | timeout=7.5, |
| #53 | provider="openai-codex", |
| #54 | model="gpt-5.1-mini", |
| #55 | ) |
| #56 | finally: |
| #57 | set_host_llm_backend(None) |
| #58 | |
| #59 | assert result == "out" |
| #60 | assert captured == { |
| #61 | "prompt": "hello", |
| #62 | "max_tokens": 128, |
| #63 | "temperature": 0.1, |
| #64 | "timeout": 7.5, |
| #65 | "provider": "openai-codex", |
| #66 | "model": "gpt-5.1-mini", |
| #67 | } |
| #68 | |
| #69 | |
| #70 | def test_call_host_llm_swallows_exception_returns_none(): |
| #71 | def boom(*a, **k): |
| #72 | raise RuntimeError("provider exploded") |
| #73 | |
| #74 | set_host_llm_backend(CallableLLMBackend("test", boom)) |
| #75 | try: |
| #76 | assert call_host_llm("anything", max_tokens=64) is None |
| #77 | finally: |
| #78 | set_host_llm_backend(None) |
| #79 | |
| #80 | |
| #81 | def test_callable_llm_backend_dispatches_to_func(): |
| #82 | seen = [] |
| #83 | |
| #84 | def fake(prompt, *, max_tokens, temperature, timeout, provider=None, model=None): |
| #85 | seen.append(prompt) |
| #86 | return prompt.upper() |
| #87 | |
| #88 | backend = CallableLLMBackend("upper", fake) |
| #89 | out = backend.complete( |
| #90 | "hi", |
| #91 | max_tokens=32, |
| #92 | temperature=0.0, |
| #93 | timeout=5.0, |
| #94 | ) |
| #95 | assert out == "HI" |
| #96 | assert seen == ["hi"] |
| #97 | |
| #98 | |
| #99 | def test_set_none_unregisters_backend(): |
| #100 | set_host_llm_backend(CallableLLMBackend("test", lambda *a, **k: "x")) |
| #101 | assert get_host_llm_backend() is not None |
| #102 | set_host_llm_backend(None) |
| #103 | assert get_host_llm_backend() is None |
| #104 |