The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(windows): compare encoded paths, and recognize both binary spellings
shukieshahfa0326c9fc03
diff --git a/cli/beacon/internal/embedded/embed.go b/cli/beacon/internal/embedded/embed.goindex 658a703c..228984a9 100644--- a/cli/beacon/internal/embedded/embed.go+++ b/cli/beacon/internal/embedded/embed.go@@ -11,6 +11,17 @@ import (//go:embed hooks.binvar HooksBinary []byte+// BinaryStem is the hook binary's name without any platform extension.+//+// Detection matches on this rather than on GetBinaryName. A command containing+// "beacon-hooks.exe" also contains "beacon-hooks", so the stem recognizes both spellings, while+// the platform-specific name recognizes only one -- which meant a Windows Beacon could not see a+// hook command written without the extension, and would neither repair nor remove it. Settings+// files are synced between machines and written by older builds, so both spellings genuinely occur.+//+// Writing still uses GetBinaryName: what we install must be the name this platform can execute.+const BinaryStem = "beacon-hooks"+// GetBinaryName returns the appropriate binary name for the current platformfunc GetBinaryName() string {if runtime.GOOS == "windows" {diff --git a/cli/beacon/internal/endpoint/collector/collector_test.go b/cli/beacon/internal/endpoint/collector/collector_test.goindex 2b6bd50c..db50cc4a 100644--- a/cli/beacon/internal/endpoint/collector/collector_test.go+++ b/cli/beacon/internal/endpoint/collector/collector_test.go@@ -2,6 +2,7 @@ package collectorimport ("errors"+ "fmt""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv""net""net/http"@@ -40,7 +41,11 @@ func TestConfigYAMLIncludesReleaseContractFields(t *testing.T) {"endpoint: 127.0.0.1:14317","endpoint: 127.0.0.1:14318","beaconjson:",- "path: " + `"` + cfg.LogPath + `"`,+ // %q, matching how the config is generated. Hand-quoting the path only agreed with the+ // generator by accident: a POSIX path contains nothing that needs escaping, while a+ // Windows one is full of backslashes that a double-quoted YAML scalar must escape. The+ // assertion now checks the contract -- a correctly quoted path -- rather than a coincidence.+ fmt.Sprintf("path: %q", cfg.LogPath),"max_event_bytes: 65536","rotate_bytes: 10485760","rotate_archives: 5",diff --git a/cli/beacon/internal/endpoint/hooks/factory_test.go b/cli/beacon/internal/endpoint/hooks/factory_test.goindex 040da524..700b0111 100644--- a/cli/beacon/internal/endpoint/hooks/factory_test.go+++ b/cli/beacon/internal/endpoint/hooks/factory_test.go@@ -1,6 +1,7 @@package hooksimport (+ "encoding/json""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv""os""path/filepath"@@ -231,6 +232,19 @@ func TestFactoryHookStatusDetectsInstalled(t *testing.T) {}}+// jsonFragment renders a value as it appears inside a JSON document, minus the surrounding quotes.+//+// Assertions against marshaled settings must search for the encoded form: a Windows path is full+// of backslashes, and JSON escapes every one of them.+func jsonFragment(t *testing.T, value string) string {+ t.Helper()+ encoded, err := json.Marshal(value)+ if err != nil {+ t.Fatalf("encode %q: %v", value, err)+ }+ return strings.Trim(string(encoded), `"`)+}+func TestInstallFactoryUsesSystemConfigForSystemLog(t *testing.T) {home := t.TempDir()testenv.SetHome(t, home)@@ -247,16 +261,21 @@ func TestInstallFactoryUsesSystemConfigForSystemLog(t *testing.T) {if err != nil {t.Fatalf("read Factory settings: %v", err)}- // The point of this test is that a /var/log system log path selects the *system* config,- // not the user one. The system path is per-OS, so assert against the resolved value- // rather than a hardcoded macOS string -- which is what previously made this fail the- // moment the suite ran on Linux.- wantConfig := "BEACON_ENDPOINT_CONFIG='" + endpointconfig.SystemConfigPath() + "'"+ // A system log path must select the *system* config, not the user one. Both halves are+ // compared against the JSON-encoded form, because that is what lands in the file: Factory+ // settings are marshaled, so a Windows path's backslashes are escaped on the way in and a+ // search for the raw string finds nothing. That breaks the assertion in both directions --+ // the positive check reports the system config as not chosen when it was, and the negative+ // check cannot see the user config being chosen wrongly. On POSIX the two forms are+ // identical, which is why the raw comparison held until Windows joined the gate.+ //+ // The resolved values are used rather than hardcoded strings, since both are per-OS.+ wantConfig := jsonFragment(t, "BEACON_ENDPOINT_CONFIG='"+endpointconfig.SystemConfigPath()+"'")if !strings.Contains(string(data), wantConfig) {t.Fatalf("Factory hook did not use system config for system log; want %s in:\n%s",wantConfig, string(data))}- if strings.Contains(string(data), endpointconfig.ConfigPath(true)) {+ if unwanted := jsonFragment(t, endpointconfig.ConfigPath(true)); strings.Contains(string(data), unwanted) {t.Fatalf("Factory hook used the user config for a system log path:\n%s", string(data))}}diff --git a/cli/beacon/internal/endpoint/hooks/runtime.go b/cli/beacon/internal/endpoint/hooks/runtime.goindex caad5822..56950199 100644--- a/cli/beacon/internal/endpoint/hooks/runtime.go+++ b/cli/beacon/internal/endpoint/hooks/runtime.go@@ -121,7 +121,7 @@ func endpointCommandPrefix(platform, binaryPath, logPath, configPath string) strfunc isEndpointHookCommand(command, platform string) bool {hasPlatform := platform == "" || commandHasPlatform(command, platform)- hasBeaconBinary := strings.Contains(command, embedded.GetBinaryName())+ hasBeaconBinary := strings.Contains(command, embedded.BinaryStem)hasLegacyBinary := strings.Contains(command, "asym-hooks")if strings.Contains(command, "BEACON_ENDPOINT_MODE=1") && hasBeaconBinary {diff --git a/cli/beacon/internal/endpoint/hooks/scope_test.go b/cli/beacon/internal/endpoint/hooks/scope_test.goindex 2619c3f9..9b22031e 100644--- a/cli/beacon/internal/endpoint/hooks/scope_test.go+++ b/cli/beacon/internal/endpoint/hooks/scope_test.go@@ -59,3 +59,31 @@ func TestSystemLocationMatchIsPlatformAppropriate(t *testing.T) {t.Errorf("%q-other must not be treated as being under %q", dir, dir)}}++// Detection matches the binary stem, not the platform-specific filename.+//+// A settings file is a portable artifact: it gets synced between machines, committed to dotfiles,+// and written by older builds. Matching on GetBinaryName meant a Windows Beacon recognized only+// "beacon-hooks.exe" and was blind to a command naming "beacon-hooks" -- so it would neither repair+// nor remove a hook it had every reason to own, and `hooks status` would report not-installed for a+// hook sitting in the file.+func TestHookDetectionRecognizesBothBinarySpellings(t *testing.T) {+ for _, command := range []string{+ `BEACON_ENDPOINT_MODE=1 '/home/u/.beacon/endpoint/hooks/beacon-hooks' --platform cursor`,+ `BEACON_ENDPOINT_MODE=1 'C:\Users\u\.beacon\endpoint\hooks\beacon-hooks.exe' --platform cursor`,+ } {+ if !isEndpointHookCommand(command, "cursor") {+ t.Errorf("command not recognized as a Beacon hook: %s", command)+ }+ }++ // Still not a licence to claim anything: an unrelated command must not be adopted.+ for _, command := range []string{+ `echo keep`,+ `/usr/local/bin/some-other-tool --platform cursor`,+ } {+ if isEndpointHookCommand(command, "cursor") {+ t.Errorf("unrelated command was claimed as a Beacon hook: %s", command)+ }+ }+}