* feat(src): migrate second-brain RAG CLI + tests * fix(embedder): strip hardcoded ai.slaid098.dev endpoint * refactor: rename slaid098/opencode to opencode-config * docs(handoff): add pr-5 handoff + ADR-001 * fix(docs): rebase handoff/ADR naming to PR number + drop dangling ADR-009 refs * fix(tests): update script paths + assertions for opencode-config migration * fix(pyproject): update cov + ruff paths config/scripts -> .opencode/scripts * docs: update project map + handoff + ADR --------- Co-authored-by: opencode-agent <agent@slaid098.dev>
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
import os
|
|
|
|
os.environ.setdefault("AI_PROVIDER_API_URL", "http://test/v1")
|
|
|
|
from typing import NoReturn
|
|
from unittest.mock import patch
|
|
|
|
import httpx
|
|
import pytest
|
|
from src.memory.embedder import embed_texts
|
|
|
|
|
|
def test_embed_texts_success() -> None:
|
|
fake_embedding = [0.1, 0.2, 0.3]
|
|
|
|
class FakeResponse:
|
|
status_code = 200
|
|
|
|
def json(self):
|
|
return {
|
|
"data": [{"embedding": fake_embedding, "index": 0}],
|
|
"model": "gemini-embedding-2-preview",
|
|
}
|
|
|
|
def raise_for_status(self) -> None:
|
|
pass
|
|
|
|
def mock_post(self, url, **kwargs):
|
|
assert "embeddings" in url
|
|
return FakeResponse()
|
|
|
|
with patch.object(httpx.Client, "post", mock_post):
|
|
result = embed_texts(["test text"])
|
|
|
|
assert len(result) == 1
|
|
assert result[0] == fake_embedding
|
|
|
|
|
|
def test_embed_texts_empty() -> None:
|
|
assert embed_texts([]) == []
|
|
|
|
|
|
def test_embed_texts_api_error() -> None:
|
|
class FakeErrorResponse:
|
|
status_code = 401
|
|
|
|
def raise_for_status(self) -> NoReturn:
|
|
msg = "Unauthorized"
|
|
raise httpx.HTTPStatusError(
|
|
msg,
|
|
request=None,
|
|
response=self,
|
|
)
|
|
|
|
def json(self):
|
|
return {}
|
|
|
|
def mock_post(self, url, **kwargs):
|
|
return FakeErrorResponse()
|
|
|
|
with patch.object(httpx.Client, "post", mock_post), pytest.raises(httpx.HTTPStatusError):
|
|
embed_texts(["test"])
|