Files
magpie/internal/provider/migrate_handover_test.go
T
yetone 7d7dba31ae provider: removing or turning off a moved subscription's plugin moves nothing back
The built-ins are being retired (the owner, 10-16: 陆续把内置Provider下线掉),
so the last way back to one is gone. MoveBack, moveBack and releasePlugin
are removed, with the Left flag they set.

- SetPluginOff only turns the plugin off. A moved subscription stays
  moved, off with it.
- RemovePlugin records the moved ids as the new state "removed". The
  record keeps its accounts, which plugin.Remove leaves in the plugin's
  auth store. Nothing moves or installs it by itself: MoveRetiring
  skips it and keepMovedCurrent reads only "plugin".
- HandOver turns a removed record whose plugin is installed and current
  back into "plugin", record and all. So does Adopt (the editor's Move).
- MoveRetiring moves an old "back" record again, whatever Left said.
- Plugins page, rm/off confirms: "{names} stops working until the plugin
  is installed again. Its accounts are kept." / "... while the plugin
  is off." The status after removing no longer says it is back on the
  built-in.
- Strings: five old strings dropped ("Moving back…" among them), three
  new ones in zh, zh-TW, ja and de.
- `magpie plugins rm`/`off` say the same in their output.
- Docs: provider-plugins.md (the states table, the Move-back paragraph)
  and AGENTS.md.

Tests:
- TestNoWayBack is new. It covers a "back" record moved again, the
  plugin turned off (still moved, accounts kept), removed (removed, not
  reinstalled by keepMovedCurrent or MoveRetiring), installed again
  (HandOver), and removed again then Adopt.
- TestReleasePlugin and TestMoveBackKeepsLapse asserted the way back
  and are deleted.
- TestMove, TestHandOver, TestMoveTidiesItsPlugin and
  TestAdoptBeforeSigningIn no longer call MoveBack. TestKeepMovedCurrent
  uses the removed state.
- plugin-release.test.cjs checks the new asks and that the status names
  no built-in.

Run:
- Broken by hand:
  - With HEAD's migrate.go, TestNoWayBack is red at "turning the plugin
    off moved it back".
  - With HandOver's removed branch disabled, it is red at "installed
    again: map[], moved false".
- go test -tags nogui ./internal/provider -run
  'TestMove|TestNoWayBack|TestHandOver|TestKeepMovedCurrent|TestAdopt|TestInstallPlugin|TestWorkBuddyCheckin|Plugin|Migrat':
  ok.
- GUI (NODE_PATH playwright, --test-concurrency=1): plugin-release,
  plugin-move and i18n-keys, chromium and webkit: 17/17.
- gofmt -l clean; GOOS=linux and windows go vet of provider, gui and cli.
- Full suite: go test -tags nogui ./... -count=1 -timeout 90m at this commit rebased on 9b04c4e20 (with the TestFailOpen fix after it): 66 packages ok, none red. Before that fix, at bff7cbd24, 65 ok and internal/middleware TestFailOpen red under load (fixed at its cause in the next commit).
2026-10-16 22:58:41 +08:00

76 lines
2.9 KiB
Go

package provider
import (
"os"
"testing"
"github.com/yetone/magpie/internal/plugin"
)
// A deprecated built-in whose plugin the user installed is handed to it
// (ARNO on Discord: Qoder CN listed twice, the built-in and the plugin's,
// once the Qoder plugin served it): one with no accounts at once, one with
// accounts only when asked to move them, through Move. One the plugin is
// signed in to under its own id already stays as it is; one moved whose
// plugin the user removed is the plugin's again once it is installed, and
// nothing happens while the plugin isn't installed.
func TestHandOver(t *testing.T) {
ctx, abs, installs := fakePlugin(t)
reset := func(ls ...savedLogin) {
t.Helper()
_ = plugin.SignOut(ctx, "fakeco", "")
os.Remove(migrationsPath())
setFakeLogins(t, ls...)
}
// not installed: nothing, and nothing installed for it
if out := HandOver(ctx, true); len(out) != 0 || Moved("fakeco") || *installs != 0 {
t.Fatalf("with no plugin: %v, moved %v, %d installs", out, Moved("fakeco"), *installs)
}
if _, err := plugin.Add(ctx, abs); err != nil {
t.Fatal(err)
}
// installed, no accounts either side: the plugin's at once
reset()
if out := HandOver(ctx, false); out["fakeco"] != nil || !Moved("fakeco") {
t.Fatalf("no accounts: %v, moved %v", out, Moved("fakeco"))
}
// the user removed the plugin: nothing moves or installs it until they
// install it again, and then it is the plugin's at once
if err := RemovePlugin(ctx, abs); err != nil {
t.Fatal(err)
}
if out := HandOver(ctx, true); len(out) != 0 || Moved("fakeco") || pluginListed(abs) {
t.Fatalf("plugin removed: %v, moved %v, listed %v", out, Moved("fakeco"), pluginListed(abs))
}
if _, err := plugin.Add(ctx, abs); err != nil {
t.Fatal(err)
}
if out := HandOver(ctx, false); out["fakeco"] != nil || !Moved("fakeco") {
t.Fatalf("installed again: %v, moved %v", out, Moved("fakeco"))
}
// the built-in has an account: moved only when accounts are asked for
reset(fakeLogin("a@fake", "r-a", true, true))
if out := HandOver(ctx, false); len(out) != 0 || Moved("fakeco") {
t.Fatalf("accounts not asked for: %v, moved %v", out, Moved("fakeco"))
}
if out := HandOver(ctx, true); out["fakeco"] != nil || !Moved("fakeco") || len(fakeSaved(t)) != 0 || !plugin.SignedIn("fakeco") {
t.Fatalf("accounts asked for: %v, moved %v, built-in's %+v", out, Moved("fakeco"), fakeSaved(t))
}
// the plugin signed in on its own, the built-in not moved: left as it
// is, its models in use under the plugin's own id
reset()
if _, err := plugin.Import(ctx, "fakeco", map[string]any{"type": "oauth", "refresh": "r-b", "access": "a", "expires": 9e15, "accountId": "b@fake"}); err != nil {
t.Fatal(err)
}
if _, err := plugin.Providers(ctx); err != nil {
t.Fatal(err)
}
if out := HandOver(ctx, true); len(out) != 0 || Moved("fakeco") {
t.Fatalf("the plugin signed in on its own: %v, moved %v", out, Moved("fakeco"))
}
}