Files
magpie/internal/agent/claude_in_desktop_test.go
T
yetone fccf86d62e agents: Claude Code found only inside Claude Desktop says so
cybercaius (Discord, Windows): with Claude Code uninstalled and only
Claude Desktop installed again, the Agents page still listed Claude Code
by its ~\.claude, with nothing saying why. Desktop 2.7032 fetches its own
Claude Code for its Code tab (<userData>\claude-code\<version>\claude.exe,
Claude-3p's folder in its gateway mode), which reads the same
~/.claude/settings.json, so the card is right to stay. desktopdir finds
that copy and its newest version; with no Claude Code of its own, the CLI
reports InDesktop (and DesktopVersion once Desktop fetched one), and the
card carries an "In Claude Desktop" tag (en, zh, zh-TW, ja, de) whose
tooltip names the version and settings path and says Desktop's Code
sessions in WSL use the WSL card. A Claude Code of its own still wins.

Run:
- TestClaudeCodeInDesktop and the desktopdir tests: ok. Broken by hand:
  red with the change taken out.
- node --test internal/gui/tests/claude-in-desktop.test.cjs (en, zh,
  zh-TW, ja, de; 980 and 560 wide): mote Chromium 10 of 10 ok; WSL box
  (magpie-desktop) Chromium 18 of 18 and WebKit 28 of 28 ok with
  i18n-keys and agent-app-version beside it. On the old app.js the 10
  Chromium cases are red (that run ended without its summary line).
- i18n-keys: ok.
Not run on macOS WebKit: a bare WebKit launch on mote hangs at 60s with
no test involved. agent-app-version's Chromium closed mid-run on mote
(display link error under load ~60); it passes on Linux.
2026-10-29 12:42:52 +08:00

59 lines
2.2 KiB
Go

package agent
import (
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/desktopdir"
)
// cybercaius (Discord, Windows): Claude Code and Desktop uninstalled, only
// Desktop installed again, and the Agents page still listed Claude Code by
// its ~\.claude with nothing saying why. Desktop includes a Claude Code
// for its Code tab (%APPDATA%\Claude\claude-code\<version>\claude.exe) that
// reads the same ~\.claude\settings.json, so with no Claude Code of its own
// found, the CLI says it is Desktop's, with that copy's version once
// Desktop has fetched it; one of its own found, it is that one.
func TestClaudeCodeInDesktop(t *testing.T) {
old := desktopdir.OS
desktopdir.OS = "windows"
t.Cleanup(func() { desktopdir.OS = old })
home, _ := desktopSandbox(t)
t.Setenv("PATH", t.TempDir())
versions, latests = memo{}, memo{}
t.Cleanup(func() { versions, latests = memo{}, memo{} })
file(t, filepath.Join(home, ".claude", "settings.json"), `{}`)
a := claude(home)
if c, ok := a.CLI(); ok || c.InDesktop {
t.Fatalf("neither Claude Code nor Desktop here: %+v", c)
}
// Desktop installed (Squirrel's setup), its Code tab not used yet
file(t, filepath.Join(home, "AppData", "Local", "AnthropicClaude", "claude.exe"), "MZ")
if c, ok := a.CLI(); !ok || !c.InDesktop || c.DesktopVersion != "" || c.Version != "" {
t.Fatalf("Desktop installed: %+v %v", c, ok)
}
// and the Claude Code it fetched, two versions, one in its 3p mode's folder
file(t, filepath.Join(home, "AppData", "Roaming", "Claude", "claude-code", "2.1.300", "claude.exe"), "MZ")
file(t, filepath.Join(home, "AppData", "Local", "Claude-3p", "claude-code", "2.1.310", "claude.exe"), "MZ")
if c, ok := a.CLI(); !ok || !c.InDesktop || c.DesktopVersion != "2.1.310" {
t.Fatalf("Desktop's Claude Code: %+v %v", c, ok)
}
// Claude Code's own on PATH: that one, not Desktop's
bin := t.TempDir()
file(t, filepath.Join(bin, exe("claude")), "")
os.Chmod(filepath.Join(bin, exe("claude")), 0o755)
t.Setenv("PATH", bin)
if c, _ := a.CLI(); c.InDesktop || c.Path == "" {
t.Fatalf("its own on PATH: %+v", c)
}
// in a WSL distro, never Desktop's
w := claude(home)
w.WSL = "Ubuntu"
t.Setenv("PATH", t.TempDir())
if c, _ := w.CLI(); c.InDesktop {
t.Fatalf("WSL: %+v", c)
}
}