# Prefer a local Linux venv (WSL/Linux/macOS) so `make validate` finds requirements-dev.txt.
PYTHON ?= $(firstword $(wildcard .venv/bin/python3 .venv-wsl/bin/python3) python3)
BASE_URL ?= http://localhost:8080
CA_FILE ?=
ACTION_SCRIPT ?= scripts/restart.sh
TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",)

.PHONY: help check validate test load test-persistence secrets up test-level4 db-checks evidence

help:
	@echo "check: offline structure; validate: full OpenAPI; test: running API; load: synthetic writes"
	@echo "secrets, up: local stand; test-level4, db-checks: lab2 level 4; evidence: collect evidence/"

check:
	$(PYTHON) scripts/check_contract.py

validate:
	$(PYTHON) scripts/validate_openapi.py

test:
	$(PYTHON) tests/smoke.py --base-url $(BASE_URL)

load:
	$(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS)

test-persistence:
	$(PYTHON) tests/resilience.py \
		--base-url $(BASE_URL) \
		--action-script $(ACTION_SCRIPT) \
		--mode persistence

secrets:
	sh scripts/init-secrets.sh

up: secrets
	docker compose --profile tests up -d --build api api_short_ttl

test-level4:
	$(PYTHON) student-tests/level4.py --base-url $(BASE_URL)

db-checks:
	docker compose --profile tools run --rm db_checks

evidence:
	sh scripts/run_evidence.sh
