Files
magpie/internal/gui/providers_move_test.go
T
yetone 9fcf6a6e7f provider: every deprecated built-in moves onto its plugin, and there's no way back
The owner, 10-16: 陆续把内置Provider下线掉…一定要下线完毕. The plugins now do
what the built-ins did (the parity batch up to 53009f81a), so the built-ins
are retired:

- MoveRetiring moves every subscription with a mover (retiring is
  MovableIDs, the list was empty) that still has built-in accounts, from
  the gateway's hourly loop, six hours after a failed try as before.
- A user who moved back is moved again. Only a move back made by removing
  or turning off the plugin (Migration.Left) is left as it is.
- There is no move back from the GUI or the CLI. provider/moveback and
  `magpie plugins move-back` answer that the built-ins are retired. A
  moved subscription's editor says it stays on its plugin and shows no
  button, and the success line no longer offers to go back. New strings
  in zh, zh-TW, ja and de; the three unused ones are gone ("Moving back…"
  stays, for removing a plugin).
- AGENTS.md and docs/subsystems/provider-plugins.md say so.

Tests:
- TestMoveRetiring's subtests check that a moved-back subscription is
  moved again and an off or removed plugin's is not.
- TestMoveBackRefused goes red on the old handler.
- plugin-move.test.cjs checks that a moved Zed has no button and says it
  stays.

What was run, at 63be47717 with this change:
- go test -tags nogui ./... -count=1 -timeout 90m: 65 packages ok. The
  gateway was red on TestUsageKeepsTimeToFirstToken (#2575, new) and
  TestVisionWaitIsntTheDescribersTime (#2444) at load ~260. Neither file
  is touched here, and both pass alone with -count=3.
- gofmt -l is clean; GOOS=linux and GOOS=windows go vet of provider, gui
  and cli pass.
- GUI, both engines: plugin-move, plugin-move-unserved and i18n-keys pass
  23 of 23.
- The other plugin-*.test.cjs files go red under parallel load as they do
  on untouched main (#1544, commented with the runs). Serially, then alone,
  they pass 28 of 28.
2026-10-16 22:58:40 +08:00

110 lines
3.8 KiB
Go

package gui
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A move goes on though the page that asked for it closes: stopped
// halfway, it leaves the accounts in neither place.
func TestMoveOutlivesRequest(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"))
t.Setenv("PATH", t.TempDir())
oldMove, oldAdopt := moveProvider, adoptProvider
t.Cleanup(func() { moveProvider, adoptProvider = oldMove, oldAdopt })
var got []string
check := func(ctx context.Context, id string) error {
_, deadline := ctx.Deadline()
if ctx.Err() != nil || !deadline {
got = append(got, id+": stopped with the page")
} else {
got = append(got, id+": going")
}
return nil
}
moveProvider, adoptProvider = check, check
mux := http.NewServeMux()
providerRoutes(mux, nil)
for _, action := range []string{"move", "adopt"} {
ctx, cancel := context.WithCancel(context.Background())
cancel() // the page went away
r := httptest.NewRequest("POST", "/api/provider/"+action, strings.NewReader(`{"id":"zed"}`)).WithContext(ctx)
mux.ServeHTTP(httptest.NewRecorder(), r)
}
if strings.Join(got, ",") != "zed: going,zed: going" {
t.Fatalf("%v", got)
}
}
// Try again in the editor moves with the models as the editor shows them
// picked: the failed move said to untick one the plugin doesn't serve,
// and the untick wasn't saved (noting_ever on X: deep-model unticked, and
// WorkBuddy AI's move failed on deep-model all the same). A move that
// says no models leaves the picks as they are.
func TestMoveTakesEditorPicks(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"))
t.Setenv("PATH", t.TempDir())
if err := provider.Save(provider.Provider{ID: "sub", Name: "Sub", Chat: "http://127.0.0.1:1/v1", Models: []string{"auto", "deep-model"}}); err != nil {
t.Fatal(err)
}
oldMove := moveProvider
t.Cleanup(func() { moveProvider = oldMove })
var seen [][]string
moveProvider = func(ctx context.Context, id string) error {
p, err := provider.Find(id)
if err != nil {
return err
}
seen = append(seen, p.Models)
return nil
}
mux := http.NewServeMux()
providerRoutes(mux, nil)
for _, body := range []string{`{"id":"sub"}`, `{"id":"sub","models":["auto"]}`, `{"id":"sub"}`} {
w := httptest.NewRecorder()
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/move", strings.NewReader(body)))
if w.Code != http.StatusOK {
t.Fatalf("%s: %d %s", body, w.Code, w.Body)
}
}
if fmt.Sprint(seen) != "[[auto deep-model] [auto] [auto]]" {
t.Fatalf("the move saw the picks %v", seen)
}
}
// The built-ins are retired: a move back is refused, and nothing is moved.
func TestMoveBackRefused(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("PATH", t.TempDir())
oldMove, oldAdopt := moveProvider, adoptProvider
t.Cleanup(func() { moveProvider, adoptProvider = oldMove, oldAdopt })
moved := false
moveProvider = func(context.Context, string) error { moved = true; return nil }
adoptProvider = moveProvider
mux := http.NewServeMux()
providerRoutes(mux, nil)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, httptest.NewRequest("POST", "/api/provider/moveback", strings.NewReader(`{"id":"zed"}`)))
if rec.Code < 400 || !strings.Contains(rec.Body.String(), "retired") || moved {
t.Fatalf("%d %s moved=%v", rec.Code, rec.Body.String(), moved)
}
}