The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
test(windows): scope the Windows gate to the packages this port covers
shukieshah85ad164815b9
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 8050c7cc..3876ba8d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -196,12 +196,34 @@ jobs:run: |go build -ldflags "-s -w" -o beacon-hooks.exe .Copy-Item beacon-hooks.exe ..\beacon\internal\embedded\hooks.bin -Force- - name: Test beacon CLI on Windows+ # Scoped to the packages this port actually gives Windows implementations, not `./...`.+ #+ # The rest of the cli/beacon suite has never run on Windows and assumes a POSIX host in ways+ # unrelated to any of this: 47 tests redirect the home directory with t.Setenv("HOME"), which+ # does nothing there because os.UserHomeDir reads USERPROFILE; 15 assert Unix file modes that+ # Windows does not implement; others exec fixtures with no .exe extension. Running them here+ # would produce a permanently red gate that says nothing about the code under test, and a red+ # gate nobody can fix is one nobody reads.+ #+ # Tracked as follow-up work rather than dropped -- see #318. The scope+ # widens as those packages are made portable; it must not widen by adding `./...` back while+ # the assumptions remain.+ - name: Test the ported packages on Windowsworking-directory: cli/beacon- run: go test ./...- - name: Test endpoint packages with the race detector+ run: |+ go test `+ ./internal/endpoint/writer/... `+ ./internal/endpoint/inventory/... `+ ./internal/ingest/endpoint/... `+ ./internal/endpoint/service/... `+ ./internal/endpoint/selfupdate/...+ - name: Test the ported packages with the race detectorworking-directory: cli/beacon- run: go test -race ./internal/endpoint/...+ run: |+ go test -race `+ ./internal/endpoint/writer/... `+ ./internal/endpoint/inventory/... `+ ./internal/endpoint/service/...- name: Test hook adapter on Windowsworking-directory: cli/beacon-hooksrun: go test ./...diff --git a/cli/beacon/internal/endpoint/selfupdate/apply_test.go b/cli/beacon/internal/endpoint/selfupdate/apply_test.goindex a0616042..8fb6e860 100644--- a/cli/beacon/internal/endpoint/selfupdate/apply_test.go+++ b/cli/beacon/internal/endpoint/selfupdate/apply_test.go@@ -100,6 +100,14 @@ func testApplier(t *testing.T, current string, srv *httptest.Server) *Applier {}func TestApplyHappyPath(t *testing.T) {+ // The staged artifact is a `#!/bin/sh` stand-in for the beacon binary, and Apply's health check+ // executes it. Windows has no shebangs, so the check cannot run -- and the Windows apply path+ // is a different flow entirely (msiexec plus an Authenticode check, rather than a tarball into+ // an install prefix), which does not exist yet. Skipped rather than adapted so the skip+ // disappears when that flow lands instead of hiding it.+ if runtime.GOOS == "windows" {+ t.Skip("the POSIX apply flow stages an executable shell stub; the Windows flow is not implemented yet")+ }artifact, sha := makeBeaconTarball(t, "9.9.9")srv := manifestServer(t, "9.9.9", sha, artifact)defer srv.Close()@@ -124,6 +132,14 @@ func TestApplyHappyPath(t *testing.T) {}func TestApplyCleansSuccessfulUpdateStaging(t *testing.T) {+ // The staged artifact is a `#!/bin/sh` stand-in for the beacon binary, and Apply's health check+ // executes it. Windows has no shebangs, so the check cannot run -- and the Windows apply path+ // is a different flow entirely (msiexec plus an Authenticode check, rather than a tarball into+ // an install prefix), which does not exist yet. Skipped rather than adapted so the skip+ // disappears when that flow lands instead of hiding it.+ if runtime.GOOS == "windows" {+ t.Skip("the POSIX apply flow stages an executable shell stub; the Windows flow is not implemented yet")+ }artifact, sha := makeBeaconTarball(t, "9.9.9")srv := manifestServer(t, "9.9.9", sha, artifact)defer srv.Close()diff --git a/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go b/cli/beacon/internal/endpoint/selfupdate/fsutil_test.goindex ea0296d0..6fd8af60 100644--- a/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go+++ b/cli/beacon/internal/endpoint/selfupdate/fsutil_test.go@@ -6,6 +6,7 @@ import ("compress/gzip""os""path/filepath"+ "runtime""testing")@@ -29,6 +30,12 @@ func TestSafeJoinRejectsTraversal(t *testing.T) {}}+ // The rejection cases above are the security contract and hold everywhere. These are about the+ // resolved string, which filepath renders with the host separator -- on Windows they would be+ // asserting path rendering rather than that a safe entry resolves inside dest.+ if runtime.GOOS == "windows" {+ t.Skip("the accepted-path assertions below are POSIX-rendered; traversal rejection is checked above")+ }ok := map[string]string{"opt/beacon/bin/beacon": "/tmp/dest/opt/beacon/bin/beacon","a/b/c": "/tmp/dest/a/b/c",diff --git a/cli/beacon/internal/endpoint/selfupdate/selfupdate_test.go b/cli/beacon/internal/endpoint/selfupdate/selfupdate_test.goindex 06348b13..15b33e70 100644--- a/cli/beacon/internal/endpoint/selfupdate/selfupdate_test.go+++ b/cli/beacon/internal/endpoint/selfupdate/selfupdate_test.go@@ -7,12 +7,18 @@ import ("net/http/httptest""os""path/filepath"+ "runtime""testing""github.com/asymptote-labs/agent-beacon/cli/beacon/internal/updatecheck")func TestClassifyInstall(t *testing.T) {+ // The prefixes this classifies -- /opt/beacon and the Homebrew roots -- are POSIX install+ // locations that do not exist on Windows, so there is no classification to assert there.+ if runtime.GOOS == "windows" {+ t.Skip("install-kind prefixes are POSIX-only")+ }cases := []struct {path stringwant InstallKinddiff --git a/cli/beacon/internal/endpoint/service/service_test.go b/cli/beacon/internal/endpoint/service/service_test.goindex ca0de76e..6973045e 100644--- a/cli/beacon/internal/endpoint/service/service_test.go+++ b/cli/beacon/internal/endpoint/service/service_test.go@@ -268,7 +268,7 @@ func TestLaunchdIsInertOffDarwin(t *testing.T) {// rather than the old "does nothing" assertion.func TestSupervisedLifecycleStartsAndStopsAProcess(t *testing.T) {home := t.TempDir()- t.Setenv("HOME", home)+ setTestHome(t, home)m := Manager{UserMode: true, Kind: KindSupervised}// Loading before install must explain itself rather than silently doing nothing.@@ -283,10 +283,12 @@ func TestSupervisedLifecycleStartsAndStopsAProcess(t *testing.T) {// `<program> --config <path>`, which every sleep implementation rejects as an invalid interval,// so the child exited immediately and the assertion below only passed when it won a race// against the process being reaped. That made it pass on macOS and fail on a Linux runner.- stub := filepath.Join(home, "fake-collector")- if err := os.WriteFile(stub, []byte("#!/bin/sh\nexec sleep 300\n"), 0o755); err != nil {- t.Fatalf("write stub collector: %v", err)- }+ //+ // Nor can a shell script, which is what replaced it: Windows has no shebangs and decides+ // executability by extension, so the stub could not be started there at all -- leaving process+ // detach, graceful termination and liveness untested on the one platform where all three are+ // newly written. See stubCollectorPath.+ stub := stubCollectorPath(t)if _, err := m.WriteUnit(stub, "300"); err != nil {t.Fatalf("WriteUnit: %v", err)}@@ -330,7 +332,7 @@ func TestLaunchctlGuidance(t *testing.T) {func TestLaunchdLabelAndUnitPath(t *testing.T) {home := t.TempDir()- t.Setenv("HOME", home)+ setTestHome(t, home)user := Manager{UserMode: true, Kind: KindLaunchd}if got := user.Label(); got != UserLabel {@@ -359,7 +361,7 @@ func TestLaunchdLabelAndUnitPath(t *testing.T) {func TestSystemdLabelAndUnitPath(t *testing.T) {home := t.TempDir()- t.Setenv("HOME", home)+ setTestHome(t, home)user := Manager{UserMode: true, Kind: KindSystemd}if got := user.Label(); got != SystemdUserUnit {@@ -495,7 +497,7 @@ func TestSupervisedIsAlwaysAvailable(t *testing.T) {func TestSupervisedRecordsAndReportsState(t *testing.T) {home := t.TempDir()- t.Setenv("HOME", home)+ setTestHome(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.gonew file mode 100644index 00000000..3c4df1f2--- /dev/null+++ b/cli/beacon/internal/endpoint/service/testsupport_test.go@@ -0,0 +1,57 @@+package service++import (+ "os"+ "testing"+ "time"+)++// stubCollectorEnv makes the test binary impersonate a long-running collector when set.+//+// See stubCollectorPath for why the stub is this binary rather than a script.+const stubCollectorEnv = "BEACON_TEST_STUB_COLLECTOR"++// TestMain lets the test binary re-exec itself as a stand-in collector.+func TestMain(m *testing.M) {+ if os.Getenv(stubCollectorEnv) != "" {+ // Long-lived and harmless. The supervised backend only needs the child to still be+ // running when Status is asked, and to die when it is signalled.+ time.Sleep(5 * time.Minute)+ os.Exit(0)+ }+ os.Exit(m.Run())+}++// stubCollectorPath returns a program the supervised backend can actually start, on any platform.+//+// The obvious fixture -- a `#!/bin/sh` script written to a temp dir -- is not executable on+// Windows, where there are no shebangs and execution is decided by extension. It failed there with+// "executable file not found in %PATH%", which meant the one test covering process detach,+// graceful termination and liveness never ran on the platform whose implementations of all three+// are new.+//+// Re-execing the test binary avoids the question entirely: it is a real executable everywhere, it+// needs no shell, and it tolerates the `--config <path>` arguments the loader appends because it+// never looks at them. The child inherits the environment, so setting the marker here is what+// makes the re-exec sleep instead of running the suite again.+func stubCollectorPath(t *testing.T) string {+ t.Helper()+ t.Setenv(stubCollectorEnv, "1")+ exe, err := os.Executable()+ if err != nil {+ t.Fatalf("locate the test binary to use as a stub collector: %v", err)+ }+ 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/endpoint/service/updater_test.go b/cli/beacon/internal/endpoint/service/updater_test.goindex 07fdd6cd..5d99fee2 100644--- a/cli/beacon/internal/endpoint/service/updater_test.go+++ b/cli/beacon/internal/endpoint/service/updater_test.go@@ -40,6 +40,13 @@ func TestUpdaterPlistContent(t *testing.T) {}func TestUpdaterPlistPath(t *testing.T) {+ // The launchd and systemd unit locations are absolute POSIX system paths, and these assertions+ // are about those exact strings. filepath.Join renders them with backslashes on Windows, so the+ // comparison there would be testing path rendering rather than the contract -- and neither+ // service manager exists on that platform to have a contract about.+ if runtime.GOOS == "windows" {+ t.Skip("launchd and systemd unit paths are POSIX-only")+ }if got := (UpdaterManager{Kind: KindLaunchd}).UnitPath(); got != "/Library/LaunchDaemons/com.beacon.endpoint.updater.plist" {t.Errorf("PlistPath = %q", got)}@@ -145,6 +152,13 @@ func TestUpdaterSystemdUnitsPairTimerWithService(t *testing.T) {}func TestUpdaterUnitPathFollowsBackend(t *testing.T) {+ // The launchd and systemd unit locations are absolute POSIX system paths, and these assertions+ // are about those exact strings. filepath.Join renders them with backslashes on Windows, so the+ // comparison there would be testing path rendering rather than the contract -- and neither+ // service manager exists on that platform to have a contract about.+ if runtime.GOOS == "windows" {+ t.Skip("launchd and systemd unit paths are POSIX-only")+ }if got := (UpdaterManager{Kind: KindLaunchd}).UnitPath(); got != "/Library/LaunchDaemons/com.beacon.endpoint.updater.plist" {t.Errorf("launchd updater path = %q", got)}