Skip to content

test: add initial backend test suite - #23

Merged
g-eoj merged 2 commits into
mainfrom
feat/add-tests
Feb 27, 2026
Merged

test: add initial backend test suite#23
g-eoj merged 2 commits into
mainfrom
feat/add-tests

Conversation

@g-eoj

@g-eoj g-eoj commented Feb 27, 2026

Copy link
Copy Markdown
Owner

Adds a pytest suite covering the testable surface of the Python backend.

Coverage (53 tests, 47% overall):

  • test_server.py — SSE formatting helpers, CORS origins, /api/query, /api/session, /api/health
  • test_types.py — Pydantic model validation for all types in _types.py
  • test_tools.pybuild_url_restricted_query unit tests (I/O-heavy functions excluded)
  • test_utils.pyLimitDeps and check_env

Infrastructure:

  • conftest.py sets required env vars and mocks transformers before import to avoid HuggingFace downloads in CI
  • Adds pytest-cov and httpx as dev dependencies

Not covered yet: _graph.py agent nodes (require a running vLLM instance).

Closes #9

Greptile Summary

This PR establishes a solid test foundation for the Python backend with 53 tests achieving 47% coverage. The test suite is well-structured with appropriate mocking strategies to avoid external dependencies (HuggingFace downloads, API calls) during CI runs.

Key additions:

  • Comprehensive endpoint tests for SSE streaming, CORS, health checks, and session management
  • Full Pydantic model validation coverage for all types
  • Unit tests for URL query building with good edge case handling
  • Infrastructure tests for rate limiting and environment validation
  • Proper test isolation using fixtures and pytest's monkeypatch

Notable decisions:

  • conftest.py mocks the transformers module at import time to prevent model downloads
  • I/O-heavy functions (search_web, search_papers, read_url) intentionally excluded as documented
  • Agent graph nodes (_graph.py) deferred to future work requiring live vLLM instance

The tests follow Python best practices with clear naming, good documentation, and appropriate use of pytest features.

Confidence Score: 5/5

  • Safe to merge - well-structured test suite with only minor style improvements possible
  • Test implementation is solid with proper isolation, appropriate mocking, and comprehensive coverage of testable components. Only one minor style issue found (unused parameter). The acknowledged gaps in coverage are reasonable given the I/O-heavy nature of excluded functions.
  • No files require special attention

Important Files Changed

Filename Overview
api/tests/conftest.py Sets required env vars and mocks transformers to prevent HuggingFace downloads during test runs
api/tests/test_server.py Comprehensive tests for SSE helpers, CORS configuration, and FastAPI endpoints; one unused parameter found
api/tests/test_types.py Thorough validation tests for all Pydantic models covering valid/invalid inputs and edge cases
api/tests/test_tools.py Well-structured unit tests for build_url_restricted_query with good edge case coverage
api/tests/test_utils.py Tests for LimitDeps and check_env with appropriate use of monkeypatching for isolation
api/pyproject.toml Adds pytest-cov and httpx dev dependencies with proper pytest and coverage configuration

Last reviewed commit: fb76484

Covers server SSE helpers and endpoints, Pydantic model validation,
tool utility functions, and LimitDeps/check_env in _utils.

Adds pytest-cov and httpx as dev dependencies.

Closes #9

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread api/tests/test_server.py Outdated
mock_async_client.get = AsyncMock(return_value=mock_resp)
return mock_async_client

def test_returns_vllm_true_when_reachable(self, monkeypatch):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monkeypatch parameter is declared but never used in this test

@g-eoj g-eoj mentioned this pull request Feb 27, 2026
@g-eoj
g-eoj merged commit 9b512e4 into main Feb 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add backend tests

1 participant