flake-update-20260505
  1# org-todos Pi extension Makefile
  2#
  3# Usage:
  4#   make test          - Run all tests (starts dedicated test daemon)
  5#   make test-elisp    - Run elisp tests only (batch mode, no daemon)
  6#   make test-ts       - Run TypeScript tests only (starts test daemon)
  7#   make test-unit     - Run TypeScript unit tests only (no Emacs needed)
  8#   make build         - Build TypeScript
  9#   make clean         - Clean build artifacts
 10
 11SHELL := bash
 12
 13# Paths
 14ELISP_DIR := ../../../../config/emacs/site-lisp
 15ELISP_ABS := $(shell cd $(ELISP_DIR) && pwd)
 16ELISP_FILES := org-batch-functions.el pi-org-todos.el
 17ELISP_TEST := pi-org-todos-test.el
 18
 19# Test daemon configuration
 20TEST_SOCKET := pi-org-todos-test
 21TEST_DAEMON_TIMEOUT := 15
 22
 23# Colors for output
 24GREEN := \033[0;32m
 25RED := \033[0;31m
 26YELLOW := \033[0;33m
 27NC := \033[0m # No Color
 28
 29.PHONY: all test test-elisp test-ts test-unit build clean help
 30.PHONY: test-daemon-start test-daemon-stop test-daemon-check
 31
 32all: test
 33
 34help:
 35	@echo "org-todos Pi extension"
 36	@echo ""
 37	@echo "Usage:"
 38	@echo "  make test          - Run all tests (elisp + TypeScript)"
 39	@echo "  make test-elisp    - Run elisp tests only (batch mode)"
 40	@echo "  make test-ts       - Run TypeScript tests only (uses test daemon)"
 41	@echo "  make test-unit     - Run TypeScript unit tests only (no Emacs needed)"
 42	@echo "  make build         - Build TypeScript"
 43	@echo "  make clean         - Clean build artifacts"
 44	@echo ""
 45	@echo "The test suite starts a dedicated Emacs daemon on socket"
 46	@echo "'$(TEST_SOCKET)' so it never touches your real daemon or org files."
 47
 48# Run all tests
 49test: test-elisp test-ts
 50	@echo ""
 51	@echo -e "$(GREEN)✓ All tests passed$(NC)"
 52
 53# Run elisp tests (batch mode, no daemon needed)
 54test-elisp:
 55	@echo -e "$(YELLOW)Running elisp tests...$(NC)"
 56	@cd $(ELISP_DIR) && emacs --batch \
 57		-l org \
 58		-l org-ql \
 59		-l org-batch-functions.el \
 60		-l pi-org-todos.el \
 61		-l ert \
 62		-l pi-org-todos-test.el \
 63		-f ert-run-tests-batch-and-exit
 64	@echo -e "$(GREEN)✓ Elisp tests passed$(NC)"
 65
 66# Run TypeScript tests with a dedicated test daemon
 67test-ts: test-daemon-start
 68	@echo -e "$(YELLOW)Running TypeScript tests...$(NC)"
 69	@EMACS_SOCKET_NAME=$(TEST_SOCKET) bun test index.test.ts; \
 70		status=$$?; \
 71		$(MAKE) --no-print-directory test-daemon-stop; \
 72		exit $$status
 73	@echo -e "$(GREEN)✓ TypeScript tests passed$(NC)"
 74
 75# Run only TypeScript unit tests (no Emacs needed)
 76test-unit:
 77	@echo -e "$(YELLOW)Running TypeScript unit tests...$(NC)"
 78	@bun test index.test.ts --test-name-pattern "unit tests"
 79	@echo -e "$(GREEN)✓ TypeScript unit tests passed$(NC)"
 80
 81# Start a dedicated test Emacs daemon
 82test-daemon-start:
 83	@echo -e "$(YELLOW)Starting test Emacs daemon (socket: $(TEST_SOCKET))...$(NC)"
 84	@# Kill any leftover test daemon
 85	@EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(kill-emacs)' 2>/dev/null || true
 86	@sleep 0.5
 87	@# Start a plain daemon, then load config via emacsclient
 88	@emacs --daemon="$(TEST_SOCKET)" 2>/dev/null || true
 89	@for i in $$(seq 1 $(TEST_DAEMON_TIMEOUT)); do \
 90		if EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(+ 1 1)' >/dev/null 2>&1; then \
 91			break; \
 92		fi; \
 93		sleep 0.5; \
 94	done
 95	@EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval \
 96		'(progn (add-to-list (quote load-path) "$(ELISP_ABS)") (load "$(CURDIR)/test-init.el") t)' \
 97		>/dev/null 2>&1
 98	@if EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(fboundp (quote pi/org-todo-list))' 2>/dev/null | grep -q t; then \
 99		echo -e "$(GREEN)✓ Test daemon ready$(NC)"; \
100	else \
101		echo -e "$(RED)Error: Test daemon failed to load pi-org-todos$(NC)"; \
102		EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(kill-emacs)' 2>/dev/null || true; \
103		exit 1; \
104	fi
105
106# Stop the test daemon
107test-daemon-stop:
108	@echo -e "$(YELLOW)Stopping test daemon...$(NC)"
109	@EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(kill-emacs)' 2>/dev/null || true
110	@echo -e "$(GREEN)✓ Test daemon stopped$(NC)"
111
112# Check if test daemon is running
113test-daemon-check:
114	@if EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(+ 1 1)' >/dev/null 2>&1; then \
115		echo -e "$(GREEN)✓ Test daemon is running (socket: $(TEST_SOCKET))$(NC)"; \
116	else \
117		echo -e "$(RED)✗ Test daemon is not running$(NC)"; \
118		exit 1; \
119	fi
120
121# Build TypeScript
122build:
123	@echo -e "$(YELLOW)Building TypeScript...$(NC)"
124	@bun build index.ts --target=node --outdir dist --external @mariozechner/pi-coding-agent --external @mariozechner/pi-tui
125	@echo -e "$(GREEN)✓ Build complete: dist/index.js$(NC)"
126
127# Clean build artifacts
128clean:
129	@rm -rf dist
130	@rm -f *.log
131	@# Stop test daemon if running
132	@EMACS_SOCKET_NAME=$(TEST_SOCKET) emacsclient --eval '(kill-emacs)' 2>/dev/null || true
133	@echo -e "$(GREEN)✓ Cleaned$(NC)"
134
135# Development helpers
136.PHONY: watch dev
137
138# Watch for changes and rebuild
139watch:
140	@echo "Watching for changes..."
141	@while true; do \
142		inotifywait -q -e modify index.ts $(ELISP_DIR)/pi-org-todos.el 2>/dev/null || sleep 2; \
143		clear; \
144		make build || true; \
145	done
146
147# Quick dev cycle: build and run unit tests
148dev: build test-unit