# Browser Hybrid - Development Commands

.PHONY: help install lint test test-unit test-integration test-live coverage clean build publish

help:
	@echo "Browser Hybrid - Available Commands"
	@echo "==================================="
	@echo ""
	@echo "Installation:"
	@echo "  make install        Install package in dev mode"
	@echo "  make install-prod   Install package (production)"
	@echo ""
	@echo "Linting & Formatting:"
	@echo "  make lint           Run ruff linting"
	@echo "  make format         Format code with ruff"
	@echo "  make format-check   Check formatting (CI)"
	@echo "  make typecheck       Run mypy type checking"
	@echo ""
	@echo "Testing:"
	@echo "  make test           Run all unit tests"
	@echo "  make test-parallel  Run unit tests in parallel"
	@echo "  make test-verbose  Run unit tests with verbose output"
	@echo "  make test-live      Run live tests (requires Chrome)"
	@echo "  make test-smoke     Run smoke tests (requires Chrome)"
	@echo "  make test-integration Run all integration tests"
	@echo "  make test-all       Run ALL tests including integration"
	@echo ""
	@echo "Coverage:"
	@echo "  make coverage       Run tests with coverage report"
	@echo ""
	@echo "Building & Publishing:"
	@echo "  make build          Build distribution packages"
	@echo "  make publish        Publish to PyPI (requires PYPI_API_TOKEN)"
	@echo ""
	@echo "Cleanup:"
	@echo "  make clean          Remove build artifacts"
	@echo "  make distclean      Remove all generated files"

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

install-prod:
	pip install -e .

lint:
	ruff check src/ tests/

format:
	ruff format src/ tests/

format-check:
	ruff format --check src/ tests/

typecheck:
	mypy src/browser_hybrid/

test:
	pytest tests/ --ignore=tests/test_live.py --ignore=tests/test_smoke.py --ignore=tests/test_reconnection.py -v

test-parallel:
	pytest tests/ --ignore=tests/test_live.py --ignore=tests/test_smoke.py --ignore=tests/test_reconnection.py -v -n auto --dist=worksteal

test-verbose:
	pytest tests/ --ignore=tests/test_live.py --ignore=tests/test_smoke.py --ignore=tests/test_reconnection.py -v --tb=long

test-live:
	@if [ ! -n "$$(pgrep -f 'remote-debugging-port=9222')" ]; then \
		echo "Chrome not running with --remote-debugging-port=9222"; \
		echo "Start Chrome with: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222 &"; \
		exit 1; \
	fi
	LIVE_TESTS=1 pytest tests/test_live.py -v --tb=short

test-smoke:
	@if [ ! -n "$$(pgrep -f 'remote-debugging-port=9222')" ]; then \
		echo "Chrome not running with --remote-debugging-port=9222"; \
		exit 1; \
	fi
	LIVE_TESTS=1 pytest tests/test_smoke.py -v --tb=short

test-integration:
	@if [ ! -n "$$(pgrep -f 'remote-debugging-port=9222')" ]; then \
		echo "Chrome not running with --remote-debugging-port=9222"; \
		exit 1; \
	fi
	LIVE_TESTS=1 pytest tests/test_live.py tests/test_smoke.py -v --tb=short

test-all:
	pytest tests/ -v --tb=short

coverage:
	pytest tests/ --ignore=tests/test_live.py --ignore=tests/test_smoke.py --ignore=tests/test_reconnection.py \
		--cov=browser_hybrid \
		--cov-report=term-missing \
		--cov-report=html \
		--cov-report=xml

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

distclean: clean
	rm -rf .coverage htmlcov/ coverage.xml

build: clean
	python -m build

publish: build
	python -m twine upload dist/* --verbose