# hxprobe — standalone Makefile. Requires uv (https://docs.astral.sh/uv/).
#
# This project is fully self-contained (own pyproject.toml, own uv.lock) and
# this Makefile works the same whether run from inside a parent monorepo or
# after `cp -r`'ing hxprobe/ into its own repo. It does not depend on, and is
# not depended on by, the parent repo's root Makefile — the two are kept
# independent on purpose so a change to one can't break the other.

PYTHON ?= python3.14
ARGS   ?=

.DEFAULT_GOAL := help

# ── help ──────────────────────────────────────────────────────────────────────

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

# ── targets ───────────────────────────────────────────────────────────────────

.PHONY: deps
deps: ## sync the venv from uv.lock; idempotent
	uv sync

.PHONY: run
run: deps ## run hxprobe (pass flags via ARGS="…")
	uv run $(PYTHON) -m hxprobe $(ARGS)

.PHONY: lint
lint: deps ## lint with ruff
	uv run ruff check .

.PHONY: fmt
fmt: deps ## format with ruff
	uv run ruff format .

.PHONY: test
test: deps ## run hermetic unit tests
	uv run pytest tests -m "not integration" -v $(ARGS)

.PHONY: test-integration
test-integration: deps ## run integration tests against live internet services (HTTP/2, redirects)
	uv run pytest tests -m integration -v $(ARGS)

.PHONY: check
check: lint test ## run the full gate: lint + hermetic tests

.PHONY: clean
clean: ## remove bytecode, caches, and egg-info
	@find . -type d -name '__pycache__' -exec rm -rf {} + 2>/dev/null; \
	find . -name '*.pyc' -delete 2>/dev/null; \
	rm -rf *.egg-info .pytest_cache .ruff_cache; true
