Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(endpoint): align manual apply guardrails

shukieshahb30f49f0b9ca
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index e79e8cb7..ef8920ce 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -20,6 +20,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/selfupdate"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/service"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/updatecheck"
"github.com/spf13/cobra"
)
@@ -1288,6 +1289,47 @@ func TestApplyUpdateInsecureRequiresInstallPrefix(t *testing.T) {
}
}
+func TestEndpointUpdateCheckWinsOverApply(t *testing.T) {
+ oldCheck := endpointUpdateOpts.check
+ oldApply := endpointUpdateOpts.apply
+ t.Cleanup(func() {
+ endpointUpdateOpts.check = oldCheck
+ endpointUpdateOpts.apply = oldApply
+ })
+ endpointUpdateOpts.check = true
+ endpointUpdateOpts.apply = true
+ res := selfupdate.CheckResult{
+ ManifestResult: updatecheck.ManifestResult{UpdateAvailable: true},
+ Install: selfupdate.Install{Kind: selfupdate.InstallSystemPkg},
+ HasArtifact: true,
+ }
+ if err := maybeReturnAfterUpdateReport(res); err != nil {
+ t.Fatalf("maybeReturnAfterUpdateReport = %v, want nil check-only return", err)
+ }
+}
+
+func TestEndpointUpdateApplyRejectsHomebrew(t *testing.T) {
+ oldCheck := endpointUpdateOpts.check
+ oldApply := endpointUpdateOpts.apply
+ oldInsecure := endpointUpdateOpts.allowInsecure
+ t.Cleanup(func() {
+ endpointUpdateOpts.check = oldCheck
+ endpointUpdateOpts.apply = oldApply
+ endpointUpdateOpts.allowInsecure = oldInsecure
+ })
+ endpointUpdateOpts.check = false
+ endpointUpdateOpts.apply = true
+ endpointUpdateOpts.allowInsecure = false
+ res := selfupdate.CheckResult{
+ ManifestResult: updatecheck.ManifestResult{UpdateAvailable: true},
+ Install: selfupdate.Install{Kind: selfupdate.InstallHomebrew},
+ HasArtifact: true,
+ }
+ if err := maybeReturnAfterUpdateReport(res); err == nil || !strings.Contains(err.Error(), "Homebrew") {
+ t.Fatalf("maybeReturnAfterUpdateReport = %v, want Homebrew apply rejection", err)
+ }
+}
+
func TestCompletionAndDocsCommandsRegistered(t *testing.T) {
for _, name := range []string{"completion", "docs"} {
cmd, _, err := rootCmd.Find([]string{name})
diff --git a/cli/beacon/cmd/endpoint_update.go b/cli/beacon/cmd/endpoint_update.go
index 8ce8321b..2fb7a7f7 100644
--- a/cli/beacon/cmd/endpoint_update.go
+++ b/cli/beacon/cmd/endpoint_update.go
@@ -141,6 +141,19 @@ func runEndpointUpdate(cmd *cobra.Command, args []string) error {
fmt.Printf("This build is below the minimum supported version; updating is strongly recommended.\n")
}
+ if err := maybeReturnAfterUpdateReport(res); err != nil || !endpointUpdateOpts.apply || endpointUpdateOpts.check {
+ return err
+ }
+
+ return applyUpdate(cmd.Context(), current)
+}
+
+func maybeReturnAfterUpdateReport(res selfupdate.CheckResult) error {
+ if endpointUpdateOpts.check && endpointUpdateOpts.apply {
+ fmt.Println("--check was set; no package was downloaded or applied.")
+ return nil
+ }
+
if !endpointUpdateOpts.apply {
switch res.Install.Kind {
case selfupdate.InstallHomebrew:
@@ -164,7 +177,7 @@ func runEndpointUpdate(cmd *cobra.Command, args []string) error {
case selfupdate.InstallHomebrew:
fmt.Println("Installed via Homebrew. Update with:")
fmt.Println(" brew upgrade beacon")
- return nil
+ return fmt.Errorf("manual apply is not supported for Homebrew installs")
case selfupdate.InstallOther:
return fmt.Errorf("manual apply is supported only for the system package install (detected: %s)", res.Install.Kind)
}
@@ -172,8 +185,7 @@ func runEndpointUpdate(cmd *cobra.Command, args []string) error {
return fmt.Errorf("no signed endpoint package artifact is available for %s", res.ArchKey)
}
}
-
- return applyUpdate(cmd.Context(), current)
+ return nil
}
func emitManualCheckEvent(opts selfupdate.CheckEventOptions) error {