# Single source of truth for local + CI checks. Both .github/workflows/ci.yml
# and the human pre-push gate call these targets, so what passes locally is
# what passes in CI — no divergence.
#
# `make check` is the gate. Run it before every `git push`.

UV := uv run

.PHONY: help check lint format format-check types test test-api test-unit smoke mcpb dxt clean

help:
	@echo "Targets:"
	@echo "  make check        Full pre-push gate (lint + format + types + tests)."
	@echo "                    Run before every git push. Mirrors CI exactly."
	@echo "  make lint         ruff check"
	@echo "  make format       ruff format (writes changes)"
	@echo "  make format-check ruff format --check (CI-style; read-only)"
	@echo "  make types        mypy on src + tests"
	@echo "  make test         pytest tests/api + tests/unit"
	@echo "  make test-api     pytest tests/api"
	@echo "  make test-unit    pytest tests/unit"
	@echo "  make smoke        scripts/smoke_http.py (needs a running HTTP server)"
	@echo "  make mcpb         Build dist/inoreader-mcp-<version>.mcpb (Claude Desktop ext)"
	@echo "  make dxt          Alias of \`make mcpb\` — kept for the older settings.json allowlist"

check: lint format-check types test
	@echo "OK — local gate passed (matches CI)."

lint:
	$(UV) ruff check .

format:
	$(UV) ruff format .

format-check:
	$(UV) ruff format --check .

types:
	$(UV) mypy src tests

test: test-api test-unit

# Tests are split — combining tests/api + tests/unit in one process
# intermittently deadlocked teardown (respx + aiosqlite + pytest-asyncio
# competing for the event loop). Separate processes side-step it.
test-api:
	$(UV) pytest tests/api -q

test-unit:
	$(UV) pytest tests/unit -q

smoke:
	$(UV) python scripts/smoke_http.py

mcpb:
	$(UV) python scripts/build_mcpb.py

# Backward-compat alias — the file extension is .mcpb (formerly .dxt).
dxt: mcpb
