From 1fc6c2e8a79d47b07d64dea6ab701324729cbcd1 Mon Sep 17 00:00:00 2001 From: Ben Firestone Date: Wed, 9 Sep 2026 01:15:01 -0700 Subject: [PATCH 1/4] feat(self): migrate to native selfupdate-go v0.2.0 updates --- README.md | 18 +- cmd/arc/self.go | 25 +- cmd/arc/self_lifecycle.go | 162 ++++++++++ cmd/arc/self_lifecycle_test.go | 259 +++++++++++++++ cmd/arc/self_test.go | 16 +- go.mod | 2 +- go.sum | 4 +- scripts/install.sh | 563 ++++++++------------------------- scripts/install_test.py | 119 +++++++ 9 files changed, 708 insertions(+), 460 deletions(-) create mode 100644 cmd/arc/self_lifecycle.go create mode 100644 cmd/arc/self_lifecycle_test.go create mode 100644 scripts/install_test.py diff --git a/README.md b/README.md index 777e7179..ed11f3bc 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ Key Differences: curl -fsSL https://raw.githubusercontent.com/sentiolabs/arc/main/scripts/install.sh | bash ``` +The bootstrap script verifies the release checksum. If Arc is already installed, +use `arc self update`. The script still accepts `--force` and `--tag=vX.Y.Z` +for reinstalls and updates from older Arc binaries. + ### Linux Packages Download `.deb`, `.rpm`, or `.pkg.tar.zst` (Arch) from the [latest release](https://github.com/sentiolabs/arc/releases/latest). @@ -503,7 +507,19 @@ release tag is preserved for downloads. Older Arc binaries may need a one-time `arc self update --force` when switching from undotted to dotted RC tags. `arc self update` asks for confirmation before installing. Pass `-y` or `--yes` -to skip the prompt in scripts. +to skip the prompt in scripts. Updates use `selfupdate-go` v0.2.0 to download +and verify the release archive, then atomically replace the current executable. +No shell installer, curl, or wget is needed for self-updates. A running local +server is stopped only after verification and restarted using the installed +binary; a stopped server stays stopped. Major/minor updates retain the +pre-update database backup. + +Package-managed binaries (including Homebrew, system packages, and Nix) must be +updated with their package manager. Native updates refuse managed paths and +unwritable installation directories instead of moving Arc to another location. +On macOS, the native installer also performs ad-hoc signing. If the server fails +to restart after a successful update, the command reports that the binary was +updated and instructs you to retry `arc server start`. Nightlies are tagged automatically as `v-nightly.`. The next patch, not the released version, is what makes a nightly sort above the current diff --git a/cmd/arc/self.go b/cmd/arc/self.go index c7ffcb74..c772a766 100644 --- a/cmd/arc/self.go +++ b/cmd/arc/self.go @@ -1,5 +1,5 @@ // Package main provides the self-management commands for the arc CLI, -// delegating update and channel logic to github.com/sentiolabs/go-selfupdate. +// delegating update and channel logic to github.com/sentiolabs/selfupdate-go. package main import ( @@ -11,31 +11,30 @@ import ( "github.com/sentiolabs/arc/internal/project" "github.com/sentiolabs/arc/internal/storage/sqlite" "github.com/sentiolabs/arc/internal/version" - "github.com/sentiolabs/go-selfupdate" - "github.com/sentiolabs/go-selfupdate/cobracmd" + "github.com/sentiolabs/selfupdate-go" + "github.com/sentiolabs/selfupdate-go/cobracmd" "golang.org/x/mod/semver" ) // cliName is the binary name, which is also arc's GitHub repository name. const cliName = "arc" -// installScriptURL is arc's install script, run with --force --tag=. -const installScriptURL = "https://raw.githubusercontent.com/sentiolabs/arc/main/scripts/install.sh" - -// selfCmd is registered by main.go. It is the go-selfupdate command tree with +// selfCmd is registered by main.go. It is the selfupdate-go command tree with // arc's wiring: GitHub releases of sentiolabs/arc, the channel from // ~/.arc/config.toml, and a database backup before a major or minor bump. var selfCmd = cobracmd.New(newSelfUpdater(), cobracmd.WithCheckShorthand("c")) // newSelfUpdater builds arc's updater. func newSelfUpdater() *selfupdate.Updater { + lifecycle := newUpdateLifecycle() return &selfupdate.Updater{ - Name: cliName, - Version: version.Short(), - Source: &selfupdate.GitHubSource{Owner: "sentiolabs", Repo: cliName}, - Store: arcChannelStore(), - Installer: &selfupdate.ScriptInstaller{ScriptURL: installScriptURL}, - PreInstall: preInstallBackup(backupArcDatabase), + Name: cliName, + Version: version.Short(), + Source: &selfupdate.GitHubSource{Owner: "sentiolabs", Repo: cliName}, + Store: arcChannelStore(), + Installer: lifecycle, + PreInstall: lifecycle.preInstall, + PostInstall: lifecycle.postInstall, } } diff --git a/cmd/arc/self_lifecycle.go b/cmd/arc/self_lifecycle.go new file mode 100644 index 00000000..bde50dfa --- /dev/null +++ b/cmd/arc/self_lifecycle.go @@ -0,0 +1,162 @@ +package main + +import ( + "context" + "errors" + "fmt" + "os" + "os/exec" + "path/filepath" + "time" + + "github.com/sentiolabs/selfupdate-go" +) + +const updateRecoveryTimeout = 30 * time.Second + +// updateLifecycle keeps daemon downtime inside the verified installation phase. +// The callbacks also let tests exercise failure recovery without a real daemon. +type updateLifecycle struct { + installer selfupdate.Installer + resolve func() error + running func() bool + stop func(context.Context) error + start func(context.Context) error + backup func(context.Context, string, string) error + restart bool +} + +// newUpdateLifecycle wires the archive installer to the local daemon. +func newUpdateLifecycle() *updateLifecycle { + archive := &selfupdate.ArchiveInstaller{Name: cliName} + lifecycle := &updateLifecycle{ + installer: archive, + running: func() bool { + _, running := isServerRunning() + return running + }, + backup: preInstallBackup(backupArcDatabase), + } + lifecycle.resolve = func() error { + exe, err := os.Executable() + if err != nil { + return fmt.Errorf("locate executable: %w", err) + } + archive.TargetPath, err = filepath.EvalSymlinks(exe) + if err != nil { + return fmt.Errorf("resolve executable: %w", err) + } + // Capture the selected config after Cobra has parsed global flags. + args := []string{} + if configPath != "" { + args = append(args, "--config", configPath) + } + run := func(ctx context.Context, action string) error { + //nolint:gosec // Execute only our own canonical binary with fixed server actions. + cmd := exec.CommandContext(ctx, archive.TargetPath, append(args, "server", action)...) + cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr + return cmd.Run() + } + lifecycle.stop = func(ctx context.Context) error { return run(ctx, "stop") } + lifecycle.start = func(ctx context.Context) error { return run(ctx, "start") } + return nil + } + return lifecycle +} + +// Sweep preserves upstream cleanup even when no newer release is available. +func (l *updateLifecycle) Sweep() error { + if sweeper, ok := l.installer.(selfupdate.Sweeper); ok { + return sweeper.Sweep() + } + return nil +} + +// Prepare resolves the executable before it can become an unlinked inode. +// No daemon operation runs until download and verification have succeeded. +func (l *updateLifecycle) Prepare(ctx context.Context, rel selfupdate.Release) (selfupdate.Staged, error) { + l.restart = false + if l.resolve != nil { + if err := l.resolve(); err != nil { + return nil, err + } + } + staged, err := l.installer.Prepare(ctx, rel) + if err != nil { + return nil, err + } + return &lifecycleStaged{Staged: staged, lifecycle: l}, nil +} + +// preInstall preserves backup policy and verifies that stopping actually worked. +func (l *updateLifecycle) preInstall(ctx context.Context, current, latest string) error { + if err := ctx.Err(); err != nil { + return err + } + if err := l.backup(ctx, current, latest); err != nil { + return err + } + if !l.running() { + return nil + } + // Arm recovery before stopping: cancellation can arrive after the daemon exits. + l.restart = true + if err := l.stop(ctx); err != nil { + return fmt.Errorf("stop server: %w", err) + } + if l.running() { + return errors.New("server is still running after stop; update aborted") + } + return ctx.Err() +} + +func (l *updateLifecycle) postInstall(_ context.Context, _, _ string) error { + // Once replaced, restore service even if the update context was cancelled. + return l.recoverServer() +} + +// restartServer makes a single restoration attempt, avoiding duplicate starts. +func (l *updateLifecycle) restartServer(ctx context.Context) error { + if !l.restart { + return nil + } + l.restart = false + if l.running() { + return nil + } + if err := l.start(ctx); err != nil { + return fmt.Errorf("restart server (run 'arc server start' to retry): %w", err) + } + return nil +} + +// recoverServer bounds service restoration independently of Ctrl-C. +func (l *updateLifecycle) recoverServer() error { + ctx, cancel := context.WithTimeout(context.Background(), updateRecoveryTimeout) + defer cancel() + return l.restartServer(ctx) +} + +// lifecycleStaged restores a stopped daemon even when PreInstall aborts. +// Upstream defers Close immediately after successful preparation. +type lifecycleStaged struct { + selfupdate.Staged + lifecycle *updateLifecycle +} + +// Commit returns both replacement and recovery errors when both fail. +func (s *lifecycleStaged) Commit(ctx context.Context) error { + if err := s.Staged.Commit(ctx); err != nil { + return errors.Join(err, s.lifecycle.recoverServer()) + } + return nil +} + +func (s *lifecycleStaged) Close() error { + // Upstream ignores Close errors, so recovery failure must also be visible. + err := s.lifecycle.recoverServer() + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "Warning: update recovery failed: %v\n", err) + } + return errors.Join(err, s.Staged.Close()) +} diff --git a/cmd/arc/self_lifecycle_test.go b/cmd/arc/self_lifecycle_test.go new file mode 100644 index 00000000..69fee2dd --- /dev/null +++ b/cmd/arc/self_lifecycle_test.go @@ -0,0 +1,259 @@ +package main + +import ( + "archive/tar" + "bytes" + "compress/gzip" + "context" + "crypto/sha256" + "errors" + "fmt" + "io" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "runtime" + "testing" + + "github.com/sentiolabs/selfupdate-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +type stagedFixture struct { + commit func(context.Context) error + close func() error +} + +func (s stagedFixture) Commit(ctx context.Context) error { return s.commit(ctx) } +func (s stagedFixture) Close() error { return s.close() } + +type installerFixture struct { + prepare func(context.Context, selfupdate.Release) (selfupdate.Staged, error) + sweep func() error +} + +func (i installerFixture) Prepare(ctx context.Context, rel selfupdate.Release) (selfupdate.Staged, error) { + return i.prepare(ctx, rel) +} + +func (i installerFixture) Sweep() error { + if i.sweep != nil { + return i.sweep() + } + return nil +} + +type lifecycleScenario struct { + name string + running, prepareFail, stopFail, staysRunning, commitFail, cancel, cancelCommit, restartFail bool + want []string + wantError string +} + +func TestUpdateLifecycle(t *testing.T) { + scenarios := []lifecycleScenario{ + { + name: "running", running: true, + want: []string{"sweep", "prepare", "backup", "stop", "commit", "start", "close"}, + }, + {name: "stopped", want: []string{"sweep", "prepare", "backup", "commit", "close"}}, + { + name: "prepare failure", running: true, prepareFail: true, + want: []string{"sweep", "prepare"}, wantError: "prepare update", + }, + { + name: "stop failure after exit", running: true, stopFail: true, + want: []string{"sweep", "prepare", "backup", "stop", "start", "close"}, wantError: "stop server", + }, + { + name: "still running", running: true, staysRunning: true, + want: []string{"sweep", "prepare", "backup", "stop", "close"}, wantError: "still running", + }, + { + name: "commit failure", running: true, commitFail: true, + want: []string{"sweep", "prepare", "backup", "stop", "commit", "start", "close"}, + wantError: "install update", + }, + { + name: "cancel after stop", running: true, cancel: true, + want: []string{"sweep", "prepare", "backup", "stop", "start", "close"}, wantError: "context canceled", + }, + { + name: "cancel after commit", running: true, cancelCommit: true, + want: []string{"sweep", "prepare", "backup", "stop", "commit", "start", "close"}, + }, + { + name: "restart failure", running: true, restartFail: true, + want: []string{"sweep", "prepare", "backup", "stop", "commit", "start", "close"}, + wantError: "binary was updated", + }, + } + for _, scenario := range scenarios { + t.Run(scenario.name, func(t *testing.T) { runLifecycleScenario(t, scenario) }) + } +} + +func runLifecycleScenario(t *testing.T, scenario lifecycleScenario) { + t.Helper() + var events []string + running := scenario.running + ctx, cancel := context.WithCancel(t.Context()) + defer cancel() + l := fixtureLifecycle(t, scenario, &running, &events, cancel) + u := fixtureUpdater(l, fakeSource{tag: "v1.1.0"}) + err := u.Update(ctx, selfupdate.UpdateOptions{Yes: true}) + if scenario.wantError != "" { + require.ErrorContains(t, err, scenario.wantError) + } else { + require.NoError(t, err) + } + assert.Equal(t, scenario.want, events) + assert.Equal(t, scenario.running && !scenario.restartFail, running) +} + +func fixtureLifecycle(t *testing.T, scenario lifecycleScenario, running *bool, + events *[]string, cancel context.CancelFunc, +) *updateLifecycle { + t.Helper() + l := &updateLifecycle{ + running: func() bool { return *running }, + backup: func(context.Context, string, string) error { *events = append(*events, "backup"); return nil }, + stop: func(context.Context) error { + *events = append(*events, "stop") + *running = scenario.staysRunning + if scenario.cancel { + cancel() + } + if scenario.stopFail { + return errors.New("stop failed") + } + return nil + }, + start: func(ctx context.Context) error { + *events = append(*events, "start") + require.NoError(t, ctx.Err(), "recovery must not inherit cancellation") + if scenario.restartFail { + return errors.New("start failed") + } + *running = true + return nil + }, + } + l.installer = fixtureInstaller(scenario, events, cancel) + return l +} + +func fixtureInstaller(scenario lifecycleScenario, events *[]string, cancel context.CancelFunc) selfupdate.Installer { + return installerFixture{ + sweep: func() error { *events = append(*events, "sweep"); return nil }, + prepare: func(context.Context, selfupdate.Release) (selfupdate.Staged, error) { + *events = append(*events, "prepare") + if scenario.prepareFail { + return nil, errors.New("download failed") + } + return stagedFixture{ + commit: func(context.Context) error { + *events = append(*events, "commit") + if scenario.cancelCommit { + cancel() + } + if scenario.commitFail { + return errors.New("rename failed") + } + return nil + }, + close: func() error { *events = append(*events, "close"); return nil }, + }, nil + }, + } +} + +func fixtureUpdater(l *updateLifecycle, source selfupdate.Source) *selfupdate.Updater { + return &selfupdate.Updater{ + Name: "arc", Version: "v1.0.0", Source: source, Installer: l, + PreInstall: l.preInstall, PostInstall: l.postInstall, Out: io.Discard, + } +} + +func TestArchiveUpdateIntegration(t *testing.T) { + for _, corrupt := range []bool{false, true} { + t.Run(fmt.Sprintf("corrupt=%v", corrupt), func(t *testing.T) { runArchiveScenario(t, corrupt) }) + } +} + +func runArchiveScenario(t *testing.T, corrupt bool) { + t.Helper() + dir := t.TempDir() + target, link := filepath.Join(dir, "arc-real"), filepath.Join(dir, "arc") + require.NoError(t, os.WriteFile(target, []byte("old"), 0o600)) + require.NoError(t, os.Symlink(target, link)) + payload := []byte("new executable") + rel := archiveRelease(t, payload, corrupt) + var events []string + running := true + l := fixtureLifecycle(t, lifecycleScenario{}, &running, &events, func() {}) + l.installer = &selfupdate.ArchiveInstaller{Name: "arc", TargetPath: link, Out: io.Discard} + u := fixtureUpdater(l, releaseFixture{rel}) + err := u.Update(t.Context(), selfupdate.UpdateOptions{Yes: true}) + actual, readErr := os.ReadFile(target) + require.NoError(t, readErr) + if corrupt { + require.Error(t, err) + assert.Equal(t, "old", string(actual)) + assert.Empty(t, events) + } else { + require.NoError(t, err) + assert.Equal(t, payload, actual) + assert.Equal(t, []string{"backup", "stop", "start"}, events) + } + assert.True(t, running) + info, err := os.Lstat(link) + require.NoError(t, err) + assert.NotZero(t, info.Mode()&os.ModeSymlink) +} + +func archiveRelease(t *testing.T, payload []byte, corrupt bool) selfupdate.Release { + t.Helper() + var archive bytes.Buffer + gz := gzip.NewWriter(&archive) + tw := tar.NewWriter(gz) + require.NoError(t, tw.WriteHeader(&tar.Header{Name: "arc", Mode: 0o755, Size: int64(len(payload))})) + _, err := tw.Write(payload) + require.NoError(t, err) + require.NoError(t, tw.Close()) + require.NoError(t, gz.Close()) + name := fmt.Sprintf("arc_1.1.0_%s_%s.tar.gz", runtime.GOOS, runtime.GOARCH) + sum := sha256.Sum256(archive.Bytes()) + if corrupt { + sum[0] ^= 1 + } + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/checksums.txt" { + _, _ = fmt.Fprintf(w, "%x %s\n", sum, name) + } else { + _, _ = w.Write(archive.Bytes()) + } + })) + t.Cleanup(server.Close) + return selfupdate.Release{Tag: "v1.1.0", Assets: []selfupdate.Asset{ + {Name: name, URL: server.URL + "/" + name}, + {Name: "checksums.txt", URL: server.URL + "/checksums.txt"}, + }} +} + +type releaseFixture struct{ release selfupdate.Release } + +func (s releaseFixture) Latest(context.Context) (selfupdate.Release, error) { return s.release, nil } + +func (s releaseFixture) List(context.Context, int) ([]selfupdate.Release, error) { + return []selfupdate.Release{s.release}, nil +} + +func TestPreInstallBackupFailureDoesNotAbort(t *testing.T) { + calls := 0 + hook := preInstallBackup(func() error { calls++; return errors.New("fixture backup failed") }) + require.NoError(t, hook(t.Context(), "v1.0.0", "v1.1.0")) + assert.Equal(t, 1, calls) +} diff --git a/cmd/arc/self_test.go b/cmd/arc/self_test.go index 30b8e329..c03a0850 100644 --- a/cmd/arc/self_test.go +++ b/cmd/arc/self_test.go @@ -6,8 +6,8 @@ import ( "path/filepath" "testing" - "github.com/sentiolabs/go-selfupdate" - "github.com/sentiolabs/go-selfupdate/cobracmd" + "github.com/sentiolabs/selfupdate-go" + "github.com/sentiolabs/selfupdate-go/cobracmd" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -49,9 +49,13 @@ func TestSelfUpdaterWiring(t *testing.T) { require.True(t, ok) assert.Equal(t, "sentiolabs", src.Owner) assert.Equal(t, "arc", src.Repo) - inst, ok := u.Installer.(*selfupdate.ScriptInstaller) + inst, ok := u.Installer.(*updateLifecycle) require.True(t, ok) - assert.Contains(t, inst.ScriptURL, "sentiolabs/arc/main/scripts/install.sh") + archive, ok := inst.installer.(*selfupdate.ArchiveInstaller) + require.True(t, ok) + assert.Equal(t, "arc", archive.Name) + assert.False(t, archive.SkipChecksum) + assert.NotNil(t, u.PostInstall) assert.NotNil(t, u.PreInstall) } @@ -121,10 +125,10 @@ func (f fakeSource) List(context.Context, int) ([]selfupdate.Release, error) { // context it was handed and reports why it stopped. type blockingInstaller struct{ started chan struct{} } -func (b *blockingInstaller) Install(ctx context.Context, _ string) error { +func (b *blockingInstaller) Prepare(ctx context.Context, _ selfupdate.Release) (selfupdate.Staged, error) { close(b.started) <-ctx.Done() - return ctx.Err() + return nil, ctx.Err() } // useFakeSelfCmd swaps rootCmd's real self command for one driving u, so the diff --git a/go.mod b/go.mod index 197813d5..226b6d58 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/labstack/echo/v4 v4.15.0 github.com/oapi-codegen/runtime v1.1.2 github.com/pressly/goose/v3 v3.26.0 - github.com/sentiolabs/go-selfupdate v0.1.2 + github.com/sentiolabs/selfupdate-go v0.2.0 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.9 github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum index cb666f06..7eb241a7 100644 --- a/go.sum +++ b/go.sum @@ -171,8 +171,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sentiolabs/go-selfupdate v0.1.2 h1:YU11mxu2YvB8GSQy0Zag+AgpRWkkXn5bovYOFFscbt8= -github.com/sentiolabs/go-selfupdate v0.1.2/go.mod h1:EWIEmMHrf3qT8mxGo4GkZSlSNvbCrAdPWDthNrgvCiA= +github.com/sentiolabs/selfupdate-go v0.2.0 h1:zh+760Kw2+mxjYI4KSK3Pp20mFb3ivnh1TtM6z5w6aA= +github.com/sentiolabs/selfupdate-go v0.2.0/go.mod h1:j9hPo8QlYVPi8WSpOhh7XdtRhYWMIKdayyp26iNf/1Y= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE= diff --git a/scripts/install.sh b/scripts/install.sh index f5fd70c0..e0139202 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,454 +1,143 @@ #!/usr/bin/env bash -# -# Arc installation script -# Usage: curl -fsSL https://raw.githubusercontent.com/sentiolabs/arc/main/scripts/install.sh | bash -# -# Options: -# --force Force reinstall even if already up-to-date -# - -set -e - -# ============ Configuration ============ +# Bootstrap Arc. Existing installations update with `arc self update`. +# Legacy updaters still call this URL with --force --tag=. +set -euo pipefail REPO="sentiolabs/arc" -BINARY_NAME="arc" FORCE="${FORCE:-false}" TAG="${TAG:-}" -# ============ Output Formatting ============ - -# Detect terminal capabilities -if [[ -t 1 ]] && command -v tput &> /dev/null && [[ $(tput colors 2>/dev/null || echo 0) -ge 8 ]]; then - RED='\033[0;31m' - GREEN='\033[0;32m' - YELLOW='\033[1;33m' - BLUE='\033[0;34m' - BOLD='\033[1m' - DIM='\033[2m' - NC='\033[0m' -else - RED='' - GREEN='' - YELLOW='' - BLUE='' - BOLD='' - DIM='' - NC='' -fi - -log_info() { - echo -e "${BLUE}→${NC} $1" -} - -log_success() { - echo -e "${GREEN}✓${NC} $1" -} - -log_warning() { - echo -e "${YELLOW}!${NC} $1" -} - -log_error() { - echo -e "${RED}✗${NC} $1" >&2 -} - -log_step() { - echo -e "${DIM} $1${NC}" -} - -# ============ Version Detection ============ - -# Get installed arc version -get_installed_version() { - if command -v arc &> /dev/null; then - # arc --version outputs: "arc vX.Y.Z (commit) built date with go" - # Extract just the version - local version_output - version_output=$(arc --version 2>/dev/null || echo "") - echo "$version_output" | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1 - fi -} - -# Normalize version strings for comparison (remove 'v' prefix) -normalize_version() { - echo "$1" | sed 's/^v//' -} - -# Compare versions: returns 0 if equal, 1 if first > second, 2 if first < second -compare_versions() { - local v1 v2 - v1=$(normalize_version "$1") - v2=$(normalize_version "$2") - - if [[ "$v1" == "$v2" ]]; then - return 0 - fi - - # Use sort -V for version comparison if available - if printf '%s\n%s' "$v1" "$v2" | sort -V -C 2>/dev/null; then - return 2 # v1 < v2 - else - return 1 # v1 > v2 - fi -} - -# ============ Platform Detection ============ - -detect_platform() { - local os arch - - case "$(uname -s)" in - Darwin) - os="darwin" - ;; - Linux) - os="linux" - ;; - *) - log_error "Unsupported operating system: $(uname -s)" - exit 1 - ;; - esac - - case "$(uname -m)" in - x86_64|amd64) - arch="amd64" - ;; - aarch64|arm64) - arch="arm64" - ;; - *) - log_error "Unsupported architecture: $(uname -m)" - exit 1 - ;; +usage() { + cat <<'HELP' +Arc Installer +Usage: install.sh [--force|-f] [--tag TAG|--tag=TAG] + +Installs the latest stable release, or a specific --tag. +Existing installations: use arc self update (native, checksum-verified updates). +--force reinstalls; --force and --tag remain supported for older Arc updaters. +FORCE and TAG may also be set as environment variables. +HELP +} +fail() { echo "Error: $*" >&2; exit 1; } +while [[ $# -gt 0 ]]; do + case "$1" in + --force|-f) FORCE=true; shift ;; + --tag) [[ $# -ge 2 && -n "$2" ]] || fail '--tag requires a value'; TAG="$2"; shift 2 ;; + --tag=*) TAG="${1#*=}"; [[ -n "$TAG" ]] || fail '--tag requires a value'; shift ;; + --help|-h) usage; exit 0 ;; + *) fail "Unknown option: $1" ;; esac +done +[[ -z "$TAG" || "$TAG" =~ ^v?[0-9A-Za-z][0-9A-Za-z.+-]*$ ]] || fail 'Invalid release tag' - echo "${os}_${arch}" -} - -# ============ Server Management ============ - -SERVER_WAS_RUNNING="false" - -check_server_running() { - if ! command -v arc &> /dev/null; then - return 1 - fi - arc server status &>/dev/null -} - -stop_existing_server() { - if ! command -v arc &> /dev/null; then - return 0 - fi - - if check_server_running; then - SERVER_WAS_RUNNING="true" - log_step "Stopping arc server..." - if arc server stop 2>/dev/null; then - log_step "Server stopped" - fi - fi - return 0 -} - -restart_server_if_needed() { - if [[ "$SERVER_WAS_RUNNING" == "true" ]]; then - log_step "Restarting arc server..." - if arc server start 2>/dev/null; then - log_step "Server restarted" - fi - fi -} - -# ============ macOS Code Signing ============ - -resign_for_macos() { - local binary_path=$1 - - if [[ "$(uname -s)" != "Darwin" ]]; then - return 0 - fi - - if ! command -v codesign &> /dev/null; then - return 0 - fi - - log_step "Re-signing binary for macOS..." - codesign --remove-signature "$binary_path" 2>/dev/null || true - if codesign --force --sign - "$binary_path" 2>/dev/null; then - log_step "Binary signed" - fi -} - -# ============ Release Asset Check ============ - -release_has_asset() { - local release_json=$1 - local asset_name=$2 - - if echo "$release_json" | grep -Fq "\"name\": \"$asset_name\""; then - return 0 - fi - return 1 -} - -# ============ Installation ============ - -install_from_release() { - local platform=$1 - local installed_version=$2 - local tmp_dir - - tmp_dir=$(mktemp -d) - - local latest_version - local release_json - - if [[ -n "$TAG" ]]; then - # Install a specific version - latest_version="$TAG" - log_info "Installing specific version: ${latest_version}" - local tag_url="https://api.github.com/repos/${REPO}/releases/tags/${TAG}" - - if command -v curl &> /dev/null; then - release_json=$(curl -fsSL "$tag_url" 2>/dev/null) - elif command -v wget &> /dev/null; then - release_json=$(wget -qO- "$tag_url" 2>/dev/null) - else - log_error "Neither curl nor wget found" - rm -rf "$tmp_dir" - return 1 - fi - else - # Fetch latest release - log_info "Checking latest release..." - local latest_url="https://api.github.com/repos/${REPO}/releases/latest" - - if command -v curl &> /dev/null; then - release_json=$(curl -fsSL "$latest_url" 2>/dev/null) - elif command -v wget &> /dev/null; then - release_json=$(wget -qO- "$latest_url" 2>/dev/null) - else - log_error "Neither curl nor wget found" - rm -rf "$tmp_dir" - return 1 - fi - - latest_version=$(echo "$release_json" | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') - fi - - if [[ -z "$latest_version" ]]; then - log_error "Failed to fetch latest version" - rm -rf "$tmp_dir" - return 1 - fi - - # Version comparison (skip for specific tag installs) - if [[ -z "$TAG" ]] && [[ -n "$installed_version" ]] && [[ "$FORCE" != "true" ]]; then - if compare_versions "$installed_version" "$latest_version"; then - log_success "arc ${installed_version} is already up to date" - rm -rf "$tmp_dir" - return 2 # Special return code: already up to date - fi - log_info "Updating arc ${installed_version} → ${latest_version}" - else - log_info "Installing arc ${latest_version}" - fi - - # Download - local archive_name="${BINARY_NAME}_${latest_version#v}_${platform}.tar.gz" - local download_url="https://github.com/${REPO}/releases/download/${latest_version}/${archive_name}" - - if ! release_has_asset "$release_json" "$archive_name"; then - log_error "No prebuilt binary for ${platform}" - rm -rf "$tmp_dir" - return 1 - fi - - log_info "Downloading ${archive_name}..." - cd "$tmp_dir" - - if command -v curl &> /dev/null; then - if ! curl -fsSL --progress-bar -o "$archive_name" "$download_url"; then - log_error "Download failed" - cd - > /dev/null || cd "$HOME" - rm -rf "$tmp_dir" - return 1 - fi - elif command -v wget &> /dev/null; then - if ! wget -q --show-progress -O "$archive_name" "$download_url" 2>/dev/null; then - # Fallback without progress for older wget - if ! wget -q -O "$archive_name" "$download_url"; then - log_error "Download failed" - cd - > /dev/null || cd "$HOME" - rm -rf "$tmp_dir" - return 1 - fi - fi - fi - - # Extract - log_step "Extracting..." - if ! tar -xzf "$archive_name"; then - log_error "Failed to extract archive" - cd - > /dev/null || cd "$HOME" - rm -rf "$tmp_dir" - return 1 - fi - - # Determine install location - local install_dir - if [[ -w /usr/local/bin ]]; then - install_dir="/usr/local/bin" - else - install_dir="$HOME/.local/bin" - mkdir -p "$install_dir" - fi - - # Stop server before replacing binary - stop_existing_server - - # Install - log_step "Installing to ${install_dir}..." - if [[ -w "$install_dir" ]]; then - mv "$BINARY_NAME" "$install_dir/" +installed="$(command -v arc || true)" +if [[ -n "$installed" && "$FORCE" != true && -z "$TAG" ]]; then + echo 'Arc is already installed. Run: arc self update' + exit 0 +fi +case "$(uname -s)" in + Linux) os=linux ;; + Darwin) os=darwin ;; + *) fail 'Supported operating systems: Linux and macOS' ;; +esac +case "$(uname -m)" in + x86_64|amd64) arch=amd64 ;; + aarch64|arm64) arch=arm64 ;; + *) fail 'Supported architectures: amd64 and arm64' ;; +esac + +download() { + if command -v curl >/dev/null 2>&1; then + curl -fsSL "$1" -o "$2" + elif command -v wget >/dev/null 2>&1; then + wget -qO "$2" "$1" else - sudo mv "$BINARY_NAME" "$install_dir/" + fail 'Install curl or wget first' fi - - resign_for_macos "$install_dir/$BINARY_NAME" - - cd - > /dev/null || cd "$HOME" - rm -rf "$tmp_dir" - - log_success "Installed arc ${latest_version} to ${install_dir}/${BINARY_NAME}" - - # Restart server if it was running before update - restart_server_if_needed - - # PATH warning - if [[ ":$PATH:" != *":$install_dir:"* ]]; then - echo "" - log_warning "${install_dir} is not in your PATH" - echo -e " Add to your shell profile: ${BOLD}export PATH=\"\$PATH:$install_dir\"${NC}" - fi - - return 0 -} - -# ============ Verification ============ - -verify_installation() { - if ! command -v arc &> /dev/null; then - return 1 - fi - - echo "" - echo -e "${BOLD}arc${NC} is ready!" - echo "" - arc --version 2>/dev/null || echo "arc (development build)" - echo "" - echo "Get started:" - echo " arc quickstart Quick start guide" - echo " arc init Initialize project" - echo " arc server start Start the server" - echo "" } -# ============ Help ============ - -show_help() { - echo "Arc Installer" - echo "" - echo "Usage: $0 [options]" - echo "" - echo "Options:" - echo " --force Force reinstall even if already up-to-date" - echo " --tag TAG Install a specific version (e.g., v0.2.0-rc.1)" - echo " --help Show this help message" - echo "" - echo "Examples:" - echo " curl -fsSL https://raw.githubusercontent.com/sentiolabs/arc/main/scripts/install.sh | bash" - echo " curl -fsSL ... | bash -s -- --force" - echo " curl -fsSL ... | bash -s -- --tag=v0.2.0-rc.1" - echo "" -} - -# ============ Main ============ - -main() { - # Parse arguments - while [[ $# -gt 0 ]]; do - case "$1" in - --force|-f) - FORCE="true" - shift - ;; - --tag) - TAG="$2" - shift 2 - ;; - --tag=*) - TAG="${1#*=}" - shift - ;; - --help|-h) - show_help - exit 0 - ;; - *) - log_error "Unknown option: $1" - show_help - exit 1 - ;; - esac +# Install beside the existing executable for legacy updates; resolve symlinks. +if [[ -n "$installed" ]]; then + while [[ -L "$installed" ]]; do + link="$(readlink "$installed")" + if [[ "$link" = /* ]]; then installed="$link"; else installed="$(dirname "$installed")/$link"; fi done - - echo "" - echo -e "${BOLD}Arc Installer${NC}" - echo "" - - # Detect platform - local platform - platform=$(detect_platform) - log_step "Platform: ${platform}" - - # Check installed version - local installed_version - installed_version=$(get_installed_version) - if [[ -n "$installed_version" ]]; then - log_step "Installed: ${installed_version}" - fi - - # Install - local result - if install_from_release "$platform" "$installed_version"; then - verify_installation - exit 0 - else - result=$? - if [[ $result -eq 2 ]]; then - # Already up to date - exit 0 + install_dir="$(cd "$(dirname "$installed")" && pwd -P)" + target="$install_dir/$(basename "$installed")" +elif [[ -w /usr/local/bin ]]; then + install_dir=/usr/local/bin + target="$install_dir/arc" +else + install_dir="$HOME/.local/bin" + mkdir -p "$install_dir" + target="$install_dir/arc" +fi +[[ -w "$install_dir" ]] || fail "Not writable: $install_dir. Use your package manager or install to a user-writable directory." + +tmp_dir="$(mktemp -d)" +restart=false +replacement='' +server_running() { + [[ -n "$installed" ]] && "$installed" server status --json 2>/dev/null | grep -Eq '"running"[[:space:]]*:[[:space:]]*true' +} +cleanup() { + result=$? + trap - EXIT + [[ -z "$replacement" ]] || rm -f "$replacement" + rm -rf "$tmp_dir" + if [[ "$restart" == true ]] && ! server_running; then + if ! "$target" server start; then + echo "Error: server restart failed; run '$target server start' to retry" >&2 + result=1 fi fi - - # Installation failed - echo "" - log_error "Installation failed" - echo "" - echo "Manual installation options:" - echo "" - echo " 1. Download from https://github.com/${REPO}/releases/latest" - echo " Extract and move 'arc' to your PATH" - echo "" - echo " 2. Build from source (requires Go 1.26+):" - echo " git clone https://github.com/${REPO}.git" - echo " cd arc && make build" - echo "" - exit 1 + exit "$result" } +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM -main "$@" +if [[ -z "$TAG" ]]; then + download "https://api.github.com/repos/$REPO/releases/latest" "$tmp_dir/release.json" + TAG="$(sed -nE 's/.*"tag_name"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/p' "$tmp_dir/release.json" | head -1)" +fi +[[ -n "$TAG" && "$TAG" =~ ^v?[0-9A-Za-z][0-9A-Za-z.+-]*$ ]] || fail 'Could not resolve release tag' +archive="arc_${TAG#v}_${os}_${arch}.tar.gz" +base="https://github.com/$REPO/releases/download/$TAG" +echo "Downloading Arc $TAG..." +download "$base/$archive" "$tmp_dir/$archive" +download "$base/checksums.txt" "$tmp_dir/checksums.txt" +expected="$(awk -v asset="$archive" '$2 == asset || $2 == "*" asset {print $1}' "$tmp_dir/checksums.txt")" +[[ "$expected" =~ ^[[:xdigit:]]{64}$ ]] || fail "Missing or ambiguous checksum for $archive" +if command -v sha256sum >/dev/null 2>&1; then + actual="$(sha256sum "$tmp_dir/$archive")" +elif command -v shasum >/dev/null 2>&1; then + actual="$(shasum -a 256 "$tmp_dir/$archive")" +else + fail 'Install sha256sum or shasum first' +fi +[[ "${actual%% *}" == "$expected" ]] || fail 'Archive checksum mismatch' +# Extract only the binary, never arbitrary archive paths or links. +tar -xOzf "$tmp_dir/$archive" arc > "$tmp_dir/arc" +[[ -s "$tmp_dir/arc" ]] || fail 'Archive contains no arc binary' +chmod 755 "$tmp_dir/arc" + +# Stage on the target filesystem before stopping the daemon. +replacement="$(mktemp "$install_dir/.arc-install.XXXXXX")" +cp "$tmp_dir/arc" "$replacement" +chmod 755 "$replacement" +if [[ "$os" == darwin ]] && command -v codesign >/dev/null 2>&1; then + codesign --force --sign - "$replacement" +fi +if server_running; then + restart=true + "$installed" server stop + if server_running; then fail 'Server is still running after stop; installation aborted'; fi +fi +mv -f "$replacement" "$target" +replacement='' +echo "Installed Arc $TAG to $target" +if [[ ":$PATH:" != *":$install_dir:"* ]]; then + echo "Add $install_dir to your PATH." +fi +echo 'Get started: arc quickstart' diff --git a/scripts/install_test.py b/scripts/install_test.py new file mode 100644 index 00000000..d5a33221 --- /dev/null +++ b/scripts/install_test.py @@ -0,0 +1,119 @@ +"""Isolated bootstrap/legacy installer checks; no real Arc or daemon is invoked.""" +import hashlib +import io +import os +from pathlib import Path +import shutil +import subprocess +import tarfile +import tempfile +import unittest + +SCRIPT = Path(__file__).with_name("install.sh").resolve() +FAKE_ARC = """#!/bin/sh +case "$2" in + status) printf '{"running":%s}\\n' "$(cat "$FIXTURE/state")" ;; + stop) echo stop >> "$FIXTURE/events"; echo false > "$FIXTURE/state" ;; + start) echo start >> "$FIXTURE/events"; echo true > "$FIXTURE/state" ;; +esac +""" + + +class InstallTest(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name) + self.bin = self.root / "bin" + self.bin.mkdir() + (self.root / "home").mkdir() + (self.root / "tmp").mkdir() + (self.root / "state").write_text("false\n") + (self.root / "events").touch() + self.env = dict(os.environ, PATH=f"{self.bin}:/usr/bin:/bin", + HOME=str(self.root / "home"), FIXTURE=str(self.root), + TMPDIR=str(self.root / "tmp"), FORCE="false", TAG="") + self.write_command("arc", FAKE_ARC) + self.write_command("uname", '#!/bin/sh\ncase "$1" in -s) echo Linux;; -m) echo x86_64;; esac\n') + self.write_command("curl", """#!/bin/sh +url="$2" +out="$4" +echo "$url" >> "$FIXTURE/downloads" +case "$url" in + */latest) echo '{"tag_name":"v1.1.0"}' > "$out" ;; + */checksums.txt) cp "$FIXTURE/checksums.txt" "$out" ;; + *.tar.gz) cp "$FIXTURE/archive.tar.gz" "$out" ;; + *) exit 22 ;; +esac +""") + self.payload = (FAKE_ARC + "# updated\n").encode() + with tarfile.open(self.root / "archive.tar.gz", "w:gz") as archive: + info = tarfile.TarInfo("arc") + info.size = len(self.payload) + info.mode = 0o755 + archive.addfile(info, io.BytesIO(self.payload)) + digest = hashlib.sha256((self.root / "archive.tar.gz").read_bytes()).hexdigest() + (self.root / "checksums.txt").write_text(f"{digest} arc_1.1.0_linux_amd64.tar.gz\n") + + def write_command(self, name, body): + path = self.bin / name + path.write_text(body) + path.chmod(0o755) + + def run_install(self, *args, success=True): + result = subprocess.run(["/bin/bash", str(SCRIPT), *args], env=self.env, + capture_output=True, text=True, timeout=15) + self.assertEqual(result.returncode == 0, success, result.stdout + result.stderr) + self.assertEqual(list((self.root / "tmp").iterdir()), []) + self.assertEqual(list(self.bin.glob(".arc-install.*")), []) + return result + + def test_existing_install_guidance(self): + result = self.run_install() + self.assertIn("arc self update", result.stdout) + self.assertFalse((self.root / "downloads").exists()) + self.assertEqual((self.bin / "arc").read_text(), FAKE_ARC) + + def test_legacy_update_restarts_running_server(self): + (self.root / "state").write_text("true\n") + self.run_install("--force", "--tag=v1.1.0") + self.assertEqual((self.bin / "arc").read_bytes(), self.payload) + self.assertEqual((self.root / "events").read_text(), "stop\nstart\n") + + def test_legacy_update_leaves_stopped_server_stopped(self): + self.env.update(FORCE="true", TAG="v1.1.0") + self.run_install() + self.assertEqual((self.bin / "arc").read_bytes(), self.payload) + self.assertEqual((self.root / "events").read_text(), "") + + def test_checksum_failure(self): + (self.root / "checksums.txt").write_text("0" * 64 + " arc_1.1.0_linux_amd64.tar.gz\n") + self.run_install("--tag", "v1.1.0", success=False) + self.assertEqual((self.bin / "arc").read_text(), FAKE_ARC) + self.assertEqual((self.root / "events").read_text(), "") + + def test_missing_asset(self): + (self.root / "archive.tar.gz").unlink() + self.run_install("--force", success=False) + self.assertEqual((self.bin / "arc").read_text(), FAKE_ARC) + self.assertEqual((self.root / "events").read_text(), "") + + def test_failed_replace_recovers_server(self): + (self.root / "state").write_text("true\n") + self.write_command("mv", "#!/bin/sh\nexit 1\n") + self.run_install("--force", success=False) + self.assertEqual((self.bin / "arc").read_text(), FAKE_ARC) + self.assertEqual((self.root / "events").read_text(), "stop\nstart\n") + + def test_fresh_install(self): + if os.access("/usr/local/bin", os.W_OK): + self.skipTest("Fresh-install default is system-writable; do not touch it") + (self.bin / "arc").unlink() + self.assertIsNone(shutil.which("arc", path=self.env["PATH"])) + self.run_install() + self.assertEqual((self.root / "home/.local/bin/arc").read_bytes(), self.payload) + self.assertEqual((self.root / "events").read_text(), "") + + +if __name__ == "__main__": + unittest.main() From ed1eba5b5e2974d0aed30ecb55ae54904a3422b2 Mon Sep 17 00:00:00 2001 From: Ben Firestone Date: Wed, 9 Sep 2026 10:47:21 -0700 Subject: [PATCH 2/4] fix(ci): exclude test fixtures from goconst analysis --- .golangci.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 86ca5c5f..272e9fbc 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -56,6 +56,10 @@ linters: # Detailed settings for specific linters settings: + goconst: + # Excluding test diagnostics alone still lets fixture strings inflate + # duplicate counts in production files. Skip tests during analysis too. + ignore-tests: true revive: rules: - name: use-any From fe5293bfb0c1eccc1676005317b784dac7fbcfad Mon Sep 17 00:00:00 2001 From: Ben Firestone Date: Fri, 18 Sep 2026 15:23:37 -0700 Subject: [PATCH 3/4] fix(self): finish server shutdown before cancellation recovery --- cmd/arc/self_lifecycle.go | 8 ++++++-- cmd/arc/self_lifecycle_test.go | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cmd/arc/self_lifecycle.go b/cmd/arc/self_lifecycle.go index bde50dfa..13547112 100644 --- a/cmd/arc/self_lifecycle.go +++ b/cmd/arc/self_lifecycle.go @@ -99,9 +99,13 @@ func (l *updateLifecycle) preInstall(ctx context.Context, current, latest string if !l.running() { return nil } - // Arm recovery before stopping: cancellation can arrive after the daemon exits. + // Let the stop helper finish waiting for shutdown even if the update is + // cancelled. Killing it after SIGTERM can leave recovery observing a live + // daemon that is about to exit, causing it to skip the restart. l.restart = true - if err := l.stop(ctx); err != nil { + stopCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), updateRecoveryTimeout) + defer cancel() + if err := l.stop(stopCtx); err != nil { return fmt.Errorf("stop server: %w", err) } if l.running() { diff --git a/cmd/arc/self_lifecycle_test.go b/cmd/arc/self_lifecycle_test.go index 69fee2dd..dc1b4978 100644 --- a/cmd/arc/self_lifecycle_test.go +++ b/cmd/arc/self_lifecycle_test.go @@ -15,6 +15,7 @@ import ( "path/filepath" "runtime" "testing" + "time" "github.com/sentiolabs/selfupdate-go" "github.com/stretchr/testify/assert" @@ -95,6 +96,41 @@ func TestUpdateLifecycle(t *testing.T) { } } +func TestUpdateLifecycleCancellationDuringStop(t *testing.T) { + var events []string + running := true + shutdownFinished := false + ctx, cancel := context.WithCancel(t.Context()) + defer cancel() + l := fixtureLifecycle(t, lifecycleScenario{}, &running, &events, cancel) + l.stop = func(stopCtx context.Context) error { + events = append(events, "stop") + // SIGTERM has been sent, but the daemon is still shutting down when + // the user cancels. CommandContext would kill the stop helper here. + cancel() + if err := stopCtx.Err(); err != nil { + return err + } + deadline, ok := stopCtx.Deadline() + require.True(t, ok, "shutdown must still have a timeout") + assert.InDelta(t, updateRecoveryTimeout.Seconds(), time.Until(deadline).Seconds(), 1) + running = false + shutdownFinished = true + return nil + } + u := fixtureUpdater(l, fakeSource{tag: "v1.1.0"}) + err := u.Update(ctx, selfupdate.UpdateOptions{Yes: true}) + // If the stop helper was cancelled, the daemon exits after recovery has + // already observed it running and skipped the restart. + if !shutdownFinished { + running = false + } + require.ErrorIs(t, err, context.Canceled) + assert.True(t, shutdownFinished, "wait for shutdown before recovering") + assert.True(t, running, "restore the server after cancelling the update") + assert.Equal(t, []string{"sweep", "prepare", "backup", "stop", "start", "close"}, events) +} + func runLifecycleScenario(t *testing.T, scenario lifecycleScenario) { t.Helper() var events []string From 523717b2cbb97151450d304161502df85fea0db4 Mon Sep 17 00:00:00 2001 From: Ben Firestone Date: Fri, 18 Sep 2026 15:41:16 -0700 Subject: [PATCH 4/4] fix(deps): upgrade selfupdate-go to v0.2.1 --- README.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ed11f3bc..d7bd9434 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ release tag is preserved for downloads. Older Arc binaries may need a one-time `arc self update --force` when switching from undotted to dotted RC tags. `arc self update` asks for confirmation before installing. Pass `-y` or `--yes` -to skip the prompt in scripts. Updates use `selfupdate-go` v0.2.0 to download +to skip the prompt in scripts. Updates use `selfupdate-go` v0.2.1 to download and verify the release archive, then atomically replace the current executable. No shell installer, curl, or wget is needed for self-updates. A running local server is stopped only after verification and restarted using the installed diff --git a/go.mod b/go.mod index 226b6d58..11d0ea8c 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/labstack/echo/v4 v4.15.0 github.com/oapi-codegen/runtime v1.1.2 github.com/pressly/goose/v3 v3.26.0 - github.com/sentiolabs/selfupdate-go v0.2.0 + github.com/sentiolabs/selfupdate-go v0.2.1 github.com/spf13/cobra v1.10.2 github.com/spf13/pflag v1.0.9 github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum index 7eb241a7..0cdb27d6 100644 --- a/go.sum +++ b/go.sum @@ -171,8 +171,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qq github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sentiolabs/selfupdate-go v0.2.0 h1:zh+760Kw2+mxjYI4KSK3Pp20mFb3ivnh1TtM6z5w6aA= -github.com/sentiolabs/selfupdate-go v0.2.0/go.mod h1:j9hPo8QlYVPi8WSpOhh7XdtRhYWMIKdayyp26iNf/1Y= +github.com/sentiolabs/selfupdate-go v0.2.1 h1:MjLxKIhSZaJr2prrHAFhNTKiTM1hVY1Ti67IGWQTxkw= +github.com/sentiolabs/selfupdate-go v0.2.1/go.mod h1:j9hPo8QlYVPi8WSpOhh7XdtRhYWMIKdayyp26iNf/1Y= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=