registry.json's `icon` can be an https URL: Kilo Code (https://github.com/Kilo-Org.png), Search1API (https://s1.dev/icon.png), PowerContext (a raw.githubusercontent SVG) and GoAnyAPI (https://goanyapi.com/logo.png). It reached the page as it was, and app.js icon() took any name for a bundled file (icons/<url>.svg), so the Discover card, the plugin's page and Kilo's agent row showed the generic cube. A market picture now goes through the path a plugin's own picture already takes (pluginOwnIcon / RepoIcons). Only a public https host is fetched, the size is capped, and the file is kept as file:<hash> and served from /api/icons. The page never loads a remote URL. Until the picture is in, the icon is "", which the page draws as the cube. - provider.MarketIcon / MarketPicture. PluginIcon (installed plugins) uses them. - agent pluggedIcon (an agent plugin's row, which is Kilo's case) uses them too. - gui listingIcons: /api/plugins/listings and /api/plugins/market keep the market's picture icons and the npm icons in one RepoIcons call (the market waits up to 3s, the listings don't wait). The market's own slice is not changed. - app.js icon(): a name with ':' or '/' that isn't file:/data: is drawn as the cube, never asked for as icons/<url>.svg. A kept picture that fails to load already falls back to the cube through the img's onerror. app.js stays under its budget: two comments were shortened, with no raise. Tests: - TestMarketIconURLKept (provider): an https icon becomes file: and is fetched once, a bundled name is unchanged, and http:// is refused. - TestRegistryIconPictureKept (gui): listings give file: for a data: icon, keep a bundled name, and give "" for javascript:. The market's listing is not mutated. - plugin-registry-icon.test.cjs: Chromium and WebKit, en/zh/zh-TW/ja/de at 980 and 420. A kept picture is drawn on the card and on its page. A URL shows the cube. A 404 picture shows the cube, not a blank. A bundled icon stays bundled. Nothing is asked of another host. What was run: - Before the rebase (mote): - focused Go tests: ok. - plugin-registry-icon: 22/22. - real use, sandbox HOME, the four real registry URLs: each fetched and kept as file: (Kilo png 1455 B, s1 png 4426 B, PowerContext svg 40309 B, goanyapi png 21878 B). - At the rebased fix (ondca3e2d71), on mote: - go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok. - Linux and Windows builds: ok. gofmt clean. - go test -tags nogui -count=1 -timeout 45m: internal/gui, provider, agent and plugin all ok. - GUI on mote: the 58 Plugins-page files were run twice. Both runs were red by browsers crashing or failing to launch (#4125: pboard crashes, SEGV, newContext "browser has been closed"). origin/main's agent-plugin-agents fails the same way there. - GUI on the Linux box (wsl-run), at this head: - plugin-registry-icon, icon-tile, i18n-keys and plugin-card-update: ok, except plugin-card-update in WebKit, which is red the same at origin/main46fb0c1b9(#3079, commented). - plugin-registry-icon was first red there in WebKit: the Discover list is drawn again as the market comes in, so a card could detach mid-scroll. The test's scroll now looks again; it passes 20/20 in both engines. - The Chromium reds plugin-github (80 -> 79) and plugin-move-unserved (Model 1) are red the same at origin/main46fb0c1b9(#3218, #4410/#4392). Broken by hand: - MarketIcon returning its input made both Go tests red. The listing gave the raw data URI and javascript:alert(1), and PluginIcon gave the https URL. - Without the app.js guard, plugin-registry-icon was 0/22: it asked for http://magpie.test/icons/https://s1.dev/icon.png.svg. Not run yet: the whole GUI suite, the full go test ./..., Windows test runs and the real GUI app. They run after the push, and each red gets its own issue.
79 lines
3.0 KiB
Go
79 lines
3.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
)
|
|
|
|
// registry.json gives Kilo Code, Search1API and PowerContext an https
|
|
// picture as their icon, not a bundled icon's name. A provider or agent
|
|
// the market gives such an icon shows it as a plugin's own picture is
|
|
// shown: fetched through FetchIcon's checks and kept, "" until it is in,
|
|
// and never the URL itself, which the page took for a bundled file's
|
|
// name and drew as the generic cube. A bundled name is given as it is,
|
|
// and a picture magpie doesn't take is refused.
|
|
func TestMarketIconURLKept(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"))
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte(`{"version":1,"plugins":[
|
|
{"package":"@magpie-community/agent-kilo","name":"Kilo Code","kind":"agent","community":true,"icon":"https://kilo.example/kilo.png","providers":["kilo-p"]},
|
|
{"package":"@magpie-community/opencode-copilot-auth","name":"GitHub Copilot","icon":"githubcopilot","providers":["github-copilot"],"community":true},
|
|
{"package":"@magpie-community/opencode-plain-auth","name":"Plain","icon":"http://plain.example/x.png","providers":["plain"],"community":true}
|
|
]}`))
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_PLUGIN_MARKET", srv.URL)
|
|
plugin.RefreshMarket()
|
|
t.Cleanup(plugin.RefreshMarket)
|
|
plugin.Market(context.Background())
|
|
|
|
png := []byte("\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR")
|
|
var fetched atomic.Int32
|
|
was := fetchPluginIcon
|
|
t.Cleanup(func() { fetchPluginIcon = was })
|
|
fetchPluginIcon = func(_ context.Context, u string) (string, error) {
|
|
fetched.Add(1)
|
|
if u != "https://kilo.example/kilo.png" {
|
|
t.Errorf("fetched %q", u)
|
|
}
|
|
return StoreIcon(png)
|
|
}
|
|
|
|
kilo := plugin.Provider{ID: "kilo-p", Spec: "@magpie-community/agent-kilo"}
|
|
got := PluginIcon(kilo)
|
|
if strings.Contains(got, "://") {
|
|
t.Fatalf("the market's https icon went to the page as %q", got)
|
|
}
|
|
for i := 0; i < 200 && !strings.HasPrefix(got, "file:"); i++ {
|
|
time.Sleep(20 * time.Millisecond)
|
|
got = PluginIcon(kilo)
|
|
}
|
|
if !strings.HasPrefix(got, "file:") || IconFile(strings.TrimPrefix(got, "file:")) == "" {
|
|
t.Fatalf("after the fetch = %q, want a kept picture", got)
|
|
}
|
|
if ic := MarketIcon(plugin.Icon(kilo.Spec, kilo.ID)); ic != got {
|
|
t.Errorf("MarketIcon = %q, PluginIcon = %q", ic, got)
|
|
}
|
|
if ic := PluginIcon(plugin.Provider{ID: "github-copilot", Spec: "@magpie-community/opencode-copilot-auth"}); ic != "githubcopilot" {
|
|
t.Errorf("a bundled name = %q", ic)
|
|
}
|
|
if ic := PluginIcon(plugin.Provider{ID: "plain", Spec: "@magpie-community/opencode-plain-auth"}); ic != "" {
|
|
t.Errorf("plain http = %q, want refused", ic)
|
|
}
|
|
if n := fetched.Load(); n != 1 {
|
|
t.Errorf("fetched %d times", n)
|
|
}
|
|
}
|