SHELL := /bin/bash

.PHONY: run down logs test smoke test-solver-sanitize

run:
	docker compose up --build

down:
	docker compose down

logs:
	docker compose logs -f

test:
	cd solver-api && npm test
	cd gui-ts && npm test
	./solver-c/test_solver

# ASan/UBSan regression for solver-c (rebuilds a throwaway binary under solver-c/)
test-solver-sanitize:
	cd solver-c && gcc -std=c99 -fsanitize=address,undefined -g -O1 \
	  -Iinclude \
	  src/solver_common.c src/json_stdin.c src/trajectory.c src/solver_diagnostic.c \
	  src/solver.c src/solver_fea.c src/solver_fourier.c \
	  tests/test_solver.c -lm -o test_solver_sanitize && ./test_solver_sanitize

smoke:
	@echo "Checking API health..."
	@for i in {1..30}; do \
		if curl --fail --silent http://localhost:4400/health > /dev/null; then \
			echo "API healthy"; \
			break; \
		fi; \
		sleep 1; \
		if [ $$i -eq 30 ]; then \
			echo "API did not become healthy in time"; \
			exit 1; \
		fi; \
	done
	@echo "Checking solve endpoint with base case..."
	@curl --fail --silent http://localhost:4400/solve/default > /dev/null && echo "Solve endpoint healthy"
