Files
magpie/internal/cli/claude_desktop_launch_cli_test.go
T
yetone 6bc0d1e203 claude-desktop: Claude Magpie's Code tab on a Claude Code folder of its own (#6459)
The Separate app (Claude Magpie.app, #5671) kept its own Desktop
userData, but its Code tab's bundled Claude Code still read and wrote
the user's ~/.claude: their CLAUDE.md, skills, plugins and history went
into the twin, and the twin's sessions into theirs (xMopf7RF on X).

An opt-in, macOS-only switch under the Separate app's Advanced fold
(settings.DesktopIsolatedClaude, POST /api/settings/desktop-isolated-
claude, `magpie claude-desktop launcher claude-dir on|off`) gives it
~/.claude-magpie-desktop:

- desktopiso.Script exports CLAUDE_CONFIG_DIR in the app's launch
  script; turning the option on or off remakes the app, and the hint
  says to quit and reopen Claude Magpie, since a running one keeps its
  environment.
- desktopOn writes Desktop's model windows, caps and explore entries
  into that folder's settings.json instead of ~/.claude's while it is on
  (desktopCodeDir, desktopClaudeSync); off moves them back. The folder
  is kept when it is turned off, and shows as the claude# row "Claude
  Code · Claude Magpie".
- The fold is drawn by claudemagpie.js, imported the first time it
  shows; what stays in app.js is the import (isoLazy) and the fold's
  place, 216 bytes, so the core budget goes up by 180 (the 36 of room
  there was taken first).

Run:
- gofmt -l clean; go vet ./internal/... on darwin, GOOS=windows and
  GOOS=linux -tags nogui vet of agent, cli, desktopiso, gui, settings,
  settingsapi (mote).
- go test agent, cli, desktopiso, desktopdir, settings, settingsapi,
  gui, library on mote: all ok except cli's three healthcheck/update
  tests, which ask the gateway mote's own magpie serves on :3425
  (#6223, the same with or without this change).
- TestCoreScriptBudget and TestSettingsSaveKeepsWhatItDoesNotSend at
  this commit and the next.
- GUI on mote, Chromium and WebKit: desktop-isolated-claude (five
  languages, 1100 and 640px), desktop-isolated, i18n-keys,
  i18n-en-no-cjk, old-webkit, and every agent*/desktop*/claude* file
  (98 files, 1,595 of 1,662 pass). Every red is the same on origin/main
  92bce5c72 run alone: old-webkit (#6467, #5919), agent-details-ready
  (#6373), agent-switch-accounts (#5925), claude-quota-onboarding
  (#6179), agent-menu-label (#6371), desktop-tiers Chromium (#6475).
- A real Claude Desktop on mote in a sandbox HOME (~/sb6459, removed
  after): `claude-desktop magpie`, `launcher add`, `launcher claude-dir
  on`. The window and caps moved into .claude-magpie-desktop/
  settings.json, ~/.claude kept only its theme, the script exported
  CLAUDE_CONFIG_DIR, and the launched Desktop's main process and
  children had it in their environment. `claude-dir off` moved them
  back and dropped the export; `launcher remove` removed the app.
  mote's real ~/.claude was listed before and after: unchanged.

Broken by hand:
- desktopOn without the clone-folder branch: TestClaudeDesktopIsolated
  ClaudeDir red (the window stays in ~/.claude).
- The fold without its ontoggle: desktop-isolated-claude red ("shut by
  the redraw").
- settingsapi not keeping the field: TestSettingsSaveKeepsWhatItDoes
  NotSend red.

Not tried: a Code-tab session driven in the real Desktop's UI, so
bundled Claude Code writing into the folder was not seen in this run
(an earlier look at #6459 saw it). Library has no targets for the
clone's folder yet (#6469). The whole GUI suite (1,484 files) was not
run; the files on the Agents page and every i18n file were.
2026-11-13 16:02:12 +08:00

111 lines
4.1 KiB
Go

package cli
import (
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
)
// `magpie claude-desktop launcher` (#5671): add and remove turn the
// isolated Desktop on and off, nothing else is a word it takes, --help
// changes nothing, and off a Mac it refuses.
func TestClaudeDesktopLauncher(t *testing.T) {
helpHome(t)
var calls []bool
st := agent.DesktopIsolated{}
here := true
oldSet, oldHere := setDesktopIsolated, desktopIsolatedHere
t.Cleanup(func() { setDesktopIsolated, desktopIsolatedHere = oldSet, oldHere })
setDesktopIsolated = func(_ string, on bool) (string, error) {
calls = append(calls, on)
st.On = on
st.Launcher = ""
if on {
st.Launcher = "/Users/x/Applications/Claude Magpie.app"
}
return st.Launcher, nil
}
desktopIsolatedHere = func() (agent.DesktopIsolated, bool) { return st, here }
for _, c := range []struct {
args []string
want string
calls []bool
}{
{[]string{"claude-desktop", "launcher"}, "run `magpie claude-desktop launcher add`", nil},
{[]string{"claude-desktop", "launcher", "--help"}, "magpie claude-desktop launcher [add|remove]", nil},
{[]string{"claude-desktop", "launcher", "add"}, "Claude Magpie: /Users/x/Applications/Claude Magpie.app", []bool{true}},
{[]string{"claude-app", "launcher"}, "/Users/x/Applications/Claude Magpie.app\n", []bool{true}},
{[]string{"claude-desktop", "launcher", "remove"}, "removed /Users/x/Applications/Claude Magpie.app", []bool{true, false}},
} {
out, err := runOut(t, c.args...)
if err != nil || !strings.Contains(out, c.want) {
t.Errorf("%v: %q %v, want %q", c.args, out, err, c.want)
}
if len(calls) != len(c.calls) {
t.Fatalf("%v: calls %v, want %v", c.args, calls, c.calls)
}
}
for _, bad := range [][]string{{"claude-desktop", "launcher", "--force"}, {"claude-desktop", "launcher", "add", "x"}} {
if _, err := runOut(t, bad...); err == nil {
t.Errorf("%v took", bad)
}
}
here = false
if _, err := runOut(t, "claude-desktop", "launcher", "add"); err == nil || !strings.Contains(err.Error(), "macOS only") {
t.Errorf("off a Mac: %v", err)
}
if len(calls) != 2 {
t.Fatalf("calls %v", calls)
}
}
// `magpie claude-desktop launcher claude-dir` (#6459): on and off reach
// the setting, nothing says which folder, another word refuses, and off a
// Mac it refuses too.
func TestClaudeDesktopLauncherClaudeDir(t *testing.T) {
helpHome(t)
var calls []bool
st := agent.DesktopIsolated{On: true, Launcher: "/Users/x/Applications/Claude Magpie.app", ClaudeDir: "/Users/x/.claude-magpie-desktop"}
here := true
oldSet, oldHere := setDesktopIsolatedClaude, desktopIsolatedHere
t.Cleanup(func() { setDesktopIsolatedClaude, desktopIsolatedHere = oldSet, oldHere })
setDesktopIsolatedClaude = func(_ string, on bool) error {
calls = append(calls, on)
st.Claude = on
return nil
}
desktopIsolatedHere = func() (agent.DesktopIsolated, bool) { return st, here }
for _, c := range []struct {
args []string
want string
calls []bool
}{
{[]string{"claude-desktop", "launcher", "claude-dir"}, "~/.claude: run", nil},
{[]string{"claude-desktop", "launcher", "claude-dir", "on"}, "Quit Claude Magpie and open it again", []bool{true}},
{[]string{"claude-desktop", "launcher", "claude-dir"}, "/Users/x/.claude-magpie-desktop\n", []bool{true}},
{[]string{"claude-desktop", "launcher", "claude-dir", "off"}, "Claude Code in Claude Magpie: ~/.claude", []bool{true, false}},
} {
out, err := runOut(t, c.args...)
if err != nil || !strings.Contains(out, c.want) {
t.Errorf("%v: %q %v, want %q", c.args, out, err, c.want)
}
if len(calls) != len(c.calls) {
t.Fatalf("%v: calls %v, want %v", c.args, calls, c.calls)
}
}
for _, bad := range [][]string{{"claude-desktop", "launcher", "claude-dir", "yes"}, {"claude-desktop", "launcher", "claude-dir", "on", "x"}} {
if _, err := runOut(t, bad...); err == nil {
t.Errorf("%v took", bad)
}
}
here = false
if _, err := runOut(t, "claude-desktop", "launcher", "claude-dir", "on"); err == nil || !strings.Contains(err.Error(), "macOS only") {
t.Errorf("off a Mac: %v", err)
}
if len(calls) != 2 {
t.Fatalf("calls %v", calls)
}
}