Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces): Cua Spaces Local uses the bundle id com.trycua.spaces.macos.local (#5884)

cua-agents[bot]152a5653b482
diff --git a/apps/cua-spaces-macos/README.md b/apps/cua-spaces-macos/README.md
index b6d5eac482..d24ca18701 100644
--- a/apps/cua-spaces-macos/README.md
+++ b/apps/cua-spaces-macos/README.md
@@ -68,12 +68,12 @@ prints them), so nothing here hard-codes one.
| | Stable | Local |
|---|---|---|
| App | `Cua Spaces.app` | `Cua Spaces Local.app` |
-| Bundle id | `com.trycua.spaces.macos` | `com.trycua.spaces.local` |
+| Bundle id | `com.trycua.spaces.macos` | `com.trycua.spaces.macos.local` |
| Info.plist | no channel keys | `CuaChannel=local`, `CuaEnv=staging`, `CuaHome=~/.cua-local`, `CuaHelperLabel`, `CuaUrlScheme` |
| Cua deployment | prod (`CUA_ENV` picks another) | staging (`CUA_ENV=prod` opts in) |
| Cua home | `~/.cua` (`~/.cua/envs/staging` on staging) | `~/.cua-local` on staging; `~/.cua-local/envs/prod` under the `CUA_ENV=prod` opt-in |
| Sign-in Keychain service | `ai.cua.session` (`.staging` on staging) | `ai.cua.session.local` (`.staging` on staging) |
-| Helper login item | `com.trycua.spaces.helper` | `com.trycua.spaces.local.helper` (plist file and `AssociatedBundleIdentifiers` stamped to match) |
+| Helper login item | `com.trycua.spaces.helper` | `com.trycua.spaces.local.helper` (plist file stamped to match; `AssociatedBundleIdentifiers` is the Local bundle id) |
| URL scheme | `cua://` | `cua-local://` |
| Updater | Sparkle feed and key | none (`SUFeedURL`, `SUPublicEDKey` removed): it never offers or installs an update |
@@ -356,7 +356,7 @@ The Local build shares nothing with the released app. Every name comes from
| | Cua Spaces | Cua Spaces Local |
|---|---|---|
| App | `/Applications/Cua Spaces.app` | `~/Applications/Cua Spaces Local.app` |
-| Bundle id | `com.trycua.spaces.macos` | `com.trycua.spaces.local` |
+| Bundle id | `com.trycua.spaces.macos` | `com.trycua.spaces.macos.local` |
| CLI | `~/.local/bin/cua` | `~/.local/bin/cua-local` |
| Home | `~/.cua` | `~/.cua-local` |
| Backend | production | staging (`CUA_ENV=prod` opts in) |
@@ -422,13 +422,28 @@ It unregisters the Local helper login item and removes the app, `cua-local`,
(`ai.cua.session.local*`). It keeps `~/Cua Volume Local` and the permissions
macOS granted.
+**The Local bundle id changed.** The first Local builds were
+`com.trycua.spaces.local`; Local is now `com.trycua.spaces.macos.local` (Stable
+plus `.local`; the launchd ids, ports, `cua-local` and `~/.cua-local` did not
+change). `install-local.sh` finds an app with the old id at the Local path,
+unregisters its helper login item, removes it, installs the renamed app, and
+then removes what the old id left in `~/Library` (its Application Support
+folder, preferences, caches, web view data, cookies and window state). It says
+so in one line. If the new copy fails to verify, the old app and its login item
+are put back. Your sign-in (`~/.cua-local`) and `~/Cua Volume Local` stay, and
+macOS asks for the renamed app's permissions once; the old id's permission rows
+stay in macOS's list unused (`tccutil` cannot clear them for an app that is
+gone). `uninstall-local.sh` removes both ids' leftovers. Neither touches
+anything Stable owns. Because the new id is Stable's plus a suffix, compare
+bundle ids whole, never by prefix.
+
There is one Local slot per Mac: an Internal build from CI uses the same
identity, so it and a build from source replace each other.
`scripts/tests/install-local-test.sh` checks all of this against a fake `HOME`
and a fake build: a Stable install is byte-identical before and after install,
rebuild and uninstall, a wrong bundle id is refused, a failed copy is rolled
-back. `CUA_TEST_SIGNING_KEYCHAIN=<keychain>` adds the certificate-signing checks.
+back, an app with the old Local id is replaced and its leftovers removed. `CUA_TEST_SIGNING_KEYCHAIN=<keychain>` adds the certificate-signing checks.
## Release
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
index 66d22c5fed..b26d834a3f 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppEnvironment.swift
@@ -20,8 +20,8 @@ public enum AppEnvironment {
/// The bundle identity (the Keyvault's trusted-caller requirement names
/// it; see README "Keyvault identity"). A Local build keeps its settings
- /// in its own folder, `com.trycua.spaces.local`, never Stable's.
- public static let bundleIdentifier = isLocalChannel ? "com.trycua.spaces.local" : "com.trycua.spaces.macos"
+ /// in its own folder, `com.trycua.spaces.macos.local`, never Stable's.
+ public static let bundleIdentifier = isLocalChannel ? "com.trycua.spaces.macos.local" : "com.trycua.spaces.macos"
/// `$HOME`, so a temp HOME (tests, captures) keeps every file away from
/// the account's real Library (`FileManager` ignores `$HOME`).
diff --git a/apps/cua-spaces-macos/scripts/_local-common.sh b/apps/cua-spaces-macos/scripts/_local-common.sh
index 1aefac906a..94f44ba810 100644
--- a/apps/cua-spaces-macos/scripts/_local-common.sh
+++ b/apps/cua-spaces-macos/scripts/_local-common.sh
@@ -14,12 +14,15 @@
# shellcheck disable=SC2034 # each script uses some of these names
# --- Local (what these scripts install and remove) ---------------------------
-LOCAL_BUNDLE_ID="com.trycua.spaces.local" # CuaChannel::bundle_id
+LOCAL_BUNDLE_ID="com.trycua.spaces.macos.local" # CuaChannel::bundle_id
+# The id Local's first builds had (CuaChannel::legacy_bundle_id): what the
+# installer moves away from and the uninstaller also cleans up.
+LOCAL_LEGACY_BUNDLE_ID="com.trycua.spaces.local" # CuaChannel::legacy_bundle_id
LOCAL_APP_DIR_NAME="Cua Spaces Local.app" # CuaChannel::app_path
LOCAL_CLI_NAME="cua-local" # CuaChannel::cli_name
LOCAL_URL_SCHEME="cua-local" # CuaChannel::url_scheme
LOCAL_HOME_DIR_NAME=".cua-local" # CuaChannel::home_dir
-LOCAL_APP_SUPPORT_DIR_NAME="com.trycua.spaces.local" # CuaChannel::app_support_dir_name
+LOCAL_APP_SUPPORT_DIR_NAME="com.trycua.spaces.macos.local" # CuaChannel::app_support_dir_name
LOCAL_HELPER_LABEL="com.trycua.spaces.local.helper" # CuaChannel::helper_label
LOCAL_HOST_LABEL="com.trycua.spacesd.host.local" # CuaChannel::host_label
LOCAL_VOLUME_NAME="Cua Volume Local" # CuaChannel::volume_name
@@ -28,17 +31,20 @@ LOCAL_LUME_DIR_NAME=".lume-local" # CuaChannel::lume_dir
# CuaChannel::keychain_service(Prod) and (Staging). The sign-in and the device
# key live under these services, one item per account.
LOCAL_KEYCHAIN_SERVICES=("ai.cua.session.local" "ai.cua.session.local.staging")
-# What macOS keeps under ~/Library for the Local bundle id: preferences, caches,
-# web view data and saved window state. Every name carries the Local bundle id
-# (Stable's are the same folders with its own id, which are never listed here).
-LOCAL_LIBRARY_LEAVES=(
- "Preferences/$LOCAL_BUNDLE_ID.plist"
- "Caches/$LOCAL_BUNDLE_ID"
- "HTTPStorages/$LOCAL_BUNDLE_ID"
- "WebKit/$LOCAL_BUNDLE_ID"
- "Cookies/$LOCAL_BUNDLE_ID.binarycookies"
- "Saved Application State/$LOCAL_BUNDLE_ID.savedState"
-)
+# What macOS keeps under ~/Library for a bundle id: preferences, caches, web view
+# data, cookies and saved window state. `library_leaves ID` prints their paths
+# below ~/Library, one per line; every one carries ID whole. The Local id is
+# Stable's plus ".local", so none of these names is a Stable one (Stable's are
+# the same folders with its own id, which are never listed here).
+library_leaves() {
+ printf '%s\n' \
+ "Preferences/$1.plist" \
+ "Caches/$1" \
+ "HTTPStorages/$1" \
+ "WebKit/$1" \
+ "Cookies/$1.binarycookies" \
+ "Saved Application State/$1.savedState"
+}
# --- Stable (what these scripts must never create, replace or remove) --------
# Only used to refuse a bundle that carries a Stable identity.
@@ -87,9 +93,20 @@ plist_url_schemes() {
done
}
+# Succeeds when `app` is a Cua Spaces Local bundle with the bundle id Local's
+# first builds had (com.trycua.spaces.local). The id is compared whole.
+is_legacy_local_bundle() {
+ local app="$1"
+ [ ! -L "$app" ] && [ -f "$app/Contents/Info.plist" ] \
+ && [ "$(bundle_id_of "$app")" = "$LOCAL_LEGACY_BUNDLE_ID" ]
+}
+
# Succeeds when `path` is absent or a Cua Spaces Local bundle, the only thing
-# these scripts may replace or remove. Anything else, a Stable app included, is
-# refused with the reason.
+# these scripts may replace or remove: one with the Local bundle id, or with
+# the one Local had before (they move that one to the new id). Anything else, a
+# Stable app included, is refused with the reason. Ids are compared whole: the
+# Local id is Stable's plus ".local", so a prefix test would take one for the
+# other.
require_local_bundle_or_absent() {
local app="$1" id
if [ ! -e "$app" ] && [ ! -L "$app" ]; then
@@ -104,7 +121,7 @@ require_local_bundle_or_absent() {
return 1
fi
id="$(bundle_id_of "$app")"
- if [ "$id" != "$LOCAL_BUNDLE_ID" ]; then
+ if [ "$id" != "$LOCAL_BUNDLE_ID" ] && [ "$id" != "$LOCAL_LEGACY_BUNDLE_ID" ]; then
err "refusing to touch $app: its bundle id is '${id:-none}', not $LOCAL_BUNDLE_ID"
return 1
fi
@@ -133,6 +150,71 @@ quit_local_app() {
fi
}
+# The old Local app's helper login item and processes: the app unregisters its
+# own login item (the same call the host setup makes), then it is stopped, and
+# the helper job is booted out in case the app could not do it. Nothing but the
+# Local helper label is named. `app` must be a Local bundle (checked by the
+# caller).
+retire_local_app() {
+ local app="$1"
+ if [ -x "$app/Contents/MacOS/CuaSpacesMac" ]; then
+ CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 \
+ || warn "the app could not unregister its helper; remove $LOCAL_APP_DIR_NAME from System Settings > Login Items if it stays."
+ fi
+ quit_local_app "$app"
+ launchctl bootout "gui/$(id -u)/$LOCAL_HELPER_LABEL" >/dev/null 2>&1 || true
+}
+
+# Removes what the old Local bundle id left under ~/Library: its Application
+# Support folder and the files macOS keeps for a bundle id. Every name carries
+# the old id whole (and none is a name of the current Local id or of Stable's).
+# Prints each path it removed, one per line.
+remove_legacy_local_data() {
+ local leaf path
+ while IFS= read -r leaf; do
+ case "$leaf" in
+ *"$LOCAL_LEGACY_BUNDLE_ID"*) ;;
+ *) continue ;;
+ esac
+ path="$HOME/Library/$leaf"
+ if [ -e "$path" ] || [ -L "$path" ]; then
+ rm -rf "$path"
+ printf '%s\n' "$path"
+ fi
+ done < <(printf '%s\n' "Application Support/$LOCAL_LEGACY_BUNDLE_ID"; library_leaves "$LOCAL_LEGACY_BUNDLE_ID")
+}
+
+# Succeeds when the Local app at `app` has its helper login item registered
+# and enabled (what `--service-helper status` reports).
+local_helper_enabled() {
+ local app="$1"
+ [ -x "$app/Contents/MacOS/CuaSpacesMac" ] || return 1
+ CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper status 2>/dev/null | grep -q '"status":"enabled"'
+}
+
+# Registers the helper login item of the Local app at `app` (the app does it
+# itself: only a bundle's own code may), best effort. `what` names the app in
+# the warning.
+register_local_helper() {
+ local app="$1" what="$2"
+ [ -x "$app/Contents/MacOS/CuaSpacesMac" ] || return 0
+ CUA_CHANNEL=local "$app/Contents/MacOS/CuaSpacesMac" --service-helper register >/dev/null 2>&1 \
+ || warn "$what's helper login item could not be registered; open the app and set up this Mac again."
+}
+
+# Puts back what `retire_local_app` took from an old Local app that is restored
+# after a failed install: LaunchServices knows it again and, when `helper_was_enabled`
+# is 1, its helper login item is registered again (best effort).
+restore_retired_local_app() {
+ local app="$1" helper_was_enabled="$2"
+ if [ -x "$LSREGISTER" ]; then
+ "$LSREGISTER" -f "$app" >/dev/null 2>&1 || true
+ fi
+ if [ "$helper_was_enabled" = 1 ]; then
+ register_local_helper "$app" "the previous app"
+ fi
+}
+
# --- Where Local may write -----------------------------------------------------
# The absolute path with `.`, `..` and every symlink resolved, whether or not
diff --git a/apps/cua-spaces-macos/scripts/build-app.sh b/apps/cua-spaces-macos/scripts/build-app.sh
index d7c6a832d1..7c0435027f 100755
--- a/apps/cua-spaces-macos/scripts/build-app.sh
+++ b/apps/cua-spaces-macos/scripts/build-app.sh
@@ -27,7 +27,7 @@
#
# --channel local builds "Cua Spaces Local.app", which runs beside an
# installed Cua Spaces and cannot touch it (CUA-1776): the Local bundle id
-# (com.trycua.spaces.local), name, helper login item (label and plist file
+# (com.trycua.spaces.macos.local), name, helper login item (label and plist file
# name), URL scheme (cua-local, not cua) and cua home (~/.cua-local), staging
# by default (CuaEnv), and no Sparkle feed or key, so it never offers or
# installs an update. Every name comes from CuaChannel (scripts/channel-names.sh,
diff --git a/apps/cua-spaces-macos/scripts/install-local.sh b/apps/cua-spaces-macos/scripts/install-local.sh
index 8bb254811e..08aa7c0b44 100755
--- a/apps/cua-spaces-macos/scripts/install-local.sh
+++ b/apps/cua-spaces-macos/scripts/install-local.sh
@@ -53,6 +53,15 @@
# the Local one (it refuses). The build is staged, signed and verified first;
# the live copy is swapped only then, and put back if the copy fails to verify.
#
+# An old Cua Spaces Local (the bundle id com.trycua.spaces.local, before the
+# rename to com.trycua.spaces.macos.local) at the Local path is replaced: its
+# login item is unregistered, the app is removed, and once the new app is
+# installed its old settings in ~/Library go too, and its helper login item is
+# registered again for the new app (a failed copy puts the old app and its login
+# item back). ~/.cua-local (the sign-in) and Cua Volume Local stay.
+# macOS asks for the renamed app's permissions once; the old id's permission rows
+# stay in macOS's list (macOS cannot clear them for an app that is gone), unused.
+#
# Signing: the stable local certificate shared with Cua Driver's local install
# (libs/cua-driver/scripts/_local-signing.sh), so the Screen Recording and
# Accessibility grants of Cua Spaces Local survive a rebuild. Without it the
@@ -679,7 +688,7 @@ reset_spaces_local_tcc() {
# helper label), no update feed. Prints every problem; fails on any.
verify_local_bundle() {
local app="$1" plist="$1/Contents/Info.plist" failures=0 id channel label schemes scheme
- local has_local_scheme=0 helper_plist associated
+ local has_local_scheme=0 helper_plist associated i
bad() { err "$app: $*"; failures=$((failures + 1)); }
@@ -728,9 +737,21 @@ EOF
[ -f "$helper_plist" ] || continue
label="$(plist_get "$helper_plist" Label || true)"
[ "$label" != "$STABLE_HELPER_LABEL" ] || bad "$(basename "$helper_plist") has the Stable helper label $STABLE_HELPER_LABEL"
+ # Each entry is compared whole: the Local id is Stable's plus ".local",
+ # so a substring test would flag the Local id itself. launchd takes the
+ # key as an array or as one string; both are read.
associated="$(plist_get "$helper_plist" AssociatedBundleIdentifiers || true)"
case "$associated" in
- *"$STABLE_BUNDLE_ID"*) bad "$(basename "$helper_plist") is associated with the Stable app $STABLE_BUNDLE_ID" ;;
+ "Array {"*)
+ i=0
+ while associated="$(plist_get "$helper_plist" "AssociatedBundleIdentifiers:$i")"; do
+ [ "$associated" != "$STABLE_BUNDLE_ID" ] || bad "$(basename "$helper_plist") is associated with the Stable app $STABLE_BUNDLE_ID"
+ i=$((i + 1))
+ done
+ ;;
+ *)
+ [ "$associated" != "$STABLE_BUNDLE_ID" ] || bad "$(basename "$helper_plist") is associated with the Stable app $STABLE_BUNDLE_ID"
+ ;;
esac
done
@@ -756,6 +777,21 @@ fi
log "installing $APP_DEST"
# The path may have been taken since the preflight.
require_local_bundle_or_absent "$APP_DEST" || exit 1
+# The old Local (bundle id com.trycua.spaces.local) is retired here, after the
+# build and its checks, so a failed build leaves it as it was. Its settings in
+# ~/Library are removed below, once the new app is in.
+REPLACING_LEGACY_LOCAL=0
+LEGACY_HELPER_WAS_ENABLED=0
+if is_legacy_local_bundle "$APP_DEST"; then
+ REPLACING_LEGACY_LOCAL=1
+ PREVIOUS_REQUIREMENT=""
+ log "found the old ${LOCAL_APP_DIR_NAME%.app} (bundle id $LOCAL_LEGACY_BUNDLE_ID): replacing it with the renamed app ($LOCAL_BUNDLE_ID) and removing its old settings. Your sign-in stays; macOS asks for the app's permissions once more."
+ if local_helper_enabled "$APP_DEST"; then LEGACY_HELPER_WAS_ENABLED=1; fi
+ retire_local_app "$APP_DEST"
+ if [ -x "$LSREGISTER" ]; then
+ "$LSREGISTER" -u "$APP_DEST" >/dev/null 2>&1 || true
+ fi
+fi
quit_local_app "$APP_DEST"
mkdir -p "$APP_PARENT"
APP_BACKUP="$APP_DEST.install-backup.$$"
@@ -781,11 +817,17 @@ else
rm -rf "$APP_DEST"
if [ -d "$APP_BACKUP" ]; then
mv "$APP_BACKUP" "$APP_DEST"
+ if [ "$REPLACING_LEGACY_LOCAL" = 1 ]; then
+ restore_retired_local_app "$APP_DEST" "$LEGACY_HELPER_WAS_ENABLED"
+ fi
die "the installed copy did not verify; restored the previous $LOCAL_APP_DIR_NAME."
fi
die "the installed copy did not verify and was removed."
fi
ok "installed $APP_DEST"
+if [ "$REPLACING_LEGACY_LOCAL" = 1 ]; then
+ remove_legacy_local_data >/dev/null
+fi
if [ "$INSTALLED_CLASS" = certificate-backed ]; then
ok "signature: certificate-backed, the same on every rebuild"
fi
@@ -796,6 +838,12 @@ if [ -x "$LSREGISTER" ]; then
"$LSREGISTER" -f "$APP_DEST" >/dev/null 2>&1 || true
fi
reset_spaces_local_tcc "$PREVIOUS_REQUIREMENT" "$INSTALLED_REQUIREMENT"
+# The old app's helper login item was enabled and was unregistered above: enable
+# the renamed app's (the same label), so the host is back at the next login
+# whether or not the app is opened now.
+if [ "$LEGACY_HELPER_WAS_ENABLED" = 1 ]; then
+ register_local_helper "$APP_DEST" "the new app"
+fi
# --- The CLI -----------------------------------------------------------------------
diff --git a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
index 64b7fe51a7..ab1957297b 100755
--- a/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
+++ b/apps/cua-spaces-macos/scripts/tests/install-local-test.sh
@@ -86,8 +86,15 @@ WEB_LOG="$WORK/web.log"
cat > "$WORK/stub.c" <<'EOF'
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
int main(int argc, char **argv) {
const char *log = getenv("STUB_LOG");
+ // `CuaSpacesMac --service-helper status`: the login item is registered
+ // (STUB_HELPER_STATUS=not-registered: it is not).
+ if (argc >= 3 && strcmp(argv[1], "--service-helper") == 0 && strcmp(argv[2], "status") == 0) {
+ const char *status = getenv("STUB_HELPER_STATUS");
+ printf("{\"status\":\"%s\"}\n", status ? status : "enabled");
+ }
FILE *f = log ? fopen(log, "a") : NULL;
if (f) {
const char *channel = getenv("CUA_CHANNEL");
@@ -116,7 +123,7 @@ set -euo pipefail
echo "$*" >> "$FAKE_BUILD_LOG"
[ "$1" = --channel ] && [ "$2" = local ] || { echo "fake build-app.sh: expected --channel local" >&2; exit 2; }
out="$4"
-id="${FAKE_BUILD_ID:-com.trycua.spaces.local}"
+id="${FAKE_BUILD_ID:-com.trycua.spaces.macos.local}"
name="${FAKE_BUILD_APP_NAME:-Cua Spaces Local}"
scheme="${FAKE_BUILD_SCHEME:-cua-local}"
helper="${FAKE_BUILD_HELPER_LABEL:-com.trycua.spaces.local.helper}"
@@ -177,12 +184,18 @@ cat > "$app/Contents/Info.plist" <<PLIST
$feed
</dict></plist>
PLIST
+# launchd takes AssociatedBundleIdentifiers as an array or as one string.
+if [ "${FAKE_BUILD_ASSOCIATED_SCALAR:-0}" = 1 ]; then
+ assoc_xml="<key>AssociatedBundleIdentifiers</key><string>$associated</string>"
+else
+ assoc_xml="<key>AssociatedBundleIdentifiers</key><array><string>$associated</string></array>"
+fi
cat > "$app/Contents/Library/LaunchAgents/$helper.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0"><dict>
<key>Label</key><string>$helper</string>
<key>BundleProgram</key><string>Contents/MacOS/CuaSpacesMac</string>
-<key>AssociatedBundleIdentifiers</key><array><string>$associated</string></array>
+$assoc_xml
</dict></plist>
PLIST
/usr/bin/codesign -s - -f -i "$id" "$app/Contents/Helpers/cua-spacesd" >/dev/null 2>&1
@@ -448,6 +461,51 @@ LOCAL_APP="$FAKE_HOME/Applications/Cua Spaces Local.app"
LOCAL_CLI="$FAKE_HOME/.local/bin/cua-local"
installed_id() { /usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$1/Contents/Info.plist" 2>/dev/null; }
+# The old Cua Spaces Local, as its first builds (bundle id com.trycua.spaces.local,
+# before the rename to com.trycua.spaces.macos.local) left it. make_legacy_data is
+# what it keeps in ~/Library; make_legacy_local adds the app at the Local path
+# (signed, as every build is), the sign-in and the Local volume.
+LEGACY_ID=com.trycua.spaces.local
+make_legacy_data() {
+ mkdir -p "$FAKE_HOME/Library/Application Support/$LEGACY_ID" "$FAKE_HOME/Library/Preferences" \
+ "$FAKE_HOME/Library/Caches/$LEGACY_ID" "$FAKE_HOME/Library/HTTPStorages/$LEGACY_ID" "$FAKE_HOME/Library/WebKit/$LEGACY_ID" \
+ "$FAKE_HOME/Library/Cookies" "$FAKE_HOME/Library/Saved Application State/$LEGACY_ID.savedState"
+ echo '{}' > "$FAKE_HOME/Library/Application Support/$LEGACY_ID/settings.json"
+ echo '<plist/>' > "$FAKE_HOME/Library/Preferences/$LEGACY_ID.plist"
+ echo 'cache' > "$FAKE_HOME/Library/Caches/$LEGACY_ID/Cache.db"
+ echo 'http' > "$FAKE_HOME/Library/HTTPStorages/$LEGACY_ID/httpstorages.sqlite"
+ echo 'web' > "$FAKE_HOME/Library/WebKit/$LEGACY_ID/data"
+ echo 'cookies' > "$FAKE_HOME/Library/Cookies/$LEGACY_ID.binarycookies"
+ echo 'state' > "$FAKE_HOME/Library/Saved Application State/$LEGACY_ID.savedState/windows.plist"
+}
+legacy_data_gone() {
+ [ ! -e "$FAKE_HOME/Library/Application Support/$LEGACY_ID" ] && [ ! -e "$FAKE_HOME/Library/Preferences/$LEGACY_ID.plist" ] \
+ && [ ! -e "$FAKE_HOME/Library/Caches/$LEGACY_ID" ] && [ ! -e "$FAKE_HOME/Library/HTTPStorages/$LEGACY_ID" ] \
+ && [ ! -e "$FAKE_HOME/Library/WebKit/$LEGACY_ID" ] && [ ! -e "$FAKE_HOME/Library/Cookies/$LEGACY_ID.binarycookies" ] \
+ && [ ! -e "$FAKE_HOME/Library/Saved Application State/$LEGACY_ID.savedState" ]
+}
+make_legacy_local() {
+ local d="$LOCAL_APP/Contents"
+ mkdir -p "$d/MacOS" "$FAKE_HOME/.cua-local/helper" "$FAKE_HOME/Cua Volume Local"
+ cp "$STUB_BIN" "$d/MacOS/CuaSpacesMac"
+ cat > "$d/Info.plist" <<PLIST
+<?xml version="1.0" encoding="UTF-8"?>
+<plist version="1.0"><dict>
+<key>CFBundleExecutable</key><string>CuaSpacesMac</string>
+<key>CFBundleIdentifier</key><string>$LEGACY_ID</string>
+<key>CFBundleName</key><string>Cua Spaces Local</string>
+<key>CFBundlePackageType</key><string>APPL</string>
+<key>CFBundleVersion</key><string>1</string>
+<key>CuaChannel</key><string>local</string>
+</dict></plist>
+PLIST
+ /usr/bin/codesign -s - -f -i "$LEGACY_ID" "$LOCAL_APP" >/dev/null 2>&1
+ echo '{"session":"local"}' > "$FAKE_HOME/.cua-local/credentials.json"
+ echo '{"label":"com.trycua.spaces.local.helper"}' > "$FAKE_HOME/.cua-local/helper/service.json"
+ echo 'my local files' > "$FAKE_HOME/Cua Volume Local/note.txt"
+ make_legacy_data
+}
+
# Every added path must be inside the Local app or be `cua-local`; nothing may
# be removed or changed. Compares two snap_all outputs.
only_local_additions() {
@@ -469,7 +527,7 @@ if [ -f "$CHANNEL_RS" ]; then
done < <(
# shellcheck disable=SC1091
. "$SCRIPTS_DIR/_local-common.sh"
- printf '%s\n' "$LOCAL_BUNDLE_ID" "$LOCAL_APP_DIR_NAME" "$LOCAL_CLI_NAME" "$LOCAL_URL_SCHEME" \
+ printf '%s\n' "$LOCAL_BUNDLE_ID" "$LOCAL_LEGACY_BUNDLE_ID" "$LOCAL_APP_DIR_NAME" "$LOCAL_CLI_NAME" "$LOCAL_URL_SCHEME" \
"$LOCAL_HOME_DIR_NAME" "$LOCAL_APP_SUPPORT_DIR_NAME" "$LOCAL_HELPER_LABEL" "$LOCAL_HOST_LABEL" \
"$LOCAL_VOLUME_NAME" "$LOCAL_LUME_BIN_NAME" "$LOCAL_LUME_DIR_NAME" "${LOCAL_KEYCHAIN_SERVICES[@]}" \
"$STABLE_BUNDLE_ID" "$STABLE_URL_SCHEME" "$STABLE_HELPER_LABEL" "$STABLE_APP_PARENT" \
@@ -490,10 +548,10 @@ install
check "install-local.sh succeeds (status $RC)" '[ "$RC" = 0 ]'
[ "$RC" = 0 ] || note "$OUT"
check "builds with --channel local debug <out>" 'grep >/dev/null -- "^--channel local debug " "$BUILD_LOG"'
-check "the app is ~/Applications/Cua Spaces Local.app with the Local bundle id" '[ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.local ]'
+check "the app is ~/Applications/Cua Spaces Local.app with the Local bundle id" '[ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.macos.local ]'
check "the signature verifies (deep, strict)" '/usr/bin/codesign --verify --deep --strict "$LOCAL_APP" 2>/dev/null'
check "nested code was re-signed with the app's identity (cua-spacesd keeps its identifier)" \
- '/usr/bin/codesign -dv "$LOCAL_APP/Contents/Helpers/cua-spacesd" 2>&1 | grep >/dev/null "^Identifier=com.trycua.spaces.local$"'
+ '/usr/bin/codesign -dv "$LOCAL_APP/Contents/Helpers/cua-spacesd" 2>&1 | grep >/dev/null "^Identifier=com.trycua.spaces.macos.local$"'
check "the nested framework is signed and sealed" '/usr/bin/codesign --verify --strict "$LOCAL_APP/Contents/Frameworks/Fake.framework" 2>/dev/null'
check "cua-local links to the bundled cua" '[ "$(readlink "$LOCAL_CLI")" = "$LOCAL_APP/Contents/MacOS/cua" ]'
check "cua-local runs the bundled cua" 'STUB_LOG="$STUB_LOG" "$LOCAL_CLI" status && grep >/dev/null "cua-local status" "$STUB_LOG"'
@@ -514,7 +572,7 @@ check "a rebuild installs over the Local app (status $RC)" '[ "$RC" = 0 ]'
check "it is the new build" '[ "$(cat "$LOCAL_APP/Contents/Resources/salt.txt")" = 2 ]'
check "no backup is left behind" '! ls "$FAKE_HOME"/Applications/*.install-backup.* >/dev/null 2>&1'
check "an ad hoc cdhash change resets the Local TCC rows, and only those" \
- 'grep >/dev/null "^tccutil reset ScreenCapture com.trycua.spaces.local\$" "$SHIM_LOG" && ! grep "^tccutil" "$SHIM_LOG" | grep -v "com.trycua.spaces.local"'
+ 'grep >/dev/null "^tccutil reset ScreenCapture com.trycua.spaces.macos.local\$" "$SHIM_LOG" && ! grep "^tccutil" "$SHIM_LOG" | grep -v "com.trycua.spaces.macos.local"'
check "Stable files are byte-identical after a rebuild" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
check "nothing but the Local app changed" '[ "$(snap_all | grep -v "Cua Spaces Local.app")" = "$(printf "%s\n" "$ALL_BEFORE" | grep -v "Cua Spaces Local.app")" ]'
@@ -528,7 +586,7 @@ check "without --no-launch the app is opened by its exact path" 'grep >/dev/null
reset_fixture
ALL_BEFORE="$(snap_all)"
install --prefix "$WORK/prefix"
-check "--prefix installs under the prefix (status $RC)" '[ "$RC" = 0 ] && [ "$(installed_id "$WORK/prefix/Applications/Cua Spaces Local.app")" = com.trycua.spaces.local ] && [ -L "$WORK/prefix/.local/bin/cua-local" ]'
+check "--prefix installs under the prefix (status $RC)" '[ "$RC" = 0 ] && [ "$(installed_id "$WORK/prefix/Applications/Cua Spaces Local.app")" = com.trycua.spaces.macos.local ] && [ -L "$WORK/prefix/.local/bin/cua-local" ]'
check "--prefix leaves the whole HOME untouched" '[ "$(snap_all)" = "$ALL_BEFORE" ]'
install --prefix /
check "a prefix that would put the app in /Applications is refused" '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "/Applications"'
@@ -692,6 +750,19 @@ uninstall --yes
check "uninstall-local.sh refuses the same bundle too" '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "refusing to touch"'
check "and removes nothing" '[ "$(snap_all)" = "$ALL_BEFORE" ] && [ -z "$(cat "$SHIM_LOG")" ]'
+# The Local id is Stable's plus ".local": an id that only starts with Stable's
+# (the notch's, com.trycua.spaces.macos.notch) is neither of them.
+reset_fixture
+mkdir -p "$FAKE_HOME/Applications"
+cp -R "$FAKE_HOME/Applications/Cua Spaces.app" "$LOCAL_APP"
+sed -i '' 's#com.trycua.spaces.macos</string>#com.trycua.spaces.macos.notch</string>#' "$LOCAL_APP/Contents/Info.plist"
+ALL_BEFORE="$(snap_all)"
+install
+check "a bundle whose id only starts with the Stable id (.macos.notch) is refused, before anything is built" \
+ '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "refusing to touch" && [ ! -s "$BUILD_LOG" ] && [ "$(snap_all)" = "$ALL_BEFORE" ]'
+uninstall --yes
+check "uninstall-local.sh refuses it too and removes nothing" '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "refusing to touch" && [ "$(snap_all)" = "$ALL_BEFORE" ] && [ -z "$(cat "$SHIM_LOG")" ]'
+
reset_fixture
mkdir -p "$FAKE_HOME/Applications/Cua Spaces Local.app/Contents"
ALL_BEFORE="$(snap_all)"
@@ -710,7 +781,8 @@ for variant in "FAKE_BUILD_ID=com.trycua.spaces.macos|bundle id" \
"FAKE_BUILD_SCHEME=cua|URL scheme" \
"FAKE_BUILD_CHANNEL=stable|CuaChannel" \
"FAKE_BUILD_HELPER_LABEL=com.trycua.spaces.helper|Stable helper label" \
- "FAKE_BUILD_ASSOCIATED=com.trycua.spaces.macos|associated with the Stable app"; do
+ "FAKE_BUILD_ASSOCIATED=com.trycua.spaces.macos|associated with the Stable app" \
+ "FAKE_BUILD_ASSOCIATED_SCALAR=1 FAKE_BUILD_ASSOCIATED=com.trycua.spaces.macos|associated with the Stable app"; do
var="${variant%%|*}"
what="${variant#*|}"
reset_fixture
@@ -721,6 +793,9 @@ for variant in "FAKE_BUILD_ID=com.trycua.spaces.macos|bundle id" \
'[ "$RC" != 0 ] && printf "%s" "$OUT" | grep -i >/dev/null "$what" && [ "$(snap_all)" = "$ALL_BEFORE" ]'
done
reset_fixture
+FAKE_BUILD_ASSOCIATED_SCALAR=1 install
+check "a login item associated with the Local id, as one string or as an array, is accepted (status $RC)" '[ "$RC" = 0 ] && [ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.macos.local ]'
+reset_fixture
ALL_BEFORE="$(snap_all)"
FAKE_BUILD_APP_NAME="Cua Spaces" install
check "a build-app.sh that ignored --channel local (made Cua Spaces.app) is refused" '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "did not build the Local channel" && [ "$(snap_all)" = "$ALL_BEFORE" ]'
@@ -839,6 +914,72 @@ check "the previous Local app is back, byte for byte" '[ "$(snap "Applications/C
check "no backup is left behind" '! ls "$FAKE_HOME"/Applications/*.install-backup.* >/dev/null 2>&1'
check "Stable files are byte-identical after the rollback" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+# --- 5a. The old Local id is replaced -------------------------------------------------------------
+
+echo "== the old Local id is replaced =="
+reset_fixture
+make_legacy_local
+STABLE_BEFORE="$(snap_stable)"
+KEPT_BEFORE="$(snap .cua-local "Cua Volume Local")"
+: > "$SHIM_LOG"; : > "$STUB_LOG"
+install
+check "installing over an app with the old id succeeds (status $RC)" '[ "$RC" = 0 ]'
+[ "$RC" = 0 ] || note "$OUT"
+check "the old id is gone: the app at the Local path has the new Local id" '[ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.macos.local ] && /usr/bin/codesign --verify --deep --strict "$LOCAL_APP" 2>/dev/null'
+check "it says so in one plain line" \
+ '[ "$(printf "%s\n" "$OUT" | grep -c "found the old Cua Spaces Local")" = 1 ] && printf "%s\n" "$OUT" | grep "found the old" | grep >/dev/null "found the old Cua Spaces Local (bundle id com.trycua.spaces.local): replacing it with the renamed app (com.trycua.spaces.macos.local)"'
+check "the old app was asked to unregister its login item, and the new app registers its own (it was enabled)" \
+ 'grep >/dev/null -- "--service-helper unregister \[CUA_CHANNEL=local\]" "$STUB_LOG" && [ "$(grep -n -- "--service-helper unregister" "$STUB_LOG" | head -1 | cut -d: -f1)" -lt "$(grep -n -- "--service-helper register" "$STUB_LOG" | head -1 | cut -d: -f1)" ]'
+check "launchd was asked about the Local helper label only" \
+ '[ "$(grep -c "^launchctl" "$SHIM_LOG")" = 1 ] && grep >/dev/null "bootout gui/[0-9]*/com.trycua.spaces.local.helper$" "$SHIM_LOG"'
+check "LaunchServices forgot the old registration, then registered the new app" \
+ 'grep >/dev/null "^lsregister -u $LOCAL_APP\$" "$SHIM_LOG" && grep >/dev/null "^lsregister -f $LOCAL_APP\$" "$SHIM_LOG"'
+check "the old id's settings, preferences, caches, web view data, cookies and window state are gone" 'legacy_data_gone'
+check "no permission rows were reset (tccutil cannot resolve an app that is gone, so none is attempted)" '! grep >/dev/null "^tccutil" "$SHIM_LOG"'
+check "the sign-in, the helper spec and Cua Volume Local are untouched" '[ "$(snap .cua-local "Cua Volume Local")" = "$KEPT_BEFORE" ]'
+check "Stable files are byte-identical" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+check "no backup is left behind" '! ls "$FAKE_HOME"/Applications/*.install-backup.* >/dev/null 2>&1'
+check "cua-local links to the new app's cua" '[ "$(readlink "$LOCAL_CLI")" = "$LOCAL_APP/Contents/MacOS/cua" ]'
+: > "$SHIM_LOG"; : > "$STUB_LOG"
+install
+check "the next install is a plain rebuild: no migration line, nothing about the old id" \
+ '[ "$RC" = 0 ] && ! printf "%s" "$OUT" | grep >/dev/null "found the old" && ! grep >/dev/null "service-helper" "$STUB_LOG"'
+
+# An old app whose login item was not registered gets none registered for the new one.
+reset_fixture
+make_legacy_local
+: > "$STUB_LOG"
+STUB_HELPER_STATUS=not-registered install
+check "an old Local without a registered login item: replaced, and no login item is registered (status $RC)" \
+ '[ "$RC" = 0 ] && [ "$(installed_id "$LOCAL_APP")" = com.trycua.spaces.macos.local ] && ! grep >/dev/null -- "--service-helper register" "$STUB_LOG"'
+
+# A build that is refused leaves the old app, its settings and its login item alone.
+reset_fixture
+make_legacy_local
+ALL_BEFORE="$(snap_all)"
+: > "$SHIM_LOG"; : > "$STUB_LOG"
+FAKE_BUILD_FEED=1 install
+check "a bad build over the old Local is refused and nothing of the old Local changed" \
+ '[ "$RC" != 0 ] && [ "$(snap_all)" = "$ALL_BEFORE" ] && ! grep >/dev/null "service-helper" "$STUB_LOG" && ! grep >/dev/null "^launchctl\|^tccutil" "$SHIM_LOG"'
+
+# A copy that fails to verify puts the old app back, and its settings were not touched.
+reset_fixture
+make_legacy_local
+: > "$SHIM_LOG"; : > "$STUB_LOG"
+FAKE_BUILD_SALT=3 FAIL_VERIFY_PATH="$LOCAL_APP" install
+check "a copy that does not verify restores the old app (the old id, not the new one)" \
+ '[ "$RC" != 0 ] && printf "%s" "$OUT" | grep >/dev/null "restored the previous" && [ "$(installed_id "$LOCAL_APP")" = "$LEGACY_ID" ] && ! ls "$FAKE_HOME"/Applications/*.install-backup.* >/dev/null 2>&1'
+check "and the old app is known to LaunchServices again and its login item is registered again" \
+ 'grep >/dev/null -- "--service-helper register \[CUA_CHANNEL=local\]" "$STUB_LOG" && [ "$(grep -n "^lsregister -u $LOCAL_APP\$" "$SHIM_LOG" | tail -1 | cut -d: -f1)" -lt "$(grep -n "^lsregister -f $LOCAL_APP\$" "$SHIM_LOG" | tail -1 | cut -d: -f1)" ]'
+check "and the old id's settings are still there" '[ -f "$FAKE_HOME/Library/Application Support/$LEGACY_ID/settings.json" ] && [ -f "$FAKE_HOME/Library/Preferences/$LEGACY_ID.plist" ]'
+
+# Old settings without an old app (it was deleted by hand) are not touched by an install:
+# only the uninstaller cleans them.
+reset_fixture
+make_legacy_data
+install
+check "old-id settings with no old app are left to the uninstaller (status $RC)" '[ "$RC" = 0 ] && ! legacy_data_gone && ! grep >/dev/null "tccutil" "$SHIM_LOG"'
+
# --- 5b. A stalled codesign -----------------------------------------------------------------------
echo "== a codesign that stalls =="
@@ -1083,20 +1224,20 @@ reset_fixture
ALL_BEFORE="$(snap_all)"
STABLE_BEFORE="$(snap_stable)"
install
-mkdir -p "$FAKE_HOME/.cua-local/helper" "$FAKE_HOME/Library/Application Support/com.trycua.spaces.local" "$FAKE_HOME/Cua Volume Local"
+mkdir -p "$FAKE_HOME/.cua-local/helper" "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" "$FAKE_HOME/Cua Volume Local"
echo '{}' > "$FAKE_HOME/.cua-local/helper/service.json"
echo '{}' > "$FAKE_HOME/.cua-local/credentials.json"
-echo '{}' > "$FAKE_HOME/Library/Application Support/com.trycua.spaces.local/settings.json"
+echo '{}' > "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local/settings.json"
echo '<plist/>' > "$FAKE_HOME/Library/LaunchAgents/com.trycua.spacesd.host.local.plist"
# What macOS keeps for the Local bundle id in ~/Library.
-mkdir -p "$FAKE_HOME/Library/Preferences" "$FAKE_HOME/Library/Caches/com.trycua.spaces.local" "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.local" \
- "$FAKE_HOME/Library/WebKit/com.trycua.spaces.local" "$FAKE_HOME/Library/Cookies" "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.local.savedState"
-echo '<plist/>' > "$FAKE_HOME/Library/Preferences/com.trycua.spaces.local.plist"
-echo 'cache' > "$FAKE_HOME/Library/Caches/com.trycua.spaces.local/Cache.db"
-echo 'http' > "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.local/httpstorages.sqlite"
-echo 'web' > "$FAKE_HOME/Library/WebKit/com.trycua.spaces.local/data"
-echo 'cookies' > "$FAKE_HOME/Library/Cookies/com.trycua.spaces.local.binarycookies"
-echo 'state' > "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.local.savedState/windows.plist"
+mkdir -p "$FAKE_HOME/Library/Preferences" "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local" "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.macos.local" \
+ "$FAKE_HOME/Library/WebKit/com.trycua.spaces.macos.local" "$FAKE_HOME/Library/Cookies" "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.macos.local.savedState"
+echo '<plist/>' > "$FAKE_HOME/Library/Preferences/com.trycua.spaces.macos.local.plist"
+echo 'cache' > "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local/Cache.db"
+echo 'http' > "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.macos.local/httpstorages.sqlite"
+echo 'web' > "$FAKE_HOME/Library/WebKit/com.trycua.spaces.macos.local/data"
+echo 'cookies' > "$FAKE_HOME/Library/Cookies/com.trycua.spaces.macos.local.binarycookies"
+echo 'state' > "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.macos.local.savedState/windows.plist"
echo 'mine' > "$FAKE_HOME/Cua Volume Local/keep.txt"
BEFORE_UNINSTALL="$(snap_all)"
: > "$SHIM_LOG"; : > "$STUB_LOG"
@@ -1112,9 +1253,9 @@ STDIN_FILE="$WORK/answer-y"; echo y > "$STDIN_FILE"
uninstall
check "answering y removes Local (status $RC)" '[ "$RC" = 0 ] && [ ! -e "$LOCAL_APP" ] && [ ! -e "$LOCAL_CLI" ] && [ ! -L "$LOCAL_CLI" ]'
STDIN_FILE=/dev/null
-check "the Local home and its app support folder are gone" '[ ! -e "$FAKE_HOME/.cua-local" ] && [ ! -e "$FAKE_HOME/Library/Application Support/com.trycua.spaces.local" ]'
+check "the Local home and its app support folder are gone" '[ ! -e "$FAKE_HOME/.cua-local" ] && [ ! -e "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" ]'
check "the Local bundle id's preferences, caches, web view data, cookies and window state are gone" \
- '[ ! -e "$FAKE_HOME/Library/Preferences/com.trycua.spaces.local.plist" ] && [ ! -e "$FAKE_HOME/Library/Caches/com.trycua.spaces.local" ] && [ ! -e "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.local" ] && [ ! -e "$FAKE_HOME/Library/WebKit/com.trycua.spaces.local" ] && [ ! -e "$FAKE_HOME/Library/Cookies/com.trycua.spaces.local.binarycookies" ] && [ ! -e "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.local.savedState" ]'
+ '[ ! -e "$FAKE_HOME/Library/Preferences/com.trycua.spaces.macos.local.plist" ] && [ ! -e "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/HTTPStorages/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/WebKit/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/Cookies/com.trycua.spaces.macos.local.binarycookies" ] && [ ! -e "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.macos.local.savedState" ]'
check "and Stable's preferences, caches, web view data, cookies and window state of the same kinds are still there" \
'[ -f "$FAKE_HOME/Library/Preferences/com.trycua.spaces.macos.plist" ] && [ -f "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos/Cache.db" ] && [ -f "$FAKE_HOME/Library/WebKit/com.trycua.spaces.macos/data" ] && [ -f "$FAKE_HOME/Library/Cookies/com.trycua.spaces.macos.binarycookies" ] && [ -f "$FAKE_HOME/Library/Saved Application State/com.trycua.spaces.macos.savedState/windows.plist" ]'
check "the Local host runner job file is gone" '[ ! -e "$FAKE_HOME/Library/LaunchAgents/com.trycua.spacesd.host.local.plist" ]'
@@ -1126,6 +1267,33 @@ check "only the Local Keychain services were deleted (both of them)" \
check "the Local volume folder is kept" '[ "$(cat "$FAKE_HOME/Cua Volume Local/keep.txt")" = mine ]'
check "Stable files are byte-identical after uninstall" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+echo "== uninstall and the old Local id =="
+reset_fixture
+make_legacy_local
+STABLE_BEFORE="$(snap_stable)"
+: > "$SHIM_LOG"; : > "$STUB_LOG"
+uninstall --yes
+check "uninstall removes an old-id app at the Local path (status $RC)" '[ "$RC" = 0 ] && [ ! -e "$LOCAL_APP" ] && printf "%s" "$OUT" | grep >/dev/null "found the old"'
+check "the old app unregistered its login item, and launchd was asked about the two Local labels only" \
+ 'grep >/dev/null -- "--service-helper unregister \[CUA_CHANNEL=local\]" "$STUB_LOG" && [ "$(grep -c "^launchctl" "$SHIM_LOG")" = 2 ] && grep >/dev/null "bootout gui/[0-9]*/com.trycua.spaces.local.helper$" "$SHIM_LOG" && grep >/dev/null "bootout gui/[0-9]*/com.trycua.spacesd.host.local$" "$SHIM_LOG"'
+check "its settings, preferences, caches, web view data, cookies and window state are gone" 'legacy_data_gone'
+check "the Local home is gone, Cua Volume Local is kept" '[ ! -e "$FAKE_HOME/.cua-local" ] && [ "$(cat "$FAKE_HOME/Cua Volume Local/note.txt")" = "my local files" ]'
+check "Stable files are byte-identical" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+
+# Both ids' leftovers at once, no app of either (nothing is installed).
+reset_fixture
+make_legacy_data
+mkdir -p "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local"
+echo '{}' > "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local/settings.json"
+echo 'cache' > "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local/Cache.db"
+STABLE_BEFORE="$(snap_stable)"
+: > "$SHIM_LOG"
+uninstall --yes
+check "uninstall removes the leftovers of both ids when no app is installed (status $RC)" \
+ '[ "$RC" = 0 ] && legacy_data_gone && [ ! -e "$FAKE_HOME/Library/Application Support/com.trycua.spaces.macos.local" ] && [ ! -e "$FAKE_HOME/Library/Caches/com.trycua.spaces.macos.local" ]'
+check "and Stable files, whose names the new Local id extends, are byte-identical" '[ "$(snap_stable)" = "$STABLE_BEFORE" ]'
+check "uninstall never resets permission rows (macOS keeps them for a reinstall)" '! grep >/dev/null "^tccutil" "$SHIM_LOG"'
+
echo "== install, then uninstall, leaves the HOME as it was =="
reset_fixture
ALL_BEFORE="$(snap_all)"
diff --git a/apps/cua-spaces-macos/scripts/uninstall-local.sh b/apps/cua-spaces-macos/scripts/uninstall-local.sh
index 0e53f12515..3cab02c133 100755
--- a/apps/cua-spaces-macos/scripts/uninstall-local.sh
+++ b/apps/cua-spaces-macos/scripts/uninstall-local.sh
@@ -23,6 +23,9 @@
# and ~/Library/Application Support/com.trycua.spaces.local
# - what macOS keeps for the Local bundle id under ~/Library: its preferences,
# caches, web view data, cookies and saved window state
+# - the same for the old Local bundle id (com.trycua.spaces.local, before the
+# rename to com.trycua.spaces.macos.local): an app with that id at the Local
+# path and its ~/Library files
# - the Local Keychain items (ai.cua.session.local, ai.cua.session.local.staging)
# - optionally lume-local (libs/lume/scripts/uninstall-local.sh)
# It keeps the Cua Volume Local folder and the permissions macOS granted the
@@ -114,6 +117,7 @@ echo " app: $APP_DEST"
echo " CLI: $CLI_LINK"
echo " state: $LOCAL_HOME and $LOCAL_APP_SUPPORT"
echo " macOS leftovers: the $LOCAL_BUNDLE_ID preferences, caches, web view data and window state in ~/Library"
+echo " (and those of the old id $LOCAL_LEGACY_BUNDLE_ID, if any)"
echo " Keychain items: ${LOCAL_KEYCHAIN_SERVICES[*]}"
if [ "$YES" != 1 ]; then
confirm "Remove them?" || { log "cancelled, nothing was removed"; exit 0; }
@@ -129,14 +133,15 @@ fi
# --- The helper login item and the host runner ------------------------------------
# Only this bundle's own code may unregister its login item, so ask the app
-# (the same call the host setup makes). Without the app, stop the job.
+# (the same call the host setup makes). Without the app, stop the job. An app
+# with the old Local id at this path is handled the same way.
+if is_legacy_local_bundle "$APP_DEST"; then
+ log "found the old ${LOCAL_APP_DIR_NAME%.app} (bundle id $LOCAL_LEGACY_BUNDLE_ID); removing it too"
+fi
if [ -x "$APP_DEST/Contents/MacOS/CuaSpacesMac" ]; then
log "unregistering the helper login item"
- CUA_CHANNEL=local "$APP_DEST/Contents/MacOS/CuaSpacesMac" --service-helper unregister >/dev/null 2>&1 \
- || warn "the app could not unregister its helper; remove $LOCAL_APP_DIR_NAME from System Settings > Login Items if it stays."
fi
-quit_local_app "$APP_DEST"
-launchctl bootout "$GUI_DOMAIN/$LOCAL_HELPER_LABEL" >/dev/null 2>&1 || true
+retire_local_app "$APP_DEST"
# The plain runner (`cua host setup` without the app) has its own Local label.
launchctl bootout "$GUI_DOMAIN/$LOCAL_HOST_LABEL" >/dev/null 2>&1 || true
if [ -f "$HOST_JOB_PLIST" ]; then
@@ -183,7 +188,7 @@ fi
# What macOS keeps for the Local bundle id (every name carries it; Stable's
# folders have its own id and are never listed). The app is stopped above, so
# it cannot write them back.
-for leaf in "${LOCAL_LIBRARY_LEAVES[@]}"; do
+while IFS= read -r leaf; do
case "$leaf" in
*"$LOCAL_BUNDLE_ID"*) ;;
*) die "internal error: $leaf is not a Local path" ;;
@@ -193,7 +198,14 @@ for leaf in "${LOCAL_LIBRARY_LEAVES[@]}"; do
rm -rf "$leftover"
log "removed $leftover"
fi
-done
+done < <(library_leaves "$LOCAL_BUNDLE_ID")
+
+# The old Local bundle id's leftovers, from before the rename: the same kinds
+# of files under the old id (none is a name of the current id or Stable's).
+while IFS= read -r leftover; do
+ [ -n "$leftover" ] || continue
+ log "removed $leftover"
+done < <(remove_legacy_local_data)
# The Keychain tool deletes one item per call and has no wildcard: repeat per
# service (one item per account) until none is left. Local services only.
diff --git a/libs/cua/crates/cua-home/src/channel.rs b/libs/cua/crates/cua-home/src/channel.rs
index 64d1f7d4c8..311667807d 100644
--- a/libs/cua/crates/cua-home/src/channel.rs
+++ b/libs/cua/crates/cua-home/src/channel.rs
@@ -9,7 +9,7 @@
//!
//! | Name | Stable | Local |
//! |-----------------------|-----------------------------------------------|--------------------------------------------------|
-//! | Bundle id | `com.trycua.spaces.macos` (see below) | `com.trycua.spaces.local` |
+//! | Bundle id | `com.trycua.spaces.macos` | `com.trycua.spaces.macos.local` |
//! | App | `/Applications/Cua Spaces.app` | `~/Applications/Cua Spaces Local.app` |
//! | CLI | `~/.local/bin/cua` | `~/.local/bin/cua-local` |
//! | Cua home | `~/.cua` (`envs/staging` below it on staging) | `~/.cua-local` (`envs/prod` below it on prod) |
@@ -23,16 +23,18 @@
//! | URL scheme | `cua://` | `cua-local://` |
//! | Cua Volume | `~/Cua Volume` | `~/Cua Volume Local` |
//! | Lume | `lume`, `com.trycua.lume_daemon`, `:7777`, `~/.lume` | `lume-local`, `com.trycua.lume_daemon.local`, `:7787`, `~/.lume-local` |
-//! | App data | `~/Library/Application Support/com.trycua.spaces.macos` | `.../com.trycua.spaces.local` |
+//! | App data | `~/Library/Application Support/com.trycua.spaces.macos` | `.../com.trycua.spaces.macos.local` |
//! | Agent MCP server | `cua` (launches `cua mcp`) | `cua-local` (launches `cua-local mcp`) |
//! | Agent skills | `cua-spaces`, `cua-volume`, ... | `cua-spaces-local`, `cua-volume-local`, ... |
//!
-//! **Stable bundle id.** Stable is `com.trycua.spaces.macos` today. The
-//! rename to `com.trycua.spaces` is a later, separate change (CUA-1776,
-//! "PR 5": it needs a first-launch migration and makes macOS ask for the
-//! permission grants again). When it lands, [`CuaChannel::bundle_id`] and
-//! [`CuaChannel::app_support_dir_name`] change for Stable here and nowhere
-//! else.
+//! **Bundle ids.** Stable stays `com.trycua.spaces.macos`. Local is that id
+//! plus `.local`, so a future iOS app is `com.trycua.spaces.ios` (and
+//! `.ios.local`) in the same scheme. The `.macos.local` id is a dot extension
+//! of Stable's, so compare ids whole, never by prefix (`starts_with`, a shell
+//! `*id*` pattern): a prefix test would take Local for Stable. Local's first
+//! builds used `com.trycua.spaces.local` ([`CuaChannel::legacy_bundle_id`]);
+//! `install-local.sh` and `uninstall-local.sh` remove what that id left behind.
+//! The launchd ids (helper, host runner, Lume daemon) did not change.
//!
//! # Resolution
//!
@@ -313,13 +315,24 @@ impl CuaChannel {
// ----- the app ---------------------------------------------------------
/// The bundle identifier, which TCC grants and the app's data are keyed
- /// to. Stable is `com.trycua.spaces.macos` for now; it becomes
- /// `com.trycua.spaces` in a later PR (CUA-1776 "PR 5", with a first-launch
- /// migration), so nothing may hard-code it.
+ /// to. Local's is Stable's plus `.local`, which makes it a dot extension
+ /// of Stable's: compare whole ids, never by prefix.
pub fn bundle_id(self) -> &'static str {
match self {
Self::Stable => "com.trycua.spaces.macos",
- Self::Local => "com.trycua.spaces.local",
+ Self::Local => "com.trycua.spaces.macos.local",
+ }
+ }
+
+ /// The bundle identifier this channel used before the current one, which
+ /// the installers move away from: Local's first builds were
+ /// `com.trycua.spaces.local`. Stable has none. Nothing but the install
+ /// and uninstall scripts reads it: they remove the old app and what it
+ /// left in `~/Library`.
+ pub fn legacy_bundle_id(self) -> Option<&'static str> {
+ match self {
+ Self::Stable => None,
+ Self::Local => Some("com.trycua.spaces.local"),
}
}
@@ -342,11 +355,11 @@ impl CuaChannel {
/// The app's folder name below `~/Library/Application Support`.
pub fn app_support_dir_name(self) -> &'static str {
- // The same as the bundle id today (macOS convention), but a
- // separate name: the rename migration moves this folder.
+ // The same as the bundle id (macOS convention), but a separate name
+ // so a later rename of one can move the folder.
match self {
Self::Stable => "com.trycua.spaces.macos",
- Self::Local => "com.trycua.spaces.local",
+ Self::Local => "com.trycua.spaces.macos.local",
}
}
@@ -949,6 +962,7 @@ mod tests {
let s = CuaChannel::Stable;
// The Stable bundle id is renamed to com.trycua.spaces in a later PR.
assert_eq!(s.bundle_id(), "com.trycua.spaces.macos");
+ assert_eq!(s.legacy_bundle_id(), None);
assert_eq!(s.app_name(), "Cua Spaces");
assert_eq!(s.app_path(), Path::new("/Applications/Cua Spaces.app"));
assert_eq!(s.app_support_dir_name(), "com.trycua.spaces.macos");
@@ -996,16 +1010,17 @@ mod tests {
#[test]
fn local_names_are_the_designed_names() {
let l = CuaChannel::Local;
- assert_eq!(l.bundle_id(), "com.trycua.spaces.local");
+ assert_eq!(l.bundle_id(), "com.trycua.spaces.macos.local");
+ assert_eq!(l.legacy_bundle_id(), Some("com.trycua.spaces.local"));
assert_eq!(l.app_name(), "Cua Spaces Local");
assert_eq!(
l.app_path(),
user_home().join("Applications/Cua Spaces Local.app")
);
- assert_eq!(l.app_support_dir_name(), "com.trycua.spaces.local");
+ assert_eq!(l.app_support_dir_name(), "com.trycua.spaces.macos.local");
assert_eq!(
l.app_support_dir(),
- user_home().join("Library/Application Support/com.trycua.spaces.local")
+ user_home().join("Library/Application Support/com.trycua.spaces.macos.local")
);
assert_eq!(l.cli_name(), "cua-local");
assert_eq!(l.cli_path(), user_home().join(".local/bin/cua-local"));
diff --git a/libs/cua/crates/cua-home/tests/channel_isolation_test.rs b/libs/cua/crates/cua-home/tests/channel_isolation_test.rs
index f7dab7735b..a973763294 100644
--- a/libs/cua/crates/cua-home/tests/channel_isolation_test.rs
+++ b/libs/cua/crates/cua-home/tests/channel_isolation_test.rs
@@ -96,6 +96,10 @@ fn identifiers(c: CuaChannel) -> Vec<(String, String)> {
] {
ids.push((format!("agent skill {skill}"), c.skill_install_name(skill)));
}
+ // The bundle id a channel used before, which its installers move from.
+ if let Some(legacy) = c.legacy_bundle_id() {
+ ids.push(("legacy bundle id".to_string(), legacy.to_string()));
+ }
for env in ENVS {
ids.push((
format!("keychain service ({})", env.name()),
@@ -157,6 +161,29 @@ fn stable_and_local_paths_never_overlap() {
}
}
+/// Local's bundle id is Stable's plus `.local`, so a test that takes one
+/// whole id for a prefix of the other would confuse them. The two must stay
+/// different as whole ids, as folder names and as file names in `~/Library`
+/// (`<id>.plist`, `<id>.binarycookies`, `<id>.savedState`).
+#[test]
+fn local_bundle_id_extends_stable_by_a_suffix_and_stays_a_different_name() {
+ let (stable, local) = (
+ CuaChannel::Stable.bundle_id(),
+ CuaChannel::Local.bundle_id(),
+ );
+ assert_eq!(local, format!("{stable}.local"));
+ assert_ne!(stable, local);
+ for ext in ["plist", "binarycookies", "savedState"] {
+ assert_ne!(format!("{stable}.{ext}"), format!("{local}.{ext}"));
+ }
+ // The id Local used before is no extension of Stable's.
+ let legacy = CuaChannel::Local
+ .legacy_bundle_id()
+ .expect("Local has a legacy id");
+ assert!(!legacy.starts_with(stable) && legacy != local);
+ assert_eq!(CuaChannel::Stable.legacy_bundle_id(), None);
+}
+
#[test]
fn local_paths_stay_out_of_the_system_applications_folder() {
let app = CuaChannel::Local.app_path();