Skip to content

Add test suite, CI workflow, coverage gate and upload hardening - #1

Open
jotive wants to merge 2 commits into
mainfrom
claude/eloquent-hawking-5bwqax
Open

jotive wants to merge 2 commits into
mainfrom
claude/eloquent-hawking-5bwqax

Conversation

@jotive

@jotive jotive commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Tests for ingest, vector store, embeddings, chunker validation, documents API and query API. LLM, embeddings and Qdrant are stubbed; API tests use in-memory SQLite (aiosqlite added to dev extras). The tokenizer is stubbed so the suite runs offline.
  • GitHub Actions workflow: ruff lint, ruff format check, pytest with a 70% coverage gate.
  • ROADMAP item implemented: Coverage target 70% global (make coverage, enforced in CI). Also ticks the ingest and API handler test items. Coverage is now 91% (was 19% locally).
  • Safe fixes (no interface change):
    • POST /api/v1/documents/ returned 500 because updated_at was lazy-loaded outside the async session during serialization. The document is now flushed and refreshed before returning.
    • Uploads are read with a cap of MAX_FILE_SIZE + 1 instead of loading the whole body first.
    • Filenames are truncated to the 500-character column length instead of failing at the database.
    • chunk_text raises ValueError for windows that never advance (overlap >= chunk_size), which previously looped forever.

Test results

Before: 2 passed, 6 failed (chunker tests failed only because tiktoken downloads its vocabulary at runtime and the network was blocked). After: 60 passed, ruff check and format clean.

Security findings not fixed (would change behavior or need a decision)

  1. No authentication or authorization on any endpoint; any client can upload, list, read and delete all documents and query them.
  2. No rate limiting; each query and upload triggers paid OpenAI calls.
  3. QueryRequest.question has no length limit (cost and memory abuse). Adding max_length would reject previously accepted requests.
  4. Document.error_message returns raw exception text to clients and may leak internals.
  5. If ingestion raises, the error status is rolled back by get_db, so the client gets a 500 and the document row is lost instead of being stored as error.
  6. Ingestion runs synchronously in the request; pypdf parsing is CPU-bound and blocks the event loop. Encrypted or malformed PDFs surface as 500.
  7. Content type is trusted from the client; PDF magic bytes are not checked.
  8. Retrieved chunks are concatenated into the prompt unfiltered (indirect prompt injection from uploaded documents).
  9. GET /documents/ is unpaginated although default_page_size and max_page_size exist in settings.
  10. CORS uses allow_credentials=True with wildcard methods and headers; safe only while cors_origins stays an explicit allowlist.
  11. Defaults ship openai_api_key="sk-change-me" and docuquery:docuquery database credentials; /docs and /redoc are always exposed.
  12. Dockerfile runs as root and docker-compose uses qdrant/qdrant:latest.

Other notes

  • mypy app (strict) already fails on main with 17 errors, so it is not part of CI.
  • ADR-002 and ADR-003 were not written; they need the maintainers' rationale.
  • The branch name claude/eloquent-hawking-5bwqax was the pre-assigned working branch.

claude and others added 2 commits November 4, 2026 16:18
Add tests for ingest, vector store, embeddings, chunker validation and the
documents and query APIs with LLM, embeddings and Qdrant stubbed. Run the
tokenizer offline in tests. Add a GitHub Actions workflow for lint, format
check and tests with a 70% coverage gate.

Fix POST /documents/ returning 500 from a lazy-loaded updated_at, cap upload
reads at the size limit, truncate filenames to the column length and reject
chunk windows that never advance.
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.

2 participants