package server import ( "encoding/json" "os" "path/filepath" "testing" agentcommand "agent-command" "agent-system-backend/internal/cmdbus" ) type pair struct { ID string `json:"id"` Button bool `json:"button"` Chat bool `json:"chat"` } type nopAudit struct{} func (nopAudit) AppendAudit(agentcommand.AuditEnvelope) error { return nil } // 每个内置命令都必须在 command-pairs.json 里同时声明按钮入口与对话入口。 // 新命令漏登记则本测试失败,合入被挡住。 func TestBuiltinCommandsHaveDualEntryPairs(t *testing.T) { raw, err := os.ReadFile(filepath.Join("testdata", "command-pairs.json")) if err != nil { t.Fatal(err) } var pairs []pair if err := json.Unmarshal(raw, &pairs); err != nil { t.Fatal(err) } byID := map[string]pair{} for _, p := range pairs { byID[p.ID] = p } s := &Server{Bus: cmdbus.New(nopAudit{}, nil, nil)} s.WireBuiltinCommands() for _, cmd := range s.Bus.List() { p, ok := byID[cmd.Spec.ID] if !ok || !p.Button || !p.Chat { t.Errorf("command %s missing dual-entry pair (button and chat)", cmd.Spec.ID) } } }