.PHONY: install test test-all test-unit test-integration test-adapter \
        test-kernel test-runner test-server coverage lint help

# ─── Setup ────────────────────────────────────────────────────────────────────

install:
	pip3.11 install -e ".[dev]"

# ─── Test targets ─────────────────────────────────────────────────────────────

## Run unit tests only (default, no live kernel needed)
test:
	pytest -m "not integration"

## Run ALL tests including real-kernel integration tests
test-all:
	pytest -m "unit or integration"

## Alias for test
test-unit:
	pytest -m "not integration"

## Run integration tests only (requires ipykernel)
test-integration:
	pytest -m integration -v

## Run only notebook_adapter tests
test-adapter:
	pytest tests/test_notebook_adapter.py -v

## Run only kernel_session tests
test-kernel:
	pytest tests/test_kernel_session.py -v

## Run only notebook_runner tests
test-runner:
	pytest tests/test_notebook_runner.py -v

## Run only server tool tests
test-server:
	pytest tests/test_server_tools.py -v

# ─── Coverage ─────────────────────────────────────────────────────────────────

## Unit test coverage report (terminal)
coverage:
	pytest -m "not integration" \
	  --cov=src/universal_notebook_mcp \
	  --cov-report=term-missing \
	  --cov-report=html:htmlcov

## Open coverage report in browser (macOS / Linux)
coverage-open: coverage
	open htmlcov/index.html 2>/dev/null || xdg-open htmlcov/index.html

# ─── Lint ─────────────────────────────────────────────────────────────────────

## Run ruff linter
lint:
	ruff check src/ tests/

# ─── Help ─────────────────────────────────────────────────────────────────────

help:
	@echo ""
	@echo "  make install           Install package + dev dependencies"
	@echo ""
	@echo "  make test              Unit tests only (fast, no kernel needed)"
	@echo "  make test-all          Unit + integration tests"
	@echo "  make test-integration  Integration tests only (needs ipykernel)"
	@echo ""
	@echo "  make test-adapter      Isolated notebook_adapter tests"
	@echo "  make test-kernel       Isolated kernel_session tests"
	@echo "  make test-runner       Isolated notebook_runner tests"
	@echo "  make test-server       Isolated server tool tests"
	@echo ""
	@echo "  make coverage          Coverage report (unit tests)"
	@echo "  make lint              Ruff linter"
	@echo ""
