Skip to content

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

fix(endpoint): decouple update mode from config validation

shukieshah4d0c9cc216ee
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index d121988a..7753c5b0 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -1168,16 +1168,54 @@ func TestEndpointUpdateCommandsRegistered(t *testing.T) {
func TestConfigAutoUpdateModeDoesNotFallBackOnSystemLoadError(t *testing.T) {
systemErr := fmt.Errorf("invalid system config")
got := configAutoUpdateModeFrom(
- func() (endpointconfig.Config, error) { return endpointconfig.Config{}, systemErr },
- func() (endpointconfig.Config, error) {
- return endpointconfig.Config{AutoUpdate: &endpointconfig.AutoUpdate{Mode: "check-only"}}, nil
- },
+ func() (string, error) { return "", systemErr },
+ func() (string, error) { return "check-only", nil },
)
if got != "" {
t.Fatalf("mode = %q, want empty when system config load fails", got)
}
}
+func TestAutoUpdateModeIgnoresDestinationValidation(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "config.json")
+ writeTestFile(t, path, `{
+ "user_mode": false,
+ "log_path": "/var/log/beacon-agent/runtime.jsonl",
+ "collector": {"grpc_port":4317,"http_port":4318},
+ "harnesses": ["claude"],
+ "destinations": {"splunk_hec": {"endpoint": "https://splunk.example"}},
+ "auto_update": {"mode": "check-only"}
+}`)
+ got, err := autoUpdateModeFromPath(path)
+ if err != nil {
+ t.Fatalf("autoUpdateModeFromPath: %v", err)
+ }
+ if got != "check-only" {
+ t.Fatalf("mode = %q, want check-only", got)
+ }
+ if err := setConfigAutoUpdateModeAt(path, "off"); err != nil {
+ t.Fatalf("setConfigAutoUpdateModeAt: %v", err)
+ }
+ data, err := os.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var raw map[string]json.RawMessage
+ if err := json.Unmarshal(data, &raw); err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := raw["destinations"]; !ok {
+ t.Fatalf("destinations were not preserved: %s", data)
+ }
+ mode, err := autoUpdateModeFromPath(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if mode != "off" {
+ t.Fatalf("mode after set = %q, want off", mode)
+ }
+}
+
func TestEndpointSystemLogPathUsesSystemPathForPackageInstall(t *testing.T) {
oldDetect := detectUpdateInstall
oldLogPath := endpointOpts.logPath
diff --git a/cli/beacon/cmd/endpoint_update.go b/cli/beacon/cmd/endpoint_update.go
index 5b5d794f..8f97614d 100644
--- a/cli/beacon/cmd/endpoint_update.go
+++ b/cli/beacon/cmd/endpoint_update.go
@@ -2,6 +2,7 @@ package cmd
import (
"context"
+ "encoding/json"
"fmt"
"os"
"time"
@@ -46,26 +47,40 @@ func init() {
// system config (i.e. a user-mode install).
func configAutoUpdateMode() string {
return configAutoUpdateModeFrom(
- func() (endpointconfig.Config, error) { return endpointconfig.Load(false) },
- func() (endpointconfig.Config, error) { return endpointconfig.Load(true) },
+ func() (string, error) { return autoUpdateModeFromPath(endpointconfig.ConfigPath(false)) },
+ func() (string, error) { return autoUpdateModeFromPath(endpointconfig.ConfigPath(true)) },
)
}
-func configAutoUpdateModeFrom(loadSystem, loadUser func() (endpointconfig.Config, error)) string {
- if cfg, err := loadSystem(); err == nil {
- if cfg.AutoUpdate != nil {
- return cfg.AutoUpdate.Mode
- }
- return ""
+func configAutoUpdateModeFrom(loadSystem, loadUser func() (string, error)) string {
+ if mode, err := loadSystem(); err == nil {
+ return mode
} else if !os.IsNotExist(err) {
return ""
}
- if cfg, err := loadUser(); err == nil && cfg.AutoUpdate != nil {
- return cfg.AutoUpdate.Mode
+ if mode, err := loadUser(); err == nil {
+ return mode
}
return ""
}
+func autoUpdateModeFromPath(path string) (string, error) {
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return "", err
+ }
+ var partial struct {
+ AutoUpdate *endpointconfig.AutoUpdate `json:"auto_update"`
+ }
+ if err := json.Unmarshal(data, &partial); err != nil {
+ return "", err
+ }
+ if partial.AutoUpdate == nil {
+ return "", nil
+ }
+ return partial.AutoUpdate.Mode, nil
+}
+
func runEndpointUpdate(cmd *cobra.Command, args []string) error {
if endpointUpdateServiceOpts.scheduled {
return runScheduledUpdate(cmd.Context())
diff --git a/cli/beacon/cmd/endpoint_update_service.go b/cli/beacon/cmd/endpoint_update_service.go
index 82035354..16f41811 100644
--- a/cli/beacon/cmd/endpoint_update_service.go
+++ b/cli/beacon/cmd/endpoint_update_service.go
@@ -2,8 +2,10 @@ package cmd
import (
"context"
+ "encoding/json"
"fmt"
"os"
+ "path/filepath"
"time"
"github.com/spf13/cobra"
@@ -55,17 +57,40 @@ func init() {
// setConfigAutoUpdateMode persists the auto-update mode in the system endpoint
// config, creating a default config if none exists.
func setConfigAutoUpdateMode(mode string) error {
- cfg, err := endpointconfig.Load(false)
+ return setConfigAutoUpdateModeAt(endpointconfig.ConfigPath(false), mode)
+}
+
+func setConfigAutoUpdateModeAt(path, mode string) error {
+ data, err := os.ReadFile(path)
if err != nil {
if !os.IsNotExist(err) {
return err
}
- cfg = endpointconfig.Default(false, writer.DefaultPath(false))
+ cfg := endpointconfig.Default(false, writer.DefaultPath(false))
+ cfg.AutoUpdate = &endpointconfig.AutoUpdate{Mode: mode}
+ data, err := json.MarshalIndent(cfg, "", " ")
+ if err != nil {
+ return err
+ }
+ if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
+ return err
+ }
+ return os.WriteFile(path, data, 0644)
+ }
+ var raw map[string]json.RawMessage
+ if err := json.Unmarshal(data, &raw); err != nil {
+ return err
+ }
+ autoUpdate, err := json.Marshal(endpointconfig.AutoUpdate{Mode: mode})
+ if err != nil {
+ return err
+ }
+ raw["auto_update"] = autoUpdate
+ out, err := json.MarshalIndent(raw, "", " ")
+ if err != nil {
+ return err
}
- cfg.UserMode = false
- cfg.AutoUpdate = &endpointconfig.AutoUpdate{Mode: mode}
- _, err = endpointconfig.Save(cfg)
- return err
+ return os.WriteFile(path, out, 0644)
}
func requireRootForUpdater() error {