Files
magpie/internal/agent/stash_unwire_model_test.go
T
yetone f62e93b8aa agent: Claude's Unwire gives up the stashed model in every case (#4258)
The #4258 patch kept the model in the stash until the write that puts it
back or takes magpie's out has gone through. When neither write runs (the
stash kept one of magpie's models and the user has picked their own
since), the model stayed stashed after the Unwire. Before the patch,
unroute's unstash always took it out. It is now forgotten after the
switch in every case that returns nil, which is main's behaviour with
#4258's ordering.

Run (mica, at this tree): TestClaudeDisconnectLeavesNoModelStashed is ok
here and ok at main's claude.go, codex.go and stash.go. With 46b365337's
claude.go alone it is red ("the stash still holds a model after the
Unwire: relay/glm-4.6"). TestDisconnectFailureKeepsStashedOriginals is ok.
gofmt -l clean; go vet of internal/{provider,davsync,agent} on darwin,
GOOS=windows and GOOS=linux is ok.

Not changed: the other agents' restore paths, filed as #6601.
2026-11-14 13:08:40 +08:00

42 lines
1.4 KiB
Go

package agent
import (
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/edit"
)
// #4258's review: unroute leaves the model stashed for its caller, so
// Claude Code's Unwire that neither puts the model back nor takes magpie's
// out (the stash kept one of magpie's, an older magpie's doing, and the
// user picked their own since) still gives it up, as unroute's unstash did
// before: no model outlives the Disconnect to come back at a later one.
// Unwire is called alone here: Disconnect reaches it only while a field is
// still magpie's, and the main model is the user's own in this case.
func TestClaudeDisconnectLeavesNoModelStashed(t *testing.T) {
home := syncHome(t)
path := filepath.Join(home, ".claude", "settings.json")
writeFile(t, path, `{"model":"native-original"}`)
a := claude(home)
if err := a.Connect(); err != nil {
t.Fatal(err)
}
stash(map[string]string{"claude.model": "relay/glm-4.6"})
if !isMagpie("relay/glm-4.6") {
t.Fatal("relay/glm-4.6 is no model of magpie's here")
}
if err := edit.SetJSON(path, edit.KV{Path: "model", Value: "opus-by-hand"}); err != nil {
t.Fatal(err)
}
if err := a.Unwire(); err != nil {
t.Fatal(err)
}
if got := stashShared()["claude.model"]; got != "" {
t.Fatalf("the stash still holds a model after the Unwire: %q", got)
}
if got, _ := edit.GetJSON(path, "model"); got != "opus-by-hand" {
t.Fatalf("the user's own pick went: %q", got)
}
}