Files
magpie/internal/gui/providers_move_test.go
T
yetone 7116b583d8 providers: a deprecated built-in subscription not signed in to offers its plugin when clicked, instead of badging every tile (user: 已弃用的内置 subscription provider,如果没有安装的话,点击后引导安装,而不是一股脑地显示已弃用来污染视觉) — v0.1.628 put a Deprecated badge on every Add-sheet tile with a plugin (Zed, Devin, Qoder…, signed in or not) and a line under the grid explaining it. The badge now stays only where it means something: a subscription signed in through the built-in (its row, its tile, the notice over the list); a tile not signed in to has no badge, its tooltip saying it signs in through a community plugin, and the line under the grid is gone. Clicking that tile no longer starts magpie's own sign-in: a panel in its place (as the risk and site questions are) names the plugin package, says in a line why sign-ins are moving to plugins, and offers Install and sign in, with Use the built-in and Cancel. Install and sign in posts provider/adopt: provider.Adopt installs the plugin (to its mover's minimum version) and puts the subscription onto it as a move does (migrations.json state plugin, Installed when it installed it), with no accounts to carry; one that turns out to have accounts is moved (Move) instead, and a failure takes away a plugin it installed. The subscription is then the plugin's in place (its tile, name and icon as before, no second tile under From plugins, the plugin's provider id the built-in's), and its sign-in goes on through the plugin, the vendor's risk warning first as before; the panel shows a spinner while installing (the first plugin also fetches Bun) and the error, with Try again, if it fails. Moving back works as for a move with no accounts and takes away the plugin it installed. /api/providers carries movesTo (each deprecated built-in's plugin). Nothing was installed or signed in to for real. TestAdoptBeforeSigningIn (the fake plugin: adopted, installed once, provider id kept; back removes it; with an account it moves) and deprecated-subscriptions.test.cjs (Chromium and WebKit, en and zh: no badge on Zed or Claude, Cursor and Kiro badged, the offer, Use the built-in reaching the risk question, Install and sign in → adopt → the plugin's sign-in, no From plugins section) fail without the change; TestMoveOutlivesRequest covers adopt. mobile-web, plugin-move, plugin-move-overflow, plugin-progressive, plugin-movable-review, add-sheet, add-button, plugin-signin, plugin-moved-signin, claude-risk and provider-search pass; old-webkit's one failure (app.css:~388 :focus-visible) is on main already. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestFXInState failed once on its TempDir race, passes on the rerun; untouched).
2026-10-02 15:56:31 +08:00

46 lines
1.4 KiB
Go

package gui
import (
"context"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
)
// 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, oldBack, oldAdopt := moveProvider, moveBackProvider, adoptProvider
t.Cleanup(func() { moveProvider, moveBackProvider, adoptProvider = oldMove, oldBack, 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, moveBackProvider, adoptProvider = check, check, check
mux := http.NewServeMux()
providerRoutes(mux, nil)
for _, action := range []string{"move", "moveback", "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,zed: going" {
t.Fatalf("%v", got)
}
}