.PHONY: install install-cgc-rust test test-integration test-all lint format clean smoke

# CGC Rust engine source (relative path from llm-wiki-v3)
CGC_DIR := ../CodeGraphContext

install:
	pip install -e ".[dev,graph]"

## Install CGC with Rust-accelerated indexing (5-18x faster code analysis)
## Requires: Rust toolchain (rustc, cargo) — install via https://rustup.rs
install-cgc-rust:
	@command -v cargo >/dev/null 2>&1 || { echo "❌ Rust not installed. Run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"; exit 1; }
	@test -d $(CGC_DIR) || { echo "❌ CodeGraphContext not found at $(CGC_DIR)"; exit 1; }
	pip install maturin kuzu
	cd $(CGC_DIR) && VIRTUAL_ENV=$(CURDIR)/.venv maturin develop --release
	@python -c "from codegraphcontext._cgc_rust import parse_file; print('✅ CGC Rust engine installed (19 languages, 5-18x faster)')"

test:
	pytest tests/unit tests/llm tests/pipeline -v

test-integration:
	pytest tests/integration -v -m integration

test-all:
	pytest --cov=llm_wiki --cov-report=term-missing --cov-report=html

lint:
	ruff check src tests
	mypy src

format:
	ruff format src tests
	ruff check --fix src tests

clean:
	rm -rf build dist *.egg-info .pytest_cache .coverage htmlcov .mypy_cache .ruff_cache
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true

smoke:
	@mkdir -p /tmp/llm-wiki-smoke/raw /tmp/llm-wiki-smoke/wiki/sources /tmp/llm-wiki-smoke/wiki/entities /tmp/llm-wiki-smoke/wiki/concepts
	@echo "# Test\nSkyJoy is a loyalty program by Vietjet Air." > /tmp/llm-wiki-smoke/raw/test.md
	@echo "# Index" > /tmp/llm-wiki-smoke/wiki/index.md
	@echo "# Overview\n(empty)" > /tmp/llm-wiki-smoke/wiki/overview.md
	@llm-wiki ingest /tmp/llm-wiki-smoke/raw/test.md --vault /tmp/llm-wiki-smoke
	@ls /tmp/llm-wiki-smoke/wiki/sources/
	@echo "Smoke test passed!"
