From 65aaebca1ea69ab7d48eda51d33ef1d4eea5a0bf Mon Sep 17 00:00:00 2001 From: weichen Date: Sat, 3 Oct 2026 13:40:26 +0000 Subject: [PATCH] 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 --- schema/intentspec.sample.json | 1 + schema/roundtrip_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 schema/intentspec.sample.json create mode 100644 schema/roundtrip_test.go diff --git a/schema/intentspec.sample.json b/schema/intentspec.sample.json new file mode 100644 index 0000000..6250d5b --- /dev/null +++ b/schema/intentspec.sample.json @@ -0,0 +1 @@ +{"id":"demo.write","domain":"demo","version":1,"matcher":{"includes_any":["写"]}} diff --git a/schema/roundtrip_test.go b/schema/roundtrip_test.go new file mode 100644 index 0000000..3bf0988 --- /dev/null +++ b/schema/roundtrip_test.go @@ -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) + } +} -- 2.54.0