# Pythia build conveniences.
#
# Targets are intentionally thin wrappers around Python tooling so the
# canonical behaviour lives in versioned scripts, not in Make recipes that
# tend to drift away from how CI actually runs.

PYTHON ?= python

.PHONY: profile regen-goldens regen-fixture-sources check-goldens

# Stage 2 entry point — orchestrate the deterministic profile pipeline
# (structural + column stats + detection + modality + leakage) for a
# given run. Reads from ``data/inputs/$(RUN_ID)/source.<csv|parquet>``
# and writes ``data/profiles/$(RUN_ID)/profile.json`` plus the
# ``metadata.json`` sidecar. ``RUN_ID`` is required; the CLI enforces
# the closed grammar ``^[A-Za-z0-9_-]{1,64}$`` before touching the
# filesystem so a typo here cannot escape the run root.
#
#   make profile RUN_ID=<run-id> [MANIFEST=path/to/manifest.yml]
profile:
	@if [ -z "$(RUN_ID)" ]; then \
		echo "error: RUN_ID is required (e.g. make profile RUN_ID=demo-001)" >&2; \
		exit 2; \
	fi
	$(PYTHON) -m pythia.profile_data --run-id "$(RUN_ID)" $(if $(MANIFEST),--manifest "$(MANIFEST)",)

# Regenerate every fixture source file under tests/fixtures/profile/ *and*
# the byte-exact golden profile.json sidecars. Use this after a deliberate
# schema bump in src/pythia/schemas/profile.schema.json — hand-editing the
# goldens is forbidden because it would bypass the canonical serializer.
regen-goldens:
	$(PYTHON) tools/regen_profile_goldens.py

# Regenerate only the .csv / .parquet / .yml fixture sources. Useful when
# the schema is unchanged but a fixture's data needs a refresh.
regen-fixture-sources:
	$(PYTHON) tools/regen_profile_goldens.py --sources

# CI guard: re-run regen and assert the tree did not change. Non-zero exit
# if any fixture or golden drifted, with a unified diff for human triage.
check-goldens:
	$(PYTHON) tools/regen_profile_goldens.py --check
