Files
magpie/internal/agent/useragent_test.go
T
yetone 3c38fe5c99 agent: Zoo Code (VS Code) through its autoImportSettingsPath (wani on Discord)
wani on Discord (#feedback) asked for Zoo Code (zoocode.dev), a fork of Roo
Code for VS Code and JetBrains.

Route: Zoo Code keeps its provider profiles in VS Code's SecretStorage,
which magpie can't write. The one file it reads is the one its
zoo-code.autoImportSettingsPath setting names. On every activation
(src/utils/autoImportSettings.ts, Zoo Code 3.90.0) it imports that file as
Settings → Import does (importSettingsFromPath). magpie writes
<User>/globalStorage/zoocodeorganization.zoo-code/settings/magpie-import.json
with one profile, "magpie": apiProvider openai on the gateway's
/v1 Chat Completions, key magpie-zoo-code, the chosen model, and an
openAiCustomModelInfo built from the catalog (contextWindow, else Zoo's own
128000 default; maxTokens only when an output limit is known). It points
the setting at that file in the default settings.json and in each VS Code
profile's. A value the user set themselves is stashed and restored by
Disconnect. The file sits outside magpie's folder so that a sync keeps an
address the user moved (kept.away skips magpie's own folder). Requests say
"ZooCode/<version>", and usage names them zoo-code.

Limits (also in docs/reference.md → Zoo Code):
- Zoo reads the file only at start: the notice asks for Developer: Reload
  Window.
- While connected, each start switches Zoo back to the magpie profile.
- Disconnect stops the import but can't delete the imported profile
  from SecretStorage. The user switches away from it or deletes it in Zoo.
- VS Code Stable only.

JetBrains is not wired. Zoo Code for JetBrains runs the extension in its own
extension host, which is handed an empty configuration on every start
(RPCManager.startInitialize in Zoo-Code-JetBrains), so the setting never
reaches it. Its secrets sit in ~/.zoo-code/secrets.json, an internal store
with no lock and no documented format. Neither is a clean route.

Tests (internal/agent/zoocode_test.go):
- TestZooCode: connect, model switch, a stale key that Check reports and
  Sync fixes, and disconnect putting the user's own import path back byte
  for byte with the file removed.
- TestZooCodeFresh and TestZooCodeProfiles: VS Code profiles, including one
  made after connecting.
- TestZooCodeDetectAndUA: Roo alone is not detected; ZooCode/3.90.0 maps to
  zoo-code.
Broken by hand (the restore disabled): TestZooCode and TestZooCodeProfiles
went red.
The generated file was checked with bun against Zoo's own zod schemas
(providerSettingsWithIdSchema, isProviderName; zod 4.6.7 from its repo):
valid, every field kept, current profile in apiConfigs.

Run, set -o pipefail, GOMODCACHE pinned, sandbox HOME:
- First full run, with this change on ba319a758 at 49bec8c4f:
  - gofmt -l clean.
  - go vet darwin, GOOS=linux -tags nogui and GOOS=windows: clean.
  - go test -timeout 45m ./...: 67 packages ok, including gateway 2543s,
    gui 509s and library 2326s.
  - internal/agent was red: TestSyncKeepsAnAddressOnAnotherMachine. The
    import file was then in magpie's folder, which kept.away skips, so a
    NAS address was lost. The file was moved into Zoo's globalStorage
    folder. The package also hit the 45m deadline under load (#2544).
- After the fix: -run 'ZooCode|TestSyncKeepsAnAddressOnAnotherMachine|
  TestReverseProxyIsStillMagpie' ./internal/agent was ok in 112.9s.
- At 0aa9c53ce: gofmt -l clean, internal/agent vet clean three ways, and
  go test -timeout 90m ./internal/agent ./internal/library ./internal/gui
  ok (agent 1912s, library 1299s, gui 420s).
- GUI suite in both engines: 283/283 in chromium and 283/283 in webkit
  (playwright 1.62.0). It covers the 44 files the change can reach:
  gui-de, gui-ja, gui-zh-tw, i18n-keys, agent-notice-lang,
  models-add-and-icons, mono-icon-redraw and every agent-*.

After rebasing onto origin/main 049040283 (which changed internal/agent/claude.go):
- go vet ./internal/agent clean three ways; linux nogui and windows
  builds ok.
- -run 'ZooCode|Compact|TestSyncKeepsAnAddressOnAnotherMachine|UserAgent|AgentOf'
  ./internal/agent ok in 35.9s.
- The darwin go build of the binary hit a full disk at link (this
  machine's, 369M free), not a code error.

Not tried: real VS Code (not installed on this machine), Windows and Linux.
2026-10-21 18:43:06 +08:00

61 lines
2.3 KiB
Go

package agent
import (
"testing"
"github.com/yetone/magpie/internal/usage"
)
// Every agent's requests are told by what its own description says.
func TestAgentOf(t *testing.T) {
cases := map[string]string{
"claude-cli/2.1.0 (external, cli)": "claude",
"codex_cli_rs/0.40.0 (Mac OS 26.0; arm64)": "codex",
"GeminiCLI/0.9.0 (darwin; arm64)": "gemini",
"opencode/1.2.3": "opencode",
"mimocode/1.2.3": "mimocode",
"deveco/0.2.3 ai-sdk/provider-utils/4.0": "deveco", // 0.2.3 sends ai-sdk/provider-utils/4.0.23
"curl/8.4.0": "curl",
"oh-my-pi/1.0": "omp",
"command-code/2.0": "commandcode",
"deepseek-harness/0.3.1": "dsh",
"dsh": "dsh", // a record kept by an id already
"pi": "pi",
"grok-pager/0.2.1": "grok",
"ZCode/3.10.1": "zcode",
"Alma/1.2.0": "alma",
"HanaAgent/1.0": "hanako",
"hanako": "hanako", // its key
"atomcode/5.2.1": "atomcode",
"cline ai-sdk/openai-compatible/3.0.37": "cline",
"Vibecoding Client/1.3.104 (darwin; arm64; go1.26.2)": "mothx",
"ZooCode/3.90.0": "zoo-code",
"minimax-code": "minimax-code", // what magpie's entry sends
"MiniMaxCode": "minimax-code", // 0.6.8's own (#1605)
"": "other",
}
for ua, want := range cases {
if got := usage.AgentOf(ua); got != want {
t.Errorf("%q: got %q want %q", ua, got, want)
}
}
}
// Every agent's own gateway key (gateway.TokenFor) names it in usage: the
// ones that send no User-Agent of their own (StepCode, jcode, Prime Agent,
// Snow…) are told by that key alone (#1605's check of the class).
func TestEveryAgentNamedByItsKey(t *testing.T) {
seen := map[string]bool{}
for _, a := range Clients() {
seen[a.ID] = true
if got := usage.AgentOf(a.ID); got != a.ID {
t.Errorf("%s's key names %q", a.ID, got)
}
}
for _, id := range []string{"minimax-code", "stepcode", "jcode", "prime-agent", "snow", "deveco"} {
if !seen[id] {
t.Errorf("%s isn't among the agents usage knows", id)
}
}
}