Files
magpie/internal/agent/air_ide_test.go
T
yetone 5f0a84a003 agent: Air in JetBrains IDEs gets magpie's Magpie agent in ~/.jetbrains/acp.json (Jumy on Discord)
Jumy asked for the "air-plugin" new in IntelliJ IDEA 2026.3 (Settings ›
AI › Air). magpie's air agent wrote the Air app's acp.json, in
~/Library/Application Support/JetBrains/Air, which the IDE plugin never
reads: the plugin (com.intellij.air, air-plugin-262.8665.521-mac-arm64
from JetBrains Marketplace) loads its custom ACP agents in
AcpConfigurationLoader (intellij.air.backend.acp.runtime) from
user.home/.jetbrains/acp.json on every system, the file AI Assistant's
custom agents use too; AgentServerConfig takes command, args, env,
use_idea_mcp and use_custom_mcp. The standalone app (Air-262.1037.14,
Fleet-based) reads acp.json from its own configs folder
(genericAcpConfigPath), so the two are separate files.

Air's own agents have no base URL: JetBrains AI, the agent's own login,
or an Anthropic, OpenAI, Gemini or OpenRouter key under AI › Air ›
Accounts. So the IDE gets the same route as the app: a new air-ide agent
("Air (JetBrains IDEs)", aliases air-plugin, air-in-ides) writes a
Magpie entry (opencode acp, OPENCODE_CONFIG naming magpie-opencode.json
beside acp.json) and nothing else; the user's agents and
default_mcp_settings stay, and disconnecting takes out that entry and
that file. air and air-ide share airAt. air-ide shows for an IDE config
folder of 2026.2 or later (the plugin is bundled from 2026.3), or with
its entry already in acp.json. Notice in en, zh, zh-TW, ja, de; README,
reference and agent-wiring rows.

Run at this head (rebased on ed978e560), on mote:
- go test -tags nogui ./internal/agent ./internal/gui: ok.
  ./internal/cli: TestEveryRouteHasACommandOrIsNamed red, the
  checkin-account route, #4826, not this change.
- go vet darwin, GOOS=linux, GOOS=windows (agent, gui); gofmt -l clean.
- -run Air on Windows (win-run) and Linux (wsl-run): ok.
- GUI i18n-keys, agent-notice-lang, about-notices, agents-last-known in
  chromium and webkit: all pass.
Broken by hand: air-ide on the app's folder fails
TestAirIDEAddsMagpieAgent; a version check of > in place of >= fails
TestAirIDEDetectedByIDEVersion on GoLand2026.2.
Not tried: a real IntelliJ IDEA 2026.3 with the plugin listing Magpie
(the plugin's watcher should pick up acp.json; JetBrains' docs say to
restart the IDE, which the notice says); opencode acp itself was checked
under the app's entry in 5a0559d37, the entry is the same here.
2026-11-02 19:00:29 +08:00

124 lines
4.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package agent
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"github.com/yetone/magpie/internal/edit"
)
// jetBrainsConfigs is where a JetBrains IDE keeps its config folders on
// this system, under a sandbox home.
func jetBrainsConfigs(home string) string {
switch runtime.GOOS {
case "darwin":
return filepath.Join(home, "Library", "Application Support", "JetBrains")
case "windows":
return filepath.Join(home, "AppData", "Roaming", "JetBrains")
}
return filepath.Join(home, ".config", "JetBrains")
}
// Air in an IDE (the Air plugin, Settings › AI › Air) reads its custom ACP
// agents from ~/.jetbrains/acp.json, not the Air app's folder: magpie adds
// its Magpie agent there, keeps what the IDE and the user put in the file
// (AI Assistant's agents, default_mcp_settings), and taking it off takes
// out that entry and its OpenCode config alone.
func TestAirIDEAddsMagpieAgent(t *testing.T) {
home, appDir := airHome(t, "/opt/bin/opencode")
acp := filepath.Join(home, ".jetbrains", "acp.json")
// the file as AI Assistant's "Add Custom Agent" leaves it, with an
// agent of the user's
user := `{
"default_mcp_settings": {
"use_idea_mcp": true,
"use_custom_mcp": true
},
"agent_servers": {
"Goose": {"command": "/usr/local/bin/goose", "args": ["acp"], "use_idea_mcp": false}
}
}
`
writeFile(t, acp, user)
a := airIDE(home, filepath.Join(home, ".config"))
if a.Path != acp {
t.Fatalf("path %s", a.Path)
}
if err := a.Apply("model", "magpie/fake/m1"); err != nil {
t.Fatal(err)
}
cfg := filepath.Join(home, ".jetbrains", "magpie-opencode.json")
for k, v := range map[string]string{
"default_mcp_settings.use_idea_mcp": "true",
"agent_servers.Goose.command": "/usr/local/bin/goose",
"agent_servers.Goose.use_idea_mcp": "false",
"agent_servers.Magpie.command": "/opt/bin/opencode",
"agent_servers.Magpie.args.0": "acp",
"agent_servers.Magpie.env.OPENCODE_CONFIG": cfg,
} {
if got, _ := edit.GetJSON(acp, k); got != v {
t.Fatalf("%s = %q, want %q\n%s", k, got, v, readFile(acp))
}
}
if v, _ := edit.GetJSON(cfg, "provider.magpie.options.baseURL"); v != gatewayV1() {
t.Fatalf("baseURL = %q\n%s", v, readFile(cfg))
}
if v := a.Field("model").Get(); v != "magpie/fake/m1" {
t.Fatalf("model = %q", v)
}
if !a.Detected() {
t.Fatal("not detected with magpie's agent in acp.json")
}
if n := a.Notice(); !strings.Contains(n, "JetBrains IDE") {
t.Fatalf("notice: %q", n)
}
if d := a.Drift(); d != nil {
t.Fatalf("drift: %+v", d)
}
// the Air app's own acp.json isn't this one, and isn't written
if _, err := os.Stat(filepath.Join(appDir, "acp.json")); !os.IsNotExist(err) {
t.Fatalf("the Air app's acp.json was written: %v", err)
}
if err := a.Apply("model", ""); err != nil {
t.Fatal(err)
}
if _, ok := edit.GetJSON(acp, "agent_servers.Magpie"); ok {
t.Fatalf("Magpie still in acp.json: %s", readFile(acp))
}
for _, k := range []string{"agent_servers.Goose.command", "default_mcp_settings.use_custom_mcp"} {
if _, ok := edit.GetJSON(acp, k); !ok {
t.Fatalf("%s went: %s", k, readFile(acp))
}
}
if _, err := os.Stat(cfg); !os.IsNotExist(err) {
t.Fatalf("magpie's OpenCode config left: %v", err)
}
}
// The Air plugin is bundled from 2026.3 and installable from 2026.2, so an
// IDE config folder of 2026.2 or later shows the agent; an older IDE, the
// Air app's folder or ~/.jetbrains alone (AI Assistant's) don't.
func TestAirIDEDetectedByIDEVersion(t *testing.T) {
home, _ := airHome(t, "/opt/bin/opencode")
cfg := filepath.Join(home, ".config")
base := jetBrainsConfigs(home)
for _, d := range []string{"IntelliJIdea2026.1", "Air", "Toolbox", "PyCharm2025.3"} {
os.MkdirAll(filepath.Join(base, d), 0o755)
}
os.MkdirAll(filepath.Join(home, ".jetbrains"), 0o755)
if airIDE(home, cfg).Detected() {
t.Fatal("detected without an IDE of 2026.2 or later")
}
for _, d := range []string{"IntelliJIdea2026.3", "GoLand2026.2", "PyCharm2027.1"} {
p := filepath.Join(base, d)
os.MkdirAll(p, 0o755)
if !airIDE(home, cfg).Detected() {
t.Fatalf("not detected with %s", d)
}
os.RemoveAll(p)
}
}