Files
weichen b58595fb38 Implement the intent core
Details (original message):
Implement the intent core, conformance suite, catalog alignment, examples, and the intentctl diagnostics CLI.
2026-09-29 15:35:18 +00:00

34 lines
1.3 KiB
Go

package conformance
import (
"context"
"testing"
"testing/fstest"
"agent-intent/intent"
)
func TestRunAcceptsCompliantRecognizer(t *testing.T) {
fsys := fstest.MapFS{"specs/demo.json": &fstest.MapFile{Data: []byte(`{
"intents": [
{"id": "demo.run.status_query", "domain": "demo", "version": 1,
"matcher": {"includes_any": ["进度"]},
"slots": [{"key": "run_id", "pattern": "(?:run|任务)[:# ]*([A-Za-z0-9-]+)"}],
"handler": "taskrun.query_status"},
{"id": "demo.greet.hello", "domain": "demo", "version": 1, "matcher": {"includes_any": ["你好"]}},
{"id": "demo.greet.hi", "domain": "demo", "version": 1, "matcher": {"includes_any": ["你好"]}}
]
}`)}}
b := intent.NewRegistryBuilder(intent.Options{})
reg, err := b.BuildFS(context.Background(), fsys, "specs")
if err != nil {
t.Fatal(err)
}
rec := intent.NewRecognizer(intent.Options{}, nil, nil)
Run(t, rec, reg.Snapshot(), []Case{
{Name: "matched", Input: "查询任务 42 的进度", ExpectBranch: intent.BranchMatched, ExpectTopID: "demo.run.status_query", ExpectSlots: map[string]string{"run_id": "42"}},
{Name: "ambiguous", Input: "你好", ExpectBranch: intent.BranchAmbiguous},
{Name: "fallback", Input: "今天天气不错", ExpectBranch: intent.BranchFallback},
})
}