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>
35 lines
659 B
Go
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)
|
|
}
|
|
}
|