Why: completion claims require tool-written evidence (AGENTS.md). Evidence: SELF receipt appended by make evidence; full suite green incl. ui 103 tests and agent-command. Impact: task metadata only. Refs: .task/feature-ext-5-host-parse.md
107 lines
3.3 KiB
Go
107 lines
3.3 KiB
Go
package rdm
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
"agent-system-backend/pkg/extension"
|
|
core "agent-system-core"
|
|
)
|
|
|
|
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 {
|
|
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{ 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)
|
|
}
|
|
}
|