Files
Reims-Go/internal/plugin/locale_market_test.go
T
NwflowerandClaude Opus 5.5 e259833b5f feat(plugins): rework the plugin market and first-run language packs
Market page
- Card grid that fills the width; cards show only icon, name,
  publisher (trust mark by color and icon), version and the action.
- Paints from cache via the new PeekPluginMarket binding, then revalidates;
  cards reveal 24 at a time as the feed scrolls.
- Category chips come from the index (MarketBrowseResult.kinds) instead of
  a fixed list; the alpha toggle and source badge are gone.
- Installed/Market is a segmented control; refresh now shows feedback.
- WordmarkLoader writes the Reims-Go wordmark stroke by stroke while the
  market loads (static pulse under reduced motion).

Install and enable
- reims:plugin-install events drive a progress bar on the card.
- After install, a dialog offers to enable the plugin and lists what it can
  do in plain words (PluginInfo.risks / MarketCatalogItem.risks, derived
  from tier, permissions and contributions in risks.go).
- Enabling a plugin that provides UI languages switches to the first one
  unless the current language is among them (PluginInfo.locales).

Trust
- A package installed from the project's own index, fetched over HTTPS in
  this session, inherits the index's trust level when its SHA-256 matches.
  Third-party indexes (REIMS_GO_PLUGIN_MARKET_URL) cannot vouch and show
  every entry as community.
- Trust no longer waives review: official packages get the same scan,
  high-risk approval and L3 hash check as any other; only builtin and
  bundled plugins are pre-approved.

First launch
- When the OS language is not covered by zh-CN/en-US, the folder screen
  looks up a matching pack once (SuggestLanguagePack) and offers to install
  it; Continue installs and enables it so the UI follows the OS language.
  Before setup the market keeps its index in memory only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 05:17:45 -07:00

92 lines
3.7 KiB
Go

package plugin_test
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"reflect"
"sort"
"strings"
"testing"
"time"
"github.com/Nwflower/reims-go/internal/plugin"
)
// Entries shaped like the live index: no explicit locales, the language shows
// up in tags and in the name's translations.
const localeIndexJSON = `{
"schema": 1,
"plugins": [
{"id": "official.lang.zh-tw", "version": "1.0.0", "kind": "locale", "trust": "official", "channel": "stable",
"name": {"zh-CN": "繁体中文语言包", "en-US": "Traditional Chinese", "zh-TW": "繁體中文語言套件", "zh-HK": "繁體中文語言套件"},
"tags": ["locale", "i18n", "zh-TW", "traditional-chinese", "繁體中文"],
"download_url": "https://example.invalid/a.zip", "sha256": "SUM"},
{"id": "community.lang.ko-kr", "version": "1.0.0", "kind": "locale", "trust": "community", "channel": "stable",
"name": {"zh-CN": "韩语语言包", "en-US": "Korean", "ko-KR": "한국어 언어팩"},
"tags": ["locale", "ko-KR"],
"download_url": "https://example.invalid/b.zip", "sha256": "SUM"},
{"id": "community.lang.ja-jp-old", "version": "1.0.0", "kind": "locale", "trust": "community", "channel": "stable",
"name": {"en-US": "Japanese"}, "locales": ["ja-JP"],
"engines": {"pluginApi": "^99.0.0"},
"download_url": "https://example.invalid/c.zip", "sha256": "SUM"},
{"id": "community.theme.ko", "version": "1.0.0", "kind": "theme", "trust": "community", "channel": "stable",
"name": {"en-US": "Seoul Theme", "ko-KR": "서울 테마"},
"download_url": "https://example.invalid/d.zip", "sha256": "SUM"}
]
}`
func TestMarketEntryLocales(t *testing.T) {
var idx plugin.MarketIndex
if err := json.Unmarshal([]byte(strings.ReplaceAll(localeIndexJSON, "SUM", strings.Repeat("a", 64))), &idx); err != nil {
t.Fatal(err)
}
got := plugin.MarketEntryLocales(idx.Plugins[0])
sort.Strings(got)
// Non-language tags such as "locale" and "i18n" are dropped.
want := []string{"zh-HK", "zh-TW"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("zh-TW pack locales = %v, want %v", got, want)
}
if got := plugin.MarketEntryLocales(idx.Plugins[2]); !reflect.DeepEqual(got, []string{"ja-JP"}) {
t.Fatalf("explicit locales = %v, want [ja-JP]", got)
}
}
func TestSuggestLocalePack(t *testing.T) {
body := strings.ReplaceAll(localeIndexJSON, "SUM", strings.Repeat("a", 64))
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(body))
}))
defer srv.Close()
mc := plugin.NewMarketClient(plugin.MarketClientOptions{
Layout: plugin.PluginsLayout{}, HostVersion: "0.2.10",
URLs: []string{srv.URL + "/index.json"}, CacheTTL: time.Minute, AllowInsecureLocalhost: true,
})
suggest := func(tag string, installed ...plugin.PluginInfo) string {
if it := mc.SuggestLocalePack(context.Background(), installed, tag); it != nil {
return it.Entry.ID
}
return ""
}
cases := map[string]string{
"zh-TW": "official.lang.zh-tw",
"zh-HK": "official.lang.zh-tw", // listed among the pack's name translations
"ko-KR": "community.lang.ko-kr", // the Korean theme is not a language pack
"ko": "community.lang.ko-kr", // same language, no region
"zh-MO": "", // Chinese never matches across regions
"ja-JP": "", // only candidate is incompatible
"de-DE": "",
}
for tag, want := range cases {
if got := suggest(tag); got != want {
t.Errorf("SuggestLocalePack(%q) = %q, want %q", tag, got, want)
}
}
if got := suggest("zh-TW", plugin.PluginInfo{ID: "official.lang.zh-tw", Version: "1.0.0"}); got != "" {
t.Errorf("already-installed pack suggested again: %q", got)
}
}