Every magpie subcommand ran the start-up moves before its own work:
RenameLegacy and the effort moves list every provider and account,
which starts the bun plugin host and runs claude auth status, a full
claude -p /usage, cursor-agent about and devin auth status. Claude Code
starts `magpie mcp image` for each session and `magpie statusline` on
every message, so a machine with 16 Claude sessions held 16 plugin
hosts beside the GUI's (~1.3GB footprint), and each status line took
5s. These three talk to the running gateway and nothing else; they are
now dispatched before the moves, which become startUp so a test can
tell whether they ran.
Run at 7b1faf99f + this change (macOS, real HOME, read-only commands):
- old (origin/main build) `mcp image`: 4 child processes after 2s,
footprint 57MB; new: 0 children, 17MB.
- `statusline` against the live gateway: 5.24s old, 0.13s new, same
line printed.
- initialize + tools/list over stdio: same replies from both builds.
- TestSessionCommandsSkipStartUp: ok; red with startUp() moved back
above the dispatch by hand ("[mcp image] ran the start-up moves").
- go test -tags nogui ./internal/cli ./internal/imagemcp
./internal/claudebridge: ok. gofmt clean; go vet GOOS=linux and
GOOS=windows -tags nogui, and darwin with the GUI: clean.
Not run: the full suite. Not tried on Linux or Windows.
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// What an agent starts for each session or message (the image MCP, Claude
|
|
// Code's MCP helper, the status line) never runs the start-up moves, which
|
|
// list every provider and account and so start the plugin host and ask
|
|
// claude, cursor-agent and devin who is signed in (#3318).
|
|
func TestSessionCommandsSkipStartUp(t *testing.T) {
|
|
ran := 0
|
|
was := startUp
|
|
startUp = func() { ran++ }
|
|
t.Cleanup(func() { startUp = was })
|
|
t.Setenv("MAGPIE_ADDR", "127.0.0.1:1")
|
|
t.Setenv("MAGPIE_MCP_CALLBACK", "")
|
|
null, err := os.Open(os.DevNull)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer null.Close()
|
|
stdin := os.Stdin
|
|
os.Stdin = null
|
|
t.Cleanup(func() { os.Stdin = stdin })
|
|
for _, args := range [][]string{
|
|
{"mcp", "image"},
|
|
{"mcp", "nope"},
|
|
{"claude-mcp-helper"},
|
|
{"statusline"},
|
|
} {
|
|
_ = run(args)
|
|
if ran != 0 {
|
|
t.Fatalf("%v ran the start-up moves", args)
|
|
}
|
|
}
|
|
// and a command that reads the files still has them brought up first
|
|
_ = run([]string{"version"})
|
|
if ran != 1 {
|
|
t.Fatalf("version: start-up ran %d times, want 1", ran)
|
|
}
|
|
}
|