Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(scripts): 安装脚本在查版失败和切库失败时不再谎报成功 (#10246)
Br1efx266b69c2868c
diff --git a/scripts/install.sh b/scripts/install.shindex 254d9c3314..59c8d2999a 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -223,22 +223,30 @@ get_selfhost_ref() {checkout_server_ref() {local ref="$1"+ local expected="" head=""+ # Fetch and checkout are best-effort: a missing remote or a shallow clone+ # should not abort here. The comparison below is what decides success.if [ "$ref" = "main" ]; thengit fetch origin main --depth 1 2>/dev/null || truegit checkout --force main 2>/dev/null || truegit reset --hard origin/main 2>/dev/null || true- return+ expected=$(git rev-parse --verify --quiet 'origin/main^{commit}' 2>/dev/null || true)+ else+ git fetch origin --tags --force 2>/dev/null || true+ if git rev-parse --verify --quiet "refs/tags/$ref" >/dev/null; then+ git checkout --force "$ref" 2>/dev/null || git checkout --force "tags/$ref" 2>/dev/null || true+ else+ git fetch origin "$ref" --depth 1 2>/dev/null || true+ git checkout --force "$ref" 2>/dev/null || true+ fi+ expected=$(git rev-parse --verify --quiet "${ref}^{commit}" 2>/dev/null || true)fi- git fetch origin --tags --force 2>/dev/null || true- if git rev-parse --verify --quiet "refs/tags/$ref" >/dev/null; then- git checkout --force "$ref" 2>/dev/null || git checkout --force "tags/$ref" 2>/dev/null || true- return+ head=$(git rev-parse --verify --quiet HEAD 2>/dev/null || true)+ if [ -z "$expected" ] || [ "$expected" != "$head" ]; then+ return 1fi-- git fetch origin "$ref" --depth 1 2>/dev/null || true- git checkout --force "$ref" 2>/dev/null || true}pull_official_selfhost_images() {@@ -274,11 +282,19 @@ install_cli() {local latest_verlatest_ver=$(get_latest_version)+ if [ -z "$latest_ver" ]; then+ # An empty lookup (offline, 500, no redirect) used to fall into the+ # "versions are equal" branch below and print "up to date". The installed+ # CLI still works, so keep it — but say what actually happened.+ warn "Could not determine the latest Multica CLI release; keeping the installed $current_ver. Check your network connection and re-run the installer to upgrade."+ return 0+ fi+# Normalize: strip leading 'v' for comparisonlocal current_cmp="${current_ver#v}"local latest_cmp="${latest_ver#v}"- if [ -z "$latest_ver" ] || [ "$current_cmp" = "$latest_cmp" ]; then+ if [ "$current_cmp" = "$latest_cmp" ]; thenok "Multica CLI is up to date ($current_ver)"return 0fi@@ -357,7 +373,9 @@ setup_server() {cd "$INSTALL_DIR"fi- checkout_server_ref "$server_ref"+ if ! checkout_server_ref "$server_ref"; then+ fail "Could not check out $server_ref at $INSTALL_DIR. Check your network connection and re-run the installer."+ fiok "Repository ready at $INSTALL_DIR ($server_ref)"diff --git a/scripts/install.test.sh b/scripts/install.test.shindex c0f0b1cc72..d410d05472 100644--- a/scripts/install.test.sh+++ b/scripts/install.test.sh@@ -350,8 +350,16 @@ STUBchmod +x "$stub_bin/docker"# git: the installer takes the "existing installation" path, so only the- # fetch/checkout calls run and they are all tolerant of failure.- printf '#!/usr/bin/env bash\nexit 0\n' >"$stub_bin/git"+ # fetch/checkout calls run and they tolerate a failing remote. The installer+ # still verifies that the checkout landed on the requested ref, so rev-parse+ # has to answer consistently: HEAD and origin/main are the same commit here.+ cat >"$stub_bin/git" <<'STUB'+#!/usr/bin/env bash+case "${1:-}" in+ rev-parse) printf '1111111111111111111111111111111111111111\n' ;;+esac+exit 0+STUBchmod +x "$stub_bin/git"# brew: pretend the CLI installs cleanly so the run reaches the summary.@@ -509,10 +517,84 @@ STUBfi}+test_cli_lookup_failure_does_not_claim_up_to_date() {+ local tmp+ tmp="$(mktemp -d)"+ trap 'rm -rf "$tmp"' RETURN++ _setup_server_sandbox "$tmp"+ cp "$tmp/server/.env.example" "$tmp/server/.env"++ # The curl stub answers nothing, so the latest release cannot be determined.+ # The installed CLI still works: the installer must say so instead of the old+ # "Multica CLI is up to date (<old version>)".+ _run_with_server "$tmp" || return 1++ if grep -q "is up to date" "$tmp/install.out"; then+ echo "installer claimed the CLI was up to date without knowing the latest release" >&2+ cat "$tmp/install.out" >&2 || true+ return 1+ fi+ if ! grep -q "Could not determine the latest Multica CLI release" "$tmp/install.out" "$tmp/install.err"; then+ echo "expected an explicit note that the latest CLI release could not be determined" >&2+ cat "$tmp/install.out" >&2 || true+ return 1+ fi+ if ! grep -q "Multica server is running and CLI is ready" "$tmp/install.out"; then+ echo "installer should still finish successfully with the installed CLI" >&2+ cat "$tmp/install.out" >&2 || true+ return 1+ fi+}++test_with_server_fails_when_checkout_does_not_land() {+ local tmp+ tmp="$(mktemp -d)"+ trap 'rm -rf "$tmp"' RETURN++ _setup_server_sandbox "$tmp"+ cp "$tmp/server/.env.example" "$tmp/server/.env"++ # Every git call "succeeds", but HEAD never becomes the requested main. The+ # installer used to print "Repository ready" and continue against whatever+ # commit happened to be checked out.+ cat >"$tmp/stub-bin/git" <<'STUB'+#!/usr/bin/env bash+case "${1:-}" in+ rev-parse)+ case "$*" in+ *origin/main*) printf '2222222222222222222222222222222222222222\n' ;;+ *) printf '3333333333333333333333333333333333333333\n' ;;+ esac+ ;;+esac+exit 0+STUB+ chmod +x "$tmp/stub-bin/git"++ if _run_with_server "$tmp" >/dev/null 2>&1; then+ echo "installer must not report success when the checkout did not land on the requested ref" >&2+ cat "$tmp/install.out" >&2 || true+ return 1+ fi+ if ! grep -q "Could not check out" "$tmp/install.err"; then+ echo "expected an explicit failure about the checkout" >&2+ cat "$tmp/install.err" >&2 || true+ return 1+ fi+ if grep -q "Repository ready" "$tmp/install.out"; then+ echo "installer claimed the repository was ready despite a failed checkout" >&2+ cat "$tmp/install.out" >&2 || true+ return 1+ fi+}+test_brew_install_failure_falls_back_to_release_binarytest_brew_tap_failure_falls_back_to_release_binarytest_remote_ssh_install_prints_token_login_hinttest_local_install_does_not_print_token_login_hinttest_with_server_uses_compose_published_portstest_with_server_fails_when_compose_port_is_unavailable+test_with_server_fails_when_checkout_does_not_land+test_cli_lookup_failure_does_not_claim_up_to_dateecho "install.sh tests passed"