.PHONY: lock offline-bundle test doctor test-observability test-integration test-fullstream test-leader-failover show-capture bench-drain test-s3tables test-biglake test-s3tables-fullstream package quality-gate ci release-check

PYTHON ?= python3

test:
	PYTHONPATH=src $(PYTHON) -m unittest discover -s tests -p "test_*.py"

doctor:
	PYTHONPATH=src $(PYTHON) -m tuladb_iceberg_exporter doctor --config config/tuladb-iceberg.toml

test-observability:
	PYTHONPATH=src $(PYTHON) -m unittest tests.test_observability

test-integration:
	PYTHONPATH=src $(PYTHON) scripts/integration_smoke.py

# Cross-repo: a real tuladbd, a real exporter, full-stream metadata end to end.
# The ONLY check that exercises the C encoder against the Python decoder --
# both unit suites use their own codec, so a byte-level disagreement passes
# both and fails only in production. Skips cleanly when tuladb-core or the
# Python SDK are not checked out alongside this repo.
test-fullstream:
	PYTHONPATH=src $(PYTHON) scripts/integration_fullstream.py

# Cross-repo: a real 3-node tuladbd cluster, the leader killed mid-export and
# leadership moved with the old leader up; the exporter must follow, land every
# committed transfer exactly once, and export-gated history purge must stay
# blocked on the new leader until the exporter acks it, then resume. Serial
# (one cluster at a time). TULADB_CORE=<core checkout with tools/tuladbd and
# tools/tulactl built>; skips without one.
test-leader-failover:
	PYTHONPATH=src $(PYTHON) scripts/integration_leader_failover.py

# Real end-to-end test against AWS S3 Tables. Requires credentials and
# S3TABLES_TABLE_BUCKET_ARN; see docs/s3tables-testing.md. Billable.
test-s3tables:
	sh scripts/integration_s3tables.sh

# The same end-to-end test against GCP BigLake (Iceberg REST catalog). Requires
# Application Default Credentials and BIGLAKE_WAREHOUSE; see
# docs/biglake-testing.md. Billable.
test-biglake:
	sh scripts/integration_biglake.sh

# Live S3 Tables run driven by a REAL tuladbd and the REAL exporter, with
# full-stream metadata into BOTH tables. Billable. Requires
# S3TABLES_TABLE_BUCKET_ARN + AWS creds, plus tuladb-core and tuladb-sdk
# checked out alongside. See docs/s3tables-testing.md for the three
# environment gotchas (fsspec IO, botocore[crt], branch=main).
# Show (and check) exactly what the lake captures from TulaDB: drives a real
# tuladbd through every mutation kind the SDK exposes, exports, prints both
# tables, and FAILS if anything the engine accepted did not reach the lake.
# Doubles as living documentation and as a coverage guard for new mutation
# types. Skips cleanly without tuladb-core / the SDK alongside.
# Drain-rate benchmark under a real backlog (local Parquet sink, no AWS).
# Answers "did coalescing engage, and what is the ceiling" without spending
# money. The S3 Tables number is lower by whatever the REST commit costs.
bench-drain:
	PYTHONPATH=src $(PYTHON) scripts/bench_drain.py

show-capture:
	PYTHONPATH=src $(PYTHON) scripts/show_capture.py

test-s3tables-fullstream:
	PYTHONPATH=src $(PYTHON) scripts/integration_s3tables_fullstream.py

package:
	PYTHON=$(PYTHON) scripts/build_release.sh

# Regenerate requirements/<extra>-py3XX.txt (hashed; needs python3.11 and
# python3.12 with pip-tools).
lock:
	scripts/lock-requirements.sh

# Wheel, sdist and offline wheelhouses for this host's arch and both Pythons,
# each install-tested offline (docs/release.md, "Offline wheelhouses").
offline-bundle:
	PYTHON=$(PYTHON) scripts/build-offline-bundle.sh --arch "$$(uname -m | sed s/arm64/aarch64/)" --test

quality-gate:
	PYTHON=$(PYTHON) scripts/quality_gate.sh

ci: quality-gate

release-check: quality-gate
