agent: Claude Code's model set back to its default puts back the endpoint and token the user had before magpie and leaves them (__jingling on X: 接入后跑 magpie claude model default,会把原来的 ANTHROPIC_BASE_URL 和 token 也删掉,之后再 default 也恢复不了,复现了两次) — the model field's default deleted every env key magpie writes, the user's own ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN among them, and forgot the stash that kept them from before magpie, so Disconnect after it had nothing to put back. It now takes magpie out as Disconnect does (its endpoint, token, tiers and window, the user's endpoint and token put back from the stash) and deletes only model; an endpoint the user set themselves, wired or not, stays, as the Agents page's default option (Claude Code · their host) says. magpie's env left at a gateway address since changed (its token) still goes. In a sandbox HOME with the release binary: settings.json with // mine, model opus, env ANTHROPIC_BASE_URL https://api.deepseek.com/anthropic and a token; magpie claude deepseek/deepseek-chat, then magpie claude model default: the comment, base URL and token back, model gone; magpie claude default after it leaves them. TestAgentModelDefaultKeepsTheEndpointBefore fails on the old code. go vet, builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
This commit is contained in:
1 parent
b7fef3877f
commit
fe2603ff4f
2 files changed
+61
-15
No files matched your search
@@ -43,3 +43,51 @@ func TestAgentDefaultPutsBackTheModelBefore(t *testing.T) {
|
||||
t.Fatalf("the model field's default leaves Claude Code as installed:\n%s", s)
|
||||
}
|
||||
}
|
||||
|
||||
// `magpie claude model default` on a Claude Code wired into magpie puts
|
||||
// back the endpoint and token the user had before magpie and leaves them:
|
||||
// it took them away, and Disconnect after it had nothing to put back
|
||||
// (__jingling on X, twice).
|
||||
func TestAgentModelDefaultKeepsTheEndpointBefore(t *testing.T) {
|
||||
groupsHome(t)
|
||||
t.Setenv("CLAUDE_CONFIG_DIR", "")
|
||||
path := filepath.Join(os.Getenv("HOME"), ".claude", "settings.json")
|
||||
os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
own := "{\n \"model\": \"opus\",\n \"env\": {\n \"ANTHROPIC_BASE_URL\": \"https://relay.example.com\",\n \"ANTHROPIC_AUTH_TOKEN\": \"sk-mine\"\n }\n}\n"
|
||||
if err := os.WriteFile(path, []byte(own), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
read := func() string {
|
||||
b, _ := os.ReadFile(path)
|
||||
return string(b)
|
||||
}
|
||||
mine := func(when string) {
|
||||
t.Helper()
|
||||
s := read()
|
||||
if !strings.Contains(s, `"ANTHROPIC_BASE_URL": "https://relay.example.com"`) || !strings.Contains(s, `"ANTHROPIC_AUTH_TOKEN": "sk-mine"`) {
|
||||
t.Fatalf("%s: the user's own endpoint and token are gone:\n%s", when, s)
|
||||
}
|
||||
}
|
||||
if err := run([]string{"claude", "a/m"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s := read(); strings.Contains(s, "relay.example.com") {
|
||||
t.Fatalf("not wired:\n%s", s)
|
||||
}
|
||||
if err := run([]string{"claude", "model", "default"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mine("model default")
|
||||
if s := read(); strings.Contains(s, `"model"`) {
|
||||
t.Fatalf("model default kept a model:\n%s", s)
|
||||
}
|
||||
if err := run([]string{"claude", "default"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mine("default after it")
|
||||
// unwired, a field's default leaves the user's own endpoint too
|
||||
if err := run([]string{"claude", "model", "default"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mine("model default unwired")
|
||||
}
|
||||
+13
-15
@@ -563,24 +563,22 @@ func claudeIn(at place) *Agent {
|
||||
var writeTiers func(main string, tiers map[string]string) error
|
||||
set := func(v string) error {
|
||||
if v == "" {
|
||||
// Claude Code as installed: Anthropic's own endpoint and model
|
||||
// Claude Code's own model, on the endpoint the user had before
|
||||
// magpie: magpie steps out, putting back their endpoint and
|
||||
// token, which stay theirs (__jingling on X: magpie claude
|
||||
// model default took their ANTHROPIC_BASE_URL and token away
|
||||
// for good)
|
||||
if _, err := unroute(); err != nil {
|
||||
return err
|
||||
}
|
||||
keys := []string{"model"}
|
||||
for _, k := range claudeEnv {
|
||||
keys = append(keys, "env."+k)
|
||||
if env("ANTHROPIC_AUTH_TOKEN") == gateway.Token {
|
||||
// magpie's, left at a gateway address since changed
|
||||
for _, k := range claudeEnv {
|
||||
keys = append(keys, "env."+k)
|
||||
}
|
||||
}
|
||||
forget(at.key("claude.model"), at.key("claude.base_url"), at.key("claude.auth_token"), mainKey)
|
||||
if err := dropWindow(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dropCompact(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dropCaps(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := dropPicker(); err != nil {
|
||||
return err
|
||||
}
|
||||
return edit.DelJSON(path, keys...)
|
||||
}
|
||||
if isMagpie(v) {
|
||||
|
||||
Reference in new issue
Block a user