Skip to content

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

test(cli/beacon): make 34 more packages pass on Windows and gate them in CI

Claude9da4f69d91c3
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a613b43d..e7dbae2e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -394,30 +394,71 @@ jobs:
# validateExecutable tested the POSIX executable bit, which is never set on Windows, so
# DiscoverBinary rejected every collector binary there.
#
- # The 16 that still fail are listed in #318 with the reason each one fails. They are excluded
- # rather than tolerated: a permanently red gate is one nobody reads. The scope widens as they are
- # fixed, and must not widen by adding `./...` back while the assumptions remain.
+ # The widening for #318 found the next one: the Vector packs substitute log paths into TOML
+ # basic strings unescaped, so a Windows path turns `\t` and `\b` into control characters.
+ # internal/endpoint/asymptote, gcs and s3 assert the derived inventory path in vector.toml and
+ # fail on exactly that, so they stay excluded until the rendering is fixed rather than having
+ # the assertion bent to match.
+ #
+ # Excluded packages are listed in #318 with the reason each one fails. They are excluded rather
+ # than tolerated: a permanently red gate is one nobody reads. The scope widens as they are fixed,
+ # and must not widen by adding `./...` back while the assumptions remain.
- name: Test the ported packages on Windows
working-directory: cli/beacon
run: |
go test `
+ . `
+ ./cmd/... `
+ ./internal/account/... `
+ ./internal/auth/... `
+ ./internal/ci/... `
+ ./internal/claudesession/... `
+ ./internal/clinesession/... `
+ ./internal/codexsession/... `
+ ./internal/copilotsession/... `
+ ./internal/cursorsession/... `
./internal/devincloud/... `
+ ./internal/dshsession/... `
./internal/embedded/... `
./internal/endpoint/activity/... `
+ ./internal/endpoint/cloudwatch/... `
./internal/endpoint/collector/... `
./internal/endpoint/config/... `
+ ./internal/endpoint/dashboard/... `
+ ./internal/endpoint/datadog/... `
./internal/endpoint/detect/... `
+ ./internal/endpoint/diagnostics/... `
+ ./internal/endpoint/elastic/... `
+ ./internal/endpoint/falcon/... `
./internal/endpoint/harness/... `
./internal/endpoint/hooks/... `
./internal/endpoint/integrations/... `
./internal/endpoint/inventory/... `
+ ./internal/endpoint/lifecycle/... `
+ ./internal/endpoint/rapid7/... `
./internal/endpoint/schema/... `
./internal/endpoint/selfupdate/... `
./internal/endpoint/sentinel/... `
./internal/endpoint/service/... `
+ ./internal/endpoint/siempack/... `
+ ./internal/endpoint/sumo/... `
+ ./internal/endpoint/traceview/... `
./internal/endpoint/wazuh/... `
./internal/endpoint/writer/... `
+ ./internal/factorysession/... `
+ ./internal/fxsession/... `
+ ./internal/groksession/... `
+ ./internal/hermessession/... `
+ ./internal/learning/... `
+ ./internal/managedprivacy/... `
./internal/mcpserver/... `
+ ./internal/onboarding/... `
+ ./internal/openclawsession/... `
+ ./internal/opencodesession/... `
+ ./internal/osuser/... `
+ ./internal/pisession/... `
+ ./internal/primesession/... `
+ ./internal/testenv/... `
./internal/tokens/... `
./internal/updatecheck/... `
./internal/version/...
diff --git a/CLAUDE.md b/CLAUDE.md
index 9b18b2b0..c7f95aeb 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -485,7 +485,7 @@ unpacked through Chrome's developer mode.
## Implementation Notes
-- Prefer deterministic tests that use `t.TempDir()`, `t.Setenv("HOME", ...)`, fake binaries, and free local ports.
+- Prefer deterministic tests that use `t.TempDir()`, `testenv.SetHome(t, ...)` (`cli/beacon/internal/testenv`; a bare `t.Setenv("HOME", ...)` does not move `os.UserHomeDir` on Windows), fake binaries, and free local ports. Gate Unix permission-bit assertions with `testenv.HasPOSIXFileModes()` or `testenv.RequirePOSIXFileModes(t)`, and shell-script fixtures with `testenv.RequirePOSIXExecutableFixtures(t)`.
- Avoid tests that require root, real `launchctl` service changes, Wazuh, a live collector, or external network access.
- For macOS-only behavior, gate tests with `runtime.GOOS == "darwin"` or assert the non-Darwin contract explicitly.
- Keep endpoint event schema fields stable: `vendor`, `product`, `schema_version`, required event fields, and Wazuh-compatible JSONL output are release contracts.
diff --git a/cli/beacon/cmd/endpoint_connect_test.go b/cli/beacon/cmd/endpoint_connect_test.go
index 64ccb4c7..c3ea7fec 100644
--- a/cli/beacon/cmd/endpoint_connect_test.go
+++ b/cli/beacon/cmd/endpoint_connect_test.go
@@ -15,6 +15,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/service"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/managedprivacy"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/onboarding"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestEndpointConnectAndDisconnectCommandsRegistered(t *testing.T) {
@@ -184,7 +185,7 @@ func TestConnectRequiresSignedInAccountInUserMode(t *testing.T) {
func TestSelectedManagedPrivacyModePrefersFlagThenActiveEnrollment(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
originalOpts := connectOpts
t.Cleanup(func() { connectOpts = originalOpts })
if err := onboarding.Save(onboarding.Profile{Onboarding: onboarding.Onboarding{
diff --git a/cli/beacon/cmd/endpoint_console_user_test.go b/cli/beacon/cmd/endpoint_console_user_test.go
index 2677b968..0b3a4b6a 100644
--- a/cli/beacon/cmd/endpoint_console_user_test.go
+++ b/cli/beacon/cmd/endpoint_console_user_test.go
@@ -26,6 +26,12 @@ func TestResolveConsoleUserRejectsUnusableAccounts(t *testing.T) {
}
func TestResolveConsoleUserAcceptsTheCurrentUser(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ // osuser resolves POSIX accounts: numeric UID/GID, from the local database or NSS. A
+ // Windows account is a SID named DOMAIN\user, so there is nothing for it to resolve and
+ // the console-user handoff this serves is a macOS/Linux system-install path.
+ t.Skip("console-user resolution is POSIX-only; Windows accounts have SIDs, not UIDs")
+ }
u, err := user.Current()
if err != nil || u.Username == "root" || u.HomeDir == "" {
t.Skip("needs a non-root current user with a home directory")
diff --git a/cli/beacon/cmd/endpoint_onboarding_test.go b/cli/beacon/cmd/endpoint_onboarding_test.go
index 1ab8633e..6e126380 100644
--- a/cli/beacon/cmd/endpoint_onboarding_test.go
+++ b/cli/beacon/cmd/endpoint_onboarding_test.go
@@ -12,6 +12,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/account"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/onboarding"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"github.com/spf13/cobra"
)
@@ -77,7 +78,7 @@ func newOnboardingHarness(t *testing.T) *onboardingHarness {
t.Setenv(onboardingEnvEnabled, "")
t.Setenv(onboardingEnvEmail, "")
t.Setenv(onboardingEnvUsage, "")
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
prevLoad, prevSave, prevSend := onboardingLoad, onboardingSave, onboardingSend
prevTTY, prevRoot := onboardingIsTTY, onboardingIsRoot
diff --git a/cli/beacon/cmd/endpoint_test.go b/cli/beacon/cmd/endpoint_test.go
index b5e49ac9..1b058339 100644
--- a/cli/beacon/cmd/endpoint_test.go
+++ b/cli/beacon/cmd/endpoint_test.go
@@ -22,6 +22,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/testenv"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/updatecheck"
"github.com/spf13/cobra"
@@ -481,7 +482,7 @@ func TestRepairCollectorServiceRollsBackWhenReadinessFails(t *testing.T) {
})
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorConfigPath := filepath.Join(home, "otelcol.yaml")
plistPath := filepath.Join(home, "agent.plist")
cfg := endpointconfig.Config{
@@ -1016,7 +1017,7 @@ func TestRunEndpointDashboardPassesRequestedLogPathToHandler(t *testing.T) {
dashboardListenAndServe = oldListen
})
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
configuredLog := filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")
if _, err := endpointconfig.Save(endpointconfig.Default(true, configuredLog)); err != nil {
t.Fatalf("save endpoint config: %v", err)
@@ -1195,7 +1196,7 @@ func TestWriteInventoryEventsHonorsConfiguredRuntimes(t *testing.T) {
func TestScheduledInventoryHeartbeatAlwaysWritesAndSnapshotsOnChange(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
writeTestFile(t, filepath.Join(home, ".cursor", "mcp.json"), `{"mcpServers":{"one":{"command":"npx"}}}`)
writeTestFile(t, filepath.Join(home, ".codex", "config.toml"), `[mcp_servers.github]
@@ -1264,7 +1265,7 @@ command = "gh"
func TestInventoryHeartbeatAppendFailureLeavesStateUntouched(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logDir := t.TempDir()
logPath := filepath.Join(logDir, "runtime.jsonl")
inventoryLogPath := endpointinventory.LogPath(logPath, true)
@@ -1299,7 +1300,7 @@ func TestInventoryHeartbeatAppendFailureLeavesStateUntouched(t *testing.T) {
func TestScheduledHeartbeatInSystemModeScansTheConsoleUsersHome(t *testing.T) {
consoleHome := t.TempDir()
writeTestFile(t, filepath.Join(consoleHome, ".cursor", "mcp.json"), `{"mcpServers":{"console-one":{"command":"npx"}}}`)
- t.Setenv("HOME", t.TempDir()) // root's home: must not be what gets scanned
+ testenv.SetHome(t, t.TempDir()) // root's home: must not be what gets scanned
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
cfg := endpointconfig.Default(false, logPath)
settings := endpointconfig.InventoryConfig(cfg)
@@ -1347,7 +1348,7 @@ func TestScheduledHeartbeatInSystemModeScansTheConsoleUsersHome(t *testing.T) {
// Hooks installed by older versions still run `inventory heartbeat --trigger hook` on every prompt.
func TestHeartbeatHookTriggerIsRetired(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
oldOpts := endpointOpts
t.Cleanup(func() { endpointOpts = oldOpts })
@@ -1474,7 +1475,7 @@ func TestFilterInventorySectionsKeepsOnlyRequestedBuckets(t *testing.T) {
func TestEndpointInventoryHooksJSONIncludesDefaultHookStatuses(t *testing.T) {
old := endpointOpts
t.Cleanup(func() { endpointOpts = old })
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
endpointOpts.userMode = true
endpointOpts.logPath = filepath.Join(t.TempDir(), "runtime.jsonl")
endpointOpts.jsonOutput = true
@@ -1592,7 +1593,7 @@ func TestRunEndpointInventoryWriteEventHonorsConfigContentOptIn(t *testing.T) {
old := endpointOpts
t.Cleanup(func() { endpointOpts = old })
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
writeTestFile(t, filepath.Join(home, ".cursor", "mcp.json"), `{"mcpServers":{"one":{"command":"npx","env":{"API_TOKEN":"secret"}}}}`)
include := true
@@ -1697,7 +1698,7 @@ func TestAutoUpdateModeIgnoresDestinationValidation(t *testing.T) {
}
if info, err := os.Stat(path); err != nil {
t.Fatal(err)
- } else if got := info.Mode().Perm(); got != 0o600 {
+ } else if got := info.Mode().Perm(); testenv.HasPOSIXFileModes() && got != 0o600 {
t.Fatalf("config permissions = %v, want 0600", got)
}
data, err := os.ReadFile(path)
@@ -1738,7 +1739,13 @@ func TestEndpointSystemLogPathUsesSystemPathForPackageInstall(t *testing.T) {
endpointOpts.userMode = true
endpointOpts.systemMode = false
- if got, want := endpointSystemLogPath(), "/var/log/beacon-agent/system.jsonl"; got != want {
+ // The POSIX location is a published contract, so it stays a literal. Windows has no /var/log
+ // and keeps the system log beside its machine-wide config under %ProgramData%.
+ want := "/var/log/beacon-agent/system.jsonl"
+ if runtime.GOOS == "windows" {
+ want = filepath.Join(endpointconfig.SystemLogDir(), "system.jsonl")
+ }
+ if got := endpointSystemLogPath(); got != want {
t.Fatalf("endpointSystemLogPath = %q, want %q", got, want)
}
}
@@ -1906,7 +1913,7 @@ func TestAggregateCheckStatus(t *testing.T) {
func TestConfigValidationCheckReportsInvalidConfig(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := endpointconfig.ConfigPath(true)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
t.Fatalf("mkdir config dir: %v", err)
@@ -2017,7 +2024,7 @@ func TestPlanDoctorFixesDoesNotTreatMissingEventAsAppliedFix(t *testing.T) {
func TestApplyDoctorFixesContinuesAfterCollectorRepairFailure(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(t.TempDir(), "logs", "runtime.jsonl")
status := lifecycle.Status{
LogPath: logPath,
@@ -2280,7 +2287,7 @@ func TestEndpointGCSValidatePrintsGoogleCloudCLIInspectionGuidance(t *testing.T)
func TestEndpointAsymptoteValidatePrintsCredentialAndDashboardGuidance(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, "runtime.jsonl")
oldLogPath := endpointOpts.logPath
oldUserMode := endpointOpts.userMode
@@ -2323,13 +2330,28 @@ func captureStdout(t *testing.T, fn func() error) (string, error) {
if err != nil {
t.Fatal(err)
}
+ // Drain the pipe while fn runs rather than after it returns. A pipe holds only a fixed buffer,
+ // and a writer that fills it blocks until someone reads: reading afterwards deadlocks as soon as
+ // fn prints more than that. Linux buffers 64 KiB, so the inventory JSON fits and the bug hid;
+ // Windows buffers far less, and `endpoint inventory --json` hung in its Encode for the full test
+ // timeout.
+ type readResult struct {
+ data []byte
+ err error
+ }
+ drained := make(chan readResult, 1)
+ go func() {
+ data, err := io.ReadAll(readEnd)
+ drained <- readResult{data, err}
+ }()
os.Stdout = writeEnd
runErr := fn()
+ os.Stdout = oldStdout
if err := writeEnd.Close(); err != nil {
t.Fatal(err)
}
- os.Stdout = oldStdout
- output, err := io.ReadAll(readEnd)
+ result := <-drained
+ output, err := result.data, result.err
if err != nil {
t.Fatal(err)
}
@@ -2339,13 +2361,40 @@ func captureStdout(t *testing.T, fn func() error) (string, error) {
return string(output), runErr
}
+// captureStdout must not depend on the output fitting in a pipe buffer. It used to read only after
+// fn returned, which deadlocked `endpoint inventory --json` on Windows for the full test timeout;
+// a megabyte is past the buffer on every platform, so this pins the fix on Linux and macOS too.
+func TestCaptureStdoutDrainsOutputLargerThanAPipeBuffer(t *testing.T) {
+ payload := strings.Repeat("x", 1<<20)
+ realStdout := os.Stdout
+ done := make(chan string, 1)
+ go func() {
+ out, _ := captureStdout(t, func() error {
+ _, err := os.Stdout.WriteString(payload)
+ return err
+ })
+ done <- out
+ }()
+ select {
+ case out := <-done:
+ if len(out) != len(payload) {
+ t.Fatalf("captured %d bytes, want %d", len(out), len(payload))
+ }
+ case <-time.After(30 * time.Second):
+ // Put stdout back first: the testing package reports through it, and a deadlocked
+ // capture has left it pointing at the full pipe, so the failure would hang too.
+ os.Stdout = realStdout
+ t.Fatal("captureStdout deadlocked: fn filled the pipe and nothing was reading it")
+ }
+}
+
// A shared Mac alternates console users. Switching between them is not a change in anyone's
// inventory, so the second visit to each home must write a heartbeat and no snapshot.
func TestScheduledHeartbeatKeepsOneDigestPerConsoleUser(t *testing.T) {
alice, bob := t.TempDir(), t.TempDir()
writeTestFile(t, filepath.Join(alice, ".cursor", "mcp.json"), `{"mcpServers":{"alice-one":{"command":"npx"}}}`)
writeTestFile(t, filepath.Join(bob, ".cursor", "mcp.json"), `{"mcpServers":{"bob-one":{"command":"npx"},"bob-two":{"command":"uvx"}}}`)
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
cfg := endpointconfig.Default(false, logPath)
settings := endpointconfig.InventoryConfig(cfg)
@@ -2410,7 +2459,7 @@ func TestSystemHeartbeatScopeIgnoresServiceAccountsAtTheConsole(t *testing.T) {
// command. Every other target is still attempted.
func TestEndpointInstallHookFailureIsAWarningAndOtherHooksStillInstall(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
old := endpointOpts
t.Cleanup(func() { endpointOpts = old })
endpointOpts.userMode = true
diff --git a/cli/beacon/cmd/rules_test.go b/cli/beacon/cmd/rules_test.go
index 6ff28112..36db706b 100644
--- a/cli/beacon/cmd/rules_test.go
+++ b/cli/beacon/cmd/rules_test.go
@@ -11,6 +11,7 @@ import (
"strings"
"testing"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"github.com/spf13/cobra"
)
@@ -192,7 +193,7 @@ func TestExtractRuleTarballKeepsSameBaseNameEntries(t *testing.T) {
}
func TestRulesPullAcceptsURLWithQuery(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
prev := rulesOpts
rulesOpts.userMode, rulesOpts.systemMode, rulesOpts.force = true, false, false
t.Cleanup(func() { rulesOpts = prev })
@@ -214,7 +215,7 @@ func TestRulesPullAcceptsURLWithQuery(t *testing.T) {
}
func TestRulesPullRejectsUnsupportedPath(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
prev := rulesOpts
rulesOpts.userMode, rulesOpts.systemMode = true, false
t.Cleanup(func() { rulesOpts = prev })
diff --git a/cli/beacon/cmd/token_usage_test.go b/cli/beacon/cmd/token_usage_test.go
index 9d690723..c6794b08 100644
--- a/cli/beacon/cmd/token_usage_test.go
+++ b/cli/beacon/cmd/token_usage_test.go
@@ -8,6 +8,7 @@ import (
"strings"
"testing"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/tokens"
)
@@ -201,7 +202,7 @@ func TestTokenUsageCoverageIgnoresFiltersThatWouldHideSilentRuntimes(t *testing.
// depends on every row meaning something.
func TestTokenUsageCoverageDoesNotTreatAShellProfileAsAnInstall(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv("SHELL", "/bin/zsh")
// The only runtime evidence on this machine: a shell profile. No product configs at all.
if err := os.WriteFile(filepath.Join(home, ".zshrc"), []byte("export PATH=$PATH\n"), 0o600); err != nil {
@@ -243,7 +244,7 @@ func TestTokenUsageCoverageHarnessScopeDoesNotStrandOtherRuntimes(t *testing.T)
// Hermetic: two runtimes installed, so scoping to one has something to strand. Reading the
// real HOME here would make the test pass or fail on what the machine happens to have.
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
for _, rel := range []string{".claude/settings.json", ".codex/config.toml"} {
path := filepath.Join(home, rel)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
@@ -282,7 +283,7 @@ func TestTokenUsageCoverageHarnessScopeDoesNotStrandOtherRuntimes(t *testing.T)
// events vanish, and a runtime that spent tokens is reported inactive.
func TestTokenUsageCoverageHarnessScopeAcceptsAliases(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
line := `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"token.usage","category":"metric"},"severity":"info","endpoint":{"hostname":"h"},"harness":{"name":"vscode_copilot"},"model":"gpt-4o","session":{"id":"s1"},"gen_ai":{"usage":{"input_tokens":42}},"message":"usage"}`
if err := os.WriteFile(logPath, []byte(line+"\n"), 0o600); err != nil {
@@ -314,7 +315,7 @@ func TestTokenUsageCoverageHarnessScopeAcceptsAliases(t *testing.T) {
// has classified yet.
func TestTokenUsageCoverageHarnessScopeIsCaseInsensitiveForUnknownRuntimes(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
// An unrecognized harness, so NormalizeHarnessName passes the spelling through untouched.
line := `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"token.usage","category":"metric"},"severity":"info","endpoint":{"hostname":"h"},"harness":{"name":"NewAgent"},"model":"some-model","session":{"id":"s1"},"gen_ai":{"usage":{"input_tokens":7}},"message":"usage"}`
diff --git a/cli/beacon/internal/ci/session_test.go b/cli/beacon/internal/ci/session_test.go
index 1dff8a7b..8a9eca7f 100644
--- a/cli/beacon/internal/ci/session_test.go
+++ b/cli/beacon/internal/ci/session_test.go
@@ -6,12 +6,14 @@ import (
"os"
"path/filepath"
"runtime"
+ "strconv"
"strings"
"testing"
"time"
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/schema"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestProvisionUsesRunnerTempAndWritesCollectorConfig(t *testing.T) {
@@ -41,7 +43,9 @@ func TestProvisionUsesRunnerTempAndWritesCollectorConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if !strings.Contains(string(data), session.LogPath) {
+ // The collector config quotes the path, so on Windows its backslashes arrive escaped. Match
+ // the quoted form, which is also the stricter check everywhere else.
+ if !strings.Contains(string(data), strconv.Quote(session.LogPath)) {
t.Fatalf("collector config does not reference log path:\n%s", data)
}
}
@@ -177,6 +181,7 @@ func TestStartDetachedWritesStateAndExports(t *testing.T) {
}
func TestRunChildInjectsClaudeEnvAndBeaconPaths(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
dir := t.TempDir()
output := filepath.Join(dir, "env.txt")
child := fakeExecutable(t, "child", "#!/bin/sh\nenv > \"$1\"\n")
@@ -413,7 +418,7 @@ func TestProvisionForwardWritesSecureExporterConfig(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if perm := info.Mode().Perm(); perm != 0o600 {
+ if perm := info.Mode().Perm(); testenv.HasPOSIXFileModes() && perm != 0o600 {
t.Fatalf("token-bearing config mode = %o, want 600", perm)
}
@@ -446,6 +451,7 @@ func TestProvisionForwardMissingTokenFails(t *testing.T) {
}
func TestRunChildStripsForwardToken(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
dir := t.TempDir()
output := filepath.Join(dir, "env.txt")
t.Setenv(EnvSplunkToken, "leak-me-not")
@@ -474,6 +480,7 @@ func TestRunChildStripsForwardToken(t *testing.T) {
}
func TestRunChildStripsUploadCredentialsWhenUploadConfigured(t *testing.T) {
+ testenv.RequirePOSIXExecutableFixtures(t)
dir := t.TempDir()
output := filepath.Join(dir, "env.txt")
t.Setenv("AWS_ACCESS_KEY_ID", "aws-key")
diff --git a/cli/beacon/internal/endpoint/asymptote/asymptote_test.go b/cli/beacon/internal/endpoint/asymptote/asymptote_test.go
index 38acf4f7..a386345a 100644
--- a/cli/beacon/internal/endpoint/asymptote/asymptote_test.go
+++ b/cli/beacon/internal/endpoint/asymptote/asymptote_test.go
@@ -9,6 +9,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestVectorConfigForwardsBothStreamsOverHTTPWithABearerSecret(t *testing.T) {
@@ -64,7 +66,8 @@ func TestIngestSmokeTestChecksCredentialBeforePosting(t *testing.T) {
}
for _, want := range []string{
`BEACON_LOG="${BEACON_LOG:-/tmp/beacon/runtime.jsonl}"`,
- `BEACON_INVENTORY_LOG="${BEACON_INVENTORY_LOG:-/tmp/beacon/inventory_state.jsonl}"`,
+ // Derived with the host's separator; the assertion is that it sits beside the log.
+ `BEACON_INVENTORY_LOG="${BEACON_INVENTORY_LOG:-` + filepath.Join("/tmp/beacon", "inventory_state.jsonl") + `}"`,
"BEACON_ASYMPTOTE_INGEST_URL",
"BEACON_ASYMPTOTE_SECRETS_FILE",
"https://*)",
@@ -102,7 +105,7 @@ func TestInstallPackWritesExpectedFilesWithSafeModes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if script.Mode().Perm()&0111 == 0 {
+ if testenv.HasPOSIXFileModes() && script.Mode().Perm()&0111 == 0 {
t.Fatalf("smoke test should be executable, mode=%s", script.Mode())
}
vectorPath := filepath.Join(dir, "vector.toml")
@@ -120,7 +123,7 @@ func TestInstallPackWritesExpectedFilesWithSafeModes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
diff --git a/cli/beacon/internal/endpoint/asymptote/connect_test.go b/cli/beacon/internal/endpoint/asymptote/connect_test.go
index 9f93fb3c..a17a69ec 100644
--- a/cli/beacon/internal/endpoint/asymptote/connect_test.go
+++ b/cli/beacon/internal/endpoint/asymptote/connect_test.go
@@ -16,6 +16,7 @@ import (
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/service"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
type fakeForwarder struct {
@@ -90,7 +91,7 @@ func connectOptions(t *testing.T, fd *fakeDashboard, fwd *fakeForwarder, vector
func TestConnectWritesSecretsConfigUnitAndEnrollmentInOrder(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -170,7 +171,7 @@ func TestConnectWritesSecretsConfigUnitAndEnrollmentInOrder(t *testing.T) {
func TestConnectReusesInstallIDOnReEnrollment(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -198,7 +199,7 @@ func TestConnectReusesInstallIDOnReEnrollment(t *testing.T) {
}
func TestConnectUsesAccountEnrollmentWithoutOpeningBrowser(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
isolateVectorDiscovery(t)
var authorization string
accountServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -242,7 +243,7 @@ func TestConnectUsesAccountEnrollmentWithoutOpeningBrowser(t *testing.T) {
func TestConnectStopsBeforeTheBrowserWhenVectorIsMissingOrOld(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -268,7 +269,7 @@ func TestConnectStopsBeforeTheBrowserWhenVectorIsMissingOrOld(t *testing.T) {
func TestConnectRefusesUnsupportedServiceManagerBeforeEnrolling(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
fd := newFakeDashboard(t)
opened := false
opts := connectOptions(t, fd, &fakeForwarder{supported: false}, fakeVector(t, "0.56.0", 0))
@@ -283,7 +284,7 @@ func TestConnectRefusesUnsupportedServiceManagerBeforeEnrolling(t *testing.T) {
func TestConnectFailsWhenVectorValidateRejectsTheConfig(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
opened := false
@@ -320,7 +321,7 @@ func TestConnectFailsWhenVectorValidateRejectsTheConfig(t *testing.T) {
}
func TestConnectedNeedsEnrollmentAndForwarderConfig(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
if Connected(true) {
t.Fatal("fresh machine")
}
@@ -346,7 +347,7 @@ func TestConnectedNeedsEnrollmentAndForwarderConfig(t *testing.T) {
func TestDisconnectRemovesForwarderAndOptionallyKeepsCredentials(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
if _, err := Connect(context.Background(), connectOptions(t, fd, fwd, fakeVector(t, "0.56.0", 0))); err != nil {
@@ -395,7 +396,7 @@ func TestDisconnectRemovesForwarderAndOptionallyKeepsCredentials(t *testing.T) {
func TestStatusReportsCredentialState(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if got := Status(true, StatusOptions{}); got.Enabled || got.Message != "" {
t.Fatalf("not enrolled status = %+v", got)
}
@@ -458,7 +459,7 @@ func mustJSON(t *testing.T, v any) []byte {
func TestConnectPinsInstallIDBeforeEnrollmentSoRetriesReuseIt(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -492,7 +493,7 @@ func TestConnectPinsInstallIDBeforeEnrollmentSoRetriesReuseIt(t *testing.T) {
func TestConnectResultJSONUsesSnakeCaseAndNormalizedDashboardURL(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
opts := connectOptions(t, fd, &fakeForwarder{supported: true}, fakeVector(t, "0.56.0", 0))
@@ -518,7 +519,7 @@ func TestConnectResultJSONUsesSnakeCaseAndNormalizedDashboardURL(t *testing.T) {
func TestLoopbackIngestURLIsAcceptedEndToEnd(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fd.ingestURL = "http://127.0.0.1:9999"
@@ -548,7 +549,7 @@ func TestLoopbackIngestURLIsAcceptedEndToEnd(t *testing.T) {
func TestConnectClearsBufferOnPrivacyModeChange(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -578,7 +579,7 @@ func TestConnectClearsBufferOnPrivacyModeChange(t *testing.T) {
func TestConnectRejectedConfigOnPrivacyChangeRotatesNoKeyAndKeepsForwarderRunning(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -639,7 +640,7 @@ func TestConnectRejectedConfigOnPrivacyChangeRotatesNoKeyAndKeepsForwarderRunnin
func TestConnectPreservesBufferWhenPrivacyModeUnchanged(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
@@ -665,7 +666,7 @@ func TestConnectPreservesBufferWhenPrivacyModeUnchanged(t *testing.T) {
func TestDisconnectIgnoresALeftoverInstallIDFromACancelledConnect(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
// A connect that was cancelled after pinning the id leaves only asymptote/install-id.
if err := WriteInstallID(true, "abc123"); err != nil {
t.Fatal(err)
@@ -702,7 +703,7 @@ func TestConnectWithRealVectorOnAFreshMachine(t *testing.T) {
if vector == "" {
t.Skip("set BEACON_TEST_VECTOR_BIN to run connect against a real Vector")
}
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
fwd := &fakeForwarder{supported: true}
diff --git a/cli/beacon/internal/endpoint/asymptote/vector_test.go b/cli/beacon/internal/endpoint/asymptote/vector_test.go
index 119aad50..58f859b7 100644
--- a/cli/beacon/internal/endpoint/asymptote/vector_test.go
+++ b/cli/beacon/internal/endpoint/asymptote/vector_test.go
@@ -7,6 +7,8 @@ import (
"slices"
"strings"
"testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
// isolateVectorDiscovery hides the machine's own Vector installs from FindVector.
@@ -85,7 +87,7 @@ func TestValidateVectorConfigSurfacesVectorOutput(t *testing.T) {
func TestEnrollmentStoreUsesPrivatePermissionsAndAtomicWrites(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if _, err := LoadEnrollment(true); !errors.Is(err, ErrNotEnrolled) {
t.Fatalf("expected ErrNotEnrolled, got %v", err)
}
@@ -96,7 +98,7 @@ func TestEnrollmentStoreUsesPrivatePermissionsAndAtomicWrites(t *testing.T) {
t.Fatal(err)
}
info, err := os.Stat(SecretsPath(true))
- if err != nil || info.Mode().Perm() != 0o600 {
+ if err != nil || (testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0o600) {
t.Fatalf("secrets mode: %v %v", info, err)
}
entries, _ := os.ReadDir(Dir(true))
diff --git a/cli/beacon/internal/endpoint/cloudwatch/cloudwatch_test.go b/cli/beacon/internal/endpoint/cloudwatch/cloudwatch_test.go
index a9b7dcb6..ace8ec4e 100644
--- a/cli/beacon/internal/endpoint/cloudwatch/cloudwatch_test.go
+++ b/cli/beacon/internal/endpoint/cloudwatch/cloudwatch_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestConfigSnippetUsesConfiguredPath(t *testing.T) {
@@ -57,7 +59,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
@@ -187,6 +189,8 @@ func TestConfigSnippetFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/dashboard/server_test.go b/cli/beacon/internal/endpoint/dashboard/server_test.go
index 1cadd535..932e1bd9 100644
--- a/cli/beacon/internal/endpoint/dashboard/server_test.go
+++ b/cli/beacon/internal/endpoint/dashboard/server_test.go
@@ -13,6 +13,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/diagnostics"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/lifecycle"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/learning"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/tokens"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve"
)
@@ -444,7 +445,7 @@ func TestTokensEndpointSessionFilterIsCaseInsensitive(t *testing.T) {
}
func TestDetectionsEndpointListsBaselineRules(t *testing.T) {
- t.Setenv("HOME", t.TempDir()) // empty store -> embedded baseline
+ testenv.SetHome(t, t.TempDir()) // empty store -> embedded baseline
handler, err := Handler(Options{UserMode: true, LogPath: filepath.Join(t.TempDir(), "runtime.jsonl")})
if err != nil {
t.Fatalf("Handler returned error: %v", err)
@@ -474,7 +475,7 @@ func TestDetectionsEndpointListsBaselineRules(t *testing.T) {
}
func TestFindingsEndpointReturnsHitsLinkedToRules(t *testing.T) {
- t.Setenv("HOME", t.TempDir()) // empty store -> embedded baseline
+ testenv.SetHome(t, t.TempDir()) // empty store -> embedded baseline
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
// A destructive command the baseline "recursive-root-delete" rule matches.
line := `{"timestamp":"2026-06-11T10:00:00Z","vendor":"beacon","product":"endpoint-agent","schema_version":"1.0","event":{"kind":"agent_runtime","action":"command.executed","category":"command"},"severity":"info","endpoint":{"os":"darwin"},"harness":{"name":"claude_code"},"session":{"id":"local-session"},"command":{"command":"rm -rf /"},"message":"command.executed"}`
@@ -519,7 +520,7 @@ func TestFindingsEndpointReturnsHitsLinkedToRules(t *testing.T) {
}
func TestRunScanRejectsEmptyRuleSet(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
_, err := RunScan(true, filepath.Join(t.TempDir(), "runtime.jsonl"), t.TempDir(), "", "")
if err == nil {
t.Fatal("expected empty rule set to be rejected")
@@ -531,7 +532,7 @@ func TestRunScanRejectsEmptyRuleSet(t *testing.T) {
func TestInventoryEndpointReturnsConfigsAndMCPServers(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
// A Claude Code user config declaring one MCP server, which the inventory
// scan should discover and surface.
claudeDir := filepath.Join(home, ".claude")
diff --git a/cli/beacon/internal/endpoint/datadog/datadog_test.go b/cli/beacon/internal/endpoint/datadog/datadog_test.go
index edaa769c..afa9b531 100644
--- a/cli/beacon/internal/endpoint/datadog/datadog_test.go
+++ b/cli/beacon/internal/endpoint/datadog/datadog_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestConfigSnippetUsesConfiguredPath(t *testing.T) {
@@ -147,6 +149,8 @@ func TestConfigSnippetFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/detect/detect_test.go b/cli/beacon/internal/endpoint/detect/detect_test.go
index 3738dd15..9d02d32d 100644
--- a/cli/beacon/internal/endpoint/detect/detect_test.go
+++ b/cli/beacon/internal/endpoint/detect/detect_test.go
@@ -7,6 +7,7 @@ import (
"testing"
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
"github.com/asymptote-labs/agent-beacon/pkg/asymptoteobserve/threatrules"
)
@@ -55,7 +56,7 @@ func TestBaselineDelegates(t *testing.T) {
}
func TestLoadActiveFallsBackToBaseline(t *testing.T) {
- t.Setenv("HOME", t.TempDir()) // empty store -> baseline
+ testenv.SetHome(t, t.TempDir()) // empty store -> baseline
loaded, err := LoadActive(true, "")
if err != nil {
t.Fatalf("load active: %v", err)
@@ -66,7 +67,7 @@ func TestLoadActiveFallsBackToBaseline(t *testing.T) {
}
func TestInstallRemoveRoundTripViaUserMode(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
src := filepath.Join(t.TempDir(), "my.rule.yaml")
if err := os.WriteFile(src, []byte(ruleWithID("custom-rule")), 0o644); err != nil {
diff --git a/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go b/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go
index 870c76d9..97cbc7d3 100644
--- a/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go
+++ b/cli/beacon/internal/endpoint/diagnostics/diagnostics_test.go
@@ -84,7 +84,7 @@ func TestCheckLogPermissions(t *testing.T) {
func TestRunAndHasFailures(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := endpointconfig.Default(true, filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl"))
if _, err := endpointconfig.Save(cfg); err != nil {
t.Fatalf("save config: %v", err)
@@ -126,7 +126,7 @@ func TestRunAndHasFailures(t *testing.T) {
func TestLaunchPlistPathMatchesServiceManager(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
userPath := servicePlistPathForTest(true)
wantUserPath := filepath.Join(home, "Library", "LaunchAgents", service.UserLabel+".plist")
diff --git a/cli/beacon/internal/endpoint/elastic/elastic_test.go b/cli/beacon/internal/endpoint/elastic/elastic_test.go
index 623eddb8..513f72a0 100644
--- a/cli/beacon/internal/endpoint/elastic/elastic_test.go
+++ b/cli/beacon/internal/endpoint/elastic/elastic_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestInputSnippetUsesConfiguredPath(t *testing.T) {
@@ -240,6 +242,8 @@ func TestInputSnippetFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/falcon/falcon_test.go b/cli/beacon/internal/endpoint/falcon/falcon_test.go
index 4df128a4..91c122bd 100644
--- a/cli/beacon/internal/endpoint/falcon/falcon_test.go
+++ b/cli/beacon/internal/endpoint/falcon/falcon_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestConfigSnippetUsesConfiguredPath(t *testing.T) {
@@ -59,7 +61,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0755 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0755 {
t.Fatalf("generated smoke-test script should be 0755, mode=%s", info.Mode().Perm())
}
}
@@ -218,6 +220,8 @@ func TestSmokeTestFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/gcs/gcs_test.go b/cli/beacon/internal/endpoint/gcs/gcs_test.go
index 1266d595..39b73371 100644
--- a/cli/beacon/internal/endpoint/gcs/gcs_test.go
+++ b/cli/beacon/internal/endpoint/gcs/gcs_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
@@ -18,8 +20,10 @@ func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
if !strings.Contains(got, "/tmp/beacon/runtime.jsonl") {
t.Fatalf("script did not include configured path: %s", got)
}
- if !strings.Contains(got, "/tmp/beacon/inventory_state.jsonl") {
- t.Fatalf("script did not include derived inventory path: %s", got)
+ // Derived with the host's separator, so the expectation is too: the assertion is that the
+ // inventory stream sits beside the configured log, not what a separator looks like.
+ if want := filepath.Join("/tmp/beacon", "inventory_state.jsonl"); !strings.Contains(got, want) {
+ t.Fatalf("script did not include derived inventory path %q: %s", want, got)
}
if strings.Contains(got, "{{LOG_PATH}}") {
t.Fatalf("script still contains template token: %s", got)
@@ -65,7 +69,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm()&0111 == 0 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm()&0111 == 0 {
t.Fatalf("generated script should be executable, mode=%s", info.Mode())
}
vectorPath := filepath.Join(dir, "vector.toml")
@@ -83,7 +87,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
@@ -239,6 +243,8 @@ func TestUploadSmokeTestFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
index a32f574e..41fe667f 100644
--- a/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/inventory_job_test.go
@@ -10,6 +10,7 @@ import (
endpointconfig "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/config"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/service"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
// recordingInventoryJob stands in for service.InventoryManager and records what lifecycle asked of it.
@@ -75,7 +76,7 @@ func writeInventoryConfig(t *testing.T, userMode bool, body string) {
// No config at all is the fresh-install case, and it must mean enabled: the job is on by default.
func TestReconcileInventoryJobWritesAndLoadsWhenEnabled(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
calls := installFakeInventoryJob(t, true)
result, err := ReconcileInventoryJob(InventoryJobOptions{UserMode: true, Program: "/usr/local/bin/beacon", LogPath: "/tmp/runtime.jsonl", Load: true})
if err != nil {
@@ -90,7 +91,7 @@ func TestReconcileInventoryJobWritesAndLoadsWhenEnabled(t *testing.T) {
}
func TestReconcileInventoryJobUnloadsAndRemovesWhenDisabled(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
writeInventoryConfig(t, true, `{"user_mode":true,"inventory_heartbeat":{"enabled":false}}`)
calls := installFakeInventoryJob(t, true)
result, err := ReconcileInventoryJob(InventoryJobOptions{UserMode: true, Program: "/usr/local/bin/beacon", Load: true})
@@ -106,7 +107,7 @@ func TestReconcileInventoryJobUnloadsAndRemovesWhenDisabled(t *testing.T) {
}
func TestReconcileInventoryJobSkipsUnsupportedWithoutError(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
calls := installFakeInventoryJob(t, false)
result, err := ReconcileInventoryJob(InventoryJobOptions{UserMode: true, Program: "/usr/local/bin/beacon", Load: true})
if err != nil {
@@ -118,7 +119,7 @@ func TestReconcileInventoryJobSkipsUnsupportedWithoutError(t *testing.T) {
}
func TestReconcileInventoryJobWritesWithoutLoadingWhenAsked(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
calls := installFakeInventoryJob(t, true)
result, err := ReconcileInventoryJob(InventoryJobOptions{UserMode: true, Program: "/usr/local/bin/beacon", Load: false})
if err != nil {
@@ -155,7 +156,7 @@ func TestInventoryEnabledFromConfigFileDefaultsToTrue(t *testing.T) {
// A package upgrade re-runs install, which rebuilds config.json from defaults. An operator's
// explicit `enabled: false` has to survive that, or the job would silently come back.
func TestBuildConfigPreservesInventoryBlock(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
writeInventoryConfig(t, true, `{"user_mode":true,"log_path":"/tmp/runtime.jsonl","inventory_heartbeat":{"enabled":false,"runtimes":["cursor"]}}`)
cfg := buildConfig(InstallOptions{UserMode: true})
if cfg.Inventory == nil || cfg.Inventory.Enabled == nil || *cfg.Inventory.Enabled || len(cfg.Inventory.Runtimes) != 1 {
@@ -168,7 +169,7 @@ func TestInstallWritesTheInventoryJobWithoutLoadingItOnNoStart(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorPath := filepath.Join(home, "bin", "beacon-otelcol")
if err := os.MkdirAll(filepath.Dir(collectorPath), 0o755); err != nil {
t.Fatal(err)
@@ -213,7 +214,7 @@ func TestInstallReportsAHostWithoutASchedulerAndStillSucceeds(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorPath := filepath.Join(home, "bin", "beacon-otelcol")
if err := os.MkdirAll(filepath.Dir(collectorPath), 0o755); err != nil {
t.Fatal(err)
@@ -240,7 +241,7 @@ func TestInstallReportsAHostWithoutASchedulerAndStillSucceeds(t *testing.T) {
}
func TestUninstallRemovesTheInventoryJobForTheMode(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
old := removeInventoryJob
var removedFor []bool
removeInventoryJob = func(userMode bool) { removedFor = append(removedFor, userMode) }
@@ -283,7 +284,7 @@ func TestRollbackUnloadsALoadedInventoryJob(t *testing.T) {
}
func TestReconcileSurfacesARefusedLoad(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
installFakeInventoryJobWithLoadError(t, true, errors.New("enable --now refused"))
result, err := ReconcileInventoryJob(InventoryJobOptions{UserMode: true, Program: "/usr/local/bin/beacon", Load: true})
if err == nil || result.Loaded {
diff --git a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
index 69bd18ec..8dbe7478 100644
--- a/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/lifecycle_test.go
@@ -17,6 +17,7 @@ import (
"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/endpoint/writer"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestRestoreTargetTimestampedBackup(t *testing.T) {
@@ -37,7 +38,7 @@ func TestRestoreTargetLegacyBackup(t *testing.T) {
func TestBuildConfigAppliesInstallOptions(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, "runtime.jsonl")
collectorPath := filepath.Join(home, "bin", "otelcol")
@@ -88,7 +89,7 @@ func TestBuildConfigAppliesInstallOptions(t *testing.T) {
func TestBuildConfigPreservesAutoUpdateMode(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
configPath := endpointconfig.ConfigPath(true)
if err := os.MkdirAll(filepath.Dir(configPath), 0o755); err != nil {
t.Fatal(err)
@@ -229,7 +230,7 @@ func TestConfigureHarnessesRejectsClineAsHookManaged(t *testing.T) {
func TestConfigureHarnessesAcceptsGemini(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := endpointconfig.Config{
UserMode: true,
Harnesses: []string{"gemini"},
@@ -258,7 +259,7 @@ func TestConfigureHarnessesAcceptsGemini(t *testing.T) {
func TestWriteReadManifestRoundTrip(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
manifest := Manifest{
CreatedAt: "2026-05-12T00:00:00Z",
UserMode: true,
@@ -309,7 +310,7 @@ func TestAutoUpdateModeFromConfigFileIgnoresDestinationValidation(t *testing.T)
}
if info, err := os.Stat(path); err != nil {
t.Fatal(err)
- } else if got := info.Mode().Perm(); got != 0o600 {
+ } else if got := info.Mode().Perm(); testenv.HasPOSIXFileModes() && got != 0o600 {
t.Fatalf("permissions = %v, want 0600", got)
}
data, err := os.ReadFile(path)
@@ -437,7 +438,7 @@ func TestUninstallFallbackRemovesKnownFiles(t *testing.T) {
t.Skip("launchd paths are macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")
cfg := endpointconfig.Default(true, logPath)
for _, path := range []string{endpointconfig.ConfigPath(true), cfg.Collector.ConfigPath, logPath} {
@@ -461,7 +462,7 @@ func TestUninstallFallbackRemovesKnownFiles(t *testing.T) {
func TestConfigureHarnessesAcceptsVSCode(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := endpointconfig.Config{
UserMode: true,
Harnesses: []string{"vscode"},
@@ -498,7 +499,7 @@ func TestInstallUserModeWithoutStartingService(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorPath := filepath.Join(home, "bin", "beacon-otelcol")
if err := os.MkdirAll(filepath.Dir(collectorPath), 0755); err != nil {
t.Fatalf("mkdir fake collector dir: %v", err)
@@ -550,7 +551,7 @@ func TestInstallPreservesManagedIngestBlock(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorPath := filepath.Join(home, "bin", "beacon-otelcol")
if err := os.MkdirAll(filepath.Dir(collectorPath), 0755); err != nil {
t.Fatal(err)
@@ -593,7 +594,7 @@ func TestInstallFailsBeforeWritingArtifactsWhenCollectorMissing(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")
missingCollector := filepath.Join(home, "bin", "beacon-otelcol")
@@ -621,7 +622,7 @@ func TestInstallRollsBackArtifactsWhenFinalEventFails(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
collectorPath := filepath.Join(home, "bin", "beacon-otelcol")
if err := os.MkdirAll(filepath.Dir(collectorPath), 0755); err != nil {
t.Fatalf("mkdir fake collector dir: %v", err)
@@ -663,7 +664,7 @@ func TestRepairPreservesExistingConfigWhenReinstallFails(t *testing.T) {
t.Skip("install preflight is macOS-only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, ".beacon", "endpoint", "logs", "runtime.jsonl")
configPath := endpointconfig.ConfigPath(true)
if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
@@ -721,7 +722,7 @@ func freePort(t *testing.T) int {
func TestConfigureHarnessesAcceptsClaude(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
cfg := endpointconfig.Config{
UserMode: true,
Harnesses: []string{"claude"},
@@ -765,7 +766,7 @@ func TestSameCollectorPorts(t *testing.T) {
func TestLoadOrDefaultFallsBackToDefaultThenLoadsSavedConfig(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, "runtime.jsonl")
// No config saved yet: returns a default with the requested log path.
@@ -912,7 +913,7 @@ func TestDestinationStatusAndInstallDestinationReportEnabledHEC(t *testing.T) {
// still be the user's: each mode has its own enrollment, and the system one is root-only.
func TestStatusReportsManagedIngestForRequestedMode(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if err := asymptote.SaveEnrollment(true, asymptote.Enrollment{InstallID: "i", IngestURL: "https://ingest.example", DeviceID: "user-device", OrganizationID: "org", OrganizationName: "Org"}); err != nil {
t.Fatal(err)
}
@@ -933,7 +934,7 @@ func TestStatusReportsManagedIngestForRequestedMode(t *testing.T) {
func TestGetStatusAndResolveRuntimeLogReportRequestedConfig(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logPath := filepath.Join(home, "runtime.jsonl")
source := ResolveRuntimeLog(true, logPath)
diff --git a/cli/beacon/internal/endpoint/lifecycle/uninstall_reporting_test.go b/cli/beacon/internal/endpoint/lifecycle/uninstall_reporting_test.go
index 2bb08fb2..545307c9 100644
--- a/cli/beacon/internal/endpoint/lifecycle/uninstall_reporting_test.go
+++ b/cli/beacon/internal/endpoint/lifecycle/uninstall_reporting_test.go
@@ -5,6 +5,8 @@ import (
"path/filepath"
"strings"
"testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
// The failure this exists to catch: `beacon endpoint uninstall --system` without privileges used to
@@ -28,7 +30,7 @@ func TestUninstallRefusesAnUnprivilegedSystemRemoval(t *testing.T) {
// A user-mode uninstall needs no privileges and must not be caught by that gate.
func TestUninstallAllowsUserModeWithoutPrivileges(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if err := Uninstall(UninstallOptions{UserMode: true}); err != nil {
t.Errorf("user-mode uninstall failed with nothing installed: %v", err)
@@ -40,7 +42,7 @@ func TestUninstallAllowsUserModeWithoutPrivileges(t *testing.T) {
// to keep logs, and invisible, because the file an operator would look for was gone.
func TestUninstallRemovesRotatedArchivesToo(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logDir := filepath.Join(home, ".beacon", "endpoint", "logs")
if err := os.MkdirAll(logDir, 0o755); err != nil {
@@ -68,7 +70,7 @@ func TestUninstallRemovesRotatedArchivesToo(t *testing.T) {
// --keep-logs has to keep all of them, not just the current one.
func TestUninstallKeepLogsKeepsTheArchives(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
logDir := filepath.Join(home, ".beacon", "endpoint", "logs")
if err := os.MkdirAll(logDir, 0o755); err != nil {
diff --git a/cli/beacon/internal/endpoint/rapid7/rapid7_test.go b/cli/beacon/internal/endpoint/rapid7/rapid7_test.go
index 4c2fe607..73ca76eb 100644
--- a/cli/beacon/internal/endpoint/rapid7/rapid7_test.go
+++ b/cli/beacon/internal/endpoint/rapid7/rapid7_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
@@ -56,7 +58,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm()&0111 == 0 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm()&0111 == 0 {
t.Fatalf("generated script should be executable, mode=%s", info.Mode())
}
vectorPath := filepath.Join(dir, "vector.toml")
@@ -71,7 +73,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
@@ -194,6 +196,8 @@ func TestUploadSmokeTestFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/s3/s3_test.go b/cli/beacon/internal/endpoint/s3/s3_test.go
index cd2889cf..c92df985 100644
--- a/cli/beacon/internal/endpoint/s3/s3_test.go
+++ b/cli/beacon/internal/endpoint/s3/s3_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
@@ -18,8 +20,10 @@ func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
if !strings.Contains(got, "/tmp/beacon/runtime.jsonl") {
t.Fatalf("script did not include configured path: %s", got)
}
- if !strings.Contains(got, "/tmp/beacon/inventory_state.jsonl") {
- t.Fatalf("script did not include derived inventory path: %s", got)
+ // Derived with the host's separator, so the expectation is too: the assertion is that the
+ // inventory stream sits beside the configured log, not what a separator looks like.
+ if want := filepath.Join("/tmp/beacon", "inventory_state.jsonl"); !strings.Contains(got, want) {
+ t.Fatalf("script did not include derived inventory path %q: %s", want, got)
}
if strings.Contains(got, "{{LOG_PATH}}") {
t.Fatalf("script still contains template token: %s", got)
@@ -61,7 +65,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm()&0111 == 0 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm()&0111 == 0 {
t.Fatalf("generated script should be executable, mode=%s", info.Mode())
}
vectorPath := filepath.Join(dir, "vector.toml")
@@ -79,7 +83,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
@@ -224,6 +228,8 @@ func TestUploadSmokeTestFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/endpoint/service/forwarder_test.go b/cli/beacon/internal/endpoint/service/forwarder_test.go
index 865aad1f..78d92120 100644
--- a/cli/beacon/internal/endpoint/service/forwarder_test.go
+++ b/cli/beacon/internal/endpoint/service/forwarder_test.go
@@ -8,6 +8,8 @@ import (
"runtime"
"strings"
"testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestForwarderPlistRunsVectorResidentWithKeepAlive(t *testing.T) {
@@ -119,7 +121,7 @@ func TestForwarderLoadWaitsForTheOldJobAndVerifiesTheNewOne(t *testing.T) {
t.Skip("launchd only")
}
shrinkLaunchdWaits(t)
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
var calls []string
printsAfterBootout := 0
bootstrapped := false
@@ -163,7 +165,7 @@ func TestForwarderLoadFailsWhenTheNewInstanceNeverStarts(t *testing.T) {
t.Skip("launchd only")
}
shrinkLaunchdWaits(t)
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
bootstrapped := false
oldRun := runLaunchctlCommand
runLaunchctlCommand = func(args ...string) (string, error) {
diff --git a/cli/beacon/internal/endpoint/service/inventory_test.go b/cli/beacon/internal/endpoint/service/inventory_test.go
index 2469bcf8..12c533cd 100644
--- a/cli/beacon/internal/endpoint/service/inventory_test.go
+++ b/cli/beacon/internal/endpoint/service/inventory_test.go
@@ -9,6 +9,8 @@ import (
"strings"
"testing"
"time"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestInventoryPlistIsAOneShotIntervalJob(t *testing.T) {
@@ -144,7 +146,7 @@ func TestInventoryUnitPathsIncludeTheServiceOnSystemd(t *testing.T) {
t.Skip("POSIX paths only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
m := InventoryManager{UserMode: true, Kind: KindSystemd}
paths := m.UnitPaths()
wantTimer := filepath.Join(home, ".config", "systemd", "user", InventoryTimerUnit)
@@ -205,7 +207,7 @@ func TestInventoryWriteUnitRendersTheModeIntoThePlist(t *testing.T) {
t.Skip("launchd only")
}
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
t.Setenv(InventoryIntervalEnv, "")
m := InventoryManager{UserMode: true, Kind: KindLaunchd}
path, err := m.WriteUnit("/usr/local/bin/beacon", "/tmp/scratch/runtime.jsonl")
@@ -234,7 +236,7 @@ func TestInventoryLoadBootstrapsAndReloadsAnExistingJob(t *testing.T) {
t.Skip("launchd only")
}
shrinkLaunchdWaits(t)
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
var calls []string
alreadyLoaded := true
oldRun := runLaunchctlCommand
diff --git a/cli/beacon/internal/endpoint/siempack/pack_test.go b/cli/beacon/internal/endpoint/siempack/pack_test.go
index 3cbd1d9d..3037cfbe 100644
--- a/cli/beacon/internal/endpoint/siempack/pack_test.go
+++ b/cli/beacon/internal/endpoint/siempack/pack_test.go
@@ -5,6 +5,8 @@ import (
"path/filepath"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func testPack() Pack {
@@ -80,7 +82,7 @@ func TestPackInstallWritesRenderedFilesWithModes(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0755 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0755 {
t.Fatalf("run.sh mode = %v, want 0755", info.Mode().Perm())
}
diff --git a/cli/beacon/internal/endpoint/siempack/siempack_test.go b/cli/beacon/internal/endpoint/siempack/siempack_test.go
index 93b5a822..b62f37fd 100644
--- a/cli/beacon/internal/endpoint/siempack/siempack_test.go
+++ b/cli/beacon/internal/endpoint/siempack/siempack_test.go
@@ -6,6 +6,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestRenderLogPath(t *testing.T) {
@@ -66,7 +68,7 @@ func TestInstallWritesFilesWithModesAndLogPath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0755 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0755 {
t.Fatalf("script mode = %s, want 0755", info.Mode().Perm())
}
@@ -74,7 +76,7 @@ func TestInstallWritesFilesWithModesAndLogPath(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if configInfo.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && configInfo.Mode().Perm() != 0644 {
t.Fatalf("config mode = %s, want 0644", configInfo.Mode().Perm())
}
}
diff --git a/cli/beacon/internal/endpoint/sumo/sumo_test.go b/cli/beacon/internal/endpoint/sumo/sumo_test.go
index 56c5984a..0f4b3951 100644
--- a/cli/beacon/internal/endpoint/sumo/sumo_test.go
+++ b/cli/beacon/internal/endpoint/sumo/sumo_test.go
@@ -8,6 +8,8 @@ import (
"strings"
"testing"
"testing/fstest"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestUploadSmokeTestUsesConfiguredPath(t *testing.T) {
@@ -60,7 +62,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm()&0111 == 0 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm()&0111 == 0 {
t.Fatalf("generated script should be executable, mode=%s", info.Mode())
}
vectorPath := filepath.Join(dir, "vector.toml")
@@ -75,7 +77,7 @@ func TestInstallPackWritesExpectedFiles(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if info.Mode().Perm() != 0644 {
+ if testenv.HasPOSIXFileModes() && info.Mode().Perm() != 0644 {
t.Fatalf("generated vector config should be 0644, mode=%s", info.Mode().Perm())
}
}
@@ -200,6 +202,8 @@ func TestUploadSmokeTestFromFS_ErrorOnMissingAsset(t *testing.T) {
}
func TestInstallPack_ErrorOnWriteFailure(t *testing.T) {
+ // A 0555 directory is only read-only where Unix permission bits exist; Windows ignores them.
+ testenv.RequirePOSIXFileModes(t)
if os.Getuid() == 0 {
t.Skip("running as root: filesystem permission restrictions do not apply")
}
diff --git a/cli/beacon/internal/learning/store_test.go b/cli/beacon/internal/learning/store_test.go
index 7f2f6faa..7d72eac4 100644
--- a/cli/beacon/internal/learning/store_test.go
+++ b/cli/beacon/internal/learning/store_test.go
@@ -236,8 +236,12 @@ func setMemoryUpdatedAt(t *testing.T, store *Store, id, updatedAt string) {
func TestProjectIDForPathMatchesTheMostSpecificKnownProject(t *testing.T) {
store := Open(filepath.Join(t.TempDir(), "memory.db"))
- outer := asymptoteobserve.LearningProjectV1{ID: "project-outer", Path: "/work"}
- inner := asymptoteobserve.LearningProjectV1{ID: "project-inner", Path: "/work/repo"}
+ // Absolute on every platform, because stored project paths are: ProjectIDForPath makes the
+ // relayed path absolute before comparing, and on Windows "/work" gains a drive letter that a
+ // stored "/work" never has. Nothing here is created on disk; resolution must not touch it.
+ root := t.TempDir()
+ outer := asymptoteobserve.LearningProjectV1{ID: "project-outer", Path: filepath.Join(root, "work")}
+ inner := asymptoteobserve.LearningProjectV1{ID: "project-inner", Path: filepath.Join(root, "work", "repo")}
for _, project := range []asymptoteobserve.LearningProjectV1{outer, inner} {
memory := asymptoteobserve.LearningMemoryV1{
ID: "memory-" + project.ID,
@@ -251,7 +255,7 @@ func TestProjectIDForPathMatchesTheMostSpecificKnownProject(t *testing.T) {
}
}
- got, err := store.ProjectIDForPath("/work/repo/cli/beacon")
+ got, err := store.ProjectIDForPath(filepath.Join(root, "work", "repo", "cli", "beacon"))
if err != nil {
t.Fatalf("ProjectIDForPath: %v", err)
}
@@ -259,20 +263,22 @@ func TestProjectIDForPathMatchesTheMostSpecificKnownProject(t *testing.T) {
t.Fatalf("project ID = %q, want %q", got, inner.ID)
}
- unknown, err := store.ProjectIDForPath("/elsewhere")
+ elsewhere := filepath.Join(root, "elsewhere")
+ unknown, err := store.ProjectIDForPath(elsewhere)
if err != nil {
t.Fatalf("ProjectIDForPath: %v", err)
}
- if want := ProjectID(asymptoteobserve.LearningProjectV1{Path: "/elsewhere"}); unknown != want {
+ if want := ProjectID(asymptoteobserve.LearningProjectV1{Path: elsewhere}); unknown != want {
t.Fatalf("unknown project ID = %q, want the path-derived ID %q", unknown, want)
}
}
func TestListMemoriesScopesARelayedProjectPathToOneProject(t *testing.T) {
store := Open(filepath.Join(t.TempDir(), "memory.db"))
+ root := t.TempDir() // absolute on every platform; see TestProjectIDForPathMatchesTheMostSpecificKnownProject
for _, project := range []asymptoteobserve.LearningProjectV1{
- {ID: "project-a", Path: "/work/a"},
- {ID: "project-b", Path: "/work/b"},
+ {ID: "project-a", Path: filepath.Join(root, "work", "a")},
+ {ID: "project-b", Path: filepath.Join(root, "work", "b")},
} {
memory := asymptoteobserve.LearningMemoryV1{
ID: "memory-" + project.ID,
@@ -286,7 +292,7 @@ func TestListMemoriesScopesARelayedProjectPathToOneProject(t *testing.T) {
}
}
- memories, err := store.ListMemories(Query{ProjectPath: "/work/a/sub"})
+ memories, err := store.ListMemories(Query{ProjectPath: filepath.Join(root, "work", "a", "sub")})
if err != nil {
t.Fatalf("ListMemories: %v", err)
}
@@ -294,7 +300,7 @@ func TestListMemoriesScopesARelayedProjectPathToOneProject(t *testing.T) {
t.Fatalf("memories = %#v, want only project-a", memories)
}
- none, err := store.ListMemories(Query{ProjectPath: "/work/c"})
+ none, err := store.ListMemories(Query{ProjectPath: filepath.Join(root, "work", "c")})
if err != nil {
t.Fatalf("ListMemories: %v", err)
}
diff --git a/cli/beacon/internal/onboarding/profile_test.go b/cli/beacon/internal/onboarding/profile_test.go
index be97a5a2..8ef775c4 100644
--- a/cli/beacon/internal/onboarding/profile_test.go
+++ b/cli/beacon/internal/onboarding/profile_test.go
@@ -5,11 +5,13 @@ import (
"os"
"path/filepath"
"testing"
+
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/testenv"
)
func TestPathHonorsHome(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
want := filepath.Join(home, ProfilePath)
if got := Path(); got != want {
@@ -18,7 +20,7 @@ func TestPathHonorsHome(t *testing.T) {
}
func TestLoadMissingProfileReportsNotPrompted(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
p := Load()
if p.Prompted() {
@@ -33,7 +35,7 @@ func TestLoadMissingProfileReportsNotPrompted(t *testing.T) {
// signal; refusing to install over it would trade a real user for a lead.
func TestLoadCorruptProfileReportsNotPrompted(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ProfilePath)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
@@ -48,7 +50,7 @@ func TestLoadCorruptProfileReportsNotPrompted(t *testing.T) {
}
func TestSaveRoundTrip(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
in := Profile{
Onboarding: Onboarding{
@@ -88,8 +90,9 @@ func TestSaveRoundTrip(t *testing.T) {
// The profile holds the operator's email address, so it must not be world-readable.
func TestSaveUsesOwnerOnlyPermissions(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if err := Save(Profile{}); err != nil {
t.Fatalf("Save: %v", err)
@@ -107,8 +110,9 @@ func TestSaveUsesOwnerOnlyPermissions(t *testing.T) {
// A profile written by an older build with looser permissions gets tightened rather
// than silently kept, because os.WriteFile only applies its mode on creation.
func TestSaveTightensExistingPermissions(t *testing.T) {
+ testenv.RequirePOSIXFileModes(t)
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
path := filepath.Join(home, ProfilePath)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatalf("MkdirAll: %v", err)
@@ -131,7 +135,7 @@ func TestSaveTightensExistingPermissions(t *testing.T) {
}
func TestSavePreservesExistingInstallID(t *testing.T) {
- t.Setenv("HOME", t.TempDir())
+ testenv.SetHome(t, t.TempDir())
if err := Save(Profile{InstallID: "deadbeefdeadbeefdeadbeefdeadbeef"}); err != nil {
t.Fatalf("Save: %v", err)
@@ -148,7 +152,7 @@ func TestSavePreservesExistingInstallID(t *testing.T) {
func TestSaveWritesValidJSON(t *testing.T) {
home := t.TempDir()
- t.Setenv("HOME", home)
+ testenv.SetHome(t, home)
if err := Save(Profile{Onboarding: Onboarding{Outcome: OutcomeSkipped}}); err != nil {
t.Fatalf("Save: %v", err)
diff --git a/cli/beacon/internal/osuser/osuser_test.go b/cli/beacon/internal/osuser/osuser_test.go
index edfed20c..719d3d88 100644
--- a/cli/beacon/internal/osuser/osuser_test.go
+++ b/cli/beacon/internal/osuser/osuser_test.go
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"os/user"
+ "runtime"
"strconv"
"strings"
"testing"
@@ -100,6 +101,11 @@ func TestLookupReportsWhyWhenNSSIsUnavailable(t *testing.T) {
// The fast path must still work, and must not consult NSS for an account the local database can
// already answer -- that would put a subprocess on the hot path of every ordinary host.
func TestLookupUsesTheLocalDatabaseFirst(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ // Info carries a numeric UID and GID. Windows identifies accounts by SID, which fromUser
+ // rightly refuses to coerce, so no Windows account resolves on the local fast path.
+ t.Skip("POSIX account database; Windows accounts have SIDs, not numeric UIDs")
+ }
me, err := user.Current()
if err != nil || me.Username == "" {
t.Skip("no resolvable current user on this host")
diff --git a/cli/beacon/internal/testenv/testenv.go b/cli/beacon/internal/testenv/testenv.go
index 42a97399..78f7737d 100644
--- a/cli/beacon/internal/testenv/testenv.go
+++ b/cli/beacon/internal/testenv/testenv.go
@@ -49,11 +49,21 @@ func SetHome(t *testing.T, dir string) {
// writes. Skipping is honest in the meantime; asserting 0666 == 0600 would not be.
func RequirePOSIXFileModes(t *testing.T) {
t.Helper()
- if runtime.GOOS == "windows" {
+ if !HasPOSIXFileModes() {
t.Skip("Unix permission bits do not exist on Windows; the equivalent is an ACL check")
}
}
+// HasPOSIXFileModes reports whether this platform reports the Unix permission bits Beacon writes.
+//
+// It is the per-assertion form of RequirePOSIXFileModes, for a test that checks a mode alongside
+// other behavior: `if testenv.HasPOSIXFileModes() && perm != 0o600`. Skipping the whole test there
+// would throw away the assertions that do hold on Windows -- that the file was written, and what it
+// contains -- to avoid the one that cannot.
+func HasPOSIXFileModes() bool {
+ return runtime.GOOS != "windows"
+}
+
// 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
diff --git a/cli/beacon/internal/testenv/testenv_test.go b/cli/beacon/internal/testenv/testenv_test.go
new file mode 100644
index 00000000..b820e029
--- /dev/null
+++ b/cli/beacon/internal/testenv/testenv_test.go
@@ -0,0 +1,63 @@
+package testenv
+
+import (
+ "os"
+ "path/filepath"
+ "runtime"
+ "testing"
+)
+
+// The whole point of SetHome is that the standard library's idea of home moves with it. Asserting
+// through os.UserHomeDir rather than by reading the variables back is what makes this fail on the
+// platform where setting HOME alone was the bug.
+func TestSetHomeRedirectsUserHomeDir(t *testing.T) {
+ dir := t.TempDir()
+ SetHome(t, dir)
+
+ got, err := os.UserHomeDir()
+ if err != nil {
+ t.Fatalf("os.UserHomeDir: %v", err)
+ }
+ if got != dir {
+ t.Fatalf("os.UserHomeDir() = %q, want %q", got, dir)
+ }
+ for _, name := range []string{"HOME", "USERPROFILE"} {
+ if value := os.Getenv(name); value != dir {
+ t.Errorf("%s = %q, want %q: callers that read it directly would escape the sandbox", name, value, dir)
+ }
+ }
+}
+
+func TestSetHomeRedirectsWindowsAppDataUnderTheNewHome(t *testing.T) {
+ if runtime.GOOS != "windows" {
+ t.Skip("APPDATA and LOCALAPPDATA are only redirected on Windows")
+ }
+ dir := t.TempDir()
+ SetHome(t, dir)
+
+ for name, want := range map[string]string{
+ "APPDATA": filepath.Join(dir, "AppData", "Roaming"),
+ "LOCALAPPDATA": filepath.Join(dir, "AppData", "Local"),
+ } {
+ if got := os.Getenv(name); got != want {
+ t.Errorf("%s = %q, want %q", name, got, want)
+ }
+ }
+}
+
+// The helper is a claim about the platform, so check the claim rather than the constant: on a
+// platform that reports it, a file written 0600 must read back as 0600.
+func TestHasPOSIXFileModesMatchesWhatStatReports(t *testing.T) {
+ path := filepath.Join(t.TempDir(), "secret")
+ if err := os.WriteFile(path, []byte("x"), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ info, err := os.Stat(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ preserved := info.Mode().Perm() == 0o600
+ if HasPOSIXFileModes() != preserved {
+ t.Fatalf("HasPOSIXFileModes() = %t, but a 0600 file reads back as %o", HasPOSIXFileModes(), info.Mode().Perm())
+ }
+}