diff --git a/internal/agent/cursorlocal.go b/internal/agent/cursorlocal.go
index 5bf121252..1ce69d66b 100644
--- a/internal/agent/cursorlocal.go
+++ b/internal/agent/cursorlocal.go
@@ -35,6 +35,7 @@ import (
"github.com/yetone/magpie/internal/appdir"
"github.com/yetone/magpie/internal/gateway"
+ "github.com/yetone/magpie/internal/proc"
"github.com/yetone/magpie/internal/provider"
)
@@ -71,18 +72,20 @@ func cursorLocalRoots() []string {
home, _ := os.UserHomeDir()
switch runtime.GOOS {
case "darwin":
- return []string{"/Applications", filepath.Join(home, "Applications")}
+ return macAppFolders(home)
case "windows":
+ // LOCALAPPDATA is the user's (a test's lies under its home);
+ // ProgramFiles is the machine's, so it goes through SystemDirs
var out []string
- for _, v := range []string{"LOCALAPPDATA", "ProgramFiles"} {
- if d := os.Getenv(v); d != "" {
+ for _, d := range append([]string{os.Getenv("LOCALAPPDATA")}, proc.SystemDirs(os.Getenv("ProgramFiles"))...) {
+ if d != "" {
out = append(out, filepath.Join(d, "Programs"), d)
}
}
return out
}
- return []string{"/opt", "/usr/share", "/usr/lib", filepath.Join(home, ".local", "share"), filepath.Join(home, "Applications"),
- filepath.Join(home, ".local", "bin"), filepath.Join(home, "bin"), filepath.Join(home, "Downloads"), home}
+ return append(proc.SystemDirs("/opt", "/usr/share", "/usr/lib"), filepath.Join(home, ".local", "share"), filepath.Join(home, "Applications"),
+ filepath.Join(home, ".local", "bin"), filepath.Join(home, "bin"), filepath.Join(home, "Downloads"), home)
}
// findCursorLocal is the program of the Cursor Private Inference among the
diff --git a/internal/agent/desktopapp.go b/internal/agent/desktopapp.go
index b8aef0774..3600d113d 100644
--- a/internal/agent/desktopapp.go
+++ b/internal/agent/desktopapp.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/yetone/magpie/internal/appdir"
+ "github.com/yetone/magpie/internal/proc"
)
// An agent that is a desktop app as well as a CLI has the app's version shown
@@ -44,11 +45,11 @@ var desktopApps = map[string]desktopApp{
var appFolders = func() []string {
switch runtime.GOOS {
case "darwin":
- dirs := []string{"/Applications"}
- if home, err := os.UserHomeDir(); err == nil {
- dirs = append(dirs, filepath.Join(home, "Applications"))
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return proc.SystemDirs("/Applications")
}
- return dirs
+ return macAppFolders(home)
case "windows":
if local := appdir.Getenv("LOCALAPPDATA"); local != "" {
return []string{filepath.Join(local, "Programs")}
@@ -57,6 +58,16 @@ var appFolders = func() []string {
return nil
}
+// macAppFolders are the folders a Mac keeps apps in: /Applications and
+// home's Applications. /Applications goes through proc.SystemDirs, so in a
+// test binary testenv isolated it lies under the test's home: tests read
+// the developer's own /Applications, and on a Mac with DeepSeek Harness.app
+// installed dsh's CLI was never missing (#1823, mdwsk88). Every reader of a
+// Mac's installed apps takes its folders from here.
+func macAppFolders(home string) []string {
+ return append(proc.SystemDirs("/Applications"), filepath.Join(home, "Applications"))
+}
+
var (
plistIDRe = regexp.MustCompile(`CFBundleIdentifier\s*([^<]+)`)
plistVersionRe = regexp.MustCompile(`CFBundleShortVersionString\s*([^<]+)`)
diff --git a/internal/agent/desktopapp_test.go b/internal/agent/desktopapp_test.go
index a4e6e173a..152849a30 100644
--- a/internal/agent/desktopapp_test.go
+++ b/internal/agent/desktopapp_test.go
@@ -4,9 +4,56 @@ import (
"os"
"path/filepath"
"runtime"
+ "strings"
"testing"
+
+ "github.com/yetone/magpie/internal/proc"
+ "github.com/yetone/magpie/internal/testenv"
)
+// #1823 (mdwsk88): HasApp read the developer's own /Applications, so on a
+// Mac with DeepSeek Harness.app installed
+// TestAsideOfflineDisconnectRestoresWithoutDaemon found dsh's app, and its
+// CLI was never missing. Every folder magpie looks for installed apps in —
+// the desktop apps', Pencil's, T3 Code's, Reasonix Studio's, Cursor Private
+// Inference's — lies under the test's home, on every OS, and an app a test
+// installs in the sandbox's /Applications is the one found.
+func TestAppFoldersStayInTheTestHome(t *testing.T) {
+ sandbox := os.Getenv(testenv.Marker)
+ if sandbox == "" {
+ t.Fatal("the package's tests aren't isolated (testenv)")
+ }
+ inside := func(what, dir string) {
+ t.Helper()
+ rel, err := filepath.Rel(sandbox, dir)
+ if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || filepath.IsAbs(rel) {
+ t.Errorf("%s looks in %s, outside the test's home %s", what, dir, sandbox)
+ }
+ }
+ for _, d := range appFolders() {
+ inside("appFolders", d)
+ }
+ for _, d := range macAppFolders(sandbox) {
+ inside("macAppFolders", d)
+ }
+ for _, d := range cursorLocalRoots() {
+ inside("cursorLocalRoots", d)
+ }
+ if runtime.GOOS != "darwin" {
+ return
+ }
+ dsh := &Agent{ID: "dsh", Name: "DeepSeek Harness", Bin: "dsh"}
+ if dsh.HasApp() {
+ t.Fatal("an empty sandbox has DeepSeek Harness.app")
+ }
+ apps := proc.SystemDirs("/Applications")[0]
+ t.Cleanup(func() { os.RemoveAll(filepath.Join(apps, "DeepSeek Harness.app")) })
+ installApp(t, apps, "DeepSeek Harness.app", codexAppPlist("com.deepseek.dsh", "0.2.0"))
+ if v := dsh.AppVersion(); v != "0.2.0" {
+ t.Fatalf("the sandbox's /Applications/DeepSeek Harness.app: %q", v)
+ }
+}
+
// codexAppPlist is the Codex app's Info.plist as macOS has it (ChatGPT.app
// 26.930.31730, its keys in their order), cut to the keys around the ones
// read, with the bundle id and version given: com.openai.chat stands for
diff --git a/internal/agent/install.go b/internal/agent/install.go
index 918f45d7d..5e9c4cd2b 100644
--- a/internal/agent/install.go
+++ b/internal/agent/install.go
@@ -207,8 +207,12 @@ var npmPrefixes memo
func npmGlobalPrefix() string {
npm, err := proc.Look("npm")
if err != nil {
- npm = filepath.Join(os.Getenv("ProgramFiles"), "nodejs", "npm.cmd")
- if os.Getenv("ProgramFiles") == "" || !isFile(npm) {
+ pf := proc.SystemDirs(os.Getenv("ProgramFiles"))
+ if len(pf) == 0 {
+ return ""
+ }
+ npm = filepath.Join(pf[0], "nodejs", "npm.cmd")
+ if !isFile(npm) {
return ""
}
}
diff --git a/internal/agent/pencil.go b/internal/agent/pencil.go
index 0b44d527b..149021140 100644
--- a/internal/agent/pencil.go
+++ b/internal/agent/pencil.go
@@ -81,7 +81,7 @@ func pencilApp(home string) bool {
if runtime.GOOS != "darwin" {
return false
}
- for _, d := range []string{"/Applications", filepath.Join(home, "Applications")} {
+ for _, d := range macAppFolders(home) {
for _, n := range []string{"Pencil.app", "pen.dev.app"} {
if _, err := os.Stat(filepath.Join(d, n)); err == nil {
return true
diff --git a/internal/agent/reasonix_detect.go b/internal/agent/reasonix_detect.go
index 45e39ba97..88c7edb9c 100644
--- a/internal/agent/reasonix_detect.go
+++ b/internal/agent/reasonix_detect.go
@@ -23,7 +23,7 @@ func reasonixDetected(home string) bool {
}
}
case "darwin":
- for _, dir := range []string{"/Applications", filepath.Join(home, "Applications")} {
+ for _, dir := range macAppFolders(home) {
if reasonixStudioPackage(filepath.Join(dir, "Reasonix Studio.app", "Contents", "Resources", "app.asar")) {
return true
}
diff --git a/internal/agent/t3code.go b/internal/agent/t3code.go
index 29dba6bc3..8367a36ac 100644
--- a/internal/agent/t3code.go
+++ b/internal/agent/t3code.go
@@ -97,7 +97,7 @@ func t3App(home string) bool {
if runtime.GOOS != "darwin" {
return false
}
- for _, d := range []string{"/Applications", filepath.Join(home, "Applications")} {
+ for _, d := range macAppFolders(home) {
for _, n := range []string{"T3 Code (Alpha).app", "T3 Code.app"} {
if _, err := os.Stat(filepath.Join(d, n)); err == nil {
return true
diff --git a/internal/agent/zed_credential_other.go b/internal/agent/zed_credential_other.go
index 926d4331d..0f9e28c20 100644
--- a/internal/agent/zed_credential_other.go
+++ b/internal/agent/zed_credential_other.go
@@ -46,10 +46,9 @@ func saveZedCredential(url string) error {
// Trust the installed Zed bundle, including a CLI symlink to a custom location.
func zedAppPath(ctx context.Context) (string, error) {
home, _ := os.UserHomeDir()
- paths := []string{
+ paths := append([]string{
filepath.Join(home, "Applications", "Zed.app"), filepath.Join(home, "Applications", "Zed Preview.app"),
- "/Applications/Zed.app", "/Applications/Zed Preview.app",
- }
+ }, proc.SystemDirs("/Applications/Zed.app", "/Applications/Zed Preview.app")...)
binName := os.Getenv("MAGPIE_ZED_BIN")
if binName == "" {
binName = "zed"
diff --git a/internal/provider/zcode_models.go b/internal/provider/zcode_models.go
index c73c39dab..3b57a7110 100644
--- a/internal/provider/zcode_models.go
+++ b/internal/provider/zcode_models.go
@@ -33,6 +33,7 @@ import (
"strings"
"github.com/yetone/magpie/internal/catalog"
+ "github.com/yetone/magpie/internal/proc"
)
type zcodeBuiltin struct {
@@ -230,7 +231,7 @@ var zcodeBuiltinFiles = func() []string {
home, _ := os.UserHomeDir()
fs, _ := filepath.Glob(filepath.Join(home, ".zcode", "v2", "runtime", "provider", "*", "*", "*", "zcode-builtin.json"))
if runtime.GOOS == "darwin" {
- fs = append(fs, "/Applications/ZCode.app/Contents/Resources/config/provider/zcode-builtin.json")
+ fs = append(fs, proc.SystemDirs("/Applications/ZCode.app/Contents/Resources/config/provider/zcode-builtin.json")...)
}
return fs
}