Skip to content

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

fix(windows): give SystemBaseDir a Windows value, and gate what depends on it

shukieshaha2fe76fca931
diff --git a/cli/beacon/internal/endpoint/config/config.go b/cli/beacon/internal/endpoint/config/config.go
index e08dffd0..eaf887b0 100644
--- a/cli/beacon/internal/endpoint/config/config.go
+++ b/cli/beacon/internal/endpoint/config/config.go
@@ -14,6 +14,11 @@ const (
// LinuxSystemBaseDir follows the FHS: configuration under /etc, which is where a
// package-managed install and an admin both expect to find it.
LinuxSystemBaseDir = "/etc/beacon/endpoint"
+ // WindowsSystemBaseFallback is used when %ProgramData% is unset. Windows always defines it in
+ // practice, but a service running under an unusual profile can arrive without it, and writing
+ // to a relative path in that case would scatter machine state into whatever directory the
+ // process happened to start in.
+ WindowsSystemBaseFallback = `C:\ProgramData`
UserConfigPath = ".beacon/endpoint/config.json"
DefaultGRPCPort = 4317
@@ -29,6 +34,21 @@ func SystemBaseDir() string {
switch runtime.GOOS {
case "linux":
return LinuxSystemBaseDir
+ case "windows":
+ // %ProgramData% is the documented home for machine-wide application state that outlives
+ // any one user, and is the closest equivalent to both /Library/Application Support and
+ // /etc. Read from the environment rather than hardcoded because a redirected or localized
+ // install puts it elsewhere, and writing to the wrong root would be silent.
+ //
+ // Windows is a named case rather than sharing the default: before it was, an endpoint
+ // there resolved its state directory to the *macOS* path, so the log directory derived
+ // from it came out as "\Library\Application Support\...". Nothing would have failed
+ // loudly; it would simply have written machine state to a directory no Windows tool,
+ // installer or admin looks in.
+ if programData := os.Getenv("ProgramData"); programData != "" {
+ return filepath.Join(programData, "Beacon", "Endpoint")
+ }
+ return filepath.Join(WindowsSystemBaseFallback, "Beacon", "Endpoint")
default:
return DarwinSystemBaseDir
}
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index 9d4e153b..04b1a9eb 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -246,6 +246,7 @@ func TestDiscoverCodexDoesNotDetectConfigDirectoryOnly(t *testing.T) {
}
func TestDiscoverCodexDetectsExecutableOnPath(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
testenv.SetHome(t, home)
binDir := t.TempDir()
@@ -434,6 +435,7 @@ func TestDiscoverGeminiDoesNotDetectConfigDirectoryOnly(t *testing.T) {
}
func TestDiscoverGeminiDetectsExecutableOnPath(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
testenv.SetHome(t, home)
binDir := t.TempDir()
@@ -488,6 +490,7 @@ func TestGeminiStatusVariants(t *testing.T) {
}
func TestDiscoverFactoryDetectsExecutableOnPath(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
testenv.SetHome(t, home)
t.Setenv("SHELL", "/bin/bash")
@@ -514,6 +517,7 @@ func TestDiscoverFactoryDetectsExecutableOnPath(t *testing.T) {
}
func TestDiscoverCopilotCLIDetectsExecutableOnPath(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
testenv.SetHome(t, home)
t.Setenv("SHELL", "/bin/bash")
@@ -558,6 +562,7 @@ func TestDiscoverCopilotCLIDetectsConfigFile(t *testing.T) {
}
func TestDiscoverDevinDetectsExecutableOnPath(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
home := t.TempDir()
testenv.SetHome(t, home)
binDir := t.TempDir()
diff --git a/cli/beacon/internal/endpoint/hooks/cursor_test.go b/cli/beacon/internal/endpoint/hooks/cursor_test.go
index b1f69ccc..e7c6570a 100644
--- a/cli/beacon/internal/endpoint/hooks/cursor_test.go
+++ b/cli/beacon/internal/endpoint/hooks/cursor_test.go
@@ -170,7 +170,7 @@ func TestInstallCursorWithUnknownLevelFailsBeforeWritingTarget(t *testing.T) {
}
func TestEndpointConfigPathForHookUsesSystemConfigForSystemLog(t *testing.T) {
- if got := endpointConfigPathForHook("/var/log/beacon-agent/runtime.jsonl", true); got != endpointconfig.ConfigPath(false) {
+ if got := endpointConfigPathForHook(endpointconfig.SystemLogPath(), true); got != endpointconfig.ConfigPath(false) {
t.Fatalf("system log config path = %q, want system endpoint config", got)
}
if got := endpointConfigPathForHook("/tmp/runtime.jsonl", true); got != endpointconfig.ConfigPath(true) {
diff --git a/cli/beacon/internal/endpoint/hooks/factory_test.go b/cli/beacon/internal/endpoint/hooks/factory_test.go
index 0527ddcc..040da524 100644
--- a/cli/beacon/internal/endpoint/hooks/factory_test.go
+++ b/cli/beacon/internal/endpoint/hooks/factory_test.go
@@ -237,7 +237,7 @@ func TestInstallFactoryUsesSystemConfigForSystemLog(t *testing.T) {
status, err := InstallFactory(FactoryOptions{
Level: LevelUser,
- LogPath: "/var/log/beacon-agent/runtime.jsonl",
+ LogPath: endpointconfig.SystemLogPath(),
UserMode: true,
})
if err != nil {
diff --git a/cli/beacon/internal/testenv/testenv.go b/cli/beacon/internal/testenv/testenv.go
index 97d0e8eb..42a97399 100644
--- a/cli/beacon/internal/testenv/testenv.go
+++ b/cli/beacon/internal/testenv/testenv.go
@@ -12,6 +12,7 @@
package testenv
import (
+ "path/filepath"
"runtime"
"testing"
)
@@ -25,6 +26,15 @@ func SetHome(t *testing.T, dir string) {
t.Helper()
t.Setenv("HOME", dir)
t.Setenv("USERPROFILE", dir)
+ if runtime.GOOS == "windows" {
+ // The per-user application directories are not derived from USERPROFILE by the programs
+ // that read them -- they have their own variables, and Windows sets all of them
+ // independently. Redirecting only the profile left anything resolving %APPDATA% (VS Code's
+ // settings, for one) writing into the developer's real roaming profile while the test
+ // believed it had been sandboxed.
+ t.Setenv("APPDATA", filepath.Join(dir, "AppData", "Roaming"))
+ t.Setenv("LOCALAPPDATA", filepath.Join(dir, "AppData", "Local"))
+ }
}
// RequirePOSIXFileModes skips a test whose assertion is about Unix permission bits.
@@ -43,3 +53,24 @@ func RequirePOSIXFileModes(t *testing.T) {
t.Skip("Unix permission bits do not exist on Windows; the equivalent is an ACL check")
}
}
+
+// RequirePOSIXExecutableFixtures skips a test that stands in for a CLI with a shell script.
+//
+// Two things stop that working on Windows, and only one of them is the extension. exec.LookPath
+// resolves a bare name through PATHEXT, so a file written without one is invisible to it -- but
+// renaming the fixture to `codex.exe` fixes only the lookup. These tests then *execute* the stub to
+// read its --version output, and a `#!/bin/sh` file is not runnable on Windows whatever it is
+// called, because there are no shebangs. That is the difference from the collector fixtures, where
+// the extension alone was enough: discovery there only stats the file.
+//
+// Skipped rather than adapted because these tests are about discovery logic that is not
+// platform-specific, and the packages they live in are gated on Windows for their *path* handling.
+// A Windows fixture is possible -- copy the test binary and have TestMain impersonate the CLI, as
+// the service package does for its stub collector -- and is tracked in the Windows test-suite
+// issue rather than done here, where it would test nothing this change touches.
+func RequirePOSIXExecutableFixtures(t *testing.T) {
+ t.Helper()
+ if runtime.GOOS == "windows" {
+ t.Skip("shell-script executable fixtures cannot run on Windows; see the Windows test-suite issue")
+ }
+}