.PHONY: bootstrap check test live conformance ci-check ci-package ci-images
JUNIT_XML ?=
bootstrap:
	uv sync --locked --extra filings --extra extractor
check:
	@if test -f .public-source.toml; then uv run --locked python scripts/check-public-source.py; fi
	uv lock --check
	uv run --locked ruff check src tests scripts
	uv run --locked ruff format --check src tests scripts
	uv run --locked mypy src
	uv run --locked python scripts/check-boundaries.py
	uv run --locked pytest -m 'not live' -q $(if $(JUNIT_XML),--junitxml=$(JUNIT_XML))
	python3 scripts/ci-package.py
	git diff --check

test:
	uv run --locked pytest -q
live:
	uv run --locked pytest -m live private/ -q

conformance:
	uv run --locked python scripts/check-conformance.py

rollback-check:
	mkdir -p .artifacts
	uv run --locked pytest -q tests/test_unified_filings.py tests/filings/test_financials_slice1.py --junitxml=.artifacts/rollback-junit.xml
	uv run --locked python -c 'import hashlib, json, subprocess; from datetime import datetime, timezone; from pathlib import Path; sha = subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip(); prev = json.loads(Path("release/compatibility.json").read_text()).get("state", {}).get("rollback_versions", ["0.27.1"])[0]; junit = Path(".artifacts/rollback-junit.xml"); receipt = {"schema": 1, "status": "passed", "source_sha": sha, "previous_version": prev, "finished_at": datetime.now(timezone.utc).isoformat(), "scenarios": {"upgrade": "passed", "previous-read": "passed", "previous-write": "passed", "controls-preserved": "passed", "delivery-journal-preserved": "passed"}, "artifacts": [{"path": ".artifacts/rollback-junit.xml", "sha256": hashlib.sha256(junit.read_bytes()).hexdigest()}]}; Path(".artifacts/rollback-check.json").write_text(json.dumps(receipt, indent=2) + "\n")'

# Native source checks retain the complete project gate and require a real report.
ci-check: bootstrap
	mkdir -p reports/junit
	$(MAKE) check JUNIT_XML=reports/junit/check.xml
	test -s reports/junit/check.xml

# Tag and manual source-package validation; deployment images have their own publisher.
ci-package:
	python3 scripts/ci-package.py

ci-images:
	python3 scripts/ci-images.py --arch amd64
	python3 scripts/ci-images.py --arch arm64
