Cletus plugin kit: rules for coding agents, specification, host API, style guide, worker SDK and cletus-plugin tool
This commit is contained in:
commit
9b19d3a8be
41 files changed
+4121
No files matched your search
@@ -0,0 +1,61 @@
|
||||
package manifest
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func valid() *Plugin {
|
||||
return &Plugin{ID: "acme.gauge-check", Name: "Gauge Check", Description: "Checks gauges.", Version: "1.0.0",
|
||||
MinAppVersion: "0.5.0", HostAPI: HostAPI, Permissions: []string{"files", "net:api.example.com"},
|
||||
Tools: []Tool{{Name: "gauge_check_run"}}}
|
||||
}
|
||||
|
||||
func TestValidManifest(t *testing.T) {
|
||||
if errs := valid().Validate(); len(errs) != 0 {
|
||||
t.Fatalf("valid manifest refused: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRefusals(t *testing.T) {
|
||||
cases := map[string]func(*Plugin){
|
||||
"must be <publisher>.<name>": func(p *Plugin) { p.ID = "gauge" },
|
||||
"version": func(p *Plugin) { p.Version = "1.0" },
|
||||
"host_api": func(p *Plugin) { p.HostAPI = 1 },
|
||||
"unknown permission": func(p *Plugin) { p.Permissions = []string{"workspace"} },
|
||||
"no wildcards": func(p *Plugin) { p.Permissions = []string{"net:10.0.0.1"} },
|
||||
"Eidonix plugins": func(p *Plugin) { p.Capability = "quoting" },
|
||||
"aren't available yet": func(p *Plugin) { p.UI = []byte(`{}`) },
|
||||
"listed twice": func(p *Plugin) { p.Tools = append(p.Tools, Tool{Name: "gauge_check_run"}) },
|
||||
"its own service": func(p *Plugin) { p.Uses = []string{"acme.gauge-check:gauge.check"} },
|
||||
}
|
||||
for want, change := range cases {
|
||||
p := valid()
|
||||
change(p)
|
||||
errs := p.Validate()
|
||||
found := false
|
||||
for _, err := range errs {
|
||||
found = found || strings.Contains(err.Error(), want)
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("%s: got %v", want, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllowed(t *testing.T) {
|
||||
p := valid()
|
||||
if ok, _ := p.Allowed("host.files.resolve"); !ok {
|
||||
t.Fatal("files permission did not allow host.files.resolve")
|
||||
}
|
||||
if ok, _ := p.Allowed("host.event"); !ok {
|
||||
t.Fatal("host.event should always be allowed")
|
||||
}
|
||||
ok, need := p.Allowed("host.workspace.list")
|
||||
if ok || need != "workspace.read" {
|
||||
t.Fatalf("workspace.list = %v, %q", ok, need)
|
||||
}
|
||||
if ok, need := p.Allowed("host.code.llm.start"); ok || need != "" {
|
||||
t.Fatalf("first-party method = %v, %q", ok, need)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user