# code-merge-system developer tasks. Recipes mirror .github/workflows/ci.yml
# so `make verify` locally == the CI gates. GNU Make 3.81-compatible (macOS).

PY ?= python3

.PHONY: help setup web-build lint typecheck file-gate test test-all e2e web-test verify clean

help:
	@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
	  awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-12s\033[0m %s\n", $$1, $$2}'

setup: ## Install Python deps (pinned) + Web UI deps
	$(PY) -m pip install -c constraints.txt -e ".[dev,eval,acp]"
	cd web && npm ci

web-build: ## Build the Web UI bundle into web/dist
	cd web && npm run build

lint: ## ruff check + format check (src)
	ruff check src/
	ruff format --check src/

typecheck: ## mypy strict (src)
	mypy src

file-gate: ## Enforce the 800-line file-length gate
	$(PY) -m scripts.check_file_length

test: ## Unit tests with coverage gate
	pytest tests/unit/ --cov=src --cov-report=term-missing --cov-fail-under=80

test-all: ## Every pytest suite
	pytest

e2e: ## Hermetic integration tests (mocked LLM, real git — no API keys)
	pytest tests/integration/ -v

web-test: ## Web UI vitest suite
	cd web && npm test

verify: lint typecheck file-gate test ## Full local gate (== CI): lint + types + file-gate + unit tests

clean: ## Remove build/test caches
	rm -rf build dist .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage
	find . -type d -name __pycache__ -prune -exec rm -rf {} +
