Skip to content

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

test(hooks): pin the JSON-escaped plugin path check

Claude36a1f1814421
diff --git a/cli/beacon/internal/endpoint/hooks/cline.go b/cli/beacon/internal/endpoint/hooks/cline.go
index 3bcd710b..01d2bccb 100644
--- a/cli/beacon/internal/endpoint/hooks/cline.go
+++ b/cli/beacon/internal/endpoint/hooks/cline.go
@@ -85,15 +85,34 @@ func clineStatusFromRuntime(status runtimeStatus) ClineStatus {
return out
}
data, err := os.ReadFile(out.PluginPath)
- jsonBinaryPath, _ := json.Marshal(out.BinaryPath)
- escapedPath := string(jsonBinaryPath[1 : len(jsonBinaryPath)-1])
- if err != nil || !strings.Contains(string(data), escapedPath) || strings.Contains(string(data), "__BEACON_") {
+ if err != nil || !clinePluginReferencesBinary(string(data), out.BinaryPath) || strings.Contains(string(data), "__BEACON_") {
out.Installed = false
out.Message = fmt.Sprintf("Cline plugin at %s does not reference the active Beacon hook binary", out.PluginPath)
}
return out
}
+// clinePluginReferencesBinary reports whether a rendered plugin spawns the given hook binary.
+//
+// The path has to be compared in the form the file actually holds it. The installer writes argv
+// through json.Marshal, which escapes a backslash as two, so searching for the raw path found
+// nothing on Windows: `C:\Program Files\...` is what is in the file and `C:\Program Files\...`
+// -- one backslash each -- is what was being looked for. Every correctly installed Windows plugin
+// was reported as not referencing its own binary.
+//
+// Marshalling the path and stripping the surrounding quotes produces exactly the substring the file
+// contains, on every platform, rather than a second escaping rule maintained by hand.
+func clinePluginReferencesBinary(source, binaryPath string) bool {
+ if binaryPath == "" {
+ return false
+ }
+ encoded, err := json.Marshal(binaryPath)
+ if err != nil || len(encoded) < 2 {
+ return false
+ }
+ return strings.Contains(source, string(encoded[1:len(encoded)-1]))
+}
+
func clineEmbeddedPluginSourcePath() string {
return filepath.Clean(filepath.Join("assets", "cline", "beacon.ts"))
}
diff --git a/cli/beacon/internal/endpoint/hooks/cline_test.go b/cli/beacon/internal/endpoint/hooks/cline_test.go
index ab68aabd..44022dbe 100644
--- a/cli/beacon/internal/endpoint/hooks/cline_test.go
+++ b/cli/beacon/internal/endpoint/hooks/cline_test.go
@@ -262,3 +262,43 @@ func TestIsClineInstalledAtRequiresTheManagedMarker(t *testing.T) {
t.Error("a missing plugin was reported as installed")
}
}
+
+// The plugin holds its argv JSON-encoded, so a backslash appears doubled in the file. Comparing
+// against the raw path therefore matched nothing on Windows, and every correctly installed plugin
+// there was reported as not referencing its own binary. Asserted on the rendered source so the
+// check is exercised on every platform, not only the one that exposed the bug.
+func TestClinePluginReferencesBinaryHandlesWindowsPaths(t *testing.T) {
+ binary := `C:\Program Files\Beacon\hooks\beacon-hooks.exe`
+ source, err := renderClinePlugin(binary, `C:\ProgramData\Beacon\runtime.jsonl`, `C:\ProgramData\Beacon\config.json`)
+ if err != nil {
+ t.Fatalf("renderClinePlugin returned error: %v", err)
+ }
+
+ if !clinePluginReferencesBinary(source, binary) {
+ t.Error("a plugin rendered for this binary was not recognized as referencing it")
+ }
+ // The shape of the original bug, stated so the escaping is not "simplified" back out.
+ if strings.Contains(source, binary) {
+ t.Error("rendered plugin contains the unescaped path; the escaping this guards has changed")
+ }
+ if clinePluginReferencesBinary(source, `C:\Program Files\Beacon\hooks\other-hooks.exe`) {
+ t.Error("a plugin was reported as referencing a binary it does not spawn")
+ }
+ if clinePluginReferencesBinary(source, "") {
+ t.Error("an empty binary path was treated as a match")
+ }
+}
+
+func TestClinePluginReferencesBinaryOnPOSIXPaths(t *testing.T) {
+ binary := "/opt/beacon/hooks/beacon-hooks"
+ source, err := renderClinePlugin(binary, "/var/log/beacon/runtime.jsonl", "/etc/beacon/config.json")
+ if err != nil {
+ t.Fatalf("renderClinePlugin returned error: %v", err)
+ }
+ if !clinePluginReferencesBinary(source, binary) {
+ t.Error("a plugin rendered for this binary was not recognized as referencing it")
+ }
+ if clinePluginReferencesBinary(source, "/opt/beacon/hooks/beacon-hooks-old") {
+ t.Error("a plugin was reported as referencing a binary it does not spawn")
+ }
+}