Files
Agent-System-Dev/examples/downstream-rdm/plugin_test.go
T
weichen 93ac63fb3d Compose immutable dependency sources and preserve branch transitions
Why:
Replace repeated submodule source pointers with consumer-owned language versions and fixed application sources, keeping independent repository edits and existing branches intact.

Evidence:
SELF task receipts contain startup/sync evidence, real Go and npm consumption, Native overlay/unlink, safe transition/ref preservation, credential boundary and historical build regressions. Exact committed full composition and RDM checks follow this checkpoint; formal acceptance and GATE CI remain pending.

Impact:
Add isolated build/test composition, source provenance and safe owner refresh, adapt governance and service build callers, remove replaced index links while retaining original Git metadata, and adopt reusable dependency standards.

Refs:
Documents approved dependency-workspace r1/R1-R15 and U1-U7 implementation plan; feature/dependency-workspace task card.
2026-10-13 17:18:07 +00:00

111 lines
3.5 KiB
Go

package rdm
import (
"context"
"encoding/json"
"errors"
"testing"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/pkg/extension"
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
)
func TestCompiledSkillRegistration(t *testing.T) {
extension.ResetCompiled()
extension.RegisterCompiled(extension.InProc{ID: "rdm"})
got := extension.Compiled()
if len(got) != 1 || got[0].ID != "rdm" {
t.Fatalf("%+v", got)
}
if extension.SurfaceVersion == "" {
t.Fatal("surface version required")
}
}
// fakeRegistry 记录 register() 的登记动作,不拉起基座。
type fakeRegistry struct {
extension.Registry // Unused capabilities fail if this example starts calling them.
skills []string
commands []string
handlers int
}
func (f *fakeRegistry) AddSkill(name, markdown string) error {
f.skills = append(f.skills, name)
return nil
}
func (f *fakeRegistry) AddCommand(spec json.RawMessage) error { return nil }
func (f *fakeRegistry) AddCommandHandler(spec json.RawMessage, h extension.Handler) error {
var s struct {
ID string `json:"id"`
}
if err := json.Unmarshal(spec, &s); err != nil {
return err
}
if h == nil {
return errors.New("nil handler")
}
f.commands = append(f.commands, s.ID)
f.handlers++
return nil
}
func (f *fakeRegistry) Note(kind, name string, payload json.RawMessage) error { return nil }
func TestRegisterBindsPingHandler(t *testing.T) {
reg := &fakeRegistry{}
if err := register(reg); err != nil {
t.Fatal(err)
}
if len(reg.skills) != 1 || reg.skills[0] != "rdm-note" {
t.Fatalf("skills: %+v", reg.skills)
}
if len(reg.commands) != 1 || reg.commands[0] != "rdm.ping" || reg.handlers != 1 {
t.Fatalf("commands: %+v handlers=%d", reg.commands, reg.handlers)
}
}
// fakeHost 是下游测试里的最小句柄替身:只实现 rdm.ping 用到的能力。
type fakeHost struct {
extension.Host
owner string
}
func (f fakeHost) PluginID() string { return "rdm" }
func (f fakeHost) Owner() string { return f.owner }
func (f fakeHost) KVPut(key, value string) error { return nil }
func (f fakeHost) KVGet(key string) (string, bool, error) { return "", false, nil }
func (f fakeHost) Audit(action, target, evidence string) error { return nil }
func (f fakeHost) Complete(ctx context.Context, prompt string) (string, error) {
return "", nil
}
func (f fakeHost) KnowledgeSearch(ctx context.Context, projectID core.ID, text string, topK int) ([]core.RetrievalHit, error) {
return nil, nil
}
func (f fakeHost) KnowledgeWrite(ctx context.Context, docs []core.KnowledgeDoc, embed bool) error {
return nil
}
func (f fakeHost) TaskCreate(kind, title, conversationID string) (string, error) {
return "task_1", nil
}
func (f fakeHost) TaskUpdate(taskID, status string, progress int, errText string) error { return nil }
func (f fakeHost) ArtifactGet(artifactID string) (core.Artifact, error) {
return core.Artifact{}, errors.New("not found")
}
func (f fakeHost) ArtifactContent(artifactID string) ([]byte, error) { return nil, nil }
func (f fakeHost) ParseDocument(ctx context.Context, filename, mime string, content []byte) (core.ParsedDocument, error) {
return core.ParsedDocument{}, nil
}
func TestRdmPingHandler(t *testing.T) {
out, err := rdmPing(context.Background(), fakeHost{owner: "alice"}, extension.Request{
ID: "rdm.ping", Owner: "alice", Params: map[string]any{},
})
if err != nil {
t.Fatal(err)
}
m, _ := out.(map[string]any)
if m["pong"] != true || m["owner"] != "alice" || m["plugin"] != "rdm" {
t.Fatalf("payload: %+v", out)
}
}