Set up a Mac for a Federated Core, like CoreDesktop's configure
A macOS counterpart of CoreDesktop's configure, with the same drop-in items in configure.d/: - core: Mail, Calendar and Contacts through a configuration profile, Superpanel as an app, Nextcloud files through the Nextcloud app, and Element; with test-and-fix, password change and removal - tailscale: join the Core's network through headscale - backup: restic to Nextcloud through rclone, run by launchd through an app that can be given Full Disk Access - storage: SMB shares mounted the way Finder does, again at login and on network changes - agents, claude, opencode, hermes, sandbox: install the agents and run them in Anthropic's sandbox runtime (Seatbelt on macOS) - ai-servers: LLM servers on this Mac or the network, for the agents Apps and tools macOS lacks are offered for download, checked against their makers' Team IDs and notarization, or published SHA-256 sums. Everything runs on macOS' bash 3.2 with only built-in tools. smoketest/ runs scenarios in fresh macOS VMs with Tart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
# Smoketest
|
||||
|
||||
These tests run `configure`'s pieces on real macOS, in throwaway virtual machines made with [Tart](https://tart.run) on an Apple silicon Mac. They check what can't be checked on Linux:
|
||||
|
||||
- macOS' bash 3.2
|
||||
- JavaScript for Automation, the keychain and `profiles`
|
||||
- `dns-sd`
|
||||
- Seatbelt, which srt's sandbox uses
|
||||
- launchd
|
||||
- Gatekeeper and code signatures
|
||||
- real downloads
|
||||
|
||||
## Running it
|
||||
|
||||
On an Apple silicon Mac:
|
||||
|
||||
```
|
||||
brew install cirruslabs/cli/tart
|
||||
smoketest/run --list # scenarios and their tier
|
||||
smoketest/run # the quick scenarios
|
||||
smoketest/run --tier all # everything, including the big downloads
|
||||
smoketest/run 60-backup # one scenario (or: smoketest/run 60)
|
||||
smoketest/run --keep 50 # leave the VM running afterwards, to look around
|
||||
smoketest/run --image ghcr.io/cirruslabs/macos-sequoia-vanilla:latest # another macOS
|
||||
```
|
||||
|
||||
It tests the working copy as it is, including uncommitted changes. The first run downloads the image, about 25 GB. After that, each scenario takes a minute or two plus its own work. The backup scenario takes a few minutes, and `70-apps` downloads about 400 MB.
|
||||
|
||||
Each run writes its logs to `smoketest/results/<time>/`, one per scenario, and prints which scenarios passed.
|
||||
|
||||
## How it works
|
||||
|
||||
Each scenario runs on a fresh clone of Cirrus Labs' **vanilla** macOS image (default: Tahoe):
|
||||
|
||||
- **What's in it:** macOS as it comes, with auto-login and a user `admin` (password `admin`) who has passwordless sudo.
|
||||
- **Why vanilla:** the "base" images come with Homebrew, Node.js and jq. Those would hide the paths a new Mac takes, where `configure` has to download its tools.
|
||||
- **Gatekeeper:** the vanilla image switches Gatekeeper off, so `70-apps` switches it back on before testing downloads.
|
||||
|
||||
`run` drives each scenario from your Mac:
|
||||
|
||||
1. Clones the image with `tart clone` and starts it with `tart run --no-graphics`.
|
||||
2. Puts a throwaway SSH key in the VM. The password `admin` is entered once, through `SSH_ASKPASS`.
|
||||
3. Copies the working copy to `~/connector` in the VM.
|
||||
4. Runs `lib/runner.sh` with the scenario in the VM's desktop session, through `launchctl asuser`. That is where `configure`'s GUI pieces run on a real Mac: `open`, launchd's gui domain, the unlocked login keychain. An SSH session isn't.
|
||||
5. Stops and deletes the VM, unless `--keep` is given.
|
||||
|
||||
## Scenarios
|
||||
|
||||
| Scenario | Checks |
|
||||
|----------|--------|
|
||||
| `00-environment` | Every script parses with `/bin/bash` 3.2. None uses a tool macOS lacks: no python3, which would start installing the Command Line Tools, and no jq, timeout or mapfile. The macOS tools used are all there. |
|
||||
| `10-configure` | `configure --help`, `--list` (nothing on stderr; agent sign-ins hidden until installed), the menu, and an item's questions |
|
||||
| `20-json-keychain` | `json_get` and `json_edit` through real `osascript`; saving, replacing and deleting keychain secrets |
|
||||
| `30-core-local` | The profile: valid, passwords and names survive escaping, stable payload UUIDs, and the format of `profiles show -output stdout-xml`. Superpanel's app: built, re-signed after the icon changes, and it opens. Element's config, and `nextcloud.cfg` matching |
|
||||
| `40-mdns` | `dns-sd` output comes through a pipe and is stopped on time; the VM finds its own `_ssh._tcp` and resolves its `.local` name |
|
||||
| `50-sandbox` | Node.js and srt download and install. A stand-in agent in the sandbox can't read `~/.ssh` or the keychains, and can't write outside its project. It can use /tmp, mktemp and a pty. It reaches allowed sites only. It reaches a local LLM server only once `ai-servers` allows it. A new zsh finds the sandboxed command first. |
|
||||
| `60-backup` | restic and rclone download. A local WebDAV server stands in for Nextcloud. The Federated Backup app is built and answers whether it has Full Disk Access. launchd runs a backup, a snapshot appears, a file restores from it, and a second run the same day does nothing. Turning backups off removes the app and the job. |
|
||||
| `70-apps` *(all)* | With Gatekeeper on: an un-notarized app is turned down, and a package signed by the wrong Team ID is refused. Element, Nextcloud and Tailscale download and install, and their Team IDs match `apps.sh`. Nextcloud opens with the Core's address. |
|
||||
| `80-storage` | The launchd job is added with the first share and removed with the last; a share whose server can't be reached is skipped quickly without asking |
|
||||
|
||||
## What still needs a person
|
||||
|
||||
macOS deliberately allows these only with a click, so test them by hand on a VM (`--keep`) or a Mac. Each scenario notes which apply to it as a `skip` line.
|
||||
|
||||
- **Installing the profile:** in System Settings > Profiles, choose "Federated Core (...)", then Install. Then check Mail, Calendar and Contacts against a real Core. `configure core` notices the profile was installed.
|
||||
- **Full Disk Access for Federated Backup:** after granting it, `configure backup` says it can read all your files, and the backup log no longer has permission errors for Documents and Desktop.
|
||||
- **Mounting a real SMB share:** the sign-in window, "Remember this password in my keychain", and whether `mount volume "smb://host"` without a share offers a list of shares.
|
||||
- **Tailscale's VPN approval**, and **Nextcloud's sign-in** in the browser.
|
||||
|
||||
## Writing a scenario
|
||||
|
||||
A scenario is a bash file in `scenarios/` that sets `DESCRIPTION` and `TIER`, either `quick` or `all`, and defines `scenario`. It runs in the VM with what `configure` gives items: `CONNECTOR`, `CONF_DIR`, and `confirm` and `confirm_yes`, which always answer yes. So it can source an item and call its functions. Checks, from `lib/runner.sh`:
|
||||
|
||||
| Check | |
|
||||
|-------|---|
|
||||
| `check "what" cmd...` | ok if the command succeeds; otherwise FAIL, with its output |
|
||||
| `check_not "what" cmd...` | ok if the command fails |
|
||||
| `check_eq "what" expected actual` | ok if they're the same |
|
||||
| `skip "why"` | Note something not checked |
|
||||
| `step "what"` | A heading |
|
||||
|
||||
`check` runs its command in a subshell, so variables it sets don't last. Set those before the check.
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Run one smoketest scenario inside the VM (smoketest/run starts
|
||||
# this in the desktop session). Prints ok, FAIL or skip for each
|
||||
# check, and exits 1 if any failed.
|
||||
#
|
||||
# Usage: runner.sh <scenario file>
|
||||
#
|
||||
# A scenario sets DESCRIPTION and TIER and defines `scenario`, which calls the
|
||||
# checks below. It runs with what configure gives items (CONNECTOR, CONF_DIR,
|
||||
# confirm...), answering yes to every question, so it can source items and
|
||||
# call their functions.
|
||||
|
||||
CONNECTOR="$HOME/connector"
|
||||
CONF_DIR="$HOME/Library/Application Support/Federated Connector"
|
||||
COMPUTER="$(scutil --get ComputerName 2> /dev/null || hostname -s)"
|
||||
RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' BOLD=$'\033[1m' RESET=$'\033[0m'
|
||||
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
|
||||
export TMPDIR="${TMPDIR:-$(getconf DARWIN_USER_TEMP_DIR)}"
|
||||
FAILURES=0
|
||||
|
||||
# configure's questions, answered yes; ask takes the default
|
||||
confirm() { echo "$1 [y/N] y"; return 0; }
|
||||
confirm_yes() { echo "$1 [Y/n] y"; return 0; }
|
||||
ask() { printf -v "$1" '%s' "$3"; }
|
||||
|
||||
# wait_until without reading stdin: try every 2 seconds for up to $1
|
||||
wait_until() {
|
||||
local seconds="$1" waited=0
|
||||
shift
|
||||
while [ "$waited" -lt "$seconds" ]; do
|
||||
"$@" && return 0
|
||||
sleep 2
|
||||
waited=$((waited + 2))
|
||||
done
|
||||
"$@"
|
||||
}
|
||||
|
||||
# check <description> <command...>: ok if the command succeeds
|
||||
check() {
|
||||
local description="$1" output
|
||||
shift
|
||||
if output="$("$@" 2>&1)"; then
|
||||
echo "${GREEN}ok$RESET $description"
|
||||
else
|
||||
echo "${RED}FAIL$RESET $description"
|
||||
[ -n "$output" ] && printf '%s\n' "$output" | tail -n 15 | sed 's/^/ /'
|
||||
FAILURES=$((FAILURES + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
# check_not <description> <command...>: ok if the command fails
|
||||
check_not() {
|
||||
local description="$1"
|
||||
shift
|
||||
if "$@" > /dev/null 2>&1; then
|
||||
echo "${RED}FAIL$RESET $description (it succeeded)"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
else
|
||||
echo "${GREEN}ok$RESET $description"
|
||||
fi
|
||||
}
|
||||
|
||||
# check_eq <description> <expected> <actual>
|
||||
check_eq() {
|
||||
if [ "$2" = "$3" ]; then
|
||||
echo "${GREEN}ok$RESET $1"
|
||||
else
|
||||
echo "${RED}FAIL$RESET $1"
|
||||
echo " expected: $2"
|
||||
echo " got: $3"
|
||||
FAILURES=$((FAILURES + 1))
|
||||
fi
|
||||
}
|
||||
|
||||
skip() {
|
||||
echo "${YELLOW}skip$RESET $1"
|
||||
}
|
||||
|
||||
# A step whose output is worth seeing, run as it is
|
||||
step() {
|
||||
echo "-- $*"
|
||||
}
|
||||
|
||||
# The VM's login keychain is open in the desktop session; ssh's wouldn't be
|
||||
security unlock-keychain -p admin "$HOME/Library/Keychains/login.keychain-db" 2> /dev/null
|
||||
|
||||
cd "$HOME" || exit 1
|
||||
# shellcheck disable=SC1090
|
||||
source "$1" || { echo "Couldn't read $1"; exit 1; }
|
||||
echo "$DESCRIPTION"
|
||||
echo "(macOS $(sw_vers -productVersion), $(uname -m))"
|
||||
scenario
|
||||
echo
|
||||
if [ $FAILURES -eq 0 ]; then
|
||||
echo "${GREEN}All checks passed.$RESET"
|
||||
else
|
||||
echo "${RED}$FAILURES check(s) failed.$RESET"
|
||||
exit 1
|
||||
fi
|
||||
Executable
+181
@@ -0,0 +1,181 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Run the smoketest scenarios, each in a fresh macOS VM, with Tart
|
||||
# on an Apple silicon Mac. See README.md.
|
||||
#
|
||||
# Usage: smoketest/run [--image REF] [--tier quick|all] [--keep] [scenario...]
|
||||
# smoketest/run --list
|
||||
#
|
||||
# Runs with the bash macOS comes with (3.2).
|
||||
|
||||
# Wrapped in { ...; exit; } so bash reads the whole script up front
|
||||
{
|
||||
|
||||
SMOKETEST="$(cd "$(dirname "$0")" && pwd)"
|
||||
REPO="$(dirname "$SMOKETEST")"
|
||||
IMAGE="ghcr.io/cirruslabs/macos-tahoe-vanilla:latest"
|
||||
TIER=quick
|
||||
KEEP=0
|
||||
SCENARIOS=()
|
||||
# The vanilla images' user; it has passwordless sudo and logs in by itself
|
||||
VM_USER="admin"
|
||||
VM_PASSWORD="admin"
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
Usage: smoketest/run [options] [scenario...]
|
||||
|
||||
--image REF Tart image to clone (default: $IMAGE)
|
||||
--tier quick|all quick leaves out the slow scenarios (default: quick)
|
||||
--keep Leave each VM running afterwards, to look around in it
|
||||
--list List the scenarios and their tier
|
||||
|
||||
Scenarios are named by file name or number, e.g. 60-backup or 60.
|
||||
EOF
|
||||
}
|
||||
|
||||
scenario_var() {
|
||||
sed -nE "s/^$2=\"?([^\"]*)\"?.*/\\1/p" "$1" | head -n 1
|
||||
}
|
||||
|
||||
list() {
|
||||
local file
|
||||
for file in "$SMOKETEST"/scenarios/*.sh; do
|
||||
printf '%-20s %-6s %s\n' "$(basename "$file" .sh)" "$(scenario_var "$file" TIER)" \
|
||||
"$(scenario_var "$file" DESCRIPTION)"
|
||||
done
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--image) IMAGE="$2"; shift 2 ;;
|
||||
--tier) TIER="$2"; shift 2 ;;
|
||||
--keep) KEEP=1; shift ;;
|
||||
--list) list; exit 0 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
-*) usage; exit 2 ;;
|
||||
*) SCENARIOS+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$(uname -s)" != Darwin ] || [ "$(uname -m)" != arm64 ]; then
|
||||
echo "Tart runs macOS VMs on Apple silicon Macs only."
|
||||
exit 1
|
||||
fi
|
||||
command -v tart > /dev/null || { echo "Tart isn't installed: brew install cirruslabs/cli/tart"; exit 1; }
|
||||
|
||||
# The scenario files to run
|
||||
pick() {
|
||||
local file name want
|
||||
for file in "$SMOKETEST"/scenarios/*.sh; do
|
||||
name="$(basename "$file" .sh)"
|
||||
if [ ${#SCENARIOS[@]} -eq 0 ]; then
|
||||
[ "$TIER" = all ] || [ "$(scenario_var "$file" TIER)" = quick ] || continue
|
||||
echo "$file"
|
||||
else
|
||||
for want in "${SCENARIOS[@]}"; do
|
||||
case "$name" in "$want"|"$want"-*) echo "$file" ;; esac
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
RESULTS="$SMOKETEST/results/$(date +%Y%m%d-%H%M%S)"
|
||||
mkdir -p "$RESULTS"
|
||||
KEY="$RESULTS/id_ed25519"
|
||||
ssh-keygen -q -t ed25519 -N '' -f "$KEY" || exit 1
|
||||
|
||||
# Answers ssh's password question once, to put the key in the VM
|
||||
ASKPASS="$RESULTS/askpass"
|
||||
printf '#!/bin/sh\necho %s\n' "$VM_PASSWORD" > "$ASKPASS"
|
||||
chmod 700 "$ASKPASS"
|
||||
|
||||
SSH_OPTS=(-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR
|
||||
-o ConnectTimeout=5 -o ServerAliveInterval=15)
|
||||
|
||||
vm_ssh() {
|
||||
ssh "${SSH_OPTS[@]}" -i "$KEY" -o BatchMode=yes "$VM_USER@$IP" "$@"
|
||||
}
|
||||
|
||||
# Clone the image, start it and wait until ssh with the key works
|
||||
vm_start() {
|
||||
local name="$1" i
|
||||
echo " Cloning $IMAGE (the first time downloads it, about 25 GB)..."
|
||||
tart clone "$IMAGE" "$name" || return 1
|
||||
tart run --no-graphics "$name" > "$RESULTS/$name.tart.log" 2>&1 &
|
||||
IP="$(tart ip --wait 180 "$name")" || { echo " The VM didn't get an address."; return 1; }
|
||||
for i in $(seq 1 60); do
|
||||
SSH_ASKPASS="$ASKPASS" SSH_ASKPASS_REQUIRE=force DISPLAY=none \
|
||||
ssh "${SSH_OPTS[@]}" -o PubkeyAuthentication=no "$VM_USER@$IP" \
|
||||
'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys' \
|
||||
< "$KEY.pub" 2> /dev/null && break
|
||||
sleep 5
|
||||
done
|
||||
vm_ssh true || { echo " Couldn't ssh to the VM at $IP."; return 1; }
|
||||
# The VM logs in by itself; wait for its desktop session, which the
|
||||
# scenarios run in
|
||||
for i in $(seq 1 60); do
|
||||
vm_ssh 'pgrep -x Dock > /dev/null' && return 0
|
||||
sleep 5
|
||||
done
|
||||
echo " The VM's desktop session didn't start."
|
||||
return 1
|
||||
}
|
||||
|
||||
# The working copy, as it is now, to ~/connector in the VM
|
||||
vm_copy() {
|
||||
COPYFILE_DISABLE=1 tar -C "$REPO" --exclude ./.claude --exclude ./smoketest/results \
|
||||
--exclude ./.git -czf - . | vm_ssh 'rm -rf ~/connector && mkdir ~/connector && tar -xzf - -C ~/connector'
|
||||
}
|
||||
|
||||
# Run in the desktop session (launchctl asuser), as macOS' GUI pieces
|
||||
# (open, launchd's gui domain, Gatekeeper, the keychain) expect, rather than
|
||||
# in ssh's own session
|
||||
vm_scenario() {
|
||||
vm_ssh "sudo launchctl asuser \$(id -u) sudo -u $VM_USER -H /bin/bash ~/connector/smoketest/lib/runner.sh ~/connector/smoketest/scenarios/$1"
|
||||
}
|
||||
|
||||
vm_stop() {
|
||||
local name="$1"
|
||||
if [ $KEEP -eq 1 ]; then
|
||||
echo " Kept $name running at $IP (ssh -i \"$KEY\" $VM_USER@$IP). Afterwards: tart stop $name; tart delete $name"
|
||||
return 0
|
||||
fi
|
||||
tart stop "$name" > /dev/null 2>&1
|
||||
tart delete "$name" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
PASSED=() FAILED=()
|
||||
FILES=()
|
||||
while IFS= read -r file; do
|
||||
FILES+=("$file")
|
||||
done < <(pick)
|
||||
if [ ${#FILES[@]} -eq 0 ]; then
|
||||
echo "No scenarios to run. smoketest/run --list shows them."
|
||||
exit 2
|
||||
fi
|
||||
|
||||
for file in "${FILES[@]}"; do
|
||||
scenario="$(basename "$file" .sh)"
|
||||
name="connector-smoke-$scenario-$$"
|
||||
log="$RESULTS/$scenario.log"
|
||||
echo
|
||||
echo "== $scenario: $(scenario_var "$file" DESCRIPTION)"
|
||||
if vm_start "$name" && vm_copy; then
|
||||
vm_scenario "$(basename "$file")" 2>&1 | tee "$log"
|
||||
status=${PIPESTATUS[0]}
|
||||
else
|
||||
status=1
|
||||
echo " The VM didn't start; see $RESULTS/$name.tart.log" | tee "$log"
|
||||
fi
|
||||
vm_stop "$name"
|
||||
if [ "$status" -eq 0 ]; then PASSED+=("$scenario"); else FAILED+=("$scenario"); fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo "Passed: ${PASSED[*]:-none}"
|
||||
echo "Failed: ${FAILED[*]:-none}"
|
||||
echo "Logs: $RESULTS"
|
||||
[ ${#FAILED[@]} -eq 0 ]
|
||||
exit
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="The scripts parse with macOS' bash 3.2, and the macOS tools they use are there"
|
||||
TIER=quick
|
||||
|
||||
# Patterns, expanded in CONNECTOR
|
||||
SCRIPTS=("configure" "configure.d/*.sh" "configure.d/lib/*.sh" "system/backup" "system/backup-env.sh"
|
||||
"system/storage-mount" "sandbox/agent" "smoketest/run" "smoketest/lib/runner.sh")
|
||||
|
||||
# Commands that macOS doesn't have, or that would start installing the
|
||||
# Command Line Tools if called (python3), outside comments
|
||||
uses_missing_tools() {
|
||||
(cd "$CONNECTOR" && grep -nE '(^|[^#[:alnum:]_-])(python3|jq|gsed|gawk|timeout|realpath|mapfile|readarray|declare -A)([^[:alnum:]_-]|$)' \
|
||||
configure configure.d/*.sh configure.d/lib/*.sh system/backup system/storage-mount sandbox/agent \
|
||||
| grep -vE ':[[:space:]]*#')
|
||||
}
|
||||
|
||||
scenario() {
|
||||
local pattern file tool
|
||||
check_eq "/bin/bash is 3.2" "3.2" "${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}"
|
||||
for pattern in "${SCRIPTS[@]}"; do
|
||||
# shellcheck disable=SC2231
|
||||
for file in "$CONNECTOR"/$pattern; do
|
||||
check "parses: ${file#"$CONNECTOR"/}" /bin/bash -n "$file"
|
||||
done
|
||||
done
|
||||
check_not "no tools macOS doesn't have (python3, jq, timeout, mapfile...)" uses_missing_tools
|
||||
for tool in osascript plutil xmllint security profiles dns-sd sips osacompile codesign \
|
||||
pkgutil spctl hdiutil ditto installer launchctl shasum bunzip2 unzip nc md5 uuidgen \
|
||||
openssl scutil curl diskutil base64; do
|
||||
check "has $tool" command -v "$tool"
|
||||
done
|
||||
if command -v brew > /dev/null || [ -x /opt/homebrew/bin/brew ]; then
|
||||
skip "This image has Homebrew, so the download paths for tools Homebrew already has aren't tested"
|
||||
else
|
||||
check "no Homebrew, as on a new Mac" true
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="configure's menu, --list and an item run on bash 3.2 without errors"
|
||||
TIER=quick
|
||||
|
||||
list_quietly() {
|
||||
local out err
|
||||
err="$("$CONNECTOR/configure" --list 2>&1 > /dev/null < /dev/null)"
|
||||
[ -z "$err" ] || { echo "$err"; return 1; }
|
||||
}
|
||||
|
||||
lists() {
|
||||
"$CONNECTOR/configure" --list < /dev/null | grep -qE "^(to do|done) +$1 "
|
||||
}
|
||||
|
||||
scenario() {
|
||||
check "configure --help" "$CONNECTOR/configure" --help
|
||||
check "configure --list, nothing on stderr" list_quietly
|
||||
for item in core tailscale backup agents ai-servers storage; do
|
||||
check "--list has $item" lists "$item"
|
||||
done
|
||||
check_not "--list leaves out claude, opencode and hermes before they're installed" lists claude
|
||||
check_not "configure <unknown item> fails" "$CONNECTOR/configure" no-such-item
|
||||
check "the menu quits on q" bash -c "echo q | '$CONNECTOR/configure'"
|
||||
check "configure core asks for the Superpanel and rejects an empty one" \
|
||||
bash -c "printf '\n' | '$CONNECTOR/configure' core | grep -q \"That isn't a Superpanel address\""
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="JSON through JavaScript for Automation, and secrets in the login keychain"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/lib/json.sh"
|
||||
source "$CONNECTOR/configure.d/lib/keychain.sh"
|
||||
|
||||
scenario() {
|
||||
local file="$TMPDIR/smoke.json" pass
|
||||
check_eq "json_get reads a value" abc123 \
|
||||
"$(echo '{"ocs":{"data":{"apppassword":"abc123"}}}' | json_get 'd.ocs.data.apppassword')"
|
||||
check_not "json_get fails on false" bash -c "source '$CONNECTOR/configure.d/lib/json.sh'; echo '{\"m\":false}' | json_get d.m"
|
||||
check_not "json_get fails on bad JSON" bash -c "source '$CONNECTOR/configure.d/lib/json.sh'; echo nope | json_get d.m"
|
||||
check_eq "json_get passes arguments as a[]" true \
|
||||
"$(echo '{"x":"a b"}' | json_get 'd.x === a[0]' 'a b')"
|
||||
rm -f "$file"
|
||||
check "json_edit makes a file" json_edit "$file" 'd.k = {"m.x": a[0]};' 'v"1'
|
||||
check_eq "json_edit wrote it" 'v"1' "$(json_get 'd.k["m.x"]' < "$file")"
|
||||
check "json_edit changes it" json_edit "$file" 'd.n = 2;'
|
||||
check_eq "json_edit kept what was there" 'v"1' "$(json_get 'd.k["m.x"]' < "$file")"
|
||||
echo 'not json' > "$file"
|
||||
check_not "json_edit leaves bad JSON alone" json_edit "$file" 'd.n = 3;'
|
||||
check_eq "...and doesn't change it" 'not json' "$(cat "$file")"
|
||||
|
||||
pass="$(openssl rand -base64 24)"
|
||||
check "keychain_save" keychain_save federated-smoke test "$pass"
|
||||
check_eq "keychain_load" "$pass" "$(keychain_load federated-smoke test)"
|
||||
check "keychain_save replaces" keychain_save federated-smoke test abc
|
||||
check_eq "keychain_load gets the new one" abc "$(keychain_load federated-smoke test)"
|
||||
check_not "keychain_save refuses a secret with spaces or quotes" keychain_save federated-smoke bad 'a b"c'
|
||||
check "keychain_delete" keychain_delete federated-smoke test
|
||||
check_eq "it's gone" "" "$(keychain_load federated-smoke test)"
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="The Core item's local parts: the profile, Superpanel's app, Element's and Nextcloud's config"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/10-core.sh"
|
||||
|
||||
superpanel_opens() {
|
||||
open -g -W "$SUPERPANEL_APP"
|
||||
}
|
||||
|
||||
scenario() {
|
||||
local dir file uuid icon
|
||||
CORE_DOMAIN=smoke.invalid CORE_EMAIL=jo@smoke.invalid CORE_NAME='Jo "Q" & <Co>'
|
||||
core_names
|
||||
PASSWORD='p&ss<w>"rd '\''x' APP_PASSWORD=abc123XYZ
|
||||
|
||||
step "Mail settings for a domain without autoconfig"
|
||||
mail_settings
|
||||
check_eq "falls back to the usual IMAP server" "mail.smoke.invalid 993 SSL" "$IMAP_HOST $IMAP_PORT $IMAP_SOCKET"
|
||||
check_eq "...and SMTP" "mail.smoke.invalid 587 STARTTLS" "$SMTP_HOST $SMTP_PORT $SMTP_SOCKET"
|
||||
|
||||
step "The profile"
|
||||
dir="$(mktemp -d)"
|
||||
file="$dir/$PROFILE_NAME.mobileconfig"
|
||||
uuid="$(uuidgen)"
|
||||
check "write_profile, and plutil -lint takes it" write_profile "$file" "mail calendar contacts" "$uuid"
|
||||
check_eq "the mail password survives escaping" "$PASSWORD" \
|
||||
"$(plutil -extract PayloadContent.0.IncomingPassword raw -o - "$file")"
|
||||
check_eq "the name survives escaping" "$CORE_NAME" \
|
||||
"$(plutil -extract PayloadContent.0.EmailAccountName raw -o - "$file")"
|
||||
check_eq "CalDAV payload" com.apple.caldav.account "$(plutil -extract PayloadContent.1.PayloadType raw -o - "$file")"
|
||||
check_eq "CardDAV payload" com.apple.carddav.account "$(plutil -extract PayloadContent.2.PayloadType raw -o - "$file")"
|
||||
check_eq "payload UUIDs stay the same" "$(stable_uuid "$PROFILE_ID.mail")" \
|
||||
"$(plutil -extract PayloadContent.0.PayloadUUID raw -o - "$file")"
|
||||
check "profiles show -output stdout-xml gives a property list" bash -c \
|
||||
"source '$CONNECTOR/configure.d/lib/profile.sh'; profiles_xml | plutil -lint -s -"
|
||||
check_not "profile_installed is false for a profile that isn't" profile_installed "$PROFILE_ID"
|
||||
check "open hands the profile to System Settings" open -g "$file"
|
||||
skip "Installing it needs a click in System Settings: check that by hand (see README)"
|
||||
rm -rf "$dir"
|
||||
|
||||
step "Superpanel's app"
|
||||
SUPERPANEL="https://example.com"
|
||||
SUPERPANEL_APP="$HOME/Applications/Superpanel (smoke).app"
|
||||
check "setup_superpanel" setup_superpanel
|
||||
check "its signature checks out" codesign --verify --deep --strict "$SUPERPANEL_APP"
|
||||
check "it opens" superpanel_opens
|
||||
icon="$TMPDIR/icon.png"
|
||||
check "an icon converts to .icns" bash -c "sips -s format png -z 512 512 \
|
||||
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns \
|
||||
--out '$icon' && sips -s format icns '$icon' --out '$SUPERPANEL_APP/Contents/Resources/applet.icns'"
|
||||
check "re-signed after the icon changes" codesign --force --sign - "$SUPERPANEL_APP"
|
||||
check "...and still checks out" codesign --verify --deep --strict "$SUPERPANEL_APP"
|
||||
check "...and opens" superpanel_opens
|
||||
|
||||
step "Element and Nextcloud"
|
||||
MATRIX="https://matrix.smoke.invalid"
|
||||
check "setup_element writes Element's config" setup_element
|
||||
check_eq "...pointing at the Core" matrix.smoke.invalid \
|
||||
"$(json_get 'd.default_server_config["m.homeserver"].server_name' < "$ELEMENT_CONFIG")"
|
||||
mkdir -p "$(dirname "$NEXTCLOUD_CFG")"
|
||||
printf '[Accounts]\n0\\url=https://nextcloud.smoke.invalid\n' > "$NEXTCLOUD_CFG"
|
||||
check "files_done finds the account in nextcloud.cfg" files_done
|
||||
printf '[Accounts]\n0\\url=https://nextcloud.smoke.invalid.evil\n' > "$NEXTCLOUD_CFG"
|
||||
check_not "...and not another server's" files_done
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="Finding things on the network with dns-sd (the VM announces its own ssh)"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/lib/mdns.sh"
|
||||
|
||||
finds_type() {
|
||||
mdns_types | grep -qx '_ssh._tcp'
|
||||
}
|
||||
|
||||
finds_instance() {
|
||||
[ -n "$(mdns_instances _ssh._tcp)" ]
|
||||
}
|
||||
|
||||
resolves_own_host() {
|
||||
mdns_services _ssh._tcp | cut -d'|' -f3 | grep -qixF "$(mdns_own_host)"
|
||||
}
|
||||
|
||||
quick_enough() {
|
||||
local start=$SECONDS
|
||||
run_for 2 dns-sd -B _ssh._tcp local. > /dev/null
|
||||
[ $((SECONDS - start)) -le 4 ]
|
||||
}
|
||||
|
||||
scenario() {
|
||||
step "Remote Login is on in the VM, so it announces _ssh._tcp"
|
||||
check "run_for stops dns-sd on time" quick_enough
|
||||
check "mdns_types lists _ssh._tcp (dns-sd's output comes through a pipe)" finds_type
|
||||
check "mdns_instances lists the VM's ssh" finds_instance
|
||||
check "mdns_services resolves it to this Mac's .local name ($(mdns_own_host))" resolves_own_host
|
||||
check "mdns_hosts runs (and leaves this Mac out)" bash -c \
|
||||
"source '$CONNECTOR/configure.d/lib/mdns.sh'; ! mdns_hosts | grep -qixF \"\$(mdns_own_host)\""
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="Installs Node.js and srt, and the sandbox keeps a (fake) agent in: files, network, local servers"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/30-agents.sh"
|
||||
source "$CONNECTOR/configure.d/50-ai-servers.sh"
|
||||
PROJECT="$HOME/proj"
|
||||
|
||||
# Run a command as the "opencode" agent, in the sandbox, from a project
|
||||
sandboxed() {
|
||||
(cd "$PROJECT" && "$CONNECTOR/sandbox/bin/opencode" "$@")
|
||||
}
|
||||
|
||||
fetch() {
|
||||
sandboxed /usr/bin/curl -fsS -o /dev/null --max-time 20 "$1"
|
||||
}
|
||||
|
||||
zsh_finds_sandboxed() {
|
||||
[ "$(zsh -ic 'command -v opencode' 2> /dev/null)" = "$CONNECTOR/sandbox/bin/opencode" ]
|
||||
}
|
||||
|
||||
scenario() {
|
||||
local node server
|
||||
step "Installing Node.js and srt"
|
||||
check "tool_ensure node srt" tool_ensure node srt
|
||||
check "Node.js is 22.12 or later" node_ok
|
||||
check "srt is found" srt_path
|
||||
|
||||
# The agent is a stand-in that runs what it's given, so commands can be
|
||||
# tried in its sandbox
|
||||
mkdir -p "$HOME/.local/bin" "$PROJECT" "$HOME/.ssh"
|
||||
printf '#!/bin/bash\nexec "$@"\n' > "$HOME/.local/bin/opencode"
|
||||
chmod +x "$HOME/.local/bin/opencode"
|
||||
echo secret > "$HOME/.ssh/smoke-secret"
|
||||
|
||||
step "Files"
|
||||
check "the agent runs in the sandbox" sandboxed /usr/bin/true
|
||||
check_not "it can't read ~/.ssh" sandboxed /bin/cat "$HOME/.ssh/smoke-secret"
|
||||
check_not "it can't read the keychains" sandboxed /bin/ls "$HOME/Library/Keychains"
|
||||
check "it can write in its project" sandboxed /usr/bin/touch "$PROJECT/written"
|
||||
check_not "it can't write elsewhere in your home folder" sandboxed /usr/bin/touch "$HOME/outside"
|
||||
check "it can write in /tmp" sandboxed /usr/bin/touch /tmp/smoke-written
|
||||
check "it can make temp files (mktemp)" sandboxed /usr/bin/mktemp
|
||||
check "it can open a pty (allowPty)" sandboxed /usr/bin/script -q /dev/null /usr/bin/true
|
||||
check_not "it won't start in your home folder" bash -c "cd ~ && '$CONNECTOR/sandbox/bin/opencode' /usr/bin/true"
|
||||
check "unsandboxed runs it outside" bash -c "cd '$PROJECT' && '$CONNECTOR/sandbox/bin/unsandboxed' opencode /bin/cat '$HOME/.ssh/smoke-secret'"
|
||||
|
||||
step "Network"
|
||||
check "it reaches an allowed site (registry.npmjs.org)" fetch https://registry.npmjs.org/
|
||||
check_not "it doesn't reach others (example.com)" fetch https://example.com/
|
||||
|
||||
step "An LLM server on this Mac"
|
||||
node="$(tool_path node)"
|
||||
"$node" -e 'require("http").createServer((q, s) => { s.setHeader("content-type", "application/json");
|
||||
s.end(JSON.stringify({data: [{id: "smoke-model"}]})); }).listen(11434, "127.0.0.1")' &
|
||||
server=$!
|
||||
sleep 2
|
||||
check_eq "server_models reads its models" smoke-model "$(server_models localhost:11434)"
|
||||
check_not "the agent can't reach it before it's allowed" fetch http://localhost:11434/v1/models
|
||||
check "sandbox_allow localhost:11434" sandbox_allow localhost:11434
|
||||
check "...then it can, through srt's proxy" fetch http://localhost:11434/v1/models
|
||||
check "sandbox_disallow" sandbox_disallow localhost:11434
|
||||
check_not "...then it can't again" fetch http://localhost:11434/v1/models
|
||||
kill "$server" 2> /dev/null
|
||||
|
||||
step "Shell and Claude Code"
|
||||
check "put_on_path" put_on_path
|
||||
check "a new zsh finds sandbox/bin's opencode first" zsh_finds_sandboxed
|
||||
check "turn_on_claude_sandbox" turn_on_claude_sandbox
|
||||
check "Claude Code's sandbox is on" claude_sandbox_on
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="Backup end to end: restic and rclone, the app, launchd, the keychain, a snapshot and a restore"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/20-backup.sh"
|
||||
DAV="$HOME/davroot"
|
||||
SMOKE_FILE="$HOME/Documents/smoke-file.txt"
|
||||
|
||||
ran() {
|
||||
grep -qE 'Backup (finished|failed)' "$BACKUP_LOG" 2> /dev/null
|
||||
}
|
||||
|
||||
finished() {
|
||||
grep -q 'Backup finished' "$BACKUP_LOG" || { tail -n 30 "$BACKUP_LOG"; return 1; }
|
||||
}
|
||||
|
||||
has_snapshot() {
|
||||
[ "$(restic snapshots --host smoketest --json | json_get 'd.length')" -ge 1 ]
|
||||
}
|
||||
|
||||
restores() {
|
||||
local target="$TMPDIR/restored"
|
||||
rm -rf "$target"
|
||||
restic restore latest --host smoketest --target "$target" --include "$SMOKE_FILE" > /dev/null \
|
||||
&& cmp "$SMOKE_FILE" "$target$SMOKE_FILE"
|
||||
}
|
||||
|
||||
access_answer() {
|
||||
echo "?" > "$ACCESS_CHECK"
|
||||
open -g -W "$BACKUP_APP"
|
||||
cat "$ACCESS_CHECK"
|
||||
rm -f "$ACCESS_CHECK"
|
||||
}
|
||||
|
||||
scenario() {
|
||||
local pass answer lines DAV_SERVER
|
||||
step "Installing restic and rclone"
|
||||
check "tool_ensure restic rclone" tool_ensure restic rclone
|
||||
export PATH="$TOOLS_PATH:$PATH"
|
||||
|
||||
# A plain WebDAV server stands in for Nextcloud. Without a password, so the
|
||||
# backup's check that Nextcloud is up (status.php) answers.
|
||||
mkdir -p "$DAV" "$(dirname "$SMOKE_FILE")"
|
||||
echo ok > "$DAV/status.php"
|
||||
rclone serve webdav "$DAV" --addr 127.0.0.1:8081 > /dev/null 2>&1 &
|
||||
DAV_SERVER=$!
|
||||
sleep 3
|
||||
date > "$SMOKE_FILE"
|
||||
|
||||
WEBDAV=http://127.0.0.1:8081 BACKUP_DIR=.backup-smoketest
|
||||
mkdir -p "$CONF_DIR"
|
||||
{
|
||||
printf 'BACKUP_WEBDAV=%q\n' "$WEBDAV"
|
||||
printf 'BACKUP_USER=tester\nBACKUP_DIR=%q\nBACKUP_HOST=smoketest\nBACKUP_VENDOR=other\n' "$BACKUP_DIR"
|
||||
} > "$BACKUP_CONF"
|
||||
echo "$DAV" > "$CONF_DIR/backup-exclude"
|
||||
pass="$(openssl rand -base64 24)"
|
||||
check "the app password goes in the keychain" keychain_save "$BACKUP_KEYCHAIN" "nextcloud:$WEBDAV" smokepass
|
||||
check "the passphrase goes in the keychain" keychain_save "$BACKUP_KEYCHAIN" "passphrase:$WEBDAV/$BACKUP_DIR" "$pass"
|
||||
source "$CONNECTOR/system/backup-env.sh"
|
||||
check "backup-env.sh finds the passphrase" test -n "$RESTIC_PASSWORD_COMMAND"
|
||||
check "restic init, through rclone" restic init
|
||||
|
||||
step "The Federated Backup app and its launchd job"
|
||||
check "make_backup_app" make_backup_app
|
||||
check "the app knows which script it runs" backup_app_current
|
||||
check "its signature checks out" codesign --verify --deep --strict "$BACKUP_APP"
|
||||
answer="$(access_answer)"
|
||||
check "started as itself, it says whether it has Full Disk Access" test "$answer" = yes -o "$answer" = no
|
||||
[ "$answer" = no ] && skip "Full Disk Access needs a click in System Settings; this backup leaves protected folders out"
|
||||
touch "$CONF_DIR/backup-last"
|
||||
check "install_job" install_job
|
||||
check "launchd has the job" job_loaded
|
||||
|
||||
step "A backup, started the way configure does"
|
||||
touch "$NOW_REQUEST"
|
||||
launchctl kickstart "gui/$(id -u)/$LABEL"
|
||||
wait_until 900 ran > /dev/null
|
||||
check "it finished" finished
|
||||
check "restic has a snapshot from this Mac" has_snapshot
|
||||
check "a file comes back from it" restores
|
||||
lines="$(wc -l < "$BACKUP_LOG")"
|
||||
launchctl kickstart "gui/$(id -u)/$LABEL"
|
||||
sleep 15
|
||||
check_eq "started again within the day, it does nothing" "$lines" "$(wc -l < "$BACKUP_LOG")"
|
||||
|
||||
step "Turning backups off"
|
||||
stop_backups
|
||||
check_not "launchd no longer has the job" job_loaded
|
||||
check_not "the app is gone" test -e "$BACKUP_APP"
|
||||
kill "$DAV_SERVER" 2> /dev/null
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="Downloads Element, Nextcloud and Tailscale with Gatekeeper on: Team IDs, notarization, refusals"
|
||||
TIER=all
|
||||
|
||||
source "$CONNECTOR/configure.d/lib/json.sh"
|
||||
source "$CONNECTOR/configure.d/lib/apps.sh"
|
||||
|
||||
gatekeeper_on() {
|
||||
spctl --status | grep -q 'assessments enabled'
|
||||
}
|
||||
|
||||
# An app no one notarized: Gatekeeper should turn it down
|
||||
unnotarized_refused() {
|
||||
local app="$TMPDIR/Unnotarized.app"
|
||||
rm -rf "$app"
|
||||
osacompile -o "$app" -e 'return' && codesign --force --sign - "$app" > /dev/null 2>&1 || return 2
|
||||
! spctl --assess --type execute "$app" 2> /dev/null
|
||||
}
|
||||
|
||||
# Tailscale's package, offered as someone else's
|
||||
wrong_team_refused() {
|
||||
local pkg="$TMPDIR/tailscale.pkg"
|
||||
app_info tailscale
|
||||
curl -fsL --max-time 600 -o "$pkg" "$APP_URL" || return 2
|
||||
APP_TEAM=ZZZZZZZZZZ
|
||||
! install_pkg "$pkg"
|
||||
}
|
||||
|
||||
team_of() {
|
||||
codesign -dv "$(app_path "$1")" 2>&1 | sed -n 's/^TeamIdentifier=//p'
|
||||
}
|
||||
|
||||
nextcloud_opens() {
|
||||
open -a "$(app_path nextcloud)" --args --overrideserverurl https://nextcloud.smoke.invalid
|
||||
sleep 10
|
||||
pgrep -x Nextcloud > /dev/null
|
||||
}
|
||||
|
||||
scenario() {
|
||||
local app
|
||||
# The vanilla image turns Gatekeeper off; a real Mac has it on
|
||||
sudo spctl --global-enable 2> /dev/null || sudo spctl --master-enable 2> /dev/null
|
||||
check "Gatekeeper is on" gatekeeper_on
|
||||
gatekeeper_on || { skip "Gatekeeper couldn't be turned on, so the checks below prove less"; }
|
||||
check "Gatekeeper turns down an app no one notarized" unnotarized_refused
|
||||
check "install_pkg refuses a package signed by another Team ID" wrong_team_refused
|
||||
|
||||
for app in element nextcloud tailscale; do
|
||||
step "$app"
|
||||
check "app_install $app (its Team ID and notarization check out)" app_install "$app"
|
||||
app_info "$app"
|
||||
check_eq "$app's Team ID is the one in apps.sh" "$APP_TEAM" "$(team_of "$app")"
|
||||
done
|
||||
check "Nextcloud opens with the Core's address" nextcloud_opens
|
||||
pkill -x Nextcloud 2> /dev/null
|
||||
skip "Tailscale's VPN approval and Nextcloud's sign-in need clicks: check those by hand"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
# shellcheck shell=bash
|
||||
DESCRIPTION="Network storage's launchd job: mounts on login and network changes, skips servers it can't reach"
|
||||
TIER=quick
|
||||
|
||||
source "$CONNECTOR/configure.d/60-storage.sh"
|
||||
UNREACHABLE="smb://smoke@nas.smoke.invalid/files"
|
||||
|
||||
job_loaded() {
|
||||
launchctl print "gui/$(id -u)/$LABEL" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
skips_quickly() {
|
||||
local start=$SECONDS
|
||||
bash "$STORAGE_MOUNT" || return 1
|
||||
[ $((SECONDS - start)) -le 10 ]
|
||||
}
|
||||
|
||||
lists_unmounted() {
|
||||
[ "$(bash "$STORAGE_MOUNT" --list)" = "$UNREACHABLE|" ]
|
||||
}
|
||||
|
||||
scenario() {
|
||||
mkdir -p "$CONF_DIR"
|
||||
: > "$STORAGE_CONF"
|
||||
check "record adds a share and the job" record "$UNREACHABLE" "/Volumes/files"
|
||||
check "launchd has the job" job_loaded
|
||||
check "the plist names the script" plutil -lint "$PLIST"
|
||||
check "a server it can't reach is skipped, quickly and without asking" skips_quickly
|
||||
check "--list shows it as not mounted" lists_unmounted
|
||||
check_not "mounted_at doesn't find it" mounted_at "$UNREACHABLE"
|
||||
check "remove_share" remove_share "$UNREACHABLE"
|
||||
check_not "the job is gone with the last share" job_loaded
|
||||
skip "Mounting a real share needs another machine and the sign-in window: check by hand"
|
||||
}
|
||||
Reference in New Issue
Block a user