fix(llm): strengthen embed skip-verification test; add DEMO_MODE check to embed()

This commit is contained in:
pyr0ball 2026-05-04 16:02:26 -07:00
parent 8e2d15bcd4
commit 7526092481
2 changed files with 9 additions and 1 deletions

View file

@ -398,6 +398,11 @@ class LLMRouter:
Raises:
RuntimeError: If all eligible backends are exhausted.
"""
if os.environ.get("DEMO_MODE", "").lower() in ("1", "true", "yes"):
raise RuntimeError(
"AI inference is disabled in the public demo. "
"Run your own instance to use AI features."
)
order = (
fallback_order
if fallback_order is not None

View file

@ -189,13 +189,16 @@ def test_embed_skips_non_openai_compat_backends():
mock_client.embeddings.create.return_value = MagicMock(
data=[MagicMock(embedding=[0.1])]
)
mock_openai = MagicMock(return_value=mock_client)
with (
patch.object(router, "_is_reachable", return_value=True),
patch("circuitforge_core.llm.router.OpenAI", return_value=mock_client),
patch("circuitforge_core.llm.router.OpenAI", mock_openai),
):
result = router.embed(["hello"])
assert result == [[0.1]]
# Only ollama reached the OpenAI constructor; anthropic was skipped by type check
mock_openai.assert_called_once()
def test_embed_raises_when_all_backends_exhausted():