# QA STLC Agents — Makefile
# Mirrors Vibium's Makefile pattern: install, skills, test, clean

PYTHON   := python3
VENV     := .venv
PIP      := $(VENV)/bin/pip
PYTEST   := $(VENV)/bin/pytest

# Agent entry points (after pip install)
MCP_TC    := $(VENV)/bin/qa-test-case-manager
MCP_GH    := $(VENV)/bin/qa-gherkin-generator
MCP_PW    := $(VENV)/bin/qa-playwright-generator
MCP_HX    := $(VENV)/bin/qa-helix-writer

.PHONY: install install-dev skills test clean verify mcp-config

# ─── Install ─────────────────────────────────────────────────────────────────
install:
	$(PYTHON) -m venv $(VENV)
	$(PIP) install --upgrade pip
	$(PIP) install -e .
	@echo ""
	@echo "✓ All four MCP agents installed:"
	@echo "  $(MCP_TC)"
	@echo "  $(MCP_GH)"
	@echo "  $(MCP_PW)"
	@echo "  $(MCP_HX)"

install-dev: install
	$(PIP) install pytest pytest-asyncio

# ─── Verify auth and server startup ──────────────────────────────────────────
verify:
	@echo "Verifying MSAL auth (may open browser if no cached token)..."
	$(PYTHON) -c "from qa_stlc_agents.shared.auth import get_signed_in_user; u=get_signed_in_user(); print(f'Signed in as: {u}' if u else 'No cached account — browser will open on first tool call')"

# ─── Install skills into coding agent ────────────────────────────────────────
skills:
	@echo "Installing skills into .claude/skills/ ..."
	mkdir -p .claude/skills
	cp skills/qa-stlc/*.md .claude/skills/
	@echo "✓ Skills installed to .claude/skills/"
	@echo ""
	@echo "For VS Code Copilot, use: make skills-vscode"

skills-vscode:
	mkdir -p .github/copilot-instructions
	cp skills/qa-stlc/*.md .github/copilot-instructions/
	@echo "✓ Skills installed to .github/copilot-instructions/"

# ─── Generate .mcp.json for Claude Code ──────────────────────────────────────
mcp-config:
	@ABS=$$(pwd); \
	cat > .mcp.json <<EOF \
	{ \
	  "mcpServers": { \
	    "qa-test-case-manager": { \
	      "command": "$$ABS/$(MCP_TC)" \
	    }, \
	    "qa-gherkin-generator": { \
	      "command": "$$ABS/$(MCP_GH)" \
	    }, \
	    "qa-playwright-generator": { \
	      "command": "$$ABS/$(MCP_PW)" \
	    } \
	  } \
	} \
	EOF
	@echo "✓ .mcp.json written with absolute paths"

# ─── Test ─────────────────────────────────────────────────────────────────────
test:
	$(PYTEST) tests/ -v

# ─── Clean ────────────────────────────────────────────────────────────────────
clean:
	rm -rf $(VENV) __pycache__ dist *.egg-info
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete
	@echo "✓ Cleaned"
