mahiro233 on Discord (v0.1.3372, Kiro plugin 0.1.34): in a Chinese
window, the Kiro sheet's "Choose a sign-in method" and its choices read in
English, while the rest of the sheet is Chinese. magpie showed a plugin's
method labels, questions and choices only as the plugin wrote them, and no
plugin had a way to give them in another language.
A plugin may now give them by language, magpie's own fields beside
OpenCode's English, as a page gives its titles: a method's labels, a
question's messages, a select option's labels and hints, each
{"zh": "…", "zh-TW": "…", "ja": "…", "de": "…"}. host.js passes them on
(byLang: string values, codes of 1-16 characters, at most 16, empty ones
left out); plugin.Method and plugin.Prompt carry them; the app shows the
window's language, then its first part, else the English (inLang), on the
way picker, a question, its choices and their hints, a key's field and
the site step's other ways. `magpie plugin login` stays English. Kiro
0.1.35 gives its words in all four (plugins 588b3611).
Tests: TestPluginSignInWordsByLanguage (a plugin's words reach magpie as
given, bad ones left out, none for a plugin that gives none);
TestPluginOwnIconAndKeyHint compares a Method with reflect.DeepEqual now
that it holds a map. The GUI side is checked by plugin-ask-ways.test.cjs
in the next commit.
Run on mote at this tree: gofmt -l empty; go vet ./internal/plugin
./internal/provider ./internal/gui (darwin), linux -tags nogui, windows:
ok; go test -count=1 ./internal/plugin ./internal/provider ./internal/cli:
ok. Broken by hand: with origin/main's host.js the new test fails (no
labels, messages or hints reach magpie). Not tried: a real Kiro sign-in
(no keys or passwords entered anywhere); the full suite is queued on mote
under suite.lock after the push.
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// mahiro233 on Discord: the Kiro plugin's sign-in methods read in English
|
|
// in a Chinese window. A plugin may give its sign-in words by language,
|
|
// beside OpenCode's English ones, as a page gives its titles: a method's
|
|
// labels, a question's messages, a choice's labels and hints. They reach
|
|
// magpie as given, words that aren't a string, empty ones and a list left
|
|
// out; a plugin that gives none is read as before.
|
|
func TestPluginSignInWordsByLanguage(t *testing.T) {
|
|
sandbox(t)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
abs, _ := filepath.Abs("testdata/langwords")
|
|
if _, err := Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ps, err := Providers(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
by := map[string]Provider{}
|
|
for _, p := range ps {
|
|
by[p.ID] = p
|
|
}
|
|
quince, pear := by["quince"], by["pear"]
|
|
if len(quince.Methods) != 2 {
|
|
t.Fatalf("quince's methods = %+v", quince.Methods)
|
|
}
|
|
if want := map[string]string{"zh": "Quince 登录", "zh-TW": "Quince 登入"}; !reflect.DeepEqual(quince.Methods[0].Labels, want) {
|
|
t.Errorf("way 0's labels = %v, want %v", quince.Methods[0].Labels, want)
|
|
}
|
|
if want := map[string]string{"zh": "Quince API Key"}; !reflect.DeepEqual(quince.Methods[1].Labels, want) {
|
|
t.Errorf("way 1's labels = %v, want %v", quince.Methods[1].Labels, want)
|
|
}
|
|
if len(pear.Methods) != 1 || pear.Methods[0].Labels != nil {
|
|
t.Errorf("pear's methods = %+v, want no labels", pear.Methods)
|
|
}
|
|
|
|
q, err := NextPrompt(ctx, "quince", 0, map[string]string{})
|
|
if err != nil || q == nil {
|
|
t.Fatalf("NextPrompt = %+v, %v", q, err)
|
|
}
|
|
if want := map[string]string{"zh": "选择登录方式", "ja": "サインイン方法を選択"}; q.Message != "Choose a sign-in method" || !reflect.DeepEqual(q.Messages, want) {
|
|
t.Errorf("message = %q, %v, want %v", q.Message, q.Messages, want)
|
|
}
|
|
if len(q.Options) != 2 {
|
|
t.Fatalf("options = %+v", q.Options)
|
|
}
|
|
o := q.Options[0]
|
|
if o.Label != "Builder ID" || o.Hint != "AWS sign-in" || !reflect.DeepEqual(o.Labels, map[string]string{"zh": "Builder ID(个人)"}) || !reflect.DeepEqual(o.Hints, map[string]string{"zh": "AWS 登录"}) {
|
|
t.Errorf("option 0 = %+v", o)
|
|
}
|
|
if o := q.Options[1]; o.Label != "Sign-in page" || o.Labels != nil || o.Hints != nil {
|
|
t.Errorf("option 1 = %+v, want no words by language", o)
|
|
}
|
|
}
|