pip install -r requirements.txt
pytest tests/ -v17 tests, no network access or running Ollama instance required — see "Mocking the embedder" below.
| File | Covers |
|---|---|
tests/test_parser.py |
Tree-sitter extraction for Python/JS/Go, the anonymous-node regression, unsupported-language and SQL fallbacks |
tests/test_chunker.py |
Import-block generation, fixed-window fallback, oversized-chunk splitting |
tests/test_database.py |
Repo status lifecycle, chunk insert/fetch by vector index, metadata search, importer lookup, conversation history ordering |
tests/test_indexing_and_retrieval.py |
Full pipeline: index a sample repo → verify SQLite/FAISS linkage, hybrid retrieval, import graph resolution, re-indexing idempotency |
tests/conftest.py provides a mock_embedder fixture: a deterministic, hash-based fake
embedding model. This lets the test suite exercise every other real component (tree-sitter
parsing, chunking, SQLite, FAISS, the retriever's merge/filter logic, graph building, the
FastAPI routes) without downloading the actual sentence-transformers model — useful for CI
environments without internet access, and for keeping the suite fast (~6 seconds for all 17
tests).
The mock embedder means vector-search relevance itself isn't meaningfully tested (random vectors aren't semantically similar to anything) — this is intentional; retrieval-quality tests that need real semantics (e.g. "does this actually retrieve the login function for a paraphrased question") should be run manually with the real model, see below.
python3 -c "
from backend.embeddings.embedder import get_embedder
e = get_embedder() # downloads bge-small-en-v1.5 on first run (~130MB)
print(e.embed_query('test').shape)
"Then run the indexing pipeline against a real repo and try a few paraphrased questions through
/chat or the Streamlit UI to sanity-check retrieval quality.
ollama serve &
ollama pull llama3
python run_api.py &
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"repo_id": "<your-indexed-repo-id>", "question": "Explain this project."}'fastapi.testclient.TestClient runs the full FastAPI app in-process (no real network socket),
which is how the manual integration verification during development exercised every endpoint
(/health, /repos/upload, /repos/{id}/status, /repos/{id}/stats, /search,
/repos/{id}/graph/mermaid, /repos/{id}/summary, /repos, and /chat with a real
unreachable-Ollama error path to verify graceful degradation). This pattern is easy to extend
into a formal tests/test_api.py if you want route-level regression tests in addition to the
service-level tests already in the suite.
- Add its extension(s) to
EXTENSION_LANGUAGE_MAPinbackend/parser/language_config.py. - Add its
tree_sitter_languagesgrammar name to_TS_GRAMMAR_NAME. - Add a
LanguageProfilewith its function/class/method/import node type names (inspect a grammar's node types withtree_sitter_languages.get_parser("<lang>").parse(b"...").root_nodeand print.sexp()on a sample file to find the right type names). - Add a test case to
tests/test_parser.pymirroring the existing Python/JS/Go examples.