Files
multica/scripts/install.test.sh
Bohan Jiang eaf8b14866 fix(installer): post-merge nits from #2881 (MUL-2458) (#2922)
- Capture `brew tap` output and print the same diagnostic tail on
  failure that `brew install` already prints, so #2867-style "no
  signal" reports are gone from both Homebrew failure paths.
- Add a `brew tap` failure regression case to `scripts/install.test.sh`
  and refactor the test runner to share sandbox/curl-stub setup; both
  cases now also assert the diagnostic tail is emitted.
- Move the shell installer test out of the heavy backend job into a
  dedicated `installer` matrix job that runs on `ubuntu-latest` and
  `macos-latest`, since the installer targets macOS/Homebrew and BSD vs
  GNU `tar` / `sed` / `mktemp` differences are the next likely break.
- Surface `MULTICA_INSTALL_DIR`, `MULTICA_BIN_DIR`, and
  `MULTICA_SELFHOST_REF` in `install.sh --help` so `MULTICA_BIN_DIR`
  stops looking like a test-only knob.

Co-authored-by: multica-agent <github@multica.ai>
2026-05-20 15:18:17 +08:00

136 lines
2.9 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# Build a self-contained sandbox with stub `curl` and a tarball that the
# release-binary fallback path will download. Each test supplies its own
# `brew` stub to model a specific Homebrew failure mode.
_setup_sandbox() {
local tmp="$1"
local stub_bin="$tmp/stub-bin"
local install_bin="$tmp/install-bin"
local payload_dir="$tmp/payload"
mkdir -p "$stub_bin" "$install_bin" "$payload_dir"
cat >"$payload_dir/multica" <<'STUB'
#!/usr/bin/env bash
echo "multica v0.3.2 (commit: test)"
STUB
chmod +x "$payload_dir/multica"
tar -czf "$tmp/multica.tar.gz" -C "$payload_dir" multica
cat >"$stub_bin/curl" <<'STUB'
#!/usr/bin/env bash
if [[ "$*" == *"-sI"* ]]; then
printf 'HTTP/2 302\r\nlocation: https://github.com/multica-ai/multica/releases/tag/v0.3.2\r\n'
exit 0
fi
out=""
while [[ $# -gt 0 ]]; do
case "$1" in
-o)
out="$2"
shift 2
;;
*)
shift
;;
esac
done
if [[ -z "$out" ]]; then
echo "stub curl expected -o" >&2
exit 2
fi
cp "$MULTICA_TEST_ARCHIVE" "$out"
STUB
chmod +x "$stub_bin/curl"
}
_run_installer() {
local tmp="$1"
local out="$tmp/install.out"
local err="$tmp/install.err"
if ! PATH="$tmp/stub-bin:$tmp/install-bin:/usr/bin:/bin" \
MULTICA_BIN_DIR="$tmp/install-bin" \
MULTICA_TEST_ARCHIVE="$tmp/multica.tar.gz" \
bash "$ROOT_DIR/scripts/install.sh" >"$out" 2>"$err"; then
echo "install.sh exited non-zero" >&2
cat "$out" >&2 || true
cat "$err" >&2 || true
return 1
fi
if [[ ! -x "$tmp/install-bin/multica" ]]; then
echo "expected fallback binary at $tmp/install-bin/multica" >&2
cat "$out" >&2 || true
cat "$err" >&2 || true
return 1
fi
if ! grep -q "Homebrew output (last 80 lines):" "$err"; then
echo "expected diagnostic tail in stderr" >&2
cat "$err" >&2 || true
return 1
fi
}
test_brew_install_failure_falls_back_to_release_binary() {
local tmp
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' RETURN
_setup_sandbox "$tmp"
cat >"$tmp/stub-bin/brew" <<'STUB'
#!/usr/bin/env bash
case "${1:-}" in
tap)
exit 0
;;
install)
echo "simulated brew install failure" >&2
exit 42
;;
list)
exit 1
;;
*)
exit 0
;;
esac
STUB
chmod +x "$tmp/stub-bin/brew"
_run_installer "$tmp"
}
test_brew_tap_failure_falls_back_to_release_binary() {
local tmp
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' RETURN
_setup_sandbox "$tmp"
cat >"$tmp/stub-bin/brew" <<'STUB'
#!/usr/bin/env bash
case "${1:-}" in
tap)
echo "simulated brew tap failure" >&2
exit 17
;;
*)
echo "brew $* should not be reached after tap failure" >&2
exit 99
;;
esac
STUB
chmod +x "$tmp/stub-bin/brew"
_run_installer "$tmp"
}
test_brew_install_failure_falls_back_to_release_binary
test_brew_tap_failure_falls_back_to_release_binary
echo "install.sh tests passed"