Files
buzz/scripts/mobile-worktree-overrides.sh
Tom Brow 868e2f8f32 refactor(push): one app profile per gateway (#8206)
Buzz push currently selects an application profile, such as `dogfood`,
during client registration. We want each gateway to serve one Apple app
configured by the operator instead. This removes profile selection from
the client, relay, and gateway, while allowing internal and public
gateways to use their own Apple identities.

This PR implements that model in the Buzz source and upstream deployment
chart. Discovery, enrollment, grants, and leases no longer carry an
application-profile selector. Each gateway has one configured Apple
application and APNs transport.

The protocol changes are incompatible with the old registration format,
so relays advertise `buzz-push-v1` instead of `nip-pl`. Old clients do
not discover the new push capability. Updated clients use separate
Keychain records and register again. The [push
notes](https://github.com/block/buzz/blob/push-capability-v1/docs/buzz-push.md)
describe the experimental contract.

Landing this PR is the first step. Publish the matching gateway image
and upstream chart, then land the [shared chart
update](https://github.com/squareup/cash-helm-charts/pull/5740) and
[gateway deployment
update](https://github.com/squareup/builderbot-platform-core-infrastructure/pull/1085).
Before cutover, stop old gateway instances and check legacy registration
state. Migrations refuse to proceed if old gateway installations or
active relay leases remain; they do not delete that state.
Physical-device verification remains necessary before production
activation.

### Validation
Gateway and focused Flutter push tests pass, as do the Swift package,
simulator build, and native notification/enrichment tests. A local relay
advertises `buzz-push-v1` without `nip-pl` or `app_profiles`. The
PostgreSQL suite passed 868 tests; its two migration-test failures were
corrected and pass a focused rerun together with the gateway cutover
guard. Chart rendering and release-contract checks pass.

Desktop JavaScript tests, desktop and web builds, native desktop
compilation, mobile analysis/tests, and desktop native tests pass. The
full Rust unit lane and prescribed `just test` command pass, including
workspace integration tests against task-isolated local services. The
production overlay now requires an explicitly supplied APNs topic, with
omission and rendered-value regression coverage. The corrected Swift
checksum assertion passes the complete package suite: 78 XCTest tests
and 42 Swift Testing tests. No physical-device enrollment or production
cutover is claimed.

Local merge validation: the embedded migration test and formatting pass
after reserving profile migration 0060 behind rollback migration 0059.
The local pre-push Rust lane failed ACP timing/steering tests
(`idle_resets_on_stdout_activity`,
`keepalive_resets_idle_past_deadline`, and the failed/missing-outcome
steering tests). ACP and its dependency manifests are unchanged by this
branch; all four pass in an isolated single-thread rerun. The documented
local-check exception skips only the Rust pre-push lane for publication;
required CI remains mandatory. Mobile and desktop pre-push lanes passed.

Combined migration validation: after rollback 0059 landed, the main
merge preserves profile migration 0060 and both embedded migration
assertions. The focused migration test and formatting pass. The next
local push again failed only the unchanged ACP idle/keepalive timing
tests (1053 passed, 2 failed, 3 ignored); other lanes passed.
Publication uses the same documented local Rust-lane exception; required
CI remains mandatory.

Follow-up review fix: removed the legacy profile column from the
copied-lease fixture. All four event-follow-up contract tests pass on
isolated PostgreSQL databases, covering desired and migrated schemas in
dual and app-only modes. Formatting passes. Publication retains the
prior passing local-lane evidence and uses the authorized pre-push
exception for the known unrelated ACP timing failures; required CI
remains mandatory.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-09 15:09:53 -07:00

111 lines
5.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Writes worktree-aware identity overrides for mobile debug builds, mirroring
# the desktop dev experience in scripts/instance-env.sh: debug builds produced
# from a git worktree get a unique app identifier keyed to the WORKTREE
# DIRECTORY NAME (stable across branch switches, so installs and login state
# are bounded by worktree count) plus a display-only branch label (short SHA
# when detached).
#
# In a worktree this writes two gitignored override files consumed by the
# native build systems (so direct Xcode / Android Studio / `flutter run`
# builds pick them up too):
# mobile/ios/Flutter/WorktreeOverrides.xcconfig (Debug builds only; a
# developer's AppOverrides.xcconfig takes precedence per variable)
# mobile/android/worktree.properties (debug build type only)
# In the main checkout it removes any stale override files. Release and
# profile builds never read these overrides.
#
# Android-only test builds can opt into a more explicit side-by-side identity:
# BUZZ_ANDROID_DEBUG_APP_NAME="Buzz Huddles"
# BUZZ_ANDROID_DEBUG_ID_SUFFIX=".huddles_829c"
# Both values are validated before the generated properties file is written.
set -euo pipefail
# `just mobile-*` recipes unset these before invoking Flutter; do the same so
# an inherited GIT_DIR pointing elsewhere cannot misdetect the worktree.
unset GIT_DIR GIT_WORK_TREE
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ios_overrides="$repo_root/mobile/ios/Flutter/WorktreeOverrides.xcconfig"
android_props="$repo_root/mobile/android/worktree.properties"
# Worktree detection: in the main working tree --git-dir and --git-common-dir
# are identical; in any linked worktree they differ (same check as
# scripts/instance-env.sh).
in_worktree=0
if git -C "$repo_root" rev-parse --is-inside-work-tree &>/dev/null; then
git_dir=$(git -C "$repo_root" rev-parse --git-dir)
git_common_dir=$(git -C "$repo_root" rev-parse --git-common-dir 2>/dev/null)
if [[ -n "$git_common_dir" && "$git_dir" != "$git_common_dir" ]]; then
in_worktree=1
fi
fi
if [[ "$in_worktree" != "1" ]]; then
rm -f "$ios_overrides" "$android_props"
exit 0
fi
# Install identity comes from the worktree directory name: stable across
# branch switches, so one worktree keeps one installed app (and its login
# state) no matter how many branches it visits.
worktree_name="$(basename "$repo_root")"
# Display label is context only: the branch name, or a short SHA when the
# worktree is detached. Sanitized to [A-Za-z0-9._-] so no valid Git ref can
# break Android string resources or xcconfig values.
branch=$(git -C "$repo_root" rev-parse --abbrev-ref HEAD)
if [[ "$branch" == "HEAD" ]]; then
label_raw=$(git -C "$repo_root" rev-parse --short HEAD)
else
label_raw="${branch##*/}"
fi
label=$(printf '%s' "$label_raw" | sed -e 's/[^A-Za-z0-9._-]/-/g' -e 's/--*/-/g' -e 's/^-//' -e 's/-$//')
[[ -n "$label" ]] || label="worktree"
# iOS bundle-identifier slug: lowercase, non-alphanumerics collapsed to
# hyphens (hyphens are valid in bundle identifiers).
ios_slug=$(printf '%s' "$worktree_name" | tr '[:upper:]' '[:lower:]' | sed -e 's/[^a-z0-9]/-/g' -e 's/--*/-/g' -e 's/^-//' -e 's/-$//')
[[ -n "$ios_slug" ]] || ios_slug="worktree"
# Android applicationId segments must match [a-z][a-z0-9_]*: swap hyphens for
# underscores and prefix a letter when the slug starts with a digit.
android_slug="${ios_slug//-/_}"
case "$android_slug" in
[0-9]*) android_slug="w_$android_slug" ;;
esac
ios_bundle_id="xyz.block.buzz.dev.mobile.${ios_slug}"
android_app_name="${BUZZ_ANDROID_DEBUG_APP_NAME:-Buzz (${label})}"
android_suffix="${BUZZ_ANDROID_DEBUG_ID_SUFFIX:-.${android_slug}}"
if [[ "$android_app_name" == *$'\n'* || "$android_app_name" == *$'\r'* ]] || \
! printf '%s\n' "$android_app_name" | LC_ALL=C grep -Eq '^[A-Za-z0-9._() -]+$'; then
echo "BUZZ_ANDROID_DEBUG_APP_NAME must contain only letters, numbers, spaces, ., _, -, or parentheses" >&2
exit 2
fi
if [[ ! "$android_suffix" =~ ^\.[a-z][a-z0-9_]*$ ]]; then
echo "BUZZ_ANDROID_DEBUG_ID_SUFFIX must match \\.[a-z][a-z0-9_]* (for example .huddles_829c)" >&2
exit 2
fi
cat > "$ios_overrides" <<XCCONFIG
// Generated by scripts/mobile-worktree-overrides.sh — gitignored, do not edit.
// Applies to Debug builds only (included from Flutter/Debug.xcconfig before
// AppOverrides.xcconfig, so a developer's app-specific overrides win).
BUNDLE_IDENTIFIER = ${ios_bundle_id}
APP_DISPLAY_NAME = Buzz (${label})
XCCONFIG
cat > "$android_props" <<PROPERTIES
# Generated by scripts/mobile-worktree-overrides.sh — gitignored, do not edit.
# Applies to the debug build type only (read by android/app/build.gradle.kts).
label=${label}
appName=${android_app_name}
applicationIdSuffix=${android_suffix}
PROPERTIES
# The printed identifiers are the generated defaults; on iOS a developer's
# AppOverrides.xcconfig may override them per variable.
echo "📱 Worktree ${worktree_name}: iOS label \"${label}\" (${ios_bundle_id}); Android label \"${android_app_name}\" (xyz.block.buzz.mobile${android_suffix})"