66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package ai
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.ipao.vip/rogee/go-sip/contracts"
|
|
)
|
|
|
|
func TestValidateUsesPinnedAIContract(t *testing.T) {
|
|
raw, err := contracts.Read("examples/agent-version.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot, err := ValidateForMode(raw, ModeFullAI)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if snapshot.AgentVersionID == "" || snapshot.Digest == "" || snapshot.Mode != ModeFullAI {
|
|
t.Fatalf("snapshot = %+v", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestValidateASROnlySnapshot(t *testing.T) {
|
|
raw, err := contracts.Read("examples/agent-version-asr-only.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot, err := ValidateForMode(raw, ModeASROnly)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if snapshot.AgentVersionID == "" || snapshot.Digest == "" || snapshot.Mode != ModeASROnly {
|
|
t.Fatalf("snapshot = %+v", snapshot)
|
|
}
|
|
}
|
|
|
|
func TestASROnlyRejectsFullAIFields(t *testing.T) {
|
|
raw, err := contracts.Read("examples/invalid-asr-only-with-llm.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := ValidateForMode(raw, ModeASROnly); err == nil {
|
|
t.Fatal("expected ASR-only schema rejection")
|
|
}
|
|
}
|
|
|
|
func TestCacheRejectsChangedImmutableContent(t *testing.T) {
|
|
raw, err := contracts.Read("examples/agent-version.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot, err := Validate(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cache := NewCache()
|
|
if err := cache.Put("tenant-demo-key", snapshot); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
changed := snapshot
|
|
changed.Digest = "different"
|
|
if err := cache.Put("tenant-demo-key", changed); err == nil {
|
|
t.Fatal("expected immutable content rejection")
|
|
}
|
|
}
|