.PHONY: docs docs-build test test-all test-llm test-nova test-embedding test-rerank test-rerank-aws test-rerank-jina test-openai test-ollama test-ocr test-parse test-classify test-split test-extract test-s3 test-pinecone test-qdrant test-sqlite test-pgvector test-mongodb test-milvus test-opensearch test-weaviate test-services test-cli test-lifecycle test-mcp eval

# fast suite — every opt-in e2e group skips (RUN_* gates unset)
test:
	uv run pytest tests/

# the ingestlib CLI (init/doctor + corpus commands) — no gate
test-cli:
	uv run pytest tests/cli/

# lifecycle services (remove/sync/backfill) + replace-aware ingest — no gate
test-lifecycle:
	uv run pytest tests/services/lifecycle/ tests/services/ingest/test_replace.py

# MCP server — tools, read_only gating, http auth, CLI entrypoint — no gate
test-mcp:
	uv run pytest tests/mcp/

# entire suite including every opt-in group (needs VL server running + Bedrock access)
test-all:
	RUN_AWS_RERANK=1 RUN_OLLAMA_E2E=1 RUN_OCR_E2E=1 RUN_PARSE_E2E=1 RUN_CLASSIFY_E2E=1 RUN_SPLIT_E2E=1 RUN_EXTRACT_E2E=1 RUN_S3_E2E=1 RUN_PINECONE_E2E=1 RUN_QDRANT_E2E=1 RUN_PGVECTOR_E2E=1 RUN_MONGODB_E2E=1 RUN_MILVUS_E2E=1 RUN_OPENSEARCH_E2E=1 RUN_WEAVIATE_E2E=1 RUN_SERVICES_E2E=1 uv run pytest tests/

# --- llm layer (mirrors src/ingestlib/foundations/llm/) ---

test-llm:
	uv run pytest tests/foundations/llm/

test-nova:
	uv run pytest tests/foundations/llm/bedrock/nova/

test-embedding:
	uv run pytest tests/foundations/llm/bedrock/embedding/

# both providers — AWS-hitting tests skip without RUN_AWS_RERANK=1
test-rerank:
	uv run pytest tests/foundations/llm/bedrock/rerank/ tests/foundations/llm/jina/

# opt-in: hits amazon.rerank-v1:0 (2 RPM quota — expect ~1 min of throttle sleeps)
test-rerank-aws:
	RUN_AWS_RERANK=1 uv run pytest tests/foundations/llm/bedrock/rerank/

test-rerank-jina:
	uv run pytest tests/foundations/llm/jina/

# skips without OPENAI_API_KEY in .env
test-openai:
	uv run pytest tests/foundations/llm/openai/

# opt-in: needs a local Ollama with qwen3.5:9b + qwen3-embedding:0.6b pulled
test-ollama:
	RUN_OLLAMA_E2E=1 uv run pytest tests/foundations/llm/ollama/

# --- ocr layer (mirrors src/ingestlib/foundations/ocr/) — needs the VL inference server ---

test-ocr:
	RUN_OCR_E2E=1 uv run pytest tests/foundations/ocr/

# --- parse operation (mirrors src/ingestlib/operations/parse/) — needs VL server + the LLM provider ---

test-parse:
	RUN_PARSE_E2E=1 uv run pytest tests/operations/parse/

# --- classify operation (mirrors src/ingestlib/operations/classify/) — needs the LLM provider ---

test-classify:
	RUN_CLASSIFY_E2E=1 uv run pytest tests/operations/classify/

# --- split operation (mirrors src/ingestlib/operations/split/) — needs the LLM provider ---

test-split:
	RUN_SPLIT_E2E=1 uv run pytest tests/operations/split/

# --- extract operation (mirrors src/ingestlib/operations/extract/) — needs the LLM provider
#     (the scanned-document case also needs the VL server) ---

test-extract:
	RUN_EXTRACT_E2E=1 uv run pytest tests/operations/extract/

# --- storage (S3 artifacts) — needs AWS credentials ---

test-s3:
	RUN_S3_E2E=1 uv run pytest tests/storage/

# --- pinecone connector — needs PINECONE_API_KEY + the embedding provider ---

test-pinecone:
	RUN_PINECONE_E2E=1 uv run pytest tests/storage/pinecone/

# --- qdrant connector — needs a Qdrant server at QDRANT_URL + the embedding provider ---

test-qdrant:
	RUN_QDRANT_E2E=1 uv run pytest tests/storage/qdrant/

# --- sqlite connector — no gate: no server exists, in-process IS the real thing ---

test-sqlite:
	uv run pytest tests/storage/sqlite/

# --- pgvector connector — needs a Postgres at PGVECTOR_URL (synthetic vectors, no embedding provider) ---

test-pgvector:
	RUN_PGVECTOR_E2E=1 uv run pytest tests/storage/pgvector/

# --- mongodb connector — needs a MongoDB at MONGODB_URL with search (synthetic vectors, no embedding provider) ---

test-mongodb:
	RUN_MONGODB_E2E=1 uv run pytest tests/storage/mongodb/

# --- milvus connector — needs a Milvus at MILVUS_URL (synthetic vectors, no embedding provider) ---

test-milvus:
	RUN_MILVUS_E2E=1 uv run pytest tests/storage/milvus/

# --- opensearch connector — needs an OpenSearch domain/server at OPENSEARCH_URL ---

test-opensearch:
	RUN_OPENSEARCH_E2E=1 uv run pytest tests/storage/opensearch/

# --- weaviate connector — needs a Weaviate server at WEAVIATE_URL ---

test-weaviate:
	RUN_WEAVIATE_E2E=1 uv run pytest tests/storage/weaviate/

# --- services (ingest + retrieve) — needs the FULL stack ---

test-services:
	RUN_SERVICES_E2E=1 uv run pytest tests/services/

# --- retrieval quality eval — measurement, not a test (needs the full stack;
#     first run also needs the VL server to ingest the fixture corpus) ---

eval:
	uv run python evals/run_eval.py

# --- documentation — live preview and the strict build CI runs ---

docs:
	uv run --group docs mkdocs serve

docs-build:
	uv run --group docs mkdocs build --strict
