mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
A target declared with `agent` and `config_dir` is another config directory of a built-in Agent, such as a second Claude account. Its skills and agents paths are derived from the Agent's defaults at load time, so the config only records the directory. The same target name works for MCP (written in the Agent's format into the account's own file), for plugins (the Agent CLI runs with CLAUDE_CONFIG_DIR, CODEX_HOME or PI_CODING_AGENT_DIR) and for `mcp import --from`. Removing such a target warns when MCP config still names it instead of failing later at sync. The dashboard gains an "another account" mode in the add-target dialog and lists accounts next to the Agents on the MCP and plugin pages. Refs #289
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
)
|
|
|
|
func TestPluginAPIRequiresPreviewAndLocalOrigin(t *testing.T) {
|
|
s, _ := newTestServerWithExtras(t, nil, "")
|
|
for _, body := range []string{`{"request":{"action":"sync"}}`, `{"request":{"action":"sync"},"unknown":true}`} {
|
|
w := httptest.NewRecorder()
|
|
s.handlePluginApply(w, httptest.NewRequest(http.MethodPost, "/api/plugins/apply", strings.NewReader(body)))
|
|
if w.Code != 400 {
|
|
t.Fatalf("status %d: %s", w.Code, w.Body.String())
|
|
}
|
|
}
|
|
r := httptest.NewRequest(http.MethodPost, "http://attacker.example/api/plugins/apply", strings.NewReader(`{}`))
|
|
r.RemoteAddr = "127.0.0.1:1234"
|
|
w := httptest.NewRecorder()
|
|
s.requireLocalPlugin(s.handlePluginApply)(w, r)
|
|
if w.Code != 403 {
|
|
t.Fatalf("rebind accepted: %d", w.Code)
|
|
}
|
|
}
|
|
|
|
// The Plugins page draws its Agents from targetDefinitions, so a target that is another
|
|
// config directory of an Agent has to be one of them.
|
|
func TestPluginListIncludesAnAccountOfAnAgent(t *testing.T) {
|
|
s, _ := newTestServerWithExtras(t, nil, "")
|
|
s.cfg.Targets = map[string]config.TargetConfig{"claude-work": {Agent: "claude", ConfigDir: t.TempDir()}}
|
|
w := httptest.NewRecorder()
|
|
s.handlePluginList(w, httptest.NewRequest(http.MethodGet, "/api/plugins?hosts=false", nil))
|
|
if w.Code != 200 {
|
|
t.Fatalf("status %d: %s", w.Code, w.Body.String())
|
|
}
|
|
type definition struct {
|
|
Target string `json:"target"`
|
|
Label string `json:"label"`
|
|
}
|
|
var inventory struct {
|
|
TargetDefinitions []definition `json:"targetDefinitions"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &inventory); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.ContainsFunc(inventory.TargetDefinitions, func(d definition) bool { return d.Target == "claude-work" }) {
|
|
t.Fatalf("the account is missing: %+v", inventory.TargetDefinitions)
|
|
}
|
|
}
|