marchen_cc on X: 「从文件导入账号」 took no WorkBuddy sign-in file. The cause
was not WorkBuddy's: magpie's import reached only built-ins (Codex,
Claude, Antigravity, Factory), and a plugin had no way to say it could
read a file. This adds that for every plugin subscription:
- A plugin's auth may have import(texts, {signal}), returning sign-in
results, with importFrom (and importFroms by language) saying which
file to choose. The host's importFiles op keeps each one as a sign-in
is kept (keptAs, saved under signInKey, settled), so an account
already there comes back "updated"; it is cancellable (signInSteps)
and takes at most 100.
- /api/signin/import and `magpie accounts import <plugin> <files>` go
to provider.ImportPluginFiles when PluginImportable(id); the editor's
「从文件导入账号…」 row and the import sheet show for such a plugin, in
its own words (importSay), moved subscriptions included (subOf).
- docs/subsystems/provider-plugins.md: "Accounts from a file".
- WorkBuddy's mover min goes to 0.2.32, which reads the desktop app's
.info sign-in or a JSON credential, and sends a cloud-hosted
enterprise account (*.sso.copilot.tencent.com, *.copilot.qq.com,
*.sso.codebuddy.cn, iOA apart) to its enterprise's address (emilochen
on X), published and checked with npm view --prefer-online.
- TestCoreScriptBudget +468 for the import branch, packed to one
statement. importSay is read as the Providers rows draw, so it has
no lazy page; nothing else was moved out (#2710). The budget's
arithmetic was checked over this tree: 1,267,762, at the new cap.
Run on mote (mica's disk is full; mote over its cores) at this change
on 3f6b1b0c9; ac1702c33 (the library plugin and its GUI test, no core
script) landed after, and the core budget's arithmetic was redone at
this head:
gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
internal/{gui,plugin,provider,cli}; go test -count=1 of those four:
all ok. GUI (chromium + webkit, en and zh): plugin-import,
login-import, factory-key, plugin-moved-signin, i18n-keys: 23 pass, 1 fail: i18n-keys "a plugin's words are its own",
memory_mcp.go's "No folder", red on main since 72facf72e (#6422).
Plugins repo: workbuddy import.test.mjs 6 of 6, bun scripts/check.mjs
ok, root bun test 8534 pass / 1 fail (agy-cli smoke under load, green on a rerun: 8535 pass, 0 fail;
unrelated, plugins #1070).
Broken by hand: without the host's importFiles handler,
TestPluginImportFiles goes red; without importable in pluginSubs,
plugin-import.test.cjs goes red ("WorkBuddy lists no import").
Not tried: a real WorkBuddy desktop .info file or a real enterprise
account on a cloud-hosted domain; the fixtures follow WorkBuddy's own
client source. Not tried on Windows or Linux beyond vet.
77 lines
2.4 KiB
Go
77 lines
2.4 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A plugin subscription had no "Import accounts from a file…" (marchen_cc
|
|
// on X: WorkBuddy's): a plugin that declares auth.import is listed as
|
|
// importable with its words, and each account its import gives is kept as
|
|
// a sign-in is, one already signed in updated rather than added twice.
|
|
func TestPluginImportFiles(t *testing.T) {
|
|
sandbox(t)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
for _, name := range []string{"importer", "apiprompts"} {
|
|
abs, _ := filepath.Abs("testdata/" + name)
|
|
if _, err := Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
ps, err := Providers(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var imp, other *Provider
|
|
for i := range ps {
|
|
switch ps[i].ID {
|
|
case "importer":
|
|
imp = &ps[i]
|
|
case "apiprompts":
|
|
other = &ps[i]
|
|
}
|
|
}
|
|
if imp == nil || other == nil {
|
|
t.Fatalf("providers = %+v", ps)
|
|
}
|
|
if !imp.Importable || imp.ImportFrom != "Choose the Importer app's accounts file" || imp.ImportFroms["zh"] != "选择 Importer 的账号文件" {
|
|
t.Errorf("importer = importable %v, from %q, froms %v", imp.Importable, imp.ImportFrom, imp.ImportFroms)
|
|
}
|
|
if other.Importable {
|
|
t.Error("a plugin with no auth.import is listed as importable")
|
|
}
|
|
|
|
got, err := ImportFiles(ctx, "importer", []string{"ann:r-ann\nbad:x", "bob:r-bob"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 3 || got[0].Status != "added" || got[0].User != "ann" || got[1].Status != "failed" || got[1].Error != "Importer refused it" || got[2].Status != "added" || got[2].User != "bob" {
|
|
t.Fatalf("first import = %+v", got)
|
|
}
|
|
if got[0].Provider != "importer" || got[0].Account == "" || got[0].Account == got[2].Account {
|
|
t.Errorf("saved as %+v", got)
|
|
}
|
|
again, err := ImportFiles(ctx, "importer", []string{"ann:r-ann2"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(again) != 1 || again[0].Status != "updated" || again[0].Account != got[0].Account {
|
|
t.Errorf("ann imported again = %+v, want updated at %s", again, got[0].Account)
|
|
}
|
|
b, err := os.ReadFile(AuthPath())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(string(b), "r-ann2") || strings.Contains(string(b), `"r-ann"`) || !strings.Contains(string(b), "r-bob") {
|
|
t.Errorf("auth.json = %s", b)
|
|
}
|
|
if _, err := ImportFiles(ctx, "apiprompts", []string{"x"}); err == nil {
|
|
t.Error("a plugin with no auth.import took a file")
|
|
}
|
|
}
|