Skip to content

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

fix(windows): one shared home redirect, and a collector that is findable

shukieshah7bc650b67f03
diff --git a/beacon-sandbox/runner/shell.go b/beacon-sandbox/runner/shell.go
index 4fe7d742..5f499b80 100644
--- a/beacon-sandbox/runner/shell.go
+++ b/beacon-sandbox/runner/shell.go
@@ -96,9 +96,14 @@ func (s posixShell) WithEnv(name, value, script string) string {
// outright was indistinguishable from one that worked.
func (s posixShell) CIExecSession(logPath, _ string, claudeArgs []string) string {
inner := "claude " + strings.Join(claudeArgs, " ") + " > claude-out.json 2> claude-err.txt"
+ // stderr is surfaced on failure, not just stdout. `beacon ci exec` reports why it could not
+ // start or supervise the collector on stderr, and tailing only ci-out.txt meant a non-zero exit
+ // arrived with no explanation at all -- the reason was sitting in a file nothing ever read.
return fmt.Sprintf("beacon ci exec --harness claude --log-path %s -- sh -c %s "+
"> ci-out.txt 2> ci-err.txt; rc=$?; echo CI_EXEC_RC=$rc; "+
- "tail -c 400 ci-out.txt; exit $rc",
+ "tail -c 400 ci-out.txt; "+
+ "if [ \"$rc\" -ne 0 ]; then echo '--- ci exec stderr ---'; tail -c 800 ci-err.txt; fi; "+
+ "exit $rc",
s.Quote(logPath), s.Quote(inner))
}
@@ -259,8 +264,12 @@ $rc = $LASTEXITCODE
if ($null -eq $rc) { $rc = 0 }
"CI_EXEC_RC=$rc"
%s
+if ($rc -ne 0) {
+ '--- ci exec stderr ---'
+%s
+}
exit $rc`,
- inner, s.Quote(logPath), s.TailBytes("ci-out.txt", 400))
+ inner, s.Quote(logPath), s.TailBytes("ci-out.txt", 400), s.TailBytes("ci-err.txt", 800))
}
// PlainSession runs the agent directly, for install scenarios where a persistent collector is
diff --git a/cli/beacon/internal/endpoint/collector/collector.go b/cli/beacon/internal/endpoint/collector/collector.go
index d68ea8af..2992cefc 100644
--- a/cli/beacon/internal/endpoint/collector/collector.go
+++ b/cli/beacon/internal/endpoint/collector/collector.go
@@ -82,7 +82,7 @@ func validateExecutable(path string) error {
if info.IsDir() {
return fmt.Errorf("is a directory")
}
- if info.Mode().Perm()&0111 == 0 {
+ if !isExecutableMode(info) {
return fmt.Errorf("is not executable")
}
return nil
diff --git a/cli/beacon/internal/endpoint/collector/executable_unix.go b/cli/beacon/internal/endpoint/collector/executable_unix.go
new file mode 100644
index 00000000..1a931877
--- /dev/null
+++ b/cli/beacon/internal/endpoint/collector/executable_unix.go
@@ -0,0 +1,10 @@
+//go:build !windows
+
+package collector
+
+import "os"
+
+// isExecutableMode reports whether the file's permission bits allow execution.
+func isExecutableMode(info os.FileInfo) bool {
+ return info.Mode().Perm()&0111 != 0
+}
diff --git a/cli/beacon/internal/endpoint/collector/executable_windows.go b/cli/beacon/internal/endpoint/collector/executable_windows.go
new file mode 100644
index 00000000..53d01bb6
--- /dev/null
+++ b/cli/beacon/internal/endpoint/collector/executable_windows.go
@@ -0,0 +1,20 @@
+//go:build windows
+
+package collector
+
+import "os"
+
+// isExecutableMode reports whether the file can be executed.
+//
+// Windows has no executable permission bits. Go reports 0666 for an ordinary file and 0444 for a
+// read-only one, so the POSIX test `Perm()&0111 != 0` is false for *every* file there -- including
+// a genuine .exe. Applied unchanged, it made DiscoverBinary reject every collector binary on
+// Windows and report that none was installed.
+//
+// Executability there is decided by extension, and the caller is looking for one specific named
+// binary rather than scanning for anything runnable, so being a regular file is the meaningful
+// check: exec.LookPath already applies PATHEXT when resolving BinaryName from PATH, and the
+// explicit candidate paths name the file directly.
+func isExecutableMode(info os.FileInfo) bool {
+ return info.Mode().IsRegular()
+}
diff --git a/cli/beacon/internal/endpoint/config/config_test.go b/cli/beacon/internal/endpoint/config/config_test.go
index 7987e97f..f4da6ba5 100644
--- a/cli/beacon/internal/endpoint/config/config_test.go
+++ b/cli/beacon/internal/endpoint/config/config_test.go
@@ -1,6 +1,7 @@
package config
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -9,7 +10,7 @@ import (
func TestDefaultUserConfigUsesHomeScopedPaths(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "runtime.jsonl"))
@@ -51,7 +52,7 @@ func TestInventoryContentCaptureOptIn(t *testing.T) {
func TestSaveLoadRoundTrip(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, "logs", "runtime.jsonl")
cfg := Default(true, logPath)
@@ -104,7 +105,7 @@ func TestSaveLoadRoundTrip(t *testing.T) {
func TestSaveLoadSplunkHECRoundTripAndPrivatePermissions(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "logs", "runtime.jsonl"))
cfg.Destinations = &Destinations{SplunkHEC: &SplunkHEC{
Endpoint: "https://splunk.example:8088/services/collector",
@@ -142,7 +143,7 @@ func TestSaveLoadSplunkHECRoundTripAndPrivatePermissions(t *testing.T) {
func TestSaveRejectsIncompleteSplunkHEC(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "runtime.jsonl"))
cfg.Destinations = &Destinations{SplunkHEC: &SplunkHEC{Endpoint: "https://splunk.example:8088/services/collector"}}
@@ -153,7 +154,7 @@ func TestSaveRejectsIncompleteSplunkHEC(t *testing.T) {
func TestSaveLoadFalconHECRoundTripAndPrivatePermissions(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "logs", "runtime.jsonl"))
cfg.Destinations = &Destinations{FalconHEC: &FalconHEC{
Endpoint: "https://cloud.us.humio.com/api/v1/ingest/hec",
@@ -191,7 +192,7 @@ func TestSaveLoadFalconHECRoundTripAndPrivatePermissions(t *testing.T) {
func TestSaveRejectsIncompleteFalconHEC(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := Default(true, filepath.Join(home, "runtime.jsonl"))
cfg.Destinations = &Destinations{FalconHEC: &FalconHEC{Endpoint: "https://cloud.us.humio.com/api/v1/ingest/hec"}}
@@ -202,7 +203,7 @@ func TestSaveRejectsIncompleteFalconHEC(t *testing.T) {
func TestLoadIgnoresLegacyContentRetention(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, UserConfigPath)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir config dir: %v", err)
@@ -232,7 +233,7 @@ func TestLoadIgnoresLegacyContentRetention(t *testing.T) {
func TestLoadRejectsCorruptJSON(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, UserConfigPath)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir config dir: %v", err)
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index 139e80df..9d4e153b 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -2,6 +2,7 @@ package harness
import (
"encoding/json"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -35,7 +36,7 @@ func TestMergeCodexOTELReplacesExistingBlock(t *testing.T) {
func TestConfigureClaudeWritesTelemetryEnvAndBackup(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".claude", "settings.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir claude config dir: %v", err)
@@ -87,7 +88,7 @@ func TestConfigureClaudeWritesTelemetryEnvAndBackup(t *testing.T) {
func TestConfigureClaudeEnablesPromptLogging(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".claude", "settings.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir claude config dir: %v", err)
@@ -149,7 +150,7 @@ func TestClaudeStatusVariants(t *testing.T) {
func TestConfigureCodexWritesTelemetryBlockAndBackup(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".codex", "config.toml")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir codex config dir: %v", err)
@@ -205,7 +206,7 @@ func TestConfigureCodexWritesTelemetryBlockAndBackup(t *testing.T) {
func TestConfigureCodexEnablesPromptLogging(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path, err := ConfigureCodex(ConfigureOptions{
Endpoint: "http://127.0.0.1:4317",
@@ -225,7 +226,7 @@ func TestConfigureCodexEnablesPromptLogging(t *testing.T) {
func TestDiscoverCodexDoesNotDetectConfigDirectoryOnly(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
binDir := t.TempDir()
t.Setenv("PATH", binDir)
if err := os.MkdirAll(filepath.Join(home, ".codex"), 0755); err != nil {
@@ -246,7 +247,7 @@ func TestDiscoverCodexDoesNotDetectConfigDirectoryOnly(t *testing.T) {
func TestDiscoverCodexDetectsExecutableOnPath(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
binDir := t.TempDir()
t.Setenv("PATH", binDir)
codexPath := filepath.Join(binDir, "codex")
@@ -328,7 +329,7 @@ func TestCodexStatusVariants(t *testing.T) {
func TestConfigureGeminiWritesTelemetryAndBackup(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".gemini", "settings.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir gemini config dir: %v", err)
@@ -385,7 +386,7 @@ func TestConfigureGeminiWritesTelemetryAndBackup(t *testing.T) {
func TestConfigureGeminiEnablesPromptLoggingAndTraces(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path, err := ConfigureGemini(ConfigureOptions{
Endpoint: "http://127.0.0.1:4317",
@@ -413,7 +414,7 @@ func TestConfigureGeminiEnablesPromptLoggingAndTraces(t *testing.T) {
func TestDiscoverGeminiDoesNotDetectConfigDirectoryOnly(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
binDir := t.TempDir()
t.Setenv("PATH", binDir)
if err := os.MkdirAll(filepath.Join(home, ".gemini"), 0755); err != nil {
@@ -434,7 +435,7 @@ func TestDiscoverGeminiDoesNotDetectConfigDirectoryOnly(t *testing.T) {
func TestDiscoverGeminiDetectsExecutableOnPath(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
binDir := t.TempDir()
t.Setenv("PATH", binDir)
geminiPath := filepath.Join(binDir, "gemini")
@@ -488,7 +489,7 @@ func TestGeminiStatusVariants(t *testing.T) {
func TestDiscoverFactoryDetectsExecutableOnPath(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv("SHELL", "/bin/bash")
binDir := t.TempDir()
t.Setenv("PATH", binDir)
@@ -514,7 +515,7 @@ func TestDiscoverFactoryDetectsExecutableOnPath(t *testing.T) {
func TestDiscoverCopilotCLIDetectsExecutableOnPath(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv("SHELL", "/bin/bash")
binDir := t.TempDir()
t.Setenv("PATH", binDir)
@@ -540,7 +541,7 @@ func TestDiscoverCopilotCLIDetectsExecutableOnPath(t *testing.T) {
func TestDiscoverCopilotCLIDetectsConfigFile(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv("PATH", t.TempDir())
configPath := filepath.Join(home, ".copilot", "config.json")
if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
@@ -558,7 +559,7 @@ func TestDiscoverCopilotCLIDetectsConfigFile(t *testing.T) {
func TestDiscoverDevinDetectsExecutableOnPath(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
binDir := t.TempDir()
t.Setenv("PATH", binDir)
devinPath := filepath.Join(binDir, "devin")
@@ -586,7 +587,7 @@ func TestDiscoverDevinDetectsExecutableOnPath(t *testing.T) {
func TestDiscoverDevinDesktopDetectsAppSupport(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
appSupport := filepath.Join(home, "Library", "Application Support", "Devin")
if err := os.MkdirAll(appSupport, 0755); err != nil {
t.Fatalf("mkdir app support: %v", err)
diff --git a/cli/beacon/internal/endpoint/harness/vscode_test.go b/cli/beacon/internal/endpoint/harness/vscode_test.go
index e7541713..793755c6 100644
--- a/cli/beacon/internal/endpoint/harness/vscode_test.go
+++ b/cli/beacon/internal/endpoint/harness/vscode_test.go
@@ -1,6 +1,7 @@
package harness
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"runtime"
@@ -110,7 +111,7 @@ func TestVSCodeOTelStatus(t *testing.T) {
// a developer's own VS Code configuration.
func isolateUserConfig(t *testing.T, home string) {
t.Helper()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
}
diff --git a/cli/beacon/internal/endpoint/hooks/antigravity_test.go b/cli/beacon/internal/endpoint/hooks/antigravity_test.go
index 521bac4b..a2868e07 100644
--- a/cli/beacon/internal/endpoint/hooks/antigravity_test.go
+++ b/cli/beacon/internal/endpoint/hooks/antigravity_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -106,7 +107,7 @@ func TestReadAntigravityConfigReturnsCorruptJSONError(t *testing.T) {
func TestAntigravityConfigPathLevels(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
dir := t.TempDir()
t.Chdir(dir)
@@ -128,7 +129,7 @@ func TestAntigravityConfigPathLevels(t *testing.T) {
func TestAntigravityHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".gemini", "config", "hooks.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
diff --git a/cli/beacon/internal/endpoint/hooks/claude_test.go b/cli/beacon/internal/endpoint/hooks/claude_test.go
index 88602345..15873bf0 100644
--- a/cli/beacon/internal/endpoint/hooks/claude_test.go
+++ b/cli/beacon/internal/endpoint/hooks/claude_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -130,7 +131,7 @@ func TestClaudeSettingsPathProjectLevel(t *testing.T) {
func TestClaudeHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".claude", "settings.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
diff --git a/cli/beacon/internal/endpoint/hooks/cursor_test.go b/cli/beacon/internal/endpoint/hooks/cursor_test.go
index 9472890f..b1f69ccc 100644
--- a/cli/beacon/internal/endpoint/hooks/cursor_test.go
+++ b/cli/beacon/internal/endpoint/hooks/cursor_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -158,7 +159,7 @@ func TestInstallCursorHooksJSONDoesNotReplaceUserCommandWithBeaconEnvOnly(t *tes
func TestInstallCursorWithUnknownLevelFailsBeforeWritingTarget(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
status, err := InstallCursor(CursorOptions{Level: Level("workspace"), UserMode: true})
if err == nil {
t.Fatal("expected unknown hook level error")
diff --git a/cli/beacon/internal/endpoint/hooks/devin_test.go b/cli/beacon/internal/endpoint/hooks/devin_test.go
index 170be9c0..f7be9051 100644
--- a/cli/beacon/internal/endpoint/hooks/devin_test.go
+++ b/cli/beacon/internal/endpoint/hooks/devin_test.go
@@ -2,6 +2,7 @@ package hooks
import (
"encoding/json"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -260,7 +261,7 @@ func TestDevinConfigPathProjectLevel(t *testing.T) {
func TestDevinHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".config", "devin", "config.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
@@ -280,7 +281,7 @@ func TestDevinHookStatusDetectsInstalled(t *testing.T) {
func TestDevinDesktopHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".codeium", "windsurf", "hooks.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
diff --git a/cli/beacon/internal/endpoint/hooks/factory_test.go b/cli/beacon/internal/endpoint/hooks/factory_test.go
index 8656da60..0527ddcc 100644
--- a/cli/beacon/internal/endpoint/hooks/factory_test.go
+++ b/cli/beacon/internal/endpoint/hooks/factory_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -212,7 +213,7 @@ func TestFactorySettingsPathProjectLevel(t *testing.T) {
func TestFactoryHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".factory", "settings.json")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
@@ -232,7 +233,7 @@ func TestFactoryHookStatusDetectsInstalled(t *testing.T) {
func TestInstallFactoryUsesSystemConfigForSystemLog(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
status, err := InstallFactory(FactoryOptions{
Level: LevelUser,
diff --git a/cli/beacon/internal/endpoint/hooks/grok_test.go b/cli/beacon/internal/endpoint/hooks/grok_test.go
index c83edc76..ef91161d 100644
--- a/cli/beacon/internal/endpoint/hooks/grok_test.go
+++ b/cli/beacon/internal/endpoint/hooks/grok_test.go
@@ -2,6 +2,7 @@ package hooks
import (
"encoding/json"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -88,7 +89,7 @@ func TestRemoveGrokHooksOnlyRemovesManagedHookFile(t *testing.T) {
func TestGrokHookPathLevels(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if got, want := mustGrokHooksPath(t, LevelUser), filepath.Join(home, ".grok", "hooks", "beacon-endpoint.json"); got != want {
t.Fatalf("user Grok hook path = %q, want %q", got, want)
}
diff --git a/cli/beacon/internal/endpoint/hooks/hermes_test.go b/cli/beacon/internal/endpoint/hooks/hermes_test.go
index c35a6245..cc169c14 100644
--- a/cli/beacon/internal/endpoint/hooks/hermes_test.go
+++ b/cli/beacon/internal/endpoint/hooks/hermes_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -120,7 +121,7 @@ func TestRemoveHermesEndpointHooksPreservesOtherHooks(t *testing.T) {
func TestHermesHookStatusDetectsInstalled(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ".hermes", "config.yaml")
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatal(err)
diff --git a/cli/beacon/internal/endpoint/hooks/opencode_test.go b/cli/beacon/internal/endpoint/hooks/opencode_test.go
index 4ce281e2..bfc42a46 100644
--- a/cli/beacon/internal/endpoint/hooks/opencode_test.go
+++ b/cli/beacon/internal/endpoint/hooks/opencode_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -145,7 +146,7 @@ func TestOpenCodeInstalledUsesManagedMarker(t *testing.T) {
func TestOpenCodePluginPathLevels(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if got, want := mustOpenCodePluginPath(t, LevelUser), filepath.Join(home, ".config", "opencode", "plugins", "beacon.ts"); got != want {
t.Fatalf("user plugin path = %q, want %q", got, want)
}
diff --git a/cli/beacon/internal/endpoint/hooks/vscode_test.go b/cli/beacon/internal/endpoint/hooks/vscode_test.go
index 2771814b..f867f027 100644
--- a/cli/beacon/internal/endpoint/hooks/vscode_test.go
+++ b/cli/beacon/internal/endpoint/hooks/vscode_test.go
@@ -1,6 +1,7 @@
package hooks
import (
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"path/filepath"
"strings"
@@ -71,7 +72,7 @@ func TestRemoveVSCodeEndpointHooksPreservesOtherHooks(t *testing.T) {
func TestVSCodeHooksPathLevels(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
userPath, err := vscodeHooksPath(LevelUser)
if err != nil {
t.Fatalf("user path error: %v", err)
diff --git a/cli/beacon/internal/endpoint/service/service_test.go b/cli/beacon/internal/endpoint/service/service_test.go
index 6973045e..53e3e2e7 100644
--- a/cli/beacon/internal/endpoint/service/service_test.go
+++ b/cli/beacon/internal/endpoint/service/service_test.go
@@ -3,6 +3,7 @@ package service
import (
"errors"
"fmt"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"os"
"os/user"
"path/filepath"
@@ -268,7 +269,7 @@ func TestLaunchdIsInertOffDarwin(t *testing.T) {
// rather than the old "does nothing" assertion.
func TestSupervisedLifecycleStartsAndStopsAProcess(t *testing.T) {
home := t.TempDir()
- setTestHome(t, home)
+ testenv.SetHome(t, home)
m := Manager{UserMode: true, Kind: KindSupervised}
// Loading before install must explain itself rather than silently doing nothing.
@@ -332,7 +333,7 @@ func TestLaunchctlGuidance(t *testing.T) {
func TestLaunchdLabelAndUnitPath(t *testing.T) {
home := t.TempDir()
- setTestHome(t, home)
+ testenv.SetHome(t, home)
user := Manager{UserMode: true, Kind: KindLaunchd}
if got := user.Label(); got != UserLabel {
@@ -361,7 +362,7 @@ func TestLaunchdLabelAndUnitPath(t *testing.T) {
func TestSystemdLabelAndUnitPath(t *testing.T) {
home := t.TempDir()
- setTestHome(t, home)
+ testenv.SetHome(t, home)
user := Manager{UserMode: true, Kind: KindSystemd}
if got := user.Label(); got != SystemdUserUnit {
@@ -497,7 +498,7 @@ func TestSupervisedIsAlwaysAvailable(t *testing.T) {
func TestSupervisedRecordsAndReportsState(t *testing.T) {
home := t.TempDir()
- setTestHome(t, home)
+ testenv.SetHome(t, home)
m := Manager{UserMode: true, Kind: KindSupervised}
if st := m.Status(); st.Loaded || st.Running {
diff --git a/cli/beacon/internal/endpoint/service/testsupport_test.go b/cli/beacon/internal/endpoint/service/testsupport_test.go
index 3c4df1f2..ebda8fdc 100644
--- a/cli/beacon/internal/endpoint/service/testsupport_test.go
+++ b/cli/beacon/internal/endpoint/service/testsupport_test.go
@@ -43,15 +43,3 @@ func stubCollectorPath(t *testing.T) string {
}
return exe
}
-
-// setTestHome redirects the user's home directory for a test on every platform.
-//
-// t.Setenv("HOME") alone is a POSIX-only redirect: os.UserHomeDir reads USERPROFILE on Windows, so
-// a test that sets only HOME there silently keeps using the real profile. That is worse than a
-// plain failure -- tests write into the developer's actual ~/.beacon and then see each other's
-// state, which is why several of these reported "nothing installed yet" while finding an install.
-func setTestHome(t *testing.T, dir string) {
- t.Helper()
- t.Setenv("HOME", dir)
- t.Setenv("USERPROFILE", dir)
-}
diff --git a/cli/beacon/internal/testenv/testenv.go b/cli/beacon/internal/testenv/testenv.go
new file mode 100644
index 00000000..f29f9998
--- /dev/null
+++ b/cli/beacon/internal/testenv/testenv.go
@@ -0,0 +1,25 @@
+// Package testenv holds environment helpers shared by tests across the CLI.
+//
+// It exists for one recurring mistake. Redirecting the home directory with t.Setenv("HOME", dir)
+// is a POSIX-only redirect: os.UserHomeDir reads USERPROFILE on Windows, so a test that sets only
+// HOME there silently keeps using the real profile. That is worse than a plain failure -- tests
+// write into the developer's actual ~/.beacon and then observe each other's state, which is how
+// several of them came to report "nothing installed yet" while finding an install.
+//
+// Importing testing from a non-test file is deliberate: only _test.go files import this package,
+// so nothing reaches a shipped binary, and the alternative -- a copy of SetHome in every package
+// that needs it -- is what produced the inconsistency in the first place.
+package testenv
+
+import "testing"
+
+// SetHome redirects the user's home directory for the duration of a test, on every platform.
+//
+// Both variables are set because different code reaches for different ones: os.UserHomeDir prefers
+// USERPROFILE on Windows and HOME elsewhere, while some callers read HOME directly. Setting only
+// one leaves whichever half of that split the caller happens to use pointing at the real profile.
+func SetHome(t *testing.T, dir string) {
+ t.Helper()
+ t.Setenv("HOME", dir)
+ t.Setenv("USERPROFILE", dir)
+}