Files
Agent-Intent/schema/roundtrip_test.go
T
weichenandCursor 65aaebca1e
ci / vet-and-test (pull_request) Successful in 18s
ci / docker-checkout-hostgateway (pull_request) Successful in 0s
Publish an IntentSpec JSON sample and round-trip test
Why: the intent library has to publish the shape it owns, without sharing a Go type with the other libraries.
Evidence: GOWORK=off go test -count=1 ./schema/ ./intent/ passed.
Impact: schema/ is new. Recognition behavior is unchanged.
Refs: D1
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 13:40:26 +00:00

35 lines
659 B
Go

package schema
import (
"encoding/json"
"os"
"testing"
"agent-intent/intent"
)
func TestIntentSpecRoundTrip(t *testing.T) {
raw, err := os.ReadFile("intentspec.sample.json")
if err != nil {
t.Fatal(err)
}
var spec intent.IntentSpec
if err := json.Unmarshal(raw, &spec); err != nil {
t.Fatal(err)
}
if spec.ID != "demo.write" || spec.Matcher.IncludesAny[0] != "写" {
t.Fatalf("%+v", spec)
}
back, err := json.Marshal(spec)
if err != nil {
t.Fatal(err)
}
var again intent.IntentSpec
if err := json.Unmarshal(back, &again); err != nil {
t.Fatal(err)
}
if again.ID != spec.ID || again.Version != 1 {
t.Fatalf("%+v", again)
}
}