.PHONY: fmt fmt-check clippy test-local test-debugger-socket clean coverage coverage-xml coverage-json coverage-report-json coverage-domain-list coverage-domain-evidence coverage-domain-audit coverage-domain-gate test ci ci-domains test-quality-gate cobertura

fmt:
	cargo fmt --all

fmt-check:
	cargo fmt --all -- --check

clippy:
	cargo clippy --workspace --all-targets --all-features -- -D warnings

test-local:
	cargo test --workspace --all-targets --all-features --no-fail-fast

test-debugger-socket:
	cargo test -p prometeu-host-desktop-winit --lib runner::tests -- --ignored

clean:
	cargo llvm-cov clean --workspace

coverage:
	cargo llvm-cov --workspace --all-features --html --output-dir target/llvm-cov

coverage-report-json:
	cargo llvm-cov report --json --output-path target/llvm-cov/report.json

coverage-xml:
	cargo llvm-cov report --cobertura --output-path target/llvm-cov/cobertura.xml

coverage-json:
	cargo llvm-cov report --json --summary-only --output-path target/llvm-cov/summary.json

coverage-domain-list:
	./scripts/coverage-domain-evidence.sh --list

coverage-domain-audit:
	python3 scripts/audit-coverage-domains.py --report target/llvm-cov/report.json

coverage-domain-evidence:
	@if [ -z "$(DOMAIN)" ]; then \
		echo "usage: make coverage-domain-evidence DOMAIN=<domain>"; \
		exit 1; \
	fi
	./scripts/coverage-domain-evidence.sh "$(DOMAIN)"

coverage-domain-gate:
	./scripts/coverage-domain-evidence.sh --check-all

test: fmt-check clippy test-local test-debugger-socket
# Keep the step list here: CI providers consume the repository contract.
# The runner executes each step serially even if the caller supplies make -j.
CI_DOMAIN_STEPS = clean fmt-check clippy test-quality-gate test-local test-debugger-socket coverage coverage-report-json coverage-xml coverage-json coverage-domain-audit coverage-domain-gate

ci: ci-domains
ci-domains:
	python3 scripts/run-quality-gate.py $(CI_DOMAIN_STEPS)

test-quality-gate:
	python3 -B -m unittest discover -s scripts/tests -p 'test_quality_gate.py'
cobertura: coverage-xml coverage-json
