PYTHON ?= .venv/bin/python
BOOTSTRAP_PYTHON ?= python3
NPM ?= npm

.PHONY: setup install test-fast test-integration test-fault test-security test-e2e test-ssh-integration lint typecheck frontend-build check-v1-absent check-openapi check

setup:
	test -x $(PYTHON) || $(BOOTSTRAP_PYTHON) -m venv .venv
	$(PYTHON) -m pip install --upgrade pip
	$(PYTHON) -m pip install -e 'backend[dev]'
	$(NPM) --prefix frontend ci

install: setup

test-fast:
	$(PYTHON) -m pytest tests/unit tests/contract -q

test-integration:
	$(PYTHON) -m pytest tests/integration -q

test-fault:
	$(PYTHON) -m pytest tests/fault -q

test-security:
	$(PYTHON) -m pytest tests/security -q

test-e2e:
	BACKUP_TOOL_COMPOSE_E2E=1 $(PYTHON) -m pytest tests/e2e/test_compose_v2.py -q

test-ssh-integration:
	BACKUP_TOOL_SSH_INTEGRATION=1 $(PYTHON) -m pytest tests/integration/test_ssh_backup_restore.py -q

lint:
	$(PYTHON) -m ruff check --config backend/pyproject.toml backend/src backend/alembic tests tools
	$(PYTHON) -m ruff format --check --config backend/pyproject.toml backend/src backend/alembic tests tools

typecheck:
	$(PYTHON) -m mypy --config-file backend/pyproject.toml
	$(NPM) --prefix frontend run typecheck

frontend-build:
	$(NPM) --prefix frontend run build

check-openapi:
	$(PYTHON) tools/export_openapi.py
	$(NPM) --prefix frontend run api:generate
	git diff --exit-code -- openapi/v2.json frontend/src/api/generated

check-v1-absent:
	$(PYTHON) tools/forbidden_v1_scan.py .

check: check-v1-absent check-openapi test-fast test-integration test-fault test-security lint typecheck frontend-build
