.PHONY: install test lint typecheck format docs docs-build \
        verify-licences verify-no-ai-mentions verify-coverage-floors \
        verify-changelog-completeness \
        sbom smoke verify release-preflight \
        empirical-guarantee zoo-seed-gpu zoo-seed-pull zoo-seed-verify \
        stage1-as stage1-om

install:
	# ADR-002 §Revision-history 2026-05-16 / #131: --group train pulls HARL
	# via the PEP 735 dependency group. Source-checkout developers get the
	# full test surface (including test_partner_frozen_harl and the lazy-
	# import contract test); pip-install consumers of the wheel get only
	# the safety stack and benchmark wrappers, since wheel METADATA cannot
	# ship git+URL direct references. Phase-1 follow-up tracked in #132
	# (publish harl-aht to PyPI).
	uv sync --all-extras --group dev --group train

test:
	uv run pytest

lint:
	uv run ruff check src tests
	uv run ruff format --check src tests

format:
	uv run ruff check --fix src tests
	uv run ruff format src tests

typecheck:
	uv run pyright

docs:
	uv run mkdocs serve

docs-build:
	uv run mkdocs build --strict

verify-licences:
	uv run pip-licenses --format=json --with-license-file --with-notice-file \
	    --output-file=licences.json
	uv run python scripts/check_licences.py < licences.json

verify-no-ai-mentions:
	bash scripts/check_no_ai_mentions.sh

# Guard against the release-please CHANGELOG-skip bug (#126). Re-runs a
# minimal Conventional-Commits filter over `git log <prev-tag>..HEAD` and
# asserts every release-worthy commit's short SHA appears in the top
# CHANGELOG.md section. Silent on non-release branches (top section already
# matches the latest tag → nothing to verify). Load-bearing on the
# release-please PR.
verify-changelog-completeness:
	uv run python scripts/check_changelog_completeness.py

# Per-package line-coverage floors (plan/02 §6 #2; plan/03 §6 #8;
# plan/04 §6 #5; plan/05 §6 #8; plan/06 §6 #6). Reads coverage.xml
# emitted by `make test` — runs after it in the verify chain so the
# report is fresh. Project-wide aggregate floor (80%) is still
# enforced by pyproject.toml's `[tool.coverage.report] fail_under`.
verify-coverage-floors:
	uv run python scripts/check_coverage_floors.py

sbom:
	uv run cyclonedx-py environment -o sbom.spdx.json

# Pre-upload gate for a PyPI / TestPyPI release; mirrors the build job in
# .github/workflows/release.yml. Builds fresh artefacts, validates the
# long-description render (twine) and the release metadata contract, and
# checks every runtime dep resolves from production PyPI (a TestPyPI-only
# dep would break `pip install concerto-multirobot` for end users).
# twine runs ephemerally via uvx — it stays out of the project
# dependency tree (its transitive docutils trips the ADR-012 licence
# gate, and a release tool has no business in the wheel's environment).
# twine >=6.1 is the floor that understands Metadata-Version 2.4.
release-preflight:
	rm -rf dist
	uv build
	uvx --from 'twine>=6.1' twine check --strict dist/*
	uv run python scripts/check_dist_metadata.py --check-resolvable

smoke:
	uv run pytest -m smoke -x -v

empirical-guarantee:
	uv run pytest tests/integration/test_empirical_guarantee.py -m slow --no-cov -v

zoo-seed-gpu:
	bash scripts/repro/zoo_seed.sh

# Fetch the published zoo-seed artefact + sidecar onto any host so the
# verify-only path (zoo-seed-verify) can re-check integrity without
# re-running the 2 h GPU training (plan/05 §6 #5).
#
# TODO(maintainer): replace ZOO_SEED_BASE_URL with the canonical hosting
# location once the artefact is uploaded (Zenodo is the natural home —
# see the existing `zenodo_announcement/` folder). Until then this
# target prints a friendly error so a copy-paste invocation does not
# silently leak a placeholder URL into someone's shell history.
ZOO_SEED_BASE_URL ?=
ZOO_SEED_NAME := happo_seed7_step50k.pt
ZOO_SEED_DEST_DIR := artifacts/artifacts
zoo-seed-pull:
	@if [ -z "$(ZOO_SEED_BASE_URL)" ]; then \
		echo "zoo-seed-pull: ZOO_SEED_BASE_URL is unset."; \
		echo "  Set it on the maintainer's hosting URL, e.g.:"; \
		echo "  make zoo-seed-pull ZOO_SEED_BASE_URL=https://zenodo.org/record/<NNN>/files"; \
		echo "  (The target fetches both the .pt and the .pt.json sidecar.)"; \
		exit 2; \
	fi
	mkdir -p $(ZOO_SEED_DEST_DIR)
	curl -fsSL "$(ZOO_SEED_BASE_URL)/$(ZOO_SEED_NAME)" -o "$(ZOO_SEED_DEST_DIR)/$(ZOO_SEED_NAME)"
	curl -fsSL "$(ZOO_SEED_BASE_URL)/$(ZOO_SEED_NAME).json" -o "$(ZOO_SEED_DEST_DIR)/$(ZOO_SEED_NAME).json"
	@echo "Fetched $(ZOO_SEED_NAME) + sidecar under $(ZOO_SEED_DEST_DIR)."
	@echo "Run \`make zoo-seed-verify\` to re-check the SHA-256 manifest."

zoo-seed-verify:
	uv run pytest tests/reproduction/test_zoo_seed_artifact.py -v --no-cov

# Stage-1 AS / OM reproduction shells (ADR-007 §Implementation staging
# Stage 1; plan/07 §5). Each target pre-flights the on-disk prereg
# against its committed git tag (ADR-007 §Discipline), then runs the
# chamber-side adapter + the ADR-008 evaluation pipeline. The
# resulting SpikeRun + leaderboard artefacts land under
# spikes/results/stage1-<axis>-<date>/.
stage1-as:
	bash scripts/repro/stage1_as.sh

stage1-om:
	bash scripts/repro/stage1_om.sh

verify: lint typecheck test verify-coverage-floors docs-build verify-licences verify-no-ai-mentions verify-changelog-completeness
