# Paliad — developer entrypoints.
#
# Targets here are the gate tier from the test-strategy design
# (docs/design-paliad-test-strategy-2026-05-19.md). Slice 1 lands:
#
#   make verify-migrations   — dry-run every pending migration (BEGIN..ROLLBACK)
#                              plus the full boot smoke (apply + tracker
#                              advances + /healthz returns 200).
#   make verify-mig          — alias for verify-migrations.
#   make test                — short test pass: go test ./internal/... -short
#                              plus the cmd/server package. Includes the
#                              live-DB tests when TEST_DATABASE_URL is set,
#                              skips them otherwise.
#   make test-go             — go test ./... -race (full Go suite).
#
# Future slices will extend this with:
#   make test-frontend       — bun test (Slice 3 / Slice 6)
#   make e2e                 — Playwright golden-path suite (Slice 4)
#
# All targets are idempotent. None of them write to the filesystem outside
# the test runner's working dirs. None of them touch internal/db/migrations/
# files.

.PHONY: help verify-migrations verify-mig test test-go

help:
	@echo "Paliad — developer targets"
	@echo ""
	@echo "  verify-migrations   Dry-run pending migrations + boot smoke (needs TEST_DATABASE_URL)"
	@echo "  verify-mig          Alias for verify-migrations"
	@echo "  test                Short test pass — covers gate tier"
	@echo "  test-go             Full Go suite with race detector"
	@echo ""
	@echo "Set TEST_DATABASE_URL to enable live-DB tests. Example:"
	@echo "  export TEST_DATABASE_URL=postgres://paliad:...@localhost:11833/paliad_test"

# Gate target — the test that would have caught mig 098 / mig 099 before
# deploy. Combines:
#   - TestMigrations_DryRun  (internal/db): per-migration BEGIN..ROLLBACK
#   - TestBootSmoke          (cmd/server): apply-end-to-end + tracker advances
#                                          + /healthz 200
#
# Requires TEST_DATABASE_URL. Without it, both tests skip and the target
# is effectively a no-op — guard against that explicitly so CI doesn't
# silently green a missing env var.
verify-migrations:
	@if [ -z "$$TEST_DATABASE_URL" ]; then \
		echo "ERROR: TEST_DATABASE_URL is not set."; \
		echo "       The migration gate cannot run without a scratch DB."; \
		echo "       Set TEST_DATABASE_URL to a Postgres URL the test can"; \
		echo "       open transactions against, e.g."; \
		echo "         export TEST_DATABASE_URL=postgres://paliad:PW@localhost:11833/paliad_test"; \
		exit 2; \
	fi
	@echo "==> migration dry-run (per-mig BEGIN..ROLLBACK)"
	go test -count=1 -run TestMigrations_DryRun ./internal/db/
	@echo "==> boot smoke (apply + tracker + /healthz)"
	go test -count=1 -run TestBootSmoke ./cmd/server/

verify-mig: verify-migrations

# Gate-tier test pass. -short skips the slow live-DB tests when the
# author opts out via `if testing.Short() { t.Skip(...) }`; today most of
# paliad's live-DB tests gate on TEST_DATABASE_URL instead, so -short is
# forward-compatible rather than load-bearing.
test:
	go test -short ./internal/... ./cmd/...

# Full Go suite with race detection. Slower but catches concurrent-map
# regressions that -short would skip; intended for the merge-to-main gate
# (full suite, not per-PR).
test-go:
	go test -race ./...
