zhangt2333 (#3480): magpie sent GET / (Go-http-client/1.1) about every 30s to the ANTHROPIC_BASE_URL in ~/.claude/settings.json of a Claude Code it never connected, with nothing shown and nothing to turn it off. Every read of Claude Code the Agents page makes (/api/state, /api/drift each 15s) goes through routed(), which asked a base URL that can be another way to magpie (proxyBase: an address on another machine, or one on loopback with a path of its own) whether it answers as magpie, for #1985's reverse proxy, whatever key Claude Code sends there. One read pass asked it about 65 times; the probe cache sends that as one GET once its answer is older than 20s (reachAge), every 30s on the page's poll. The address is now asked only while what Claude Code sends is for magpie (claudeProxied, claudeKeyed): a key the gateway takes (keyHolds, as Check already asks of ANTHROPIC_AUTH_TOKEN), or none where it keeps its claude.ai sign-in through magpie (claude.login, on a Claude Code magpie wired, wired_at, which Disconnect forgets, where the gateway takes any key). With a key of the user's own, the base URL is their endpoint, and nothing asks it: the reads (routed), a pick (gwAt), Check (its managed settings' and settings.json's URL), and a request's stand-ins (claudeStandInAt, now given the place, and claudeClassifierIn), a WSL distro's Claude Code's too. Check says such a Claude Code's address as it is, unasked (whatsOff: wiringOff's words, without its probe; an administrator's in managed settings too): with a model named as one of magpie's there, as a relay can name its own, "Claude Code's ANTHROPIC_BASE_URL (settings.json) is <its endpoint>, not magpie's gateway at <the gateway>", or "is gone" with none, which main said of it too once the address had answered as not magpie. #1985's proxy keeps magpie's key, so it is asked and kept as before. The key, not a record of what magpie wrote: wired_at is from 10-08 (#1218), so a Claude Code connected before it and not picked since has none, and a Claude Code magpie wired and then moved to a relay of the user's own (CC Switch, its own key) would still have that relay asked. The claude.ai sign-in can lean on it: it came with it (#1218), and its setting, on a routed Claude Code only, stamps it. Before and after, for a read, a pick or a request's stand-in while ANTHROPIC_BASE_URL is not the gateway's and proxyBase takes it: before: GET <base>/ in the background, at most every 20s after: the same while Claude Code sends a key the gateway takes or keeps its claude.ai sign-in through magpie; otherwise never, and the address is not magpie's Changed with it: a Claude Code pointed by hand at a proxy to magpie with a key of its own, drift on main too (its key "was changed"; now its address), is no longer taken as routed there, so a pick writes magpie's address and key, keeping its own for Disconnect, where it kept the proxy. Not changed: the other agents ask an address only from magpie's own entry in their config, or once on one of magpie's models (T3 Code's wired, Gemini CLI's isMagpie(model), Hermes's onMagpie and providers.magpie, dsh's usesMagpie), so none asks one of the user's own. A Claude Code magpie wired keeping its claude.ai sign-in, then moved by hand to an endpoint of the user's own with an ANTHROPIC_API_KEY alone and not disconnected, is still asked, as before: magpie reads no ANTHROPIC_API_KEY of Claude Code's. Cost: a never-connected Claude Code with its own key at such an address, the case this reaches: a read pass took 5.5 to 6.0ms on origin/main and 9.4 to 9.8ms with this (three runs each, taking turns, 200 passes, at load 46 to 50; the key's read and access.Authenticate at ~65 calls a pass), on the 15s drift poll. A connected Claude Code (the gateway's address) and one on Anthropic's own endpoint (no base URL) never get there. docs/subsystems/agent-wiring.md (Drift) says it. What was run (tree c7f75f7a, on origin/main74dcf40a, go1.26.8, linux/amd64, Linux 5.15), outside graftcp, umask 077: magpie web --no-open, built -tags nogui from origin/main and from this, each in a sandbox HOME of its own (env -i), with a settings.json on a local relay that logs what it gets (http://127.0.0.1:<port>/corp-relay, a key of its own) and listens before magpie starts, /api/drift read every 5s: model opus, 120s: main, GET /corp-relay/ (Go-http-client/1.1) every 20s from the first read, 6 in all; this, none. Neither touched settings.json. model fakeco/fake-1 (a provider magpie has), 60s: main, 3 GETs; this, none. Both said "Claude Code's ANTHROPIC_BASE_URL (settings.json) is http://127.0.0.1:<port>/corp-relay, not magpie's gateway at http://127.0.0.1:<port>" from the first read. Run once more with magpie up before the relay listened: main 5 GETs and 2, its first ask made before then, this none, the rest the same. magpie claude fakeco/fake-1, then its ANTHROPIC_BASE_URL moved by hand to the relay answering GET / as magpie, magpie's key kept, 60s: both asked it every 20s, 3 GETs, no drift. Both wrote settings.json again at start with every key and value the same (a label's "·", which the hand edit had escaped, now as is). Run once more with magpie up before the relay listened: both drifted "… is <the relay>, not magpie's gateway …" on the first read and took CLAUDE_CODE_AUTO_MODE_SERVER out of settings.json, then asked it every 20s with no drift, the address kept; main does it the same, not this change. TestClaudeOwnEndpointNeverAsked (nginx: its own key in ANTHROPIC_AUTH_TOKEN; local: in ANTHROPIC_API_KEY) and TestWSLClaudeOwnEndpointNeverAsked: pass. Broken by hand, each red: claudeProxied without claudeKeyed: "never connected: asked [https://relay.example/anthropic https://relay.example/anthropic …]" (and the WSL test) Check's addresses asked whatever the key (keyed true): "a model of magpie's name: asked [https://relay.example/anthropic]" Check's address unsaid without magpie's key: "its own key, a model of magpie's name: … ANTHROPIC_AUTH_TOKEN (settings.json) was changed, so magpie's gateway won't take its requests" (nginx), "… is gone, so Claude Code sends magpie its claude.ai sign-in …" (local) the administrator's address asked whatever the key: "its own key, an administrator's proxy: … ANTHROPIC_BASE_URL (settings.json) is https://relay.example/anthropic, not magpie's gateway …" claudeStandInAt, then claudeClassifierIn, on surelyMagpie alone: "never connected: asked [https://relay.example/anthropic]" (and the WSL test) claudeKeyed with no claude.ai branch: "the claude.ai sign-in at the proxy: drift … ANTHROPIC_BASE_URL (settings.json) is <the proxy>, not magpie's gateway …" (and the WSL test) its claude.ai branch without wired_at: local only, "asked after Disconnect: [https://relay.example/anthropic …]" its claude.ai branch on this machine's stash keys: the WSL test alone, the same as with no claude.ai branch agent-wiring.md's reverse proxy checks (TestReverseProxy…, TestClaudeBehindLocalProxyKeepsIt, …), Drift, the sign-in's and TestKeptAddress: ok, but for TestWSLColdPlaceOpensNothing (e54a7d50, #3896: a stopped distro's rows read none of its files), red at origin/main and with this change alike (#3924): the same eight looks under .hermes/profiles, none under .claude gofmt -l of every .go file: nothing. GOOS=linux, windows and darwin go vet -tags nogui ./..., GOOS=windows go vet ./...: exit 0. GOOS=linux and darwin go build -tags nogui ./..., GOOS=windows go build ./...: exit 0. Untagged linux vet and build stop at pkg-config (no libsoup-3.0 or gio-unix-2.0 here) full suite, go test -tags nogui -count=1 -timeout 45m ./... (8m19s, load 42 at its start, Bun 1.4.2 on PATH): 68 packages ok, reds in 8: internal/agent TestInstalledVersion, TestCursorFolderFromTheEditorIsNotTheCLI, TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestQoderSettingsFromAnIDEPluginIsNotTheCLI and TestOmpDetectedWithPiDir (#3141); the two Reasonix tests (#3641); TestCodexDriftReached (#3398); TestWSLColdPlaceOpensNothing (#3924, above) internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv TestProgram, umask 077 (#3640) internal/gateway TestPluginToldWhereTheAgentWorks (#3675) internal/gui TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie (#3649) internal/proc TestEnvOfChild (#3906) internal/provider: "fatal error: close of synctest channel from outside bubble" in TestUnreadLoginsWriteErrorsKeepCredentials (#3632), which ends the package's run internal/tui TestTUIFetchesSubscriptionModels/agent (#3919) On origin/main1a804859, where #3924's fix is in, with this commit cherry-picked (a scratch worktree, not this tree): go test ./internal/agent has the reds1a804859has alone, #3141's, #3398's and #3641's, and TestWSLColdPlaceOpensNothing passes. TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestInstalledVersion and TestZedAppPath come and go here: -count=5, 12 of 15 red with this and 11 of 15 at1a804859. Not tried: macOS, Windows, a real WSL distro (its Claude Code's stash keys are only tested), Claude Code itself sending through the relay, a company's real proxy. Landed by yetone in a batch of Coffemon's patches from the issues. What was run, go1.26.8, on origin/maincc81ad4ea, then again at70a0c387c(gofmt, the three vets, the changed tests, umask 077): - mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask 077; agent, provider, library and gateway with an empty .git above TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the changed tests in agent, provider, gateway and gui; the timing tests -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok. TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js 1,312,975 of 1,315,316, no budget raised. - Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink at umask 077 and two Reasonix tests under an empty .git; on Linux (wsl-run) TestProgram at umask 077 with the old program.go. With each fix's code taken back to main's, the Gemini imageConfig tests, TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced, TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto, plugin-github-hooks, plugins-more-discover, plugin-namesake were red. Broken by hand: claudeKeyed always true (both OwnEndpointNeverAsked tests red), claudeAsk a no-op (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder (the three TestGitOnDisk tests red). - GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n, gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on Linux (wsl-run). 11 files had reds (click-scroll, panel-fold, plugin-card-update, plugin-github, plugin-move*, segs-glide, tray-totals, update-*), and run again side by side they fail the same on origin/maind80d75f30(79 pass, 26 fail here; 78 and 27 there). They are click-scroll guards ("the click must not scroll the page"), varying by language from run to run (#4385). copilot-ghe's route-after-close red is #1949, seen on main244d80e23too. In Chromium on mote, Chromium segfaulted partway through files (#4125): context-map, context-scroll-end and context-tune fail the same on origin/main0911a65e7, so the batch's own files (plugin-namesake, update-auto, plugins-more-discover, plugin-github-hooks) ran in Chromium on Linux: 62 of 62. - Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote) at 472a0608f (on70a0c387c): every package ok but internal/gateway, whose five reds were #4362's (Antigravity turned-away and TestCodexSpentGrokFailingIsTold), fixed on main ind80d75f30. After the rebase on244d80e23the five pass, and gofmt, the three vets and the targeted runs above were run again: ok. In Linux the sign-in, copilot, plugin-github*, plugins-more-discover, plugin-namesake, plugin-gateway, update-auto, quota-refresh-order and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe #1949, plugin-github's click scroll, both red on main too). - Rebased again onc7171a256, over its budget fixe94bf7a08: gofmt, vet of gui, gateway, provider and plugin, TestCoreScriptBudget (core 1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini, GitOnDisk and plugin tests, and in Linux both engines i18n-keys, update-mirror, plugin-namesake, plugins-more-discover, plugin-github-hooks and update-auto (138 of 138): ok. Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its Chromium segfaulted, #4125); macOS WebKit; the real app's window.
183 lines
6.8 KiB
Go
183 lines
6.8 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// On a Claude model that is no Fable, Claude Code's fable tier is left
|
|
// unset rather than following the main model: Claude Code takes the model
|
|
// ANTHROPIC_DEFAULT_FABLE_MODEL names for a Fable model, so Opus written
|
|
// there was Fable to it, and a Claude Pro sign-in without Fable asked for
|
|
// usage credits and fell back to Haiku (Zhenzhen on Discord, magpie claude
|
|
// claude/claude-opus-5-5). So it is on another vendor's model (#2090). On a
|
|
// Fable it follows as before; a value of the user's own stays theirs.
|
|
func TestClaudeFableTierOnClaude(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
|
|
for _, p := range []provider.Provider{
|
|
{ID: "anth", Name: "Anthropic", Chat: "https://api.anthropic.com/v1", Key: "k", Models: []string{"claude-opus-5-5", "claude-sonnet-5", "claude-fable-5-1", "claude-haiku-4-5"}},
|
|
{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash"}},
|
|
{ID: "cx", Name: "Codex models", Chat: "https://codex.invalid/v1", Key: "k", Models: []string{"gpt-6.1-sol"}},
|
|
} {
|
|
if err := provider.Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
path := filepath.Join(home, ".claude", "settings.json")
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// the user's own fable model, from before magpie
|
|
if err := os.WriteFile(path, []byte(`{"env":{"ANTHROPIC_DEFAULT_FABLE_MODEL":"my-fable"}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
a := claude(home)
|
|
fable := func() (string, bool) { return edit.GetJSON(path, "env.ANTHROPIC_DEFAULT_FABLE_MODEL") }
|
|
env := func(k string) string { v, _ := edit.GetJSON(path, "env."+k); return v }
|
|
noFable := func(when string) {
|
|
t.Helper()
|
|
if v, has := fable(); has {
|
|
t.Fatalf("%s: fable tier written as %q, want it left out:\n%s", when, v, readFile(path))
|
|
}
|
|
}
|
|
|
|
if err := a.Field("model").Set("anth/claude-opus-5-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("on Opus")
|
|
if env("ANTHROPIC_DEFAULT_OPUS_MODEL") != "anth/claude-opus-5-5" || env("ANTHROPIC_DEFAULT_SONNET_MODEL") != "anth/claude-opus-5-5" || env("ANTHROPIC_DEFAULT_HAIKU_MODEL") != "anth/claude-haiku-4-5" {
|
|
t.Fatalf("the other tiers should follow as before:\n%s", readFile(path))
|
|
}
|
|
if a.Field("fable").Get() != "" {
|
|
t.Fatalf("fable shown as %q, want following", a.Field("fable").Get())
|
|
}
|
|
// Claude Code's own fable, asked of the gateway, runs on the main model
|
|
if got := claudeStandInAt(here(""), path, "claude-fable-5-1"); got != "anth/claude-opus-5-5" {
|
|
t.Fatalf("claude-fable-5-1 stands in as %q", got)
|
|
}
|
|
// another Claude model that is no Fable
|
|
if err := a.Field("model").Set("anth/claude-sonnet-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("on Sonnet")
|
|
// a Fable: the fable tier follows it
|
|
if err := a.Field("model").Set("anth/claude-fable-5-1"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "anth/claude-fable-5-1" {
|
|
t.Fatalf("on Fable, fable is %q", v)
|
|
}
|
|
if err := a.Field("model").Set("anth/claude-opus-5-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("back from Fable")
|
|
// another vendor's model is no Fable either: GPT-6.1 Sol written there
|
|
// was Fable to Claude Code, which asked for usage credits before Sol's
|
|
// first turn (#2090)
|
|
for _, m := range []string{"cx/gpt-6.1-sol", "deepseek/pro"} {
|
|
if err := a.Field("model").Set(m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("on " + m)
|
|
if env("ANTHROPIC_DEFAULT_OPUS_MODEL") != m || env("ANTHROPIC_DEFAULT_SONNET_MODEL") != m || env("ANTHROPIC_DEFAULT_HAIKU_MODEL") != m {
|
|
t.Fatalf("on %s the other tiers should follow:\n%s", m, readFile(path))
|
|
}
|
|
if got := claudeStandInAt(here(""), path, "claude-fable-5-1"); got != m {
|
|
t.Fatalf("on %s claude-fable-5-1 stands in as %q", m, got)
|
|
}
|
|
}
|
|
// the reporter's settings.json, the fable tier on Sol, from 0.1.1229:
|
|
// Follow takes it out. 0.1.1229 wrote it there following the main
|
|
// model on Sol; a fable tier on Sol before the main model moved onto
|
|
// it is one given Sol, which stays (#2257,
|
|
// TestClaudeOwnTierOnTheNewMainModelStays)
|
|
if err := a.Field("model").Set("cx/gpt-6.1-sol"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := edit.SetJSON(path, edit.KV{Path: "env.ANTHROPIC_DEFAULT_FABLE_MODEL", Value: "cx/gpt-6.1-sol"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Follow(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("Sol's older wiring after Follow")
|
|
if err := a.Field("model").Set("anth/claude-opus-5-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("back from another vendor")
|
|
|
|
// the user's pick of the main model for fable is theirs: it stays
|
|
if err := a.Field("fable").Set("anth/claude-opus-5-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "anth/claude-opus-5-5" || a.Field("fable").Get() != "anth/claude-opus-5-5" {
|
|
t.Fatalf("own fable pick: %q, shown %q", v, a.Field("fable").Get())
|
|
}
|
|
if err := a.Field("model").Set("anth/claude-sonnet-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Follow(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "anth/claude-opus-5-5" {
|
|
t.Fatalf("own fable pick lost: %q", v)
|
|
}
|
|
if err := a.Field("fable").Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("fable back to following")
|
|
|
|
// an effort picked for the fable tier keeps it on the main model at that
|
|
// effort, as the user asked
|
|
if err := a.Field("fable_effort").Set("low"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "anth/claude-sonnet-5:low" {
|
|
t.Fatalf("fable effort: %q", v)
|
|
}
|
|
if err := a.Field("fable_effort").Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("fable effort taken away")
|
|
|
|
// one the user wrote themselves while routed, not a model of magpie's,
|
|
// stays as written when the main model moves
|
|
if err := edit.SetJSON(path, edit.KV{Path: "env.ANTHROPIC_DEFAULT_FABLE_MODEL", Value: "claude-fable-5-1"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Field("model").Set("anth/claude-opus-5-5"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "claude-fable-5-1" {
|
|
t.Fatalf("the user's own fable written over: %q", v)
|
|
}
|
|
if err := edit.DelJSON(path, "env.ANTHROPIC_DEFAULT_FABLE_MODEL"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// an older magpie wrote fable on the main model: Follow takes it out
|
|
if err := edit.SetJSON(path, edit.KV{Path: "env.ANTHROPIC_DEFAULT_FABLE_MODEL", Value: "anth/claude-opus-5-5"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Follow(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
noFable("older wiring after Follow")
|
|
|
|
// magpie steps out: the user's own fable model is back
|
|
if err := a.Field("model").Set(""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, _ := fable(); v != "my-fable" {
|
|
t.Fatalf("the user's own fable not given back: %q\n%s", v, readFile(path))
|
|
}
|
|
}
|