Files
skillshare/tests/integration/plugin_test.go
T
Willie 829cbb176d fix(plugins): honor native OMP marketplace builds (#588)
* fix(plugins): honor native OMP marketplace builds

Resolve OMP entries from their native marketplace when present and inspect package.json extension-only plugins. Keep target-specific source paths, marketplace identities and components so Claude adoption and hybrid manifests remain valid.\n\nShow separate builds in text discovery without changing logical JSON selection, and cover native precedence, invalid catalogs, manifestless and hybrid packages, global/project materialization and CLI output with regression tests. Update the plugin docs and existing translations.\n\nFixes #587

* fix(plugins): preserve native build metadata across consumers

Keep OMP catalog versions in target discovery metadata and materialized marketplace entries so previews, cache guards, and native installs use the same version, including legacy catalog fallback. Cover catalog versions that differ from package manifests.

Show each dashboard discovery target's own version, components, and source path instead of presenting a merged candidate as one build.

* fix(plugins): avoid ambiguous shared build versions

Derive candidate versions from agreement across supported targets and recompute after catalog overrides. No-Agent records and lists no longer inherit an arbitrary native build version; equal versions remain available and unknown versions stay unknown.

Keep Cursor and Antigravity inventory target-specific when manifests disagree. Cover no-Agent preview and persistence, equal and unknown versions, catalog overrides, and mixed-manifest local inventories. Align English and translated plugin references.

* fix(plugins): accept Pi extension manifests for OMP catalogs

Reuse the existing OMP extension detector instead of requiring an OMP-specific manifest key. Native OMP accepts Pi extension manifests too, so the extra gate rejected supported native catalog entries.

Cover Pi-only discovery with scoped package names and global/project materialization. Align the English plugin references and all existing translations.
2026-10-20 12:22:05 +08:00

139 lines
5.2 KiB
Go

//go:build !online
package integration
import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/testutil"
)
func TestPluginCLIDiscoveryAndSelection(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig("targets: {}\nplugins:\n packages:\n demo:\n bindings:\n codex:\n id: demo@team\n")
root := filepath.Join(sb.Home, "fixture")
if err := os.MkdirAll(filepath.Join(root, ".codex-plugin"), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(root, ".codex-plugin/plugin.json"), []byte(`{"name":"demo","version":"1.0.0"}`), 0644); err != nil {
t.Fatal(err)
}
r := sb.RunCLI("plugin", "discover", root, "--json", "-g")
r.AssertSuccess(t)
var d struct {
Candidates []struct {
Name string `json:"name"`
} `json:"candidates"`
}
if err := json.Unmarshal([]byte(r.Stdout), &d); err != nil {
t.Fatal(err)
}
if len(d.Candidates) != 1 || d.Candidates[0].Name != "demo" {
t.Fatal("source discovery failed")
}
sb.RunCLI("plugin", "disable", "demo", "--target", "codex", "--json", "-g").AssertSuccess(t)
config := filepath.Join(sb.Home, ".config/skillshare/config.yaml")
data, err := os.ReadFile(config)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), "sync: false") {
t.Fatalf("selection not saved: %s", data)
}
sb.RunCLI("plugin", "enable", "demo", "--target", "codex", "--dry-run", "--json", "-g").AssertSuccess(t)
after, _ := os.ReadFile(config)
if string(after) != string(data) {
t.Fatal("preview changed configuration")
}
if _, err := os.Stat(filepath.Join(sb.Home, ".codex/config.toml")); !os.IsNotExist(err) {
t.Fatal("selection created native config")
}
sb.RunCLI("sync", "plugins", "--help").AssertSuccess(t)
}
// Pi itself installs an npm package from pi.dev; the preview says it runs install scripts.
func TestPluginAddNpmPackageThroughPi(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig("targets: {}\n")
// Native writes refuse symlinked paths, and macOS temp dirs sit under the /var symlink.
home, err := filepath.EvalSymlinks(sb.Home)
if err != nil {
t.Fatal(err)
}
bin := filepath.Join(home, "bin")
agentDir := filepath.Join(home, ".pi/agent")
fake := "#!/bin/sh\ncase \"$1\" in\n--version) echo 0.99.2 ;;\ninstall) [ \"$2\" = --help ] || printf '{\"packages\":[\"%s\"]}' \"$2\" > \"$PI_CODING_AGENT_DIR/settings.json\" ;;\nesac\n"
if err := os.MkdirAll(bin, 0755); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(agentDir, 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(bin, "pi"), []byte(fake), 0755); err != nil {
t.Fatal(err)
}
env := map[string]string{"PATH": bin + ":" + os.Getenv("PATH"), "PI_CODING_AGENT_DIR": agentDir}
r := sb.RunCLIEnv(env, "plugin", "add", "npm:demo", "--target", "pi", "--no-tui", "-g")
r.AssertSuccess(t)
settings, _ := os.ReadFile(filepath.Join(agentDir, "settings.json"))
if string(settings) != `{"packages":["npm:demo"]}` {
t.Fatalf("Pi did not install the package: %s\n%s", settings, r.Stdout+r.Stderr)
}
config, _ := os.ReadFile(filepath.Join(sb.Home, ".config/skillshare/config.yaml"))
if !strings.Contains(string(config), "id: npm:demo") {
t.Fatalf("binding not recorded: %s", config)
}
}
func TestPluginDiscoverShowsSeparateOMPBuild(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig("targets: {}\n")
root := filepath.Join(sb.Home, "fixture")
for path, data := range map[string]string{
".claude-plugin/marketplace.json": `{"name":"claude-market","plugins":[{"name":"kata","source":"./plugins/claude-code"}]}`,
".omp-plugin/marketplace.json": `{"name":"omp-market","plugins":[{"name":"kata","source":"./plugins/oh-my-pi"}]}`,
"plugins/claude-code/.claude-plugin/plugin.json": `{"name":"kata","version":"0.1.0","hooks":"./hooks/hooks.json"}`,
"plugins/oh-my-pi/package.json": `{"name":"kata","version":"2.0.0","omp":{"extensions":["./kata.ts"]}}`,
"plugins/oh-my-pi/kata.ts": "export default function () {}",
} {
file := filepath.Join(root, filepath.FromSlash(path))
if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(file, []byte(data), 0644); err != nil {
t.Fatal(err)
}
}
r := sb.RunCLI("plugin", "discover", root, "-g")
r.AssertSuccess(t)
var omp, claude bool
for _, line := range strings.Split(r.Stdout, "\n") {
if strings.Contains(line, "omp") && strings.Contains(line, "extensions") && strings.Contains(line, "plugins/oh-my-pi") && !strings.Contains(line, "hooks") && !strings.Contains(line, "claude") {
omp = true
}
if strings.Contains(line, "claude") && strings.Contains(line, "hooks") && strings.Contains(line, "plugins/claude-code") && !strings.Contains(line, "omp") && !strings.Contains(line, "extensions") {
claude = true
}
}
if !omp || !claude {
t.Fatalf("native builds were not shown separately:\n%s", r.Stdout)
}
}
func TestPluginDiscoverNpmPointsToAdd(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig("targets: {}\n")
r := sb.RunCLI("plugin", "discover", "npm:demo", "--json", "-g")
r.AssertFailure(t)
r.AssertAnyOutputContains(t, "skillshare plugin add npm:demo --target pi")
}