ci / vet-and-test (pull_request) Successful in 48s
Why: Generative UI U5 left the B-class action allowlist empty; owner authorized first entries builtin.help and system.intent. Evidence: go test ./internal/genui/ ./internal/surfacesvc/ ./internal/server/ Impact: Surface buttons may bind help/intent; button-entrance intent matches only and does not nest-dispatch write commands. Refs: docs/proposals/2026-10-12-generative-ui-bclass-help-intent.md Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
agentcommand "agent-command"
|
|
"agent-system-backend/internal/cmdbus"
|
|
)
|
|
|
|
// B 类硬化红测:button 入口命中写意图时不嵌套分发(无目标命令 receipt)。
|
|
func TestSystemIntentButtonNoNestedDispatch(t *testing.T) {
|
|
var writes int
|
|
b := cmdbus.New(nopAudit{}, nil, nil)
|
|
if err := b.RegisterBuiltin(agentcommand.CommandSpec{ID: "conversation.create", Title: "新建会话"},
|
|
"/new", func(ctx context.Context, req cmdbus.Request) (any, error) {
|
|
writes++
|
|
return map[string]any{"ok": true}, nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := b.Intents().Declare(cmdbus.Intent{
|
|
ID: "demo.new", Phrases: []string{"新建会话"}, Command: "conversation.create", Plugin: "test",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
res, err := handleSystemIntent(context.Background(), b, cmdbus.Request{
|
|
ID: "system.intent", Entrance: "button", Owner: "alice",
|
|
Params: map[string]any{"text": "请新建会话"},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m, ok := res.(map[string]any)
|
|
if !ok || m["matched"] != true || m["dispatched"] != false {
|
|
t.Fatalf("button match must not dispatch: %+v", res)
|
|
}
|
|
if writes != 0 {
|
|
t.Fatalf("nested write command must not run, writes=%d", writes)
|
|
}
|
|
|
|
// chat 入口仍可嵌套分发(既有行为)
|
|
res2, err := handleSystemIntent(context.Background(), b, cmdbus.Request{
|
|
ID: "system.intent", Entrance: "chat", Owner: "alice",
|
|
Params: map[string]any{"text": "请新建会话"},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m2, _ := res2.(map[string]any)
|
|
if m2["dispatched"] != true || writes != 1 {
|
|
t.Fatalf("chat entrance should nest-dispatch: %+v writes=%d", res2, writes)
|
|
}
|
|
}
|
|
|
|
func TestSystemIntentUnmatchedCandidates(t *testing.T) {
|
|
b := cmdbus.New(nopAudit{}, nil, nil)
|
|
_ = b.Intents().Declare(cmdbus.Intent{
|
|
ID: "demo.x", Phrases: []string{"特定短语"}, Command: "builtin.help", Plugin: "test",
|
|
})
|
|
res, err := handleSystemIntent(context.Background(), b, cmdbus.Request{
|
|
Entrance: "button", Params: map[string]any{"text": "无关内容"},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
m := res.(map[string]any)
|
|
if m["matched"] != false {
|
|
t.Fatalf("want unmatched, got %+v", res)
|
|
}
|
|
cands, _ := m["candidates"].([]map[string]any)
|
|
if len(cands) != 1 {
|
|
t.Fatalf("want 1 candidate, got %+v", m["candidates"])
|
|
}
|
|
}
|