diff --git a/scripts/instance-env.sh b/scripts/instance-env.sh index bc185d98f18..f926c74dc31 100755 --- a/scripts/instance-env.sh +++ b/scripts/instance-env.sh @@ -39,8 +39,14 @@ if git rev-parse --is-inside-work-tree &>/dev/null; then GIT_COMMON_DIR=$(git rev-parse --git-common-dir 2>/dev/null) if [[ -n "$GIT_COMMON_DIR" && "$GIT_DIR" != "$GIT_COMMON_DIR" ]]; then BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) - export BUZZ_WORKTREE_LABEL="${BRANCH_NAME##*/}" - export BUZZ_INSTANCE_SLUG=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//') + export BUZZ_WORKTREE_LABEL="${BUZZ_DEV_LABEL:-${BRANCH_NAME##*/}}" + INSTANCE_IDENTITY="${BUZZ_DEV_LABEL:-$BRANCH_NAME}" + export BUZZ_INSTANCE_SLUG=$(echo "$INSTANCE_IDENTITY" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//') + if [[ -z "$BUZZ_INSTANCE_SLUG" ]]; then + echo "BUZZ_DEV_LABEL must contain at least one letter or number" >&2 + return 1 2>/dev/null || exit 1 + fi + WORKTREE_PRODUCT_NAME=$(python3 -c 'import json,sys; print(json.dumps(f"Buzz Dev ({sys.argv[1]})"))' "$BUZZ_WORKTREE_LABEL") # BUZZ_SHARE_IDENTITY=1: reuse the main dev checkout's Nostr key so # worktrees skip onboarding and share the same identity. The per-worktree @@ -89,7 +95,7 @@ if git rev-parse --is-inside-work-tree &>/dev/null; then if swift "$GENERATE_DEV_ICON" "$BASE_ICON" "$DEV_ICON" "$BUZZ_WORKTREE_LABEL"; then echo "🌳 Worktree: ${BUZZ_WORKTREE_LABEL}" export VITE_DEV_BRANCH="$BUZZ_WORKTREE_LABEL" - BUZZ_TAURI_CONFIG="{\"build\":{\"devUrl\":\"${DEV_URL}\",\"beforeDevCommand\":\"exec ./node_modules/.bin/vite --port ${BUZZ_VITE_PORT} --strictPort\"},\"identifier\":\"xyz.block.buzz.app.dev.${BUZZ_INSTANCE_SLUG}\",\"productName\":\"Buzz Dev (${BUZZ_WORKTREE_LABEL})\",\"bundle\":{\"icon\":[\"$DEV_ICON\"]}}" + BUZZ_TAURI_CONFIG="{\"build\":{\"devUrl\":\"${DEV_URL}\",\"beforeDevCommand\":\"exec ./node_modules/.bin/vite --port ${BUZZ_VITE_PORT} --strictPort\"},\"identifier\":\"xyz.block.buzz.app.dev.${BUZZ_INSTANCE_SLUG}\",\"productName\":${WORKTREE_PRODUCT_NAME},\"bundle\":{\"icon\":[\"$DEV_ICON\"]}}" fi fi fi diff --git a/scripts/test-desktop-release-candidate.sh b/scripts/test-desktop-release-candidate.sh index 503c64eb37d..4b8fa69120c 100755 --- a/scripts/test-desktop-release-candidate.sh +++ b/scripts/test-desktop-release-candidate.sh @@ -225,4 +225,6 @@ root_sha=$(git -C "$initial" rev-parse HEAD) grep -Fq "$root_sha" "$initial/CHANGELOG.md" rm -rf "$initial" +"$repo_root/scripts/test-instance-env.sh" + echo "desktop release candidate contract passed" diff --git a/scripts/test-instance-env.sh b/scripts/test-instance-env.sh new file mode 100755 index 00000000000..181d0faceb3 --- /dev/null +++ b/scripts/test-instance-env.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +test_root=$(mktemp -d) +trap 'rm -rf "$test_root"' EXIT + +mkdir -p "$test_root/bin" "$test_root/checkout/desktop/src-tauri/icons" +touch "$test_root/checkout/desktop/src-tauri/icons/icon.icns" + +cat >"$test_root/bin/git" <"$test_root/bin/swift" <<'EOF' +#!/usr/bin/env bash +mkdir -p "$(dirname "$3")" +touch "$3" +EOF +chmod +x "$test_root/bin/swift" + +result=$( + PATH="$test_root/bin:$PATH" + BUZZ_DEV_LABEL='voice "route" \ fix' + BUZZ_SHARE_IDENTITY=0 + source "$repo_root/scripts/instance-env.sh" + printf '%s\n%s\n%s\n' \ + "$BUZZ_WORKTREE_LABEL" "$BUZZ_INSTANCE_SLUG" "$BUZZ_TAURI_CONFIG" +) + +[[ "$result" == *$'voice "route" \ fix\nvoice-route-fix\n'* ]] +config=$(printf '%s\n' "$result" | tail -1) +[[ "$(node -e 'const c=JSON.parse(process.argv[1]); process.stdout.write(c.productName)' "$config")" == 'Buzz Dev (voice "route" \ fix)' ]] + +echo "instance-env tests passed"