返回 DeepSeek-Reasonix
capability_test.go
根目录 / internal / extensioncontract / capability_test.go
1 package extensioncontract
2
3 import "testing"
4
5 func TestCapabilityKeyValidate(t *testing.T) {
6 if err := (CapabilityKey{Namespace: "reasonix", Kind: "provider", ID: "deepseek/v4"}).Validate(); err != nil {
7 t.Fatal(err)
8 }
9 if err := (CapabilityKey{Namespace: "", Kind: "provider", ID: "x"}).Validate(); err == nil {
10 t.Fatal("empty namespace accepted")
11 }
12 }
13
14 func TestCapabilityValidateSchemaHash(t *testing.T) {
15 c := Capability{
16 Key: CapabilityKey{Namespace: "plugin/example", Kind: "provider", ID: "fake/x"},
17 Version: "1.0.0",
18 }
19 if err := c.Validate(); err == nil {
20 t.Fatal("provider without schemaHash accepted")
21 }
22 c.SchemaHash = "sha256:abc"
23 if err := c.Validate(); err != nil {
24 t.Fatal(err)
25 }
26 }
27
28 func TestRequirementSatisfiedBy(t *testing.T) {
29 provided := Capability{
30 Key: CapabilityKey{Namespace: "reasonix", Kind: "provider", ID: "deepseek/v4"},
31 Version: "1.2.0",
32 SchemaHash: "sha256:p",
33 }
34 req := Requirement{
35 Capability: Capability{
36 Key: CapabilityKey{Namespace: "reasonix", Kind: "provider", ID: "deepseek/v4"},
37 },
38 VersionRange: ">=1.0.0,<2.0.0",
39 }
40 if !req.SatisfiedBy(provided) {
41 t.Fatal("range should match")
42 }
43 req.SchemaHash = "sha256:other"
44 if req.SatisfiedBy(provided) {
45 t.Fatal("schema pin mismatch should fail")
46 }
47 req.SchemaHash = ""
48 req.VersionRange = ">=2.0.0"
49 if req.SatisfiedBy(provided) {
50 t.Fatal("out of range should fail")
51 }
52 }
53
54 func TestCanonicalHashStable(t *testing.T) {
55 c := Capability{
56 Key: CapabilityKey{Namespace: "a", Kind: "tool", ID: "t"},
57 Version: "1.0.0",
58 SchemaHash: "sha256:x",
59 }
60 h1 := c.CanonicalHash()
61 h2 := c.CanonicalHash()
62 if h1 == "" || h1 != h2 {
63 t.Fatalf("hash unstable: %q vs %q", h1, h2)
64 }
65 c.Version = "1.0.1"
66 if c.CanonicalHash() == h1 {
67 t.Fatal("version change must change hash")
68 }
69 }
70
70 lines GO