.PHONY: dev backend frontend install seed test test-backend test-reset build package

# Isolated DB for the end-to-end test harness (keeps real traces untouched)
TESTDB ?= $(PWD)/tests/aeyeagent_test.db

# Start both servers concurrently (Ctrl+C kills both)
dev:
	@make -j2 backend frontend

# Backend — FastAPI on :7891 with auto-reload
backend:
	uv run uvicorn backend.main:app --port 7891 --reload

# Frontend — Vite dev server on :5173
frontend:
	cd frontend && npm run dev -- --port 8008

# Install all deps (Python + Node)
install:
	uv sync
	cd frontend && npm install

# Build the React frontend into backend/static/ for bundled pip distribution
build:
	cd frontend && npm install && npm run build

# Build a distributable wheel (run `make build` first)
package: build
	uv build

# Seed the DB with demo traces
seed:
	uv run python -m backend.demo_agent

# ── End-to-end test harness ──────────────────────────────────────────────────
# 1) make test-backend   → dashboard API on :7891 against the isolated test DB
# 2) make frontend       → UI on :5173
# 3) make test           → run every agent scenario into that DB, then refresh UI
test-backend:
	AEYEAGENT_DB="$(TESTDB)" uv run uvicorn backend.main:app --port 7891 --reload

test:
	AEYEAGENT_DB="$(TESTDB)" uv run python -m tests.run_all

# Wipe the test DB for a clean slate
test-reset:
	rm -f "$(TESTDB)" "$(TESTDB)-wal" "$(TESTDB)-shm"
