mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Native config writes refuse any symlinked ancestor, and macOS temp directories live under /var, a symlink to /private/var. The test pointed PI_CODING_AGENT_DIR into the unresolved sandbox home, so the macOS integration job blocked the change and failed on main. Resolve the home first, as the hooks test already does.
103 lines
3.5 KiB
Go
103 lines
3.5 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 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")
|
|
}
|