From 4b8c081d1ad9de206749f2021ef93114583fbd39 Mon Sep 17 00:00:00 2001 From: Dan Piths <85949566+danpiths@users.noreply.github.com> Date: Fri, 8 May 2026 19:23:38 +0530 Subject: [PATCH] fix: wrap Makefile subshell cd commands in parentheses --- Makefile | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 767e8c91c8d..11adfa9de97 100644 --- a/Makefile +++ b/Makefile @@ -153,15 +153,33 @@ install-junit-viewer: ## Install junit-viewer for HTML report generation (if not dev: install-ui install-air setup-workspace $(if $(DEBUG),install-delve) ## Start complete development environment (UI + API with proxy) @$(EXPOSE_ENV); \ - set -m; \ + set +m; \ + ui_pid=""; \ + api_pid=""; \ cleanup() { \ + $(ECHO) "$(YELLOW)[make dev] cleanup started; ui_pid=$$ui_pid api_pid=$$api_pid$(NC)"; \ trap - EXIT INT TERM HUP; \ - kill %1 %2 2>/dev/null || true; \ + for pid in "$$ui_pid" "$$api_pid"; do \ + if [ -n "$$pid" ]; then \ + children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \ + $(ECHO) "$(YELLOW)[make dev] sending TERM to pid $$pid and children: $${children:-none}$(NC)"; \ + kill -TERM $$children "$$pid" 2>/dev/null || true; \ + fi; \ + done; \ sleep 1; \ - kill -KILL %1 %2 2>/dev/null || true; \ + for pid in "$$ui_pid" "$$api_pid"; do \ + if [ -n "$$pid" ]; then \ + children="$$(pgrep -P "$$pid" 2>/dev/null || true)"; \ + $(ECHO) "$(YELLOW)[make dev] sending KILL to pid $$pid and remaining children: $${children:-none}$(NC)"; \ + kill -KILL $$children "$$pid" 2>/dev/null || true; \ + fi; \ + done; \ + $(ECHO) "$(YELLOW)[make dev] waiting for background jobs to exit...$(NC)"; \ wait 2>/dev/null || true; \ + $(ECHO) "$(GREEN)[make dev] cleanup completed.$(NC)"; \ }; \ stop_dev() { \ + $(ECHO) "$(YELLOW)[make dev] received shutdown signal; starting cleanup...$(NC)"; \ cleanup; \ exit 130; \ }; \ @@ -184,33 +202,38 @@ dev: install-ui install-air setup-workspace $(if $(DEBUG),install-delve) ## Star $(ECHO) "$(YELLOW)Starting UI development server...$(NC)"; \ $(USE_NODE); if [ -n "$(DISABLE_PROFILER)" ]; then \ $(ECHO) "$(CYAN)DevProfiler disabled for testing$(NC)"; \ - cd ui && BIFROST_DISABLE_PROFILER=1 npm run dev & \ + (cd ui && BIFROST_DISABLE_PROFILER=1 npm run dev) & \ else \ - cd ui && npm run dev & \ + (cd ui && npm run dev) & \ fi; \ + ui_pid="$$!"; \ + $(ECHO) "$(YELLOW)[make dev] UI dev server started with pid $$ui_pid$(NC)"; \ sleep 3; \ $(ECHO) "$(YELLOW)Starting API server with UI proxy...$(NC)"; \ $(MAKE) setup-workspace >/dev/null; \ if [ -n "$(DEBUG)" ]; then \ $(ECHO) "$(CYAN)Starting with air + delve debugger on port 2345...$(NC)"; \ $(ECHO) "$(YELLOW)Attach your debugger to localhost:2345$(NC)"; \ - cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.debug.toml -- \ + (cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.debug.toml -- \ -host "$(HOST)" \ -port "$(PORT)" \ -log-style "$(LOG_STYLE)" \ -log-level "$(LOG_LEVEL)" \ $(if $(PROMETHEUS_LABELS),-prometheus-labels "$(PROMETHEUS_LABELS)") \ - $(if $(APP_DIR),-app-dir "$(abspath $(APP_DIR))") & \ + $(if $(APP_DIR),-app-dir "$(abspath $(APP_DIR))")) & \ else \ - cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.toml -- \ + (cd transports/bifrost-http && BIFROST_UI_DEV=true air -c .air.toml -- \ -host "$(HOST)" \ -port "$(PORT)" \ -log-style "$(LOG_STYLE)" \ -log-level "$(LOG_LEVEL)" \ $(if $(PROMETHEUS_LABELS),-prometheus-labels "$(PROMETHEUS_LABELS)") \ - $(if $(APP_DIR),-app-dir "$(abspath $(APP_DIR))") & \ + $(if $(APP_DIR),-app-dir "$(abspath $(APP_DIR))")) & \ fi; \ - while [ "$$(jobs -r | wc -l | tr -d ' ')" -eq 2 ]; do sleep 1; done; \ + api_pid="$$!"; \ + $(ECHO) "$(YELLOW)[make dev] API dev server started with pid $$api_pid$(NC)"; \ + while kill -0 "$$ui_pid" 2>/dev/null && kill -0 "$$api_pid" 2>/dev/null; do sleep 1; done; \ + $(ECHO) "$(YELLOW)[make dev] one of the dev processes exited; running cleanup...$(NC)"; \ cleanup; \ exit 1 @@ -247,9 +270,9 @@ dev-pulse: install-ui install-pulse setup-workspace $(if $(DEBUG),install-delve) $(ECHO) "$(YELLOW)Starting UI development server...$(NC)"; \ $(USE_NODE); if [ -n "$(DISABLE_PROFILER)" ]; then \ $(ECHO) "$(CYAN)DevProfiler disabled for testing$(NC)"; \ - cd ui && BIFROST_DISABLE_PROFILER=1 npm run dev & \ + (cd ui && BIFROST_DISABLE_PROFILER=1 npm run dev) & \ else \ - cd ui && npm run dev & \ + (cd ui && npm run dev) & \ fi; \ sleep 3; \ $(ECHO) "$(YELLOW)Starting API server with UI proxy...$(NC)"; \