What: every place magpie looks for installed apps outside the home folder now goes through proc.SystemDirs, which in a test binary testenv isolated puts the path under the test's home (as it already does for Homebrew's bin, #1525): - agent: a new macAppFolders(home) (/Applications via SystemDirs, plus ~/Applications) is used by appFolders (desktop apps: Codex, dsh), pencilApp, t3App and reasonixDetected; - cursorLocalRoots: macOS through macAppFolders, Windows' ProgramFiles and Linux's /opt, /usr/share, /usr/lib through SystemDirs; - zedAppPath's /Applications/Zed*.app, npmGlobalPrefix's ProgramFiles npm fallback, and provider's /Applications/ZCode.app builtin config. Production behaviour is unchanged: SystemDirs returns paths as they are outside a sandboxed test. Why: HasApp/AppVersion read the real /Applications, so on a Mac with DeepSeek Harness.app the dsh fixture's CLI was never "missing" and the test failed every time; CI has no such app, so nobody else saw it. The same shape was in five other readers. Test: TestAppFoldersStayInTheTestHome checks every app folder lies under testenv's home (all OSes), and on macOS that an app installed in the sandbox's /Applications is the one found. Run (go1.26.8, sandbox HOME, private GOCACHE): - repro on old code: appFolders pointed at a temp folder holding a fake "DeepSeek Harness.app/Contents/Info.plist" (com.deepseek.dsh) -> TestAsideOfflineDisconnectRestoresWithoutDaemon FAIL "native fixture must report missing CLI". - break check: macAppFolders put back to the literal /Applications -> TestAppFoldersStayInTheTestHome FAIL (appFolders, macAppFolders, cursorLocalRoots look in /Applications; sandbox app not found). Restored: pass. - gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. - go test -tags nogui ./internal/agent ./internal/proc ./internal/provider: ok. - -race -count=5 on the touched agent tests: ok. Not run: the full go test ./...; Windows and Linux test runs (vet only); reasonix's Windows registry lookup and Zed's mdfind fallback still ask the machine (not folder paths) and are left as they are. Reported-by: mdwsk88
87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"debug/buildinfo"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/proc"
|
|
)
|
|
|
|
func reasonixDetected(home string) bool {
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
for _, dir := range reasonixStudioDirs() {
|
|
if (isFile(filepath.Join(dir, "Reasonix Studio.exe")) || isFile(filepath.Join(dir, "reasonix-studio.exe"))) &&
|
|
reasonixStudioPackage(filepath.Join(dir, "resources", "app.asar")) {
|
|
return true
|
|
}
|
|
}
|
|
case "darwin":
|
|
for _, dir := range macAppFolders(home) {
|
|
if reasonixStudioPackage(filepath.Join(dir, "Reasonix Studio.app", "Contents", "Resources", "app.asar")) {
|
|
return true
|
|
}
|
|
}
|
|
case "linux":
|
|
for _, bin := range []string{"reasonix-studio", "reasonix-studio-electron"} {
|
|
if path, err := proc.Look(bin); err == nil {
|
|
if resolved, err := filepath.EvalSymlinks(path); err == nil {
|
|
path = resolved
|
|
}
|
|
if reasonixStudioPackage(filepath.Join(filepath.Dir(path), "resources", "app.asar")) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
path, err := proc.Look("reasonix")
|
|
return err == nil && reasonixCLI(path)
|
|
}
|
|
|
|
var reasonixVersions = struct {
|
|
sync.Mutex
|
|
m map[goProgramKey]bool
|
|
}{m: map[goProgramKey]bool{}}
|
|
|
|
// Config alone cannot distinguish the native CLI from the historical npm 1.x
|
|
// client. Probe only a native Reasonix CLI, once per binary revision, without
|
|
// starting either its agent loop or the desktop host.
|
|
func reasonixCLI(path string) bool {
|
|
if resolved, err := filepath.EvalSymlinks(path); err == nil {
|
|
path = resolved
|
|
}
|
|
st, err := os.Stat(path)
|
|
if err != nil || !st.Mode().IsRegular() {
|
|
return false
|
|
}
|
|
key := goProgramKey{path, st.Size(), st.ModTime()}
|
|
reasonixVersions.Lock()
|
|
defer reasonixVersions.Unlock()
|
|
if v, ok := reasonixVersions.m[key]; ok {
|
|
return v
|
|
}
|
|
info, err := buildinfo.ReadFile(path)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
detected := false
|
|
if info.Path == "reasonix/cmd/reasonix" {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
b, err := proc.CommandContext(ctx, path, "--version").Output()
|
|
if err != nil {
|
|
return false // retry a failed probe; only a confirmed version is cached
|
|
}
|
|
version, ok := strings.CutPrefix(strings.TrimSpace(string(b)), "reasonix v")
|
|
detected = ok && (strings.HasPrefix(version, "2.") || strings.HasPrefix(version, "1.39."))
|
|
}
|
|
reasonixVersions.m[key] = detected
|
|
return detected
|
|
}
|