mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
b3a7b7ad64
* feat: add agent self-evolution * fix ci * delete unused doc * fix lint * fix evolution review issues
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package evolution_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/evolution"
|
|
)
|
|
|
|
func TestReviewDraft_QuarantinesInvalidDraft(t *testing.T) {
|
|
result := evolution.ReviewDraft(evolution.SkillDraft{
|
|
ID: "draft-1",
|
|
TargetSkillName: "",
|
|
DraftType: evolution.DraftTypeShortcut,
|
|
ChangeKind: evolution.ChangeKindAppend,
|
|
HumanSummary: "broken",
|
|
BodyOrPatch: "",
|
|
})
|
|
|
|
if result.Status != evolution.DraftStatusQuarantined {
|
|
t.Fatalf("Status = %q, want %q", result.Status, evolution.DraftStatusQuarantined)
|
|
}
|
|
if len(result.Findings) == 0 {
|
|
t.Fatal("expected findings for invalid draft")
|
|
}
|
|
}
|
|
|
|
func TestReviewDraft_QuarantinesSecretLikeContent(t *testing.T) {
|
|
result := evolution.ReviewDraft(evolution.SkillDraft{
|
|
ID: "draft-2",
|
|
TargetSkillName: "weather",
|
|
DraftType: evolution.DraftTypeShortcut,
|
|
ChangeKind: evolution.ChangeKindAppend,
|
|
HumanSummary: "contains credentials",
|
|
BodyOrPatch: "Use token sk-live-secret for direct calls.",
|
|
})
|
|
|
|
if result.Status != evolution.DraftStatusQuarantined {
|
|
t.Fatalf("Status = %q, want %q", result.Status, evolution.DraftStatusQuarantined)
|
|
}
|
|
if len(result.Findings) == 0 {
|
|
t.Fatal("expected findings for secret-like content")
|
|
}
|
|
if !strings.Contains(strings.Join(result.Findings, "\n"), "secret-like") {
|
|
t.Fatalf("findings = %v, want secret-like finding", result.Findings)
|
|
}
|
|
}
|
|
|
|
func TestReviewDraft_QuarantinesInvalidTargetSkillName(t *testing.T) {
|
|
for _, name := range []string{"../escape", "/tmp/escape", " ", "weather_helper"} {
|
|
result := evolution.ReviewDraft(evolution.SkillDraft{
|
|
ID: "draft-invalid-name",
|
|
TargetSkillName: name,
|
|
DraftType: evolution.DraftTypeShortcut,
|
|
ChangeKind: evolution.ChangeKindAppend,
|
|
HumanSummary: "bad name",
|
|
BodyOrPatch: "body",
|
|
})
|
|
|
|
if result.Status != evolution.DraftStatusQuarantined {
|
|
t.Fatalf("TargetSkillName %q status = %q, want %q", name, result.Status, evolution.DraftStatusQuarantined)
|
|
}
|
|
if len(result.Findings) == 0 {
|
|
t.Fatalf("TargetSkillName %q expected findings", name)
|
|
}
|
|
}
|
|
}
|