Files
yetone 50a38371df plugin: a page with its own service module is a page on the GitHub list (plugins#1226)
xiaopeng66/magpie-model-lab is a page plugin whose page talks to a
local service it ships as its main (magpie.page.service). readTagged
called any package with a main or exports a provider, so the GitHub
list showed it under Providers. Dropping the !runs check alone would
make every provider that ships a settings page (atomcode's
diagnostics page, for one) a page, so the rule is narrower: a package
with magpie.page.file and a module of its own is a page when its
keywords say "magpie-page", as every page with a main in the plugins
repository does (agent-console, amp-usage, chat, fingerprint,
free-tokens, page-model-quota, page-usage-board, page-usage-tree,
window-warmup). No provider or middleware there says it. The file
looked for in the repository is still its main. Kind only decides the
card's chip and filter; what an install loads is unchanged.

The fixture is model-lab's package.json as it is, without its 900KB
icon; a provider with a page and no keyword stays a provider.

Run (mote):
- go test -count=1 ./internal/plugin: ok (157.9s).
- go vet ./internal/plugin: ok. gofmt -l: clean.

Broken by hand: the old !runs rule with the new test: "a page with a
main: kind """, red.

Not tried: installing model-lab from the GitHub list in the real app.
2026-11-16 22:23:54 +08:00

67 lines
2.5 KiB
Go

package plugin
import (
"context"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
)
// A page whose page talks to a local service of its own ships that
// service as its main (magpie.page.service). The GitHub list read a
// package with a main as a provider, so xiaopeng66/magpie-model-lab
// showed under Providers (plugins#1226). A page that says
// "magpie-page" in its keywords, as every page in the plugins
// repository does, is a page, main or not; the file looked for is still
// its main. A provider with a page of settings beside it says no such
// keyword and stays a provider. The package.json is model-lab's, as it
// is, without its 900KB icon.
func TestTaggedPageWithMain(t *testing.T) {
var mu sync.Mutex
var asked []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, q *http.Request) {
mu.Lock()
asked = append(asked, q.URL.Path)
mu.Unlock()
name, ok := strings.CutPrefix(q.URL.Path, "/raw/")
f, err := os.ReadFile(filepath.Join("testdata/github/raw", filepath.FromSlash(name)))
if !ok || err != nil {
http.Error(w, `"Not Found"`, 404)
return
}
w.Write(f)
}))
t.Cleanup(srv.Close)
api, raw, reg := githubAPI, githubRaw, npmRegistry
githubAPI, githubRaw, npmRegistry = srv.URL, srv.URL+"/raw", srv.URL+"/npm"
t.Cleanup(func() { githubAPI, githubRaw, npmRegistry = api, raw, reg })
const repo = "xiaopeng66/magpie-model-lab"
got, keep, known, err := readTagged(context.Background(), Tagged{Spec: "github:" + repo, Repo: repo}, "main")
if !keep || !known || err != nil || got.Kind != "page" || got.Package != "magpie-pelican-bench" {
t.Fatalf("a page with a main: kind %q, package %q, kept %v, known %v, %v", got.Kind, got.Package, keep, known, err)
}
mu.Lock()
a := slices.Clone(asked)
mu.Unlock()
if !slices.Contains(a, "/raw/"+repo+"/main/index.mjs") {
t.Fatalf("its main wasn't looked for: asked %v", a)
}
got, keep, _, err = readTagged(context.Background(), Tagged{Spec: "github:someone/provider-with-page", Repo: "someone/provider-with-page"}, "main")
if !keep || err != nil || got.Kind == "page" {
t.Fatalf("a provider with a settings page: kind %q, kept %v, %v", got.Kind, keep, err)
}
// a page alone, no main, as before
got, keep, _, err = readTagged(context.Background(), Tagged{Spec: "github:someone/page-glance", Repo: "someone/page-glance"}, "main")
if !keep || err != nil || got.Kind != "page" {
t.Fatalf("a page alone: %+v, kept %v, %v", got, keep, err)
}
}