summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2026-10-22 22:17:50 +0000
committerJesse Vincent <jesse@fsck.com>2026-10-23 03:38:19 +0000
commitfa50d836bf7b0e2f08f493839dc2211ed6fb3bb9 (patch)
tree83107c790f77def76f19d5d73ce1d89518776cb3 /tests
parentb58deb3b948d4c305feeac122700100419ee2777 (diff)
brainstorming: resolve a relative --project-dir before start-server.sh cdsfix/2524-relative-project-dir
start-server.sh built SESSION_DIR, PID_FILE, LOG_FILE and BRAINSTORM_DIR from --project-dir as given, then ran `cd "$SCRIPT_DIR"` before using them. A relative project dir like `.` was re-rooted at the scripts directory, so the log and pid redirects failed and the server never reported server-started: "Server failed to start within 5 seconds". Resolve the project dir to an absolute path with `mkdir -p` + `cd && pwd` right before deriving the session paths. mkdir -p keeps the existing behavior of creating a project dir that doesn't exist yet (the Windows lifecycle test relies on it), CDPATH is cleared so a relative name can't resolve to some other directory, and `--` covers names starting with a dash. Works on bash 3.2 without realpath or readlink -f. Fixes #2524. Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
Diffstat (limited to 'tests')
-rw-r--r--tests/brainstorm-server/start-server.test.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/brainstorm-server/start-server.test.sh b/tests/brainstorm-server/start-server.test.sh
index a4802da..37fb216 100644
--- a/tests/brainstorm-server/start-server.test.sh
+++ b/tests/brainstorm-server/start-server.test.sh
@@ -109,6 +109,52 @@ else
fi
echo ""
+echo "--- start-server.sh relative --project-dir ---"
+
+cat > "$TEST_DIR/fake-bin/node" <<'EOF'
+#!/usr/bin/env bash
+echo "CAPTURED_BRAINSTORM_DIR=${BRAINSTORM_DIR:-__UNSET__}"
+exit 0
+EOF
+chmod +x "$TEST_DIR/fake-bin/node"
+
+# The script cds into its own directory before starting the server, so a
+# relative --project-dir must be resolved against the caller's cwd first.
+# Covers an existing dir and a not-yet-created one, both with spaces.
+for relative_dir in "." "new project dir"; do
+ caller_dir="$TEST_DIR/caller with space"
+ rm -rf "$caller_dir"
+ mkdir -p "$caller_dir"
+ expected_root="$(cd "$caller_dir" && pwd)"
+ if [[ "$relative_dir" != "." ]]; then
+ expected_root="$expected_root/$relative_dir"
+ fi
+
+ captured=$(
+ cd "$caller_dir" &&
+ PATH="$TEST_DIR/fake-bin:$PATH" \
+ MSYSTEM="" \
+ bash "$START_SCRIPT" --project-dir "$relative_dir" --foreground 2>&1 || true
+ )
+ brainstorm_dir=$(echo "$captured" | grep "CAPTURED_BRAINSTORM_DIR=" | head -1 | sed 's/CAPTURED_BRAINSTORM_DIR=//')
+
+ case "$brainstorm_dir" in
+ "$expected_root/.superpowers/brainstorm/"*)
+ pass "--project-dir '$relative_dir' gives the server an absolute session dir under the caller's cwd" ;;
+ *)
+ fail "--project-dir '$relative_dir' gives the server an absolute session dir under the caller's cwd" \
+ "expected prefix '$expected_root/.superpowers/brainstorm/', got: $captured" ;;
+ esac
+
+ if [[ -n "$brainstorm_dir" && -f "$brainstorm_dir/state/server.pid" ]]; then
+ pass "--project-dir '$relative_dir' writes server.pid into the project session dir"
+ else
+ fail "--project-dir '$relative_dir' writes server.pid into the project session dir" \
+ "no server.pid under '$brainstorm_dir/state', output: $captured"
+ fi
+done
+
+echo ""
echo "--- Results: $passed passed, $failed failed ---"
if [[ $failed -gt 0 ]]; then
exit 1