# the-custodian top-level Makefile

## Run e2e tests for a repo in a remote sandbox
## Usage: make e2e REPO=activity-core
## Requires: RAILIANCE01_HOST env var (or pass HOST=<ip>)
##
## Options:
##   REPO=<slug>       repository name under ~/ (required)
##   HOST=<host>       override RAILIANCE01_HOST
##   USER=root         SSH user (default: root)
##   KEY=              path to SSH key (optional)
##   KEEP=             set to 1 to keep sandbox after run
##   WORKSTREAM_ID=    state-hub workstream ID for progress event

REPO_PATH := $(HOME)/$(REPO)

ifdef HOST
  E2E_HOST_FLAG := --host $(HOST)
else
  E2E_HOST_FLAG :=
endif

ifdef USER
  E2E_USER_FLAG := --user $(USER)
else
  E2E_USER_FLAG :=
endif

ifdef KEY
  E2E_KEY_FLAG := --key $(KEY)
else
  E2E_KEY_FLAG :=
endif

ifdef KEEP
  E2E_KEEP_FLAG := --keep
else
  E2E_KEEP_FLAG :=
endif

ifdef WORKSTREAM_ID
  E2E_WS_FLAG := --workstream-id $(WORKSTREAM_ID)
else
  E2E_WS_FLAG :=
endif

.PHONY: e2e
e2e:
	@test -n "$(REPO)" || (echo "ERROR: REPO is required. Usage: make e2e REPO=activity-core"; exit 1)
	@test -d "$(REPO_PATH)" || (echo "ERROR: repo path does not exist: $(REPO_PATH)"; exit 1)
	@test -f "$(REPO_PATH)/e2e/e2e.yml" || (echo "ERROR: no e2e/e2e.yml in $(REPO_PATH)"; exit 1)
	cd "$(CURDIR)" && python3 -m e2e_framework \
		$(REPO_PATH) \
		$(E2E_HOST_FLAG) \
		$(E2E_USER_FLAG) \
		$(E2E_KEY_FLAG) \
		$(E2E_KEEP_FLAG) \
		$(E2E_WS_FLAG)
