Skip to content

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

test(discover): cover the unresolvable-home guard, and define the plugin path once

Claude5589d6f43cd2
diff --git a/cli/beacon/internal/endpoint/harness/harness.go b/cli/beacon/internal/endpoint/harness/harness.go
index 9fbad7d3..efe1a4ba 100644
--- a/cli/beacon/internal/endpoint/harness/harness.go
+++ b/cli/beacon/internal/endpoint/harness/harness.go
@@ -11,6 +11,7 @@ import (
"strings"
"time"
+ "github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/hooks"
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/integrations/cowork"
"gopkg.in/yaml.v3"
)
@@ -185,15 +186,24 @@ func DiscoverOpenCode() Harness {
func DiscoverCline() Harness {
h := Harness{Name: "cline", DisplayName: "Cline", Capability: "plugin"}
detectExecutable(&h, "cline")
- home, err := os.UserHomeDir()
+ // The guard below is the point: Cline's project install is ".cline/plugins/beacon.ts", the user
+ // layout with the home prefix removed, so an unresolved home directory does not merely produce a
+ // useless path -- it produces exactly the path a project install occupies. Discovery would read
+ // a repository's own plugin and report Cline detected with telemetry enabled for the machine, on
+ // the strength of a file in whatever directory the command ran from. DiscoverPi guards the same
+ // way.
+ //
+ // The path comes from the installer rather than being rebuilt here so there is one definition of
+ // where the plugin lives; two copies is how discovery comes to report on a file the installer
+ // does not write.
+ pluginPath, err := hooks.ClinePluginPath(hooks.LevelUser)
if err != nil {
h.TelemetryStatus = TelemetryMissing
h.Message = "Cline plugin directory could not be resolved: " + err.Error()
return h
}
- pluginPath := filepath.Join(home, ".cline", "plugins", "beacon.ts")
h.ConfigPath = pluginPath
- if !h.Detected && dirExists(filepath.Join(home, ".cline")) {
+ if !h.Detected && dirExists(filepath.Dir(filepath.Dir(pluginPath))) {
h.Detected = true
}
if fileExists(pluginPath) {
diff --git a/cli/beacon/internal/endpoint/harness/harness_test.go b/cli/beacon/internal/endpoint/harness/harness_test.go
index 28ea00df..382f12a1 100644
--- a/cli/beacon/internal/endpoint/harness/harness_test.go
+++ b/cli/beacon/internal/endpoint/harness/harness_test.go
@@ -843,3 +843,45 @@ func TestDiscoverAllIncludesCline(t *testing.T) {
}
t.Fatal("DiscoverAll does not include cline")
}
+
+// An unresolvable home directory must stop Cline discovery rather than produce a relative path.
+//
+// Cline is the sharpest case for this in the whole harness set: its project install is
+// ".cline/plugins/beacon.ts", which is the user layout with the home prefix removed. A relative
+// path therefore lands exactly where a project install lives, so discovery would read a
+// repository's own plugin and report Cline detected with telemetry enabled for the machine -- on
+// the strength of a file in whatever directory the command happened to run from.
+//
+// An empty HOME is not hypothetical for this binary: system-mode Beacon runs under launchd, and
+// some CI runners leave it unset.
+func TestDiscoverClineDoesNotFallBackToAProjectPluginWhenHomeIsUnresolvable(t *testing.T) {
+ work := t.TempDir()
+ t.Chdir(work)
+ t.Setenv("PATH", t.TempDir())
+ // An empty HOME is what makes os.UserHomeDir fail; USERPROFILE is cleared for the same reason on
+ // Windows.
+ t.Setenv("HOME", "")
+ t.Setenv("USERPROFILE", "")
+
+ pluginPath := filepath.Join(work, ".cline", "plugins", "beacon.ts")
+ if err := os.MkdirAll(filepath.Dir(pluginPath), 0755); err != nil {
+ t.Fatalf("mkdir project plugin dir: %v", err)
+ }
+ if err := os.WriteFile(pluginPath, []byte("// beacon-managed-cline-plugin:v1"), 0644); err != nil {
+ t.Fatalf("write project plugin: %v", err)
+ }
+
+ h := DiscoverCline()
+ if h.TelemetryStatus == TelemetryEnabled {
+ t.Errorf("TelemetryStatus = %q; a project plugin was reported as the user install", h.TelemetryStatus)
+ }
+ if h.ConfigPath != "" {
+ t.Errorf("ConfigPath = %q, want empty when the home directory cannot be resolved", h.ConfigPath)
+ }
+ if h.Detected {
+ t.Errorf("Detected = true from a project directory with no resolvable home")
+ }
+ if !strings.Contains(h.Message, "could not be resolved") {
+ t.Errorf("Message = %q, want it to name the unresolved directory", h.Message)
+ }
+}
diff --git a/cli/beacon/internal/endpoint/hooks/cline.go b/cli/beacon/internal/endpoint/hooks/cline.go
index 01d2bccb..c529c62d 100644
--- a/cli/beacon/internal/endpoint/hooks/cline.go
+++ b/cli/beacon/internal/endpoint/hooks/cline.go
@@ -164,6 +164,15 @@ func isClineInstalledAt(path string) bool {
// project-scoped ones, and discovers a bare .ts file dropped into either. That is why Beacon writes
// a file rather than running `cline plugin install`: no CLI has to be present, and an install works
// the same for the VS Code and JetBrains hosts, which ship no `cline` binary at all.
+// ClinePluginPath is where Beacon installs its managed Cline plugin for the given level.
+//
+// Exported so discovery asks the installer where the plugin lives instead of rebuilding the path
+// itself. Two copies of that path is how discovery comes to report on a file the installer does not
+// write.
+func ClinePluginPath(level Level) (string, error) {
+ return clinePluginPath(level)
+}
+
func clinePluginPath(level Level) (string, error) {
dir, err := clinePluginDir(level)
if err != nil {