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>
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
{"id":"demo.write","domain":"demo","version":1,"matcher":{"includes_any":["写"]}}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user